logdiffexp function