There is something wrong.
(, porpp) 4 p: 2^55x
36028797018963971 36028797018963968
The first number is a prime. It should be
returned as the result when given to porpp .
----- Original Message -----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
Date: Thursday, September 21, 2006 4:56 pm
Subject: RE: [Jprogramming] Explicit to Tacit - newbie question
> Roger Hui wrote:
> > j=. _4 4 p:"0 n are the integers that need to be
> > considered.
>
> That's nice! (And I had overlooked that -- thanks
> also for pointing it out.)
>
> Given this, I'd be inclined to write the function
> porpp (which returns a nearest prime or prime
> power) as:
>
> close=: ((i. <./)@:|@:- { ]),
> nearp=: _4 4&(p:"0)^:(0&p:)("0)@(2&>.)
> powrs=: >:@[EMAIL PROTECTED]@#:
> porpp=: (close 1,([EMAIL PROTECTED] [EMAIL PROTECTED]) ^&x: powrs)"0
>
>
> Result of:
>
> x close y is the atom from y that's nearest x.
>
> nearp y includes the largest prime not larger than y and
> the smallest prime not smaller than y (assuming these exist)
>
> powrs y is a list of somewhat plausible integer powers to be
> considered in this context
>
> porpp y is a prime or prime power nearest y
>
> porpp i. 5 20
> 1 1 2 3 4 5 5 7 8 9 11 11 11 13 13 16 16 17 17 19
> 19 19 23 23 23 25 25 27 29 29 29 31 32 32 32 37 37 37 37 37
> 41 41 41 43 43 43 47 47 47 49 49 53 53 53 53 53 53 59 59 59
> 59 61 61 64 64 64 67 67 67 67 71 71 71 73 73 73 73 79 79 79
> 79 81 83 83 83 83 83 89 89 89 89 89 89 89 97 97 97 97 97 97
> porpp 1+3^30x
> 205891132094649
>
> Note: this may produce incorrect results for some arguments
> around 2^106 or larger. This is because I expect to be able
> to represent the square root of the argument as a floating
> point number.
>
> And, of course, the definition of prime I'm using here for
> large numbers, is that implemented by p:
>
> When there are two primes or prime powers equally close
> to the argument, porpp returns the smaller.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm