Let $f,g:\Sigma^*\rightarrow\Sigma^*$. $f$ is computable in polynomial space. $g$ is computable in logarithmic space.
Show that $f \circ g$ and $g \circ f$ are computable in polynomial space. Would it be true, if both $f$ and $g$ were computable in polynomial space?
-- This is a problem from an old exam. I don't really get why is this question nontrivial. After all, if both of these functions compute their output in polynomially bounded space, for every word from $\Sigma^*$, then why does it matter if $g$ takes output of $f$ as its input?