Metallurgical manufacturing processes commonly used in the industry (rolling, extrusion, shaping, machining, etc.) usually cause residual stress development which can remain after thermal heat treatments. These stresses can be detrimental for the in-service performance of structural components, which makes their study and understanding important. Residual stress variations are usually determined at a macroscopic scale (commonly, using diffraction methods). However, stress variations at the microscopic scale of the individual crystallites (grains), are also relevant. Contrary to the macroscopic residual stresses, microscopic residual stresses are difficult to quantify using conventional procedures. We propose to use machine learning to find equations that describe microscopic residual stresses. Concretely, we show that we are able to learn equations to reproduce the diffraction profiles from microstructural characteristics using genetic programming. We evaluate the learned equations using real neutron diffraction peaks as a reference, obtaining accurate results for the most frequent grain orientations with runtimes of a few minutes.