⍭ — Prime
Keys: Alt-Backslash. Ranks: 0 monadic, 0 0 dyadic
⍭N: the prime with N primes before it. ⍭0 is 2. Integral inputs; exact integer results, except that the primality test 1⍭ gives Booleans.
⍭⁻¹N: the number of primes below N, which is the index of a prime N.
⍭⍳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 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 |
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 exact N, 3⍭N gives the same result as N××/1ₓ-÷∪⨸N. The ₓ on 1 keeps the result exact.
N←700ₓ ⋄ N××/1ₓ-÷∪⨸N ⍝ 240ₓ
3⍭700 ⍝ 240ₓUnit cells; results assemble with fill. Primality testing is deterministic through 64 bits, probabilistic above that (false-positive bound 2⁻⁶⁴).
Errors
DOMAIN: invalid selector/input; previous prime at/below 2