# Help manipulating Wilson's Theorem. [duplicate]

Possible Duplicate:
Closed form for $(p-n)!\pmod{p}$ where $p$ is prime

I would like to use Wilson's Theorem to compute

$(p - 4)! \mod p$

I've gotten as far as

$(p - 4)! \cdot (p-3) \cdot (p-2) \cdot (p-1) \equiv (p - 1) \pmod p$

However I can't figure out how to isolate

$(p - 4)! \mod p$

-

## marked as duplicate by lhf, Marvis, Qiaochu YuanMay 3 '12 at 20:52

@lhf But that doesn't give the nice closed form possible here. –  Bill Dubuque May 3 '12 at 20:37
@Bill, my answer does. –  lhf May 3 '12 at 20:48
@lhf But that's not as nice as what's below. It has $\rm\:(p\mp 1)(p-1)/6\:$ vs. $\rm\:(1\mp p)/6\:$ below. –  Bill Dubuque May 3 '12 at 21:06
I think it's dumb to close specific questions because the more general question has already been treated. I think perhaps that's what Bill is saying above as well. –  Graphth May 3 '12 at 21:11
@Graphth Generally I think it's good to close special-case dupes. My point was simply that the answer there can be simplified. I didn't recall the prior question when I composed my reply. At least we got something good from it (a simpler result). –  Bill Dubuque May 3 '12 at 21:14

Hint $\rm\ mod\ p\!:\: -1 \equiv (p-1)! = (p-1)(p-2)(p-3)(p-4)! \equiv (-1)(-2)(-3)(p-4)!$

But for $\rm\:p \ne 2,3,\: \ \ 2\cdot 3 = 6\:$ will be invertible mod $\rm\:p,\:$ so $\rm\:(p-4)! \equiv 1/6\pmod p$

Furthermore: $\rm\ \ p = 6\:k\pm 1\:\Rightarrow\:(p-4)! \equiv 1/6 \equiv (1\mp p)/6$

Note $\:$ The signed-equation denotes two equations: the top sign case, and bottom sign case. $$\begin{eqnarray}\rm\:p = 6\:\!k{\color{red}{+1}}\: &\Rightarrow& \rm\:(p-4)!\equiv 1/6\equiv (1+{\color{red}{(-1)}} p)/6&\rm\quad top\ signs \\ \rm\:p = 6\:\!k{\color{red}{-1}}\: &\Rightarrow &\rm\:(p-4)!\equiv 1/6\equiv (1+{\color{red}{(+1)}} p)/6&\rm\quad bottom\ signs \end{eqnarray}$$ Indeed, we seek $\rm\:x\:$ so $\rm\:6\:|\:1+x\:\!p,\:$ or $\rm\:mod\ 6\!:\: -1\equiv x\:\!p \equiv x\!\:s,\:$ where $\rm\:\color{red}s = (p\ mod\ 6).\:$ Therefore $\rm\:x \equiv -1/s.\:$ Here $\rm\:s\equiv \pm1\:\Rightarrow\:s^2 = 1\:\Rightarrow\: -1/s = -s/s^2 = -s.\:$ Therefore $$\rm\:p = 6\:\!k+{\color{red}{s}}\: \Rightarrow\: (p-4)!\equiv 1/6\equiv (1+{\color{red}{(-s)}}\:\! p)/6\quad abstract\ sign$$ Hence the equation that I wrote above involving the signs $\pm$ and $\mp,$ denotes two equations, the case $\rm\:s = 1\:$ of above (choose all the top signs) and case $\rm\:s = -1\:$ (choose all the bottom signs). Indeed, if we substitute $\rm\: s = \pm 1\:$ then $\rm -s = \mp 1,\:$ so we obtain said equation with signs.

Such expressions can be given a rigorous algebraic interpretation by working in certain quotient rings,$\:\!$ i.e. modulo $\rm\:s^2 = 1.\:$ Namely $\rm\:R[s]/(s^2-1) \cong R[s]/(s-1) + R[s]/(s+1)\cong R^2.\:$ Hence arithmetic in $\rm\:R\:$ with adjoined sign $\rm\:s\:$ is isomorphic to arithmetic of pairs of elements of $\rm\:R,\:$ where the first component denotes the universe where $\rm\:s = 1\:$ and the second where $\rm\:s = -1.\:$

Beware, however, that sometimes such signed expressions denote the set of equations resulting from all possible combinations of signs. In this case one adjoins multiple sign indeterminates $\rm\:s_i\:$ such that $\rm\:s_i^2 = 1.\:$ One often needs to infer from the context which denotation is intended.

-
What's the difference between using $\pm$ and $\mp$ –  John May 4 '12 at 11:35
@johnthexiii I've added a detailed explanation. –  Bill Dubuque May 4 '12 at 16:55
that was very thorough –  John May 4 '12 at 19:24

You can use the facts that $p-k \equiv -k \mod p$. Then you have to decide whether the product is invertible.

-