I assume the main motivation for the feature is ^:(<_)
----- Original Message ----- From: Bo Jacoby <bojac...@yahoo.dk> To: "programm...@jsoftware.com" <programm...@jsoftware.com> Cc: Sent: Wednesday, March 5, 2014 4:43:14 PM Subject: Re: [Jprogramming] Simple Number Theory Interesting, Dan, but why define ^:(<20) meaning ^:(i.<20) ? (-:&(+ (2&| * >:&+:)))^:(<20)11 11 17 26 13 20 10 5 8 4 2 1 2 1 2 1 2 1 2 1 2 (-:&(+ (2&| * >:&+:)))^:(i.20)11 11 17 26 13 20 10 5 8 4 2 1 2 1 2 1 2 1 2 1 2 - Bo Den 16:35 onsdag den 5. marts 2014 skrev Raul Miller <rauldmil...@gmail.com>: And with ^:(-i.|integer) where 0 >: integer > >Of course, if you want more control you'll need to be more explicit: > > >:^:(i:4) 5 6 7 >1 2 3 >2 3 4 >3 4 5 >4 5 6 >5 6 7 >6 7 8 >7 8 9 >8 9 10 >9 10 11 > >Also, >:^:(n) y is n+/y with n constrained to integers. > >Thanks, > >-- >Raul > > >On Wed, Mar 5, 2014 at 10:10 AM, Dan Bron <j...@bron.us> wrote: > >> FYI, ^:(<integer) is a synonym for ^:(i.integer) where 0 < integer < _ . >> >> -Dan >> >> >> >> ----- Original Message --------------- >> >> Subject: Re: [Jprogramming] Simple Number Theory >> From: "Linda Alvord" <lindaalv...@verizon.net> >> Date: Tue, 04 Mar 2014 21:46:16 -0500 >> To: <programm...@jsoftware.com> >> >> |. f ^:(i.80)2324 >> 2 1 2 4 8 5 10 20 40 80 53 35 23 46 92 61 122 244 488 325.... >> >> Linda >> >> >> -----Original Message----- >> From: programming-boun...@forums.jsoftware.com >> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Linda >> Alvord >> Sent: Tuesday, March 04, 2014 8:59 PM >> To: programm...@jsoftware.com >> Subject: Re: [Jprogramming] Simple Number Theory >> >> >> Also: >> >> collatz=:-:&(+2&|*>:&+:) >> collatz ^:(i.10)17 >> 17 26 13 20 10 5 8 4 2 1 >> >> f=: 13 :'-: y+(2|y)*>:+:y' >> f ^:(i.10)17 >> 17 26 13 20 10 5 8 4 2 1 >> >> collatz >> -:&(+ (2&| * >:&+:)) >> f >> [: -: ] + (2 | ]) * [: >: +: >> >> Linda >> >> >> -----Original Message----- >> From: programming-boun...@forums.jsoftware.com >> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Devon >> McCormick >> Sent: Tuesday, March 04, 2014 12:56 PM >> To: J-programming forum >> Subject: Re: [Jprogramming] Simple Number Theory >> >> "Power" is a very useful conjunction. Here's some simple examples of using >> it: >> >> >:10 NB. Start with the increment-by-one verb ">:" >> 11 >> >:^:99]10 NB. Now apply it 99 times to the argument "10" by using ^: >> 109 >> >:^:(99) 10 NB. Another way to distinguish the "power" arg from the arg >> to which it's applied. >> 109 >> >> >:^:(i.10) 10 NB. Vector arg to power shows intermediate results. >> 10 11 12 13 14 15 16 17 18 19 >> >> >:^:(25>]) 10 NB. Use verb (25>]) to control power... >> 11 >> >:^:(25>])^:_ ] 10 NB. Use with verb (25>]) "infinite" number of times >> 25 >> >> "Infinite" power keeps applying the verb until it converges (stops >> changing). >> >> So, J gives you infinite power. >> >> On Tue, Mar 4, 2014 at 10:25 AM, Raul Miller <rauldmil...@gmail.com> >> wrote: >> >> > It might be worthwhile taking a look at the different display forms of >> the >> > veb collatz. For example, consider the atomicrepresentation: >> > >> > 5!:1<'collatz' >> > +------------------------------------------------+ >> > ¦+----------------------------------------------+¦ >> > ¦¦"¦+------------------------------------------+¦¦ >> > ¦¦ ¦¦+----------------------------------+¦+---+¦¦¦ >> > ¦¦ ¦¦¦@.¦+-----------------------------+¦¦¦0¦0¦¦¦¦ >> > ¦¦ ¦¦¦ ¦¦+-------------+¦+-----------+¦¦¦+---+¦¦¦ >> > ¦¦ ¦¦¦ ¦¦¦0¦+---------+¦¦¦&¦+-------+¦¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦¦¦ ¦¦cole¦colo¦¦¦¦ ¦¦+---+¦|¦¦¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦¦¦ ¦+---------+¦¦¦ ¦¦¦0¦2¦¦ ¦¦¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦¦+-------------+¦¦ ¦¦+---+¦ ¦¦¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦¦ ¦¦ ¦+-------+¦¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦¦ ¦+-----------+¦¦¦ ¦¦¦ >> > ¦¦ ¦¦¦ ¦+-----------------------------+¦¦ ¦¦¦ >> > ¦¦ ¦¦+----------------------------------+¦ ¦¦¦ >> > ¦¦ ¦+------------------------------------------+¦¦ >> > ¦+----------------------------------------------+¦ >> > +------------------------------------------------+ >> > >> > >> > Working inwards from the outside, we see that the top level control is >> the >> > rank adverb. Its arguments are represented as a gerund and the noun 0 >> (the >> > first '0' says that this is a noun, the second is the value of the noun). >> > >> > The top level control in the gerund is the @. conjunction. And >> > http://www.jsoftware.com/help/dictionary/d621.htm says that the rank of >> @. >> > is determined by the rank of its right verb, which leads to your >> question. >> > But what is that right verb? >> > >> > According to the diagram, above, the right verb for @. has & as its top >> > level control. And according to >> > http://www.jsoftware.com/help/dictionary/d630n.htm the monadic rank of >> 2&| >> > is infinite. >> > >> > (Hopefully you do not consider this approach to be too tedious - or, if >> so, >> > hopefully you skipped down to the end and then read the last couple >> > paragraphs.) >> > >> > Thanks, >> > >> > -- >> > Raul >> > >> > >> > >> > On Tue, Mar 4, 2014 at 10:07 AM, Jon Hough <jgho...@outlook.com> wrote: >> > >> > > Thanks for all the replies.OK, I'm starting to understand more now. I >> did >> > > not know about agenda (@.). Well actually, I read about it in the >> > > jsoftware.com dictionary, but I think J is one of those things you >> have >> > > to see in action before it clicks. >> > > What I've gone with: >> > > cole =. 2&(%~) NB. even case >> > > colo =. (1&+)@(3&*) >> > > collatz =.cole`colo@.(2&|)"0 NB. Rank 0 lets us work on each element >> > of >> > > a list >> > > >> > > So my next question is how do I go about iterating this until we reach >> 1? >> > > Incidentally, it seems to me that | is rank 0 (right rank) >> > > http://www.jsoftware.com/help/dictionary/d230.htm Therefore I am >> puzzled >> > > why the verb collatz does not act on each rank 0 element of the noun. >> Why >> > > did I have to explicitly force its right rank to be 0? >> > > Regarding iterations,Bo Jacoby kindly mentioned: >> > > collatz=:-:&(+2&|*>:&+:) collatz ^:(i.10)17 >> > > 17 26 13 20 10 5 8 4 2 1 >> > > But I'm struggling to understand this verb. Any help explaining this >> > would >> > > be appreciated. Or help making my own collatz verb into an iterative >> > > function (verb). >> > > Regards,Jon >> > > > Date: Mon, 3 Mar 2014 18:59:04 -0800 >> > > > From: d...@shaw.ca >> > > > To: programm...@jsoftware.com >> > > > Subject: Re: [Jprogramming] Simple Number Theory >> > > > >> > > > This might be more readable - I had some bold faced characters so got >> > > > the extra dusting of * >> > > > >> > > > Don >> > > > >> > > > collatz=:(1 0=2|])#(3*1+]),2%~] >> > > > >> > > > collatz 4 >> > > > >> > > > 2 >> > > > >> > > > collatz 5 >> > > > >> > > > 18 >> > > > >> > > > collatz _4 >> > > > >> > > > _2 >> > > > >> > > > collatz _5 >> > > > >> > > > _12 >> > > > >> > > > >> > > > Test for odd/even is 2|nreturning 1 for odd and 0 for even 1 0=2|n >> > will >> > > > return 1 0 for odd and 0 1 for even >> > > > The (3*1+n) and n%2 terms are a two element result vector >> > > > >> > > > if odd, 1 0 # returns the odd result and if even 0 1 #returns the >> even >> > > > result. >> > > > >> > > > In this case I started with the basic (3*n+1),n%2vector and then >> used >> > > > 1 0= 2|n times this(residue is 1 for odd and 0 for even numbers) >> > > > the result is(1 0=2|y) # (3*1+y),y%2which works >> > > > I wrote this as an explicit verb s=: 13 : '(1 0=2|y)#(3*1+y),y%2' >> > > > and typed sto get a tacit form (1 0 = 2 | ]) # (3 * 1 + ]) , 2 %~ ] >> > > > generated by J >> > > > >> > > > attached collatz=:to the front and that was it. >> > > > >> > > > note that the y is replaced by ] and the y%2 is expressed using 2%~] >> J >> > > > wants the ] on the right of this operation and ~does this >> > > > There are other variations on this but this is the simplest I came up >> > > with. >> > > > >> > > > I classify myself as a beginner but I have an APL background and long >> > > > ago found C and relatives awkward I do think it is harder to come >> from >> > > > C/C++/Java to J than from APL to J - the thinking is different To me >> > > > C++ is oriented towards detailed instructions for the compiler (much >> of >> > > > this is done by the interpreter in J or APL) The problem comes >> first >> > > > in J and more times than not - use of arrays can eliminate a lot of >> > if's >> > > > and loops. >> > > > >> > > > >> > > > Don Kelly >> > > > >> > > > >> > > > On 03/03/2014 8:30 AM, Jon Hough wrote: >> > > > > Beginner question again.I quick task I set myself was to write ONE >> > > ITERATION of the Collatz function for a given positive integer. >> > > http://en.wikipedia.org/wiki/Collatz_conjecture >> > > > > >> > > > > So my verb is supposed to do 3*n+1 if n is odd and n/2 if n is >> > even.In >> > > a more imperative/OOE based language (C/C++/Java) I could write this in >> > > less than a minute. Unfortunately, I fell at the very first hurdle in >> J. >> > > > > I originally wrote my tacit verb for even ints:collatz_even >> =.2&(%~) >> > > > > collatz_even 4 >> > > > > 2 >> > > > > This works, but I had a terrible time trying to put the brackets in >> > > the right place. I am not sure why %~ needs to be bracketed. Won't J >> > parse >> > > %~ as dyadic and "know" that the left operand is 2? >> > > > > Next I tried to do the case for odd n: >> > > > > collatz_odd =. 1&+@(3&*) collatz_odd 3 >> > > > > 10 >> > > > > That seems to work ok.Now I am not sure how to do an if statement >> in >> > > J. In plain English I want "If n is even do collatz_even else do >> > > collatz_odd".The verb I wrote to test for even-ness is >> > > > > ones =. {:@#: NB. Finds the ones column values. 1 => odd, 0=> even >> > > > > 1 = ones 2 >> > > > > 0 >> > > > > So I have a test but I am not sure how to utilize this test. How >> > > should I go about doing:"If n is even do collatz_even else do >> > collatz_odd"? >> > > > > Thanks and regards,Jon >> > > > > >> > > > > >> > ---------------------------------------------------------------------- >> > > > > For information about J forums seehttp:// >> > www.jsoftware.com/forums.htm >> > > > > >> > > > >> > > > >> ---------------------------------------------------------------------- >> > > > For information about J forums see >> http://www.jsoftware.com/forums.htm >> > > >> > > ---------------------------------------------------------------------- >> > > For information about J forums see http://www.jsoftware.com/forums.htm >> > > >> > ---------------------------------------------------------------------- >> > For information about J forums see http://www.jsoftware.com/forums.htm >> > >> >> >> >> -- >> Devon McCormick, CFA > >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm