# [`⍭`](https://bpl.fast.ai//glyphs/stile-tilde.html) — Prime / Prime mode

Function. Keys: `Alt-Backslash`. Hanzi: `素`. Ranks: `0` monadic, `0 0` dyadic

`⍭N`: the prime with `N` primes before it. `⍭0` is 2. Whole inputs. Results are in the argument's domain: `ᵣ` arguments give `ᵣ` results, and a machine-integer result past 64 bits is the largest 64-bit integer. An `N` past the machine range is treated as the largest machine integer. The primality test `1⍭` gives Booleans.

`⍭⁻N`: the number of primes below `N`, which is the index of a prime `N`.

```bpl
⍭ι8ₓ               ⍝ [2 3 5 7 11 13 17 19]ₓ
⍭⁻⍭ι4ₓ            ⍝ [0 1 2 3]ₓ
⍭⁻1 2 3 4 5 6     ⍝ [0 0 1 2 2 3]ₓ
```

`K⍭N` selects an operation by the code `K`. The operations are like J's `p:`, with different codes. [Factor](circle-divide.md) gives factors and factor tables.

| K | Result |
|--- |--- |
| `¯2` | Previous prime, strictly below N |
| `1` | N is prime |
| `2` | Next prime, strictly above N |
| `3` | Euler's totient |

```bpl
1⍭¯1 0 1 2 3 4     ⍝ $f $f $f $t $t $f
2⍭1 2 3 4 5        ⍝ [2 3 5 5 7]ₓ
¯2⍭3 4 5 6         ⍝ [2 3 3 5]ₓ
3⍭1 2 3 4 5 6      ⍝ [1 1 2 2 4 2]ₓ
```

Euler's totient of `N` is `N` times the product of `1-÷p` over the distinct prime factors `p` of `N`. For one whole `N`, `3⍭N` gives the same result as `N××/1ᵣ-÷∪⨸N` in the `ᵣ` domain. With machine integers, each `÷p` would be floored to 0.

```bpl
N←700ᵣ ◇ N××/1ᵣ-÷∪⨸N     ⍝ 240ᵣ
3⍭700ᵣ                   ⍝ 240ᵣ
```

[`⍭`](https://bpl.fast.ai//glyphs/stile-tilde.html) applies to each unit. Primality uses the Baillie–PSW test, which is exact below `2⁶⁴` and a probable-prime test for larger inputs. A passing result above that range is not a proof of primality.

## Errors

- `DOMAIN`: invalid selector/input; previous prime at/below 2
