Primitive Roots of Unity
Jelly, 11 9 bytes
Thanks to @Dennis for -2 bytes!
Rg=1O÷H-*
I wanted to generate the numbers coprime to N by folding set difference over all of the roots of unity from 1 to N, but I couldn't figure out how so I used @Dennis's method.
Rg=1O÷H-* Monadic chain: 6
R Range [1,2,3,4,5,6]
g Hook gcds with range [1,2,3,2,1,6]
=1 [gcds equal to one] [1,0,0,0,1,0]
O Replicate indices [1,5]
÷H Divide by half of N [1/3,5/3]
- Numeric literal: - by itself is -1.
* Take -1 to those powers [cis π/3,cis 5π/3]
Try it here. Valid in this version of Jelly, but may not be in versions after February 1, 2016.
Jelly, 14 bytes
Rg=1O°÷×ı360Æe
Try it online!
How it works
z = e2tπi is an nth root of 1 if and only if t = k / n for some integer k.
z is primitive if and only if k and n are coprime.
Rg=1O°÷×ı360Æe Main link. Input: n
R Yield [1, ..., n].
g Compute the GCDs of reach integer and n.
=1 Compare the GCDs with 1.
O Get all indices of 1's.
This computes all the list of all k in [1, ..., n]
such that k and n are coprime.
° Convert the integers to radians.
÷ Divide the results by n.
×ı360 Multiply the quotient by the imaginary number 360i.
Æe Map exp over the results.
Julia, 48 bytes
n->cis(360deg2rad(filter(k->gcd(k,n)<2,1:n))/n)
This is a lambda function that accepts an integer and returns an array of complex floats. To call it, assign it to a variable. It uses the same approach as Dennis' Jelly answer.
Ungolfed:
function f(n::Int)
# Get the set of all k < n : gcd(k,n) = 1
K = filter(k -> gcd(k,n) < 2, 1:n)
# Convert these to radian measures
θ = deg2rad(K)
# Multiply by 360, divide by n
θ = 360 * θ / n
# Compute e^iz for all elements z of θ
return cis(θ)
end