Title: A mathematical theory for optimising parallel code