SE 507   Spring 2009
HW #1: Bertrand Meyer's Specification for Text Formatting
Due: 7:20pm, Tuesday, Feb. 17

1. In On Formalism in Specifications (from IEEE Software, January 1985, pp. 6-26), Bertrand Meyer develops a formal specification of the text formatting problem originally posed by Peter Naur and later clarified by Goodenough and Gerhart. Using the insight that he gained during the development of the formal specification, Meyer concludes the paper (see page 25) by offering a new informal specification that is much simpler and more concise than G&G's. Here it is, reworded slightly by your instructor:

Given are a nonnegative integer MAXPOS and a character set including two "break" characters BL (blank) and NL (newline). The program shall accept as input a finite sequence of characters and produce as output a sequence of characters differing from the input only insofar as
  1. every "break" (i.e., maximal sequence of consecutive break characters) occurring in the input appears as a single break character (either BL   or   NL) in the output,
  2. any MAXPOS + 1 consecutive characters includes at least one occurrence of NL, and
  3. the number of lines (i.e., occurrences of NL, plus one) is minimal (i.e., minimum among all texts satisfying the two conditions above).

Of the three conditions enumerated in Meyer's specification, the first two are clearly in accord with G&G's specification. But it is not at all obvious whether Meyer's third condition is equivalent to the analogous condition (also numbered 3) on lines 23-24 of G&G's specification.

Because G&G's wording of that condition is ambiguous (as noted on page 14), let us restate it as follows:

3'. No line of output should be such that the first word of the next line (assuming that there is a next line, of course) could be included in it without it exceeding the maximum-allowed length.

Consider Meyer's specification (as given above) and consider G&G's specification, by which is meant the specification obtained by replacing condition (3) in Meyer's by (3') immediately above.

Are the two specifications equivalent? If so, provide a convincing argument to that effect. If not, describe a counterexample that demonstrates the two specifications to be non-equivalent. That is, describe an ordered pair (x,y) such that, according to one of the specifications, y is a suitable output text for input text x, but, according to the other specification, it is not.

Note that this problem is easy, as the answer was given in class! Were you paying attention?

2. We are given a set of characters, among which are the two break characters BL (blank) and NL (newline). For a character c, define the predicate isBreakChar(c) to be true if c is either of the two break characters. That is,

isBreakChar(c) :   c=NL ∨ c=BL

For a string x (i.e., a sequence of characters),

Examples: Let x = "abcd". Then length(x) = 4 and x(3) = 'c'. If you wish, you can use subscripts, in which case you could say x3 = 'c'.

The term substring here should be understood to mean what Meyer would call a contiguous subsequence. For example, each of "abcd", "abc", "bc", and "b" is a substring of x = "abcd", but neither "acd" nor "ad" is.

Use these building blocks to develop formal (i.e., in the language of predicate logic, as in the text by Gries and Schneider) versions of the following informally stated predicates, which correspond to conditions (1), (2), and (3') from above: