Definition
Lexicographic order and componentwise order are two rules for comparing tuples, fixed-length lists of numbers such as a version written (major, minor). Lexicographic order compares the first components and reads the next component only when they are equal, the way a dictionary orders words. Componentwise order, also called product order, puts one tuple at or below another only when every component is at or below the matching one. Lexicographic order ranks every pair; componentwise order leaves some pairs, such as and , incomparable.
The idea
A device stores the version of its installed software as a pair of numbers and refuses updates that are older. Two teams read the pair differently. The release team means (major, minor): version 2.0 is the release after 1.1000, so is newer than . The security team means two independent anti-rollback §8.26 counters, the first for the boot code and the second for the application, neither of which may ever go down. An update labeled reaches a device at . The release team’s rule accepts it. The security team’s rule refuses it, because the application counter would fall from 1000 to 0. The bytes are the same, the decisions differ, and nothing in the pair says which rule applies.
Lexicographic order treats the components like the digits of a number: the leftmost one outranks everything after it, as the thousands digit alone decides between 2000 and 1999. Componentwise order treats the components as separate measurements that must all agree, like a rule that one candidate beats another only by being at least as good in every required skill. A candidate with more experience but less training is then neither better nor worse, and that missing answer is information, not a defect.
How it works
Lexicographic comparison of and :
Compare with . If they differ, the tuple with the smaller first component is the smaller tuple; stop.
Otherwise compare with in the same way, and continue to the right.
If every component is equal, the tuples are equal.
Componentwise comparison of the same tuples:
If at every position , then .
If at every position , then .
If neither holds, and are incomparable.
The two orders agree in one direction. If componentwise, then lexicographically, because at the first position where the tuples differ, has the smaller component. The reverse fails. Lexicographic order thus extends componentwise order to a ranking of every pair.
Two habits produce lexicographic order, intended or not.
Packing into one integer. Storing (major, minor) as and comparing the integers gives lexicographic order, provided the minor number stays below .
Comparing text. Comparing version strings character by character is lexicographic order on characters, not on numbers, and it puts
1.10before1.9.
Each order has its standard uses. Semantic Versioning, a widely used convention for release numbers of the form major.minor.patch, compares the three numbers lexicographically, each as a number. Vector clocks, tuples with one counter per machine that distributed systems use to record which events could have influenced which, are compared componentwise. Two incomparable vector clocks belong to events of which neither could have influenced the other.
Worked example
Compare with .
Lexicographic. The first components are 2 and 1, and , so : is newer. The second components, 0 and 1000, are never read.
Componentwise. needs , which holds, and , which fails. needs , which fails. Neither holds, so the tuples are incomparable.
For contrast, compare with . Lexicographically the first components tie at 1, and , so is smaller. Componentwise and , so again . The two orders agree, as they must whenever one tuple is componentwise at or below the other.
Packing with a 16-bit minor field turns into and into . Since , the integers agree with lexicographic order. If the minor number outgrows its field, the packing breaks: would become , the same integer as .
Comparing the text 1.10 with the text 1.9: the first characters, both 1, match; the second characters, both full stops, match; the third characters are 1 and 9, and the character 1 comes first. So the text 1.10 sorts before 1.9, although minor version 10 is newer than minor version 9. Comparing the parts between full stops as numbers gives , because .
Stated precisely
Let and be tuples of integers.
Componentwise order: if and only if for every from 1 to .
Lexicographic order: if and only if some position has for every and ; and if and only if or .
Both are partial orders §19.2.6: each is reflexive (), antisymmetric ( and together give ) and transitive ( and together give ). Lexicographic order is also total: for all and , or . Componentwise order is not total once . Finally, implies .
Packing: let be the width in bits of the second field. For pairs of non-negative integers with and , holds exactly when .
An anti-rollback rule built on either order keeps a stored floor , the tuple last accepted, and accepts a candidate tuple only if in the chosen order, or if reinstalling the same version must also be refused; it then sets . It guarantees that the device never accepts a tuple below the floor in the chosen order. That guarantee rests on three assumptions: every party uses the same order; the tuple is authenticated, meaning it lies inside the bytes that a digital signature §5.14 covers; and every component stays inside its declared range.
Limits and common mistakes
The choice of order is part of the meaning of the field, not a detail of its encoding. Write it into the format specification. Two parties that compare the same tuple under different orders reach different decisions, as the two teams above do.
Componentwise anti-rollback refuses any update that lowers any component, so it cannot work with numbering that resets the minor number at each major release: after is refused. The smallest tuple at or above both, componentwise, is , a tuple that neither team issued.
Lexicographic anti-rollback stops looking once an earlier component rises. If the second component versions the application, an update carries an older application than an installed , and lexicographic order accepts it. If each component protects something on its own, lexicographic order is the wrong rule.
Tuples of different lengths need a stated rule. Dictionary order puts a prefix first, so , while release numbering usually treats a missing component as 0, which makes the two equal.
An order says which tuple is larger. It does not show that an authorized issuer produced the tuple, and it does not handle components that wrap around at a fixed width, which serial-number arithmetic §19.3.4 addresses.
Questions answered
Is newer than ?
It depends on which order the format specifies. Under lexicographic order, which compares the first numbers and reads the second numbers only to break a tie, is newer because ; the second numbers, 0 and 1000, are never compared. That is the right reading for release numbers of the form major.minor, where 2.0 follows 1.1000. Under componentwise order, which calls one tuple newer only when none of its numbers is smaller and at least one is larger, the two tuples are incomparable: the first number rose from 1 to 2, but the second fell from 1000 to 0. That is the right reading when the two numbers are independent anti-rollback counters that must each never decrease, and a device using it refuses after .
The tuple cannot say which order applies, so the format specification must say it, and the tuple must be authenticated before either order is applied.
Related entries: Set inclusion and policy order (§15.40), Version high-water mark (§8.27), Counter wraparound (§6.21), Partial order, lattice, join, and meet (§19.2.6), Rollback versus anti-rollback (§8.26), Serial-number arithmetic and the half-range ambiguity (§19.3.4).