\section{Introduction} A hidden Markov source emits symbols while its internal state stays hidden. Suppose an observer has watched the symbols up to now and must then continue the sequence: it must generate a future with the correct conditional distribution, given what it has seen. With unlimited memory this is easy. The observer keeps the conditional distribution of the hidden state, updates it after every symbol, and at the end samples a hidden state from it and runs the source. This distribution, the \emph{posterior}, usually takes infinitely many values, so a finite memory cannot keep it exactly. How much memory is needed to generate the future within a given error, and does a quantum memory need less? We study memories that read one symbol at a time. A classical memory has $D$ states and makes a random transition that depends on the symbol. A quantum memory is a register of dimension $D$ and undergoes a quantum channel that depends on the symbol. When reading stops, the device generates the future from the same memory. Its error is the Kullback--Leibler divergence from the true conditional law of the entire future to the law of the generated future, averaged over the observed pasts. The generated law is taken after averaging over the device's own randomness: the device is judged by what it produces, not by each of its internal states separately. \subsection{The main idea} The law that a device generates is a linear function of its average memory state given the past. This average state is a probability vector with $D$ entries or a $D\times D$ density matrix, and reading a symbol changes it by a linear map. A device therefore carries \[ r_D=D\quad\text{(classical)}\qquad\text{or}\qquad r_D=D^2 \quad\text{(quantum)} \] linear coordinates, updates them linearly, and reads its forecasts off linearly. Normalization removes one independent coordinate, but the linear factorization can still have rank $r_D$. The source updates its posterior by a different kind of rule, a ratio of linear functions. The memory question thus becomes a question of approximation: how well can this nonlinear recursion be imitated by a linear recursion in $r_D$ variables? Both our upper and lower bounds answer this question, and the type of memory enters only through $r_D$. That a quantum system of dimension $D$ offers a $D^2$-dimensional linear representation is well known \cite{MonrasWinter,FanizzaLumbrerasWinter,WolfPerezGarcia}; the work here is to obtain valid updates, normalized conditional laws and matching bounds for the divergence. \subsection{Results} Throughout, every symbol matrix of the source is strictly positive. Let $n$ be the number of hidden states and $\rho_S\le n$ the rank of the matrix of word probabilities; rank one means iid output. \emph{An upper bound for every source.} Theorem~\ref{thm:universal-upper} constructs, for every source with $\rho_S\ge2$ and every $D\ge n$, a device with \[ \text{error}\ \le\ C e^{-c\,r_D^{1/m}},\qquad m=\rho_S-1 . \] The device stores the monomials of degree at most $K$ in $m$ coordinates of the posterior. There are about $K^m$ of them, and their update is linear up to an error of size $e^{-cK}$. \emph{A lower bound from test points.} Theorem~\ref{thm:nodes} applies when the symbol matrices are also invertible and $\rho_S=n$. Choose $M$ hidden-state distributions $p_i$ that long pasts can produce, and $M$ columns $h_j$ of likelihoods that long continuations can produce. Form the $M\times M$ matrix of reciprocals $1/\langle p_i,h_j\rangle$. If its least singular value is $s$, every device with $r_D