Theory of a free electron laser