On Sun, Mar 1, 2009 at 5:08 PM,  <[email protected]> wrote:
> The Wilson formula states that:
> iff p > 1 and p is prime then:
>
> !(p-1) &#8801; _1 (mod p)
>
> I used the following to determine if 13 was prime.
>    !(13-1) =&(13&|) _1
> 1

Your program does not say what you meant for it to say.

Given your decision to put the number in the formula, let's handle
that by using a name, like this:

   p=: 13

With p independently defined, one way the formula can be expressed is this:

   =/ p | _1 , ! p-1
1

Adding parentheses to emphasize the order of evaluation, here is the
same program:

   =/ (p | (_1 , (! p-1)))
1

The other programs I posted earlier work too, but would involve
receiving the number to test as a parameter.

To note one of the problems with your code, the factorial is applied
to the entirety of the computation to its right, not just to (p-1).

Tracy
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to