Why m11A=:0=4 | ]
doesn't calculate leap years correctly: In the Gregorian calendar, a normal year consists of 365 days. Because the actual length of a sidereal year (the time required for the Earth to revolve once about the Sun) is actually 365.25635 days, a "leap year" of 366 days is used once every four years to eliminate the error caused by three normal (but short) years. Any year that is evenly divisible by 4 is a leap year: for example, 1988, 1992, and 1996 are leap years. However, there is still a small error that must be accounted for. To eliminate this error, the Gregorian calendar stipulates that a year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400. For this reason, the following years are not leap years: 1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600 This is because they are evenly divisible by 100 but not by 400. The following years are leap years: 1600, 2000, 2400 This is because they are evenly divisible by both 100 and 400. Skip On Thu, May 30, 2013 at 10:13 AM, Linda Alvord <[email protected]>wrote: > Also: > > m11A=:0=4 | ] > m11A 2013 > 0 > m11A 2536 > 1 > > Linda > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Raul Miller > Sent: Thursday, May 30, 2013 8:36 AM > To: Programming forum > Subject: Re: [Jprogramming] Dot conjunction in the leap year verb > > I imagine you are talking about the definition of m11 at > http://www.jsoftware.com/help/phrases/date_time.htm > > In other words: 0: ~:/ .= 4 100 400"_ |/ ] > > For example: > (0: ~:/ .= 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004 > 0 1 0 0 0 1 > > 1900 is not a leap hear, but 2000 is. > > First off, I should perhaps note that this is old - nowadays we would leave > off the "_ from 4 100 400 because it is implied. But that's ok, either way > works: > (0: ~:/ .= 4 100 400 |/ ]) 1900 2000 2001 2002 2003 2004 > 0 1 0 0 0 1 > > Anyways, as I am sure you have already determined, the first step is to > find > remainders: > > (4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004 > 0 0 1 2 3 0 > 0 0 1 2 3 4 > 300 0 1 2 3 4 > > Also, from a reference manual point of view, here's the definition of > "dot": http://www.jsoftware.com/help/dictionary/d300.htm > > In other words ~:/ .= is like matrix inner product, with addition being > replaced by "not equals" (or "exclusive or") and with multiplication being > replaced by = > > Or, put diferently, ~:/ .= is ~:/@(v"1 _) > > In this case: > (0 (="1 _) 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004 > 1 1 0 0 0 1 > 1 1 0 0 0 0 > 0 1 0 0 0 0 > > (0 ~:/@(="1 _) 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004 > 0 1 0 0 0 1 > > In other words, if the year is divisible evenly by an odd number of > integers > from the list 4 100 400 it's a leap year, but if it's divisible evenly by > an > even number of those integers it's not a leap year. > > This corresponds to a nested if structure like this (pseudocode): > > if (year evenly divisible by 4) then > if (year evenly divisible by 100) then > if (year evenly divisible by 400) then > leap year > else > not a leap year > else > leap year > else > not a leap year > > (And, of course, modern cpu instruction piplelines struggle with > conditional > statements, so there are some real advantages to avoiding "if statements". > See, for example: > > http://software.intel.com/en-us/articles/branch-and-loop-reorganization-to-p > revent-mispredicts > but, also, mathematical equivalences are a powerful tool of thought.) > > Thanks, > > -- > Raul > > On Thu, May 30, 2013 at 12:23 AM, <[email protected]> wrote: > > Can anyone show me how's the leap year verb work? I am confused on the > use > of dot. <br/><br/>m11=: 0: ~:/ .= 4 100 400"_ |/ ] NB. Is y a leap > year?<br/>Why does it use ~:/ .= here? Is it the same as ~:/@:= ? > <br/><br/><br/><br/> > > ---------------------------------------------------------------------- > > 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 > -- Skip Cave Cave Consulting LLC Phone: 214-460-4861 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
