In this section we demonstrate how a more complex entropy structure may be produced from simpler ones using the techniques of section 4.3. The example is that of a line editor, which inputs words and checks them for spelling against a dictionary.
Words are input from a keyboard and represented on screen by the editor. A binding associates each sequence of characters with its representation on screen (in practice that is done character-by-character, but for this example we suppose it to be done by word). The correct binding is a function
where denotes the set
of all words (i.e. sequences of characters) and Reps denotes their representations
on screen. The state of a line editor is a sequence of words input so far, with the
representation of each
Initially the state is empty. The action of editing the next word extends the state
by a pair consisting of the input word
and its representation
That action is deemed to be good or benign if all words are represented correctly and
otherwise it is deemed to be evil. Such intuition is captured by taking the entropy
structure defined by the level function which captures the
number of words incorrectly represented
where projection functions and
are defined by
and
.
The resulting entropy structure
provides a
simple generic example.
Now suppose that it is deemed important to represent certain words correctly but that
other words are of less concern. Perhaps, for example, correct representation of text is
more important than that of strings of mathematical symbols; or vice versa. Such
decisions are codified by a pre-order on words. For example to ensure that words in
some set
are more
important than others, take the pre-order given by the level function
, defined
But of course in general pre-order may be total. To modify the entropy structure
to reflect that extra
information, it suffices to use the lexical pre-order in which
is refined by
. For then the
resulting pre-order
orders first states with no errors, then all states with one error,
ordered where possible by
, then states with two errors and so on. The resulting
entropy structure has the same state as
, but the more complex lexical pre-order and equivalence
defined in terms of simpler ones; we write it
.
So much for input of words.
A line editor uses a dictionary to check the spelling of the words it inputs. But the
dictionary may have some errors, or we may use an American dictionary to check a British
English text, or vice versa. Let denote the actual dictionary used by
the editor and
the correct one. (We overlook order in our dictionaries since we
are here not interested in implementing the lookup function). A word is correctly
classified by dictionary
iff both
and
would give the same answer, i.e. the word
lies in the set
where denotes the complement of subset
of
. The edit action
appends to state a word and a bit saying whether
or not that word is correctly classified by
. Thus state is given by
and the edit action given by
A good or benign action appends only correct words; an evil one commits at least one
error. That is captured by the entropy structure whose level function captures the number of words incorrectly spelt
according to
The result is another simple entropy structure .
Finally an editor uses a keyboard for entry of words and a dictionary to check the
correctness of their spelling. Let us see how to define this simply in terms of and
. Firstly, the state combines both
and
: it
consists of a single sequence of input words
Action extends state by a word together with its representation and the correctness
of its spelling
Such an action ought to be good iff it is good for both components; similarly for
benign actions; an action ought to be evil iff it is evil for at least one component. That
is achieved precisely by the conjunction entropy structure in which
is the conjunction
of pre-orders
and
.
(As an exercise, the reader may wish to define, solely in terms of the entropy
structures introduced here and the combinators of section 4.3,
an entropy structure which captures the decision that errors in representing a word on
screen are worse than a faulty dictionary. The ordering should be: first all states with
no faulty word representations, ordered by the number of faults in , then all states with just one faulty
representation, ordered by number of faults in
, and so on.)