working in logarithmic space