Practice: Mappings That Preserve Structure
Question
Error diagnosis · Classification
A submitted verification reads: "I checked
The category has five objects and eleven composable pairs.
What is wrong?
2 hints available, least help first.
Hint 1: Retrieval cue
Read each law's statement. What does it quantify over?
Hint 2: Concept cue
Count what was checked against what exists: pairs, and objects.
Direct application · Explanation
A structure has three objects
(a) How many composable triples
(b) Explain why checking a subset of them, however large, does not establish associativity.
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
A triple is composable when the endpoints meet twice: target of
Hint 2: Concept cue
Ask what a passing sample would license you to conclude about a triple you did not check.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) Fifteen.
A triple
Most of the fifteen involve at least one identity and are immediate once the identity laws hold. The triples worth attention are those built from
(b) Why a subset settles nothing.
Associativity is universally quantified: it claims the equation holds for every composable triple. A single failing triple refutes the claim outright, so the negative case is decided by one counterexample.
The positive case has no such shortcut. Triples that pass constrain only themselves. Nothing about the axioms lets agreement on one triple propagate to another. A sample that passes therefore leaves the claim exactly where it started: undecided, because the unchecked triples are precisely where a counterexample would hide.
This is why a verification should report the count. "Associativity holds" is an assertion; "associativity holds, checked on all 15 composable triples" is a verification, because a reader can confirm the enumeration was complete.
A complete answer does each of these:
- verifies category laws
Direct application · Explanation
In the category
(a) Verify the identity law at every object.
(b) Verify the composition law, showing the pair
(c)
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
The only composable pair of non-identity arrows in
Hint 2: Concept cue
For (c), list what the definition of a functor actually demands, then check whether injectivity appears on the list.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) Identity law.
All three objects check.
(b) Composition law.
The pair that carries content is
Equal ✓.
The remaining composable pairs each involve an identity,
Both laws hold, so
(c) Why collapsing is permitted.
The definition requires exactly two things: that identities go to identities, and that the image of a composite equals the composite of the images. Nothing requires
The distinction the laws draw is between losing information and being inconsistent.
What is forbidden is assigning
This is why satisfying the laws is a floor rather than a merit. A functor can be entirely uninformative and still be a functor; what it cannot be is self-contradicting.
A complete answer does each of these:
- checks functor laws
Method selection · Explanation
A colleague proposes a mapping
(a) Name the check that settles the question, and carry it out.
(b) Each of your colleague's claims is true. Explain why they nevertheless do not establish the conclusion, and say what they do establish.
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
Endpoints matching is one condition; preserving composition is another.
Hint 2: Concept cue
Count how many assignments each check examines at once.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) The composition law on the pair
Since
A complete answer does each of these:
- locates law failure
Interpretation · Evaluation
Let
A reader concludes that this verification is good evidence that naturality is an easy condition to satisfy.
(a) Assess that conclusion, showing what both routes reduce to and why.
(b) State what a verification would need in order to be evidence about how demanding the condition is, and give an example that meets the requirement.
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
Write out
Hint 2: Strategy cue
Ask whether any choice of
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) The conclusion is unsupported.
Because
and they agree for a reason that has nothing to do with which arrow was chosen. The arrow
The check was also insensitive to
A check whose outcome is fixed in advance confirms that the procedure was carried out correctly, both routes evaluated, results compared, and carries no information about the condition being checked. The example is degenerate, and reporting it as evidence about naturality's difficulty mistakes the exercise for the result.
(b) What would make it evidence.
The verification needs functors that act differently on arrows, so the two routes could in principle diverge. Then agreement is a fact about the particular transformation rather than a consequence of the shape of the example.
A case that meets this: take the list functor, where reverse satisfies
and it holds because reversing rearranges positions without examining elements.
That this is a real constraint is shown by sort, which has the same type and fails: sort inspects elements, so mapping before sorting can produce a different order than sorting before mapping, as soon as
The general point. When reporting a verification, ask whether the check could have come out the other way. If not, say so: an unfailable check is worth recording as a confirmation of method, and is not evidence about the thing checked.
A complete answer does each of these:
- verifies naturality
- reads structure preservation
Prediction · Explanation
A library defines a container type whose map operation reverses the container while mapping. The code type-checks, and the test suite, which exercises map only on single-element containers, passes.
Predict the outcome of each of the following on a three-element container
(a) Evaluating map id.
(b) An optimiser rewriting map g . map f to map (g . f).
(c) State why the test suite did not catch the defect, and what a test would have to do to catch it.
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
Count the reversals on each side of the rewrite.
Hint 2: Concept cue
Ask which law the optimiser's rewrite is a restatement of.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) map id returns
The identity law requires map id = id, so map id applied to
(b) The rewrite changes the result.
Before the rewrite, map f then map g: the first reverses to
Two reversals cancel, so the original order is restored.
After the rewrite, map (g . f) is a single map and reverses once:
The two results are reverses of one another, so they differ whenever the container has more than one distinct element.
The optimisation is valid only because the composition law is assumed: map g. map f = map (g. f) is precisely that law. With the law broken, the rewrite is unsound, and the program's output depends on whether the optimiser fired, which may vary with build flags, inlining decisions, or compiler version. That is the reason such bugs are hard to trace: the source code is unchanged, and the behaviour depends on a transformation nobody wrote.
(c) Why the tests missed it, and what would catch it.
Reversing a single-element container is the identity on it, so every law the suite could check is satisfied vacuously by the only inputs it supplies. The tests are not weak in coverage of lines, map runs every time, but in coverage of the property: they exercise the one input shape on which a reversing map is indistinguishable from a correct one.
A test that catches it checks the laws as laws: map id xs == xs and map g (map f xs) == map (g . f) xs, over containers with at least two distinct elements, ideally property-based over randomly generated containers and functions. The law is the specification, and testing anything narrower than the law tests something other than what the optimiser relies on.
A complete answer does each of these:
- checks functor laws
Error diagnosis · Evaluation
A submitted verification reads:
"
is a functor. Its object map sends to and both and to , which is well defined. Every arrow has the right source and target: matches , ; and matches . The identity law holds at all three objects. I checked the composition law on the pairs and and both agreed, so all the laws hold."
The conclusion is wrong.
(a) Identify the defect in the verification. The flaw in how it was conducted, not merely the fact that
(b) State what the writer would have found had the verification been complete.
(c) Say what the two checks they did perform contributed.
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
List every composable pair in
Hint 2: Concept cue
Ask, of each pair they checked, whether it could have failed.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) The defect: incomplete quantification.
The composition law is a claim about every composable pair. The writer checked two, and stopped. The pair carrying the content,
The flaw is in the scope of the check, not in any individual claim. Every sentence in the submission is true, which is what makes the error instructive: a verification can consist entirely of correct statements and still establish nothing, if what it quantified over was not what the law quantifies over.
(b) What a complete verification finds.
Since
(c) What the two performed checks contributed: nothing.
Both
This compounds the error rather than mitigating it. The writer performed two checks, obtained two confirmations, and reasonably felt the verification was progressing, but the confirmations were empty, and the feeling of progress came from work that carried no information. Worse, selecting the easy pairs is a natural thing to do, which is why the error recurs.
The lesson for conducting a verification. Identify in advance which checks could come out either way, and do those. Report the full list of what was checked, so a reader can see whether the informative cases were among them. A verification that names its scope can be audited; one that reports only its conclusion cannot.
A complete answer does each of these:
- locates law failure
Construction · Evaluation · Explanation
You are asked to build a mapping
(a) Attempt the construction. Work out how much freedom you have: for each arrow of
(b) Report what you find. If the construction succeeds, exhibit the failing pair and evaluate both sides; if it cannot succeed, state that and prove it.
(c) Say which single assignment would have to change to repair a broken mapping in general, and why the other two do not.
Write your answer, then compare it with the worked solution.
3 hints available, least help first.
Hint 1: Retrieval cue
How many arrows does
Hint 2: Concept cue
Both sides of the composition law live in the same hom-set. What follows if that hom-set has at most one element?
Hint 3: Strategy cue
If no assignment can fail, the task is to prove that rather than to keep searching.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) How much freedom the typing condition leaves. Fix an object map. For an arrow
|---|---|
|
|
|
|
-
necessarily, for every composable pair, for every typed
A genuine failure, and it needed the extra arrow. (c) Which assignment must change. The image of the composite,
A complete answer does each of these:
- locates law failure
- reads structure preservation
Transfer · Evaluation · Explanation
A team maintains two representations of a data schema and a translation
Write a verification report covering:
(a) Which categorical structure their setup corresponds to, and what the laws say in their terms.
(b) What their stated evidence does and does not establish.
(c) The check that would settle the claim, including what it must quantify over.
(d) What observable failure to expect in production if the claim is false, and why it would resist diagnosis.
(e) The team also maintains a routine normalise that rewrites a schema state into a canonical form, defined for both representations. They claim
Write your answer, then compare it with the worked solution.
2 hints available, least help first.
Hint 1: Retrieval cue
What are the objects, and what are the arrows? Migrations compose, that is the clue.
Hint 2: Concept cue
Restate their migration assumption as an equation, then compare it with the two functor laws.
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) The structure. Each schema representation is a category: objects are schema states, arrows are migrations, composition is applying migrations in sequence, and the identity arrow at a schema state is the null migration. Composition is associative because applying migrations in sequence is, and the null migration is a genuine identity, so the axioms hold. The translation
- The composition law says normalise claim is naturality. Let normalise supplies, for each schema state
reading: translate then normalise equals normalise then translate. (Stated for whichever pair of functors the team actually means; the shape is the same.) What it quantifies over: migrations, not schema states. This is the part teams get wrong, because normalise is defined per schema state, so it is natural to check it per schema state. The condition is indexed by arrows. A family can behave correctly at every schema state taken alone and still fail the square for some migration, that is precisely the situation the condition exists to detect, and checking only the states would miss it. Telling a real verification from an empty one. Ask whether the check could have failed. If normalise does. Agreement then reports the shape of the example, not a property of normalise. The same happens if the team tests only on schema states where normalisation is already a no-op: normalise actually interacts with, ones that touch the structures canonicalisation rewrites, so the order could matter. The diagnostic question is whether some migration in the test set would have exposed a difference had one existed. If none would, the verification has confirmed the procedure and established nothing about the claim, and the report should say so rather than recording a pass. Their assumption is load-bearing: it licenses the inference that two deployment paths agree, and real deployments rest on it. A claim that something is structure-preserving is worth exactly as much as the check behind it, and the checks they performed are the ones that cannot fail on a mapping of this kind.
A complete answer does each of these:
- verifies category laws
- checks functor laws
Construction · Direct application · Explanation
Let
A colleague proposes
(a) Check whether every arrow lands with matching source and target.
(b) Name the law
(c) Distinguish a law failure from an assignment whose arrows have the wrong endpoints, and say why the second is not a law failure at all.
(d) Suppose
Write your answer, then compare it with the worked solution.
3 hints available, least help first.
Hint 1: Retrieval cue
Check where each image arrow starts and ends before testing any law.
Hint 2: Concept cue
The composition law concerns composable pairs. This category has exactly one.
Hint 3: Strategy cue
In (d), count what naturality quantifies over: objects, or arrows?
Compare with the worked solution
Comparing does not record a result. Judging your own written answer cannot show that you can do this without help.
(a) The typing condition. Each arrow's image must run between the images of its endpoints.
| arrow | image | required | holds |
|---|---|---|---|
| yes | |||
| yes | |||
| no |
The third fails:
Isolate the law. Send
(b) The law that breaks. With the repair, the one composable pair gives
Return to the proposal as stated, with
(c) A law failure against a typing failure. Different defects, different repairs. Typing is a well-formedness requirement: an arrow sent where its endpoints do not permit means no functor was proposed and there is nothing to test. A law failure means a well-formed assignment does not preserve structure: every arrow lands legally and composition still is not respected. The first is caught by reading endpoints, the second only by composing.
(d) Naturality. A natural transformation
So the check is one equation per arrow, not per object: a square for each of
A complete answer does each of these:
- locates law failure
- verifies naturality
- reads structure preservation
Session complete
Every question in this set has been through once. What you can do now depends on how it went — practising again is worth more than moving on if any of it was uncertain.
Practice data
Your practice record is stored in this browser only. Clearing it removes every answer and every scheduled review, and cannot be undone.