Hostname: page-component-6766d58669-rxg44 Total loading time: 0 Render date: 2026-05-17T21:51:17.738Z Has data issue: false hasContentIssue false

Bottom-up computation using trees of sublists

Published online by Cambridge University Press:  11 December 2024

SHIN-CHENG MU*
Affiliation:
Institute of Information Science, Academia Sinica, Taipei, Taiwan (e-mail: scm@iis.sinica.edu.tw)
Rights & Permissions [Opens in a new window]

Abstract

Some top-down problem specifications, if executed, may compute sub-problems repeatedly. Instead, we may want a bottom-up algorithm that stores solutions of sub-problems in a table to be reused. How the table can be represented and efficiently maintained, however, can be tricky. We study a special case: computing a function ${\mathit{h}}$ taking lists as inputs such that ${\mathit{h}\;\mathit{xs}}$ is defined in terms of all immediate sublists of ${\mathit{xs}}$. Richard Bird studied this problem in 2008 and presented a concise but cryptic algorithm without much explanation. We give this algorithm a proper derivation and discovered a key property that allows it to work. The algorithm builds trees that have certain shapes—the sizes along the left spine is a prefix of a diagonal in Pascal’s triangle. The crucial function we derive transforms one diagonal to the next.

Information

Type
Functional Pearl
Creative Commons
Creative Common License - CCCreative Common License - BYCreative Common License - NCCreative Common License - SA
This is an Open Access article, distributed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike licence (http://creativecommons.org/licenses/by-nc-sa/4.0/), which permits non-commercial re-use, distribution, and reproduction in any medium, provided the same Creative Commons licence is used to distribute the re-used or adapted article and the original article is properly cited. The written permission of Cambridge University Press must be obtained prior to any commercial use.
Copyright
© The Author(s), 2024. Published by Cambridge University Press
Figure 0

Fig. 1. Computing ${\mathit{h}\;\mathtt{"abcd"}}$ top-down. String constants are shown using monospace font but without quotes, to save space.

Figure 1

Fig. 2. Computing ${\mathit{h}\;\mathtt{"abcde"}}$ bottom-up. The numbers on the left denote the levels.

Figure 2

Fig. 3. Results of ${\mathit{ch}}$.

Figure 3

Fig. 4. Applying $\mathit{mapB}\;\mathit{g}\; \circ \mathit{up}$ to ${\mathit{mapB}\;\mathit{h}\;(\mathit{ch}\;\mathrm{2}\;\mathtt{abcde})}. We abbreviate {\mathit{zipBW}\;\mathit{snoc}}$ to ${\mathit{zip}}$.

Figure 4

Fig. 5. Sizes of ${\mathsf{B}}$ alone the right spine correspond to prefixes of diagonals in Pascal’s Triangle.

Supplementary material: File

Mu supplementary material

Mu supplementary material
Download Mu supplementary material(File)
File 170.5 KB
Submit a response

Discussions

No Discussions have been published for this article.