Somewhat offtopic, but is there a generalization of the logsumexp shortcut to more than 2 variables? IIRC, it's this for 2 variables: log (exp (a) + exp (b)) = max (a,b) + log (1 + exp (-abs (a-b)))