In spite of remarkable progress in machine learning techniques, the state-of-the-art machine learning algorithms often keep machines from real-time learning (online learning) due in part to computational complexity in parameter optimization. As an alternative, a learning algorithm to train a memory in real time is proposed, which is named as the Markov chain Hebbian learning algorithm. The algorithm pursues efficient memory use during training in that (i) the weight matrix has ternary elements (-1, 0, 1) and (ii) each update follows a Markov chainthe upcoming update does not need past weight memory. The algorithm was verified by two proof-of-concept tasks (handwritten digit recognition and multiplication table memorization) in which numbers were taken as symbols.Particularly, the latter bases multiplication arithmetic on memory, which may be analogous to humans' mental arithmetic. The memory-based multiplication arithmetic feasibly offers the basis of factorization, supporting novel insight into the arithmetic.Recent progress in machine learning (particularly, deep learning) endows artificial intelligence with high precision recognition and problem-solving capabilities beyond the human level. 1,2,3 Computers on the von Neumann architecture are the platform for the breakthroughs albeit frequently powered by hardware accelerators, e.g. graphics processing unit (GPU). 4 The main memory, in this case, is used to store fragmentary information, e.g. weight matrix, representation of hidden neurons, and input datasets, intertwined among the fragments. Therefore, it is conceivable that memory organization is essential to efficient memory retrieval. To this end, memory keeping a weight matrix in place can be considered, in which the matrix matches different representations selectively as a consequence of learning. For instance, a visual input (representation) such as a hand-written '1' recalls a symbolic memory '1' (internal representation) through the stored weight matrix so that the symbolic memory can readily be recalled. In this regard, a high-density crossbar array (CBA) of twoterminal memory elements, e.g. oxide-based resistive memory and phase-change memory, is perhaps a promising solution to machine learning acceleration. 5,6,7,8,9 The connection weight between a pair of neurons is stored in each memory element in the CBA as conductance, and the weight is read out in place by monitoring current in response to a voltage. 5,6,7,8,9 Albeit promising, this approach should address the following challenges; each weight should be pre-calculated beforehand using a conventional error-correcting technique, and the pre-calculated value state needs to be accommodated by a single memory element. The former particularly hinders online learning.In this study, an easy-to-implement algorithm based on a stochastic neural network-termed as the Markov chain Hebbian learning (MCHL) algorithm is proposed. The most notable difference between the MCHL and restricted Boltzmann machine (RBM) 10,11,12,13 is that the MCHL is a discriminative...