## Bridging the Algorithm Gap: A Linear-time Functional Program for Paragraph Formatting (1999)

### Cached

### Download Links

- [wwwcms.brookes.ac.uk]
- [web.comlab.ox.ac.uk]
- [www.comlab.ox.ac.uk]
- DBLP

### Other Repositories/Bibliography

Venue: | Science of Computer Programming |

Citations: | 3 - 0 self |

### BibTeX

@TECHREPORT{Moor99bridgingthe,

author = {Oege De Moor and Jeremy Gibbons},

title = {Bridging the Algorithm Gap: A Linear-time Functional Program for Paragraph Formatting},

institution = {Science of Computer Programming},

year = {1999}

}

### OpenURL

### Abstract

In the constructive programming community it is commonplace to see formal developments of textbook algorithms. In the algorithm design community, on the other hand, it may be well known that the textbook solution to a problem is not the most eÆcient possible. However, in presenting the more eÆcient solution, the algorithm designer will usually omit some of the implementation details, thus creating an algorithm gap between the abstract algorithm and its concrete implementation. This is in contrast to the formal development, which usually proceeds all the way to the complete concrete implementation of the less eÆcient solution. We claim that the algorithm designer is forced to omit some of the details by the relative expressive poverty of the Pascal-like languages typically used to present the solution. The greater expressiveness provided by a functional language would allow the whole story to be told in a reasonable amount of space. In this paper we use a functional language to present ...

### Citations

1347 | Imperative functional programming
- Jones, Wadler
- 1993
(Show Context)
Citation Context ...re not visually pleasing). We shall make use of the functions parse :: String -? [Paragraph] unparse :: [Paragraph] -? String which are well-known text-processing primitives in functional programming =-=[5]-=-. Their definitions are included in an appendix to this paper. Using these primitives, our implementation of fmt takes a single line: ?fmt = unparse . map (par3 . concat) . parse Joe Programmer may no... |

502 |
Programming from Specifications
- Morgan
- 1994
(Show Context)
Citation Context ...unities. 1 Introduction The paragraph formatting problem [12] is a favourite example for demonstrating the effectiveness of formal methods, and two particularly convincing derivations can be found in =-=[1, 13]-=-. The algorithms derived in these references are applications of dynamic programming, and their time complexity is O(min(wn; n 2 )), where w is the maximum number of words on a line, and n is the numb... |

241 | Kids: A semiautomatic program development system
- Smith
- 1990
(Show Context)
Citation Context ...delightful elegance that characterises the functional expression of the standard algorithm. Meta-programming features in the spirit of Paige's invariant construct [17] such as those espoused by Smith =-=[20]-=- and Liu [15] might be used to circumvent this problem, but unfortunately we do not know of any modern functional language that supports those ideas. Finally, the algorithm presented here is represent... |

85 | A Transformation-based Optimiser for Haskell. Science of Computer Programming 32(1-3):3-47
- Jones, Santos
- 1998
(Show Context)
Citation Context ...optimisation switch. Indeed, this is where we claw back some of the gains obtained by handcoded optimisations in the C++ code: the ghc compiler aggressively applies optimising program transformations =-=[19]-=-. To compare the performance of the two executables, we formatted the full text of Thomas Hardy's Far from the Madding Crowd, an ASCIIsle of approximately 780Kb [10]. The three programs were run to fo... |

53 |
Breaking paragraphs into lines
- Knuth, Plass
- 1982
(Show Context)
Citation Context ...re hope to bridge the algorithm gap between abstract and concrete implementations, and thereby to facilitate communication between the two communities. 1 Introduction The paragraph formatting problem =-=[12]-=- is a favourite example for demonstrating the effectiveness of formal methods, and two particularly convincing derivations can be found in [1, 13]. The algorithms derived in these references are appli... |

49 |
Speeding up dynamic programming with applications to molecular biology
- Galil, Giancarlo
- 1989
(Show Context)
Citation Context ...the maximum number of words on a line, and n is the number of words to be formatted. Among algorithm designers it is well-known that one can solve the paragraph problem in O(n) time, independent of w =-=[7, 8, 9, 10]-=-. The presentations of these linear algorithms This paper is Technical Report CMS-TR-97-03 from the School of Computing and Mathematical Sciences, Oxford Brookes University. It is currently being subm... |

42 |
A calculus of functions for program derivation
- Bird
- 1990
(Show Context)
Citation Context ... sum of the waste on the individual lines. Using the above two monotonicity properties, one may conclude that the following dynamic programming algorithm is a valid solution to the specification par0 =-=[2]-=-. ?par1 ? = minWith waste . fold1 step start ? where ? step w ps = filter fitH (new w(minWith waste ps):map(glue w) ps) ? start w = filter fitH [ [[w]] ] ?fitH = fits . head Note that par1 is not equa... |

39 | Systematic derivation of incremental programs
- Liu, Teitelbaum
- 1995
(Show Context)
Citation Context ...egance that characterises the functional expression of the standard algorithm. Meta-programming features in the spirit of Paige's invariant construct [17] such as those espoused by Smith [20] and Liu =-=[15]-=- might be used to circumvent this problem, but unfortunately we do not know of any modern functional language that supports those ideas. Finally, the algorithm presented here is representative of a la... |

36 |
Programming from Speci
- Morgan
- 1998
(Show Context)
Citation Context ...ticularly convincing derivations can This paper is a revision of Technical Report CMS-TR-97-03 from the School of Computing and Mathematical Sciences, Oxford Brookes University. 1 be found in [1] and =-=[16]-=-. The algorithms derived in these references are applications of dynamic programming, and their time complexity is O(min(wn; n 2 )), where w is the maximum number of words on a line, and n is the numb... |

35 |
The least weight subsequence problem
- Hirschberg, Larmore
- 1987
(Show Context)
Citation Context ...the maximum number of words on a line, and n is the number of words to be formatted. Among algorithm designers it is well-known that one can solve the paragraph problem in O(n) time, independent of w =-=[7, 8, 9, 10]-=-. The presentations of these linear algorithms This paper is Technical Report CMS-TR-97-03 from the School of Computing and Mathematical Sciences, Oxford Brookes University. It is currently being subm... |

35 |
Automatic methods for program transformation
- Chin
- 1990
(Show Context)
Citation Context ...ould have to generalize from functional programming to relational programming [4], a step that is beyond the scope of this paper. 7 For eciency, we can benet from performing a tupling transformation [=-=18, 6]-=- to avoid recomputing the width of thesrst line and the cost of the remaining candidate solutions. We represent the paragraph (l:ls) by the triple (l:ls, width l, cost ls) (Because ls may be empty, we... |

33 |
Programming with invariants
- Paige
- 1986
(Show Context)
Citation Context ...r, differencing destroys some of the delightful elegance that characterises the functional expression of the standard algorithm. Meta-programming features in the spirit of Paige's invariant construct =-=[14]-=- might be used to circumvent this problem, but unfortunately we do not know of any modern functional language that supports those ideas. Finally, the algorithm presented here is representative of a la... |

20 |
Sparse dynamic programming II: convex and concave cost functions
- Eppstein
- 1992
(Show Context)
Citation Context ...the maximum number of words on a line, and n is the number of words to be formatted. Among algorithm designers it is well-known that one can solve the paragraph problem in O(n) time, independent of w =-=[7, 8, 9, 10]-=-. The presentations of these linear algorithms This paper is Technical Report CMS-TR-97-03 from the School of Computing and Mathematical Sciences, Oxford Brookes University. It is currently being subm... |

16 |
Breaking paragraphs into lines. Software practice and experience
- Knuth, Plass
- 1981
(Show Context)
Citation Context ...ween abstract and concrete implementations, and thereby facilitate communication between the constructive programming and algorithm design communities. 1 Introduction The paragraph formatting problem =-=[14-=-] is a favourite example for demonstrating the eectiveness of formal methods. Two particularly convincing derivations can This paper is a revision of Technical Report CMS-TR-97-03 from the School of C... |

13 | A generic program for sequential decision processes - Moor - 1995 |

12 | A symmetric set of efficient list operations - Hoogerwoord - 1992 |

10 |
Transformational programming and the paragraph problem
- Bird
- 1986
(Show Context)
Citation Context ...unities. 1 Introduction The paragraph formatting problem [12] is a favourite example for demonstrating the effectiveness of formal methods, and two particularly convincing derivations can be found in =-=[1, 13]-=-. The algorithms derived in these references are applications of dynamic programming, and their time complexity is O(min(wn; n 2 )), where w is the maximum number of words on a line, and n is the numb... |

9 |
Methodologies for transformations and memoing in applicative languages
- Pettorossi
- 1984
(Show Context)
Citation Context ...ould have to generalize from functional programming to relational programming [4], a step that is beyond the scope of this paper. 7 For eciency, we can benet from performing a tupling transformation [=-=18, 6]-=- to avoid recomputing the width of thesrst line and the cost of the remaining candidate solutions. We represent the paragraph (l:ls) by the triple (l:ls, width l, cost ls) (Because ls may be empty, we... |

7 |
List partitions
- Bird, Moor
- 1993
(Show Context)
Citation Context ...cond element being the remainder; drop n x is the second component of splitAt n x.) The proof that this works is an induction over all tails of the argument, and a detailed exposition can be found in =-=[3]-=-. It is perhaps interesting to note that a program involving tile is the starting point for the papers by Hirschberg and Larmore [9]; for us, it is part of a final optimisation. Adapting the algorithm... |

4 | New applications of failure functions
- Hirschberg, Larmore
- 1987
(Show Context)
Citation Context |

2 | A symmetric set of ecient list operations - Hoogerwoord - 1992 |

1 |
Many original texts as ASCII files. Available by ftp from: mrcnext.cso.uiuc.edu
- Project
(Show Context)
Citation Context ...es faster than without the -O2 switch. To compare the performance of the two executables, we formatted the full text of Thomas Hardy's Far from the madding crowd, an ASCII file of approximately 780Kb =-=[15]-=-. The three programs were run to format this file for a maximum line width of 70 characters. The CPU time and memory usage were measured using the time command provided by the UNIX C-shell. The Modula... |

1 |
Far from the Madding Crowd. Gutenberg Project
- Hardy
- 1994
(Show Context)
Citation Context ...optimising program transformations [19]. To compare the performance of the two executables, we formatted the full text of Thomas Hardy's Far from the Madding Crowd, an ASCIIsle of approximately 780Kb =-=[10]-=-. The three programs were run to format thissle for a maximum line width of 70 characters and an optimum width of 63. The CPU time was measured using the time command provided by the Linux bash shell.... |

1 |
Available by ftp from: mrcnext.cso.uiuc.edu. Many original texts as ASCII
- Project
(Show Context)
Citation Context ...optimising program transformations [18]. To compare the performance of the two executables, we formatted the full text of Thomas Hardy's Far from the Madding Crowd, an ASCIIsle of approximately 780Kb =-=[20]-=-. The three programs were run to format thissle for a maximum line width of 70 characters and an optimum width of 63. The CPU time was measured using the time command provided by the Linux bash shell.... |