LOGIC4FUN

Login ∨ Register

SortsNext Things Next

The first text box on the solver’s input form asks us to specify “Sorts”. It should be easy to understand what these are, but in fact they often cause a certain amount of confusion, so attend!

Logic puzzles (and other problems) are often about the relationship between things of different sorts. For example, the Philosophical Railway puzzle is about the relationship between people (Kant, Mill, etc) and their jobs (porter, driver, etc). Intuitively, it is obvious that a person is one sort of thing and a job is another sort of thing. The “sort” declaration box lets us say exactly that.

Sorts:

princess cardinality = 2
dwarf cardinality = 7
suitor {cardinality > 1. cardinality < 5}
peasant {}

This example shows the “sorts” box for a story in which there are exactly two princesses, seven dwarves (of course), a reasonable number of suitors and we don’t care how many peasants. Notice how the number of items of each sort is specified by using the keyword “cardinality”. You can abbreviate “cardinality” to “card” if you prefer, or write “size” instead – they all mean the same. As the example of the suitors shows, these numbers may be restricted to be between upper and lower bounds rather than specified exactly. In this case, there are both upper and lower bounds, though of course just one of the bounds could have been given.

Often, especially in logic puzzles, we know not only how many things there are of a given sort but also their names. In this case we can “enumerate” or list them. This can be very useful, as it guarantees for instance that all the named things are distinct from each other. Incidentally, it also helps the solver run more efficiently, but we’ll leave that aside for a while, since efficiency is not our present concern.

Sorts:

princess enum: Aurora, Esmerelda.
dwarf enum: Happy, Sneezy, Dopey, Sleepy, Grumpy, Bashful, Doc.
suitor {cardinality > 1. cardinality < 5}
peasant {}

The second example box shows how it might be if we know the names of the princesses and those of the dwarves, but not of the suitors or peasants.

The keyword “enum” introduces the list of names. Names in the list are separated by commas and the list ends with a period.

It is important to note that every sort, whether enumerated or not, has an order associated with it. In the case of the dwarves, Happy comes first in the order and Doc last. When we write statements about the dwarves, we can use “<” and “>” to refer to the order. For example, the condition

x > Sneezy AND x < Grumpy.

force the variable x to have as its value either Dopey or Sleepy. You will see that this ability to say things about the order is very useful for specifying puzzles and other problems. Indeed, you have already seen it used in the Muddle Management problem.