More testing seems to hold up.

    YEAR=:1900 2000 2012 2013 2014 2015 2016
   ly=:] #~ 1 3 e.~ [: (+/"2) 0 = 4 100 400 |/ ]
   ly YEAR
2000 2012 2016
   
   ly
] #~ 1 3 e.~ [: (+/"2) 0 = 4 100 400 |/ ]
   

Linda

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Roger Hui
Sent: Friday, May 31, 2013 10:15 AM
To: Programming forum
Subject: Re: [Jprogramming] Dot conjunction in the leap year verb

Trying it on 1900+i.500 would be a better test.


On Fri, May 31, 2013 at 3:22 AM, Linda Alvord <[email protected]>wrote:

> OOPS,  Not done yet.  Linda
>
> -----Original Message-----
> From: [email protected] [mailto:
> [email protected]] On Behalf Of Linda Alvord
> Sent: Friday, May 31, 2013 4:46 AM
> To: [email protected]
> Subject: Re: [Jprogramming] Dot conjunction in the leap year verb
>
>    YEAR=:1900 2000 2001 2002 2003 2004
>    ly=: 13 :'((400|/ y) e. 0 4)#y'
>    ly YEAR
> 2000 2004
>    ly
> ] #~ 0 4 e.~ 400 |/ ]
>
> Is this OK for leap year?
>
> Linda
>
> -----Original Message-----
> From: [email protected] [mailto:
> [email protected]] On Behalf Of Roger Hui
> Sent: Thursday, May 30, 2013 11:55 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Dot conjunction in the leap year verb
>
> That phrase is "mine" and embodies some history.  When I started in 
> APL decades ago I found it amusing to find novel inner products, and 
> the one used to find leap years is ≠.= in APL, not-equal dot equal. 
> The phrase found its way into the J phrase book by translation from 
> APL.  There was no @ or @: in APL.
>
> Since u . v is defined in terms of @, there is not (and can not) be 
> much of an advantage of . over @ .  I suppose @ is more open ended and using .
> provides more of a hint to the system what you intend to compute.
>
>
>
>
> On Thu, May 30, 2013 at 8:39 PM, elton wang <[email protected]> wrote:
>
> > Thanks.
> > Is the any advantage of  ~:/ .= over ~:/ @:= here in m11?
> >
> >
> >
> > ________________________________
> >  From: Raul Miller <[email protected]>
> > To: Programming forum <[email protected]>
> > Sent: Thursday, May 30, 2013 8:35 AM
> > 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-reorganizat
> > io n-to-prevent-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
> >
> ----------------------------------------------------------------------
> 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

Reply via email to