⍭ — 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 take the argument’s domain: ᵣ arguments give ᵣ results, and a machine-integer result past 64 bits gives the largest 64-bit integer. An N past the machine range counts as the largest one. 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 whole N, 3⍭N gives the same result as N××/1ᵣ-÷∪⨸N in the ᵣ domain. Machine integers would floor each ÷p to 0.
N←700ᵣ ⋄ N××/1ᵣ-÷∪⨸N ⍝ 240ᵣ
3⍭700ᵣ ⍝ 240ᵣUnit cells; results assemble with fill. 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