High statistics measurement of the positron fraction in primary cosmic rays of 0.5-500 GeV with the alpha magnetic spectrometer on the international space station