Binary numbers carried by a relation #
The layer between DescriptiveComplexity.Numbers.Binary, which decodes a set of bits
sitting on a genuine LinearOrder, and the problems carrying binary numbers,
whose order is a relation symbol of the vocabulary and therefore an
arbitrary binary relation until the yes-instances say otherwise.
DescriptiveComplexity.IsLinOrd– being a linear order, as a property of a relation, first-order and foldable into the yes-instances;DescriptiveComplexity.bitRank– the rank of a position, the number of positions strictly below it, defined for an arbitrary relation;DescriptiveComplexity.binNum– the decoding∑ 2 ^ rank, over a set of positions viafinsum, so that it is total and needs no finiteness to be stated.
Everything transports along equivalences commuting with the relations, which
is what the DecisionProblem.iso_invariant proofs of the group need.
The arithmetic the Σ₁ definitions need – that a bitwise ripple-carry chain
computes an addition – is built on DescriptiveComplexity.binNum_peel_min, which
peels the lowest position off a decoded number: binNum = bit at the bottom + 2 * (the rest), the recursion binary numbers actually satisfy. The same
recursion gives the two facts a kernel needs about whole numbers rather than
their bits: DescriptiveComplexity.binNum_inj_on, two numbers are equal exactly when
their bits agree, and DescriptiveComplexity.binNum_lt_iff, one is smaller exactly
when they differ and the higher bit is the second's – both bitwise, hence
first-order, which is why a kernel can compare numbers it has guessed.
Linear orders, as a property of a relation #
A binary relation is a linear order: reflexive, transitive, antisymmetric and total.
Equations
Instances For
Building linear orders #
Reductions into a problem carrying binary numbers have to construct the
order of the instance they produce, and a Σ₁ certificate sometimes has to
exhibit one. Both do it the same way: read the elements through a key into a
lexicographic product of orders already at hand.
A relation read through an injective key into a linear order is a linear order.
A relation that is a linear order induces a LinearOrder structure,
which is what Mathlib's order library asks for. Guessed orders – a schedule, a
circuit – arrive as relations, so this is the bridge to it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The natural order of a linear order, as a relation.
Decoding a set of positions #
The rank of a position: the number of positions strictly below it. This is the place value's exponent.
Instances For
The number encoded by the set b of positions: ∑ 2 ^ rank.
Equations
Instances For
The rank of a position transports along an equivalence commuting with the two relations.
The decoded number transports along an equivalence commuting with the three relations.
On a finite universe both are finite sums over Finsets, which is what a
decoder computes. The Decidable arguments are what makes those Finsets
constructible; nothing here needs the relations to be well-behaved.
The rank of a position, as the cardinality of a Finset.
The decoded number, as a sum over a Finset.
Peeling the lowest position #
The full adder #
Ripple-carry addition #
p is a lowest position.
Equations
- DescriptiveComplexity.MinPos Le Posn p = (Posn p ∧ ∀ (q : A), Posn q → Le p q)
Instances For
p is a highest position.
Equations
- DescriptiveComplexity.MaxPos Le Posn p = (Posn p ∧ ∀ (q : A), Posn q → Le q p)
Instances For
Ripple-carry addition is addition. If s is the bitwise sum of a
and b with carries c – each bit the exclusive or of the three, each carry
the majority of the three below – then the decoded numbers add up, the carry
in at the bottom and the carry out at the top accounting for the
difference.
A ripple-carry certificate exists. Whenever the sum fits in the
available positions, the bitwise sum and the carries that witness it can be
produced – this is the certificate that the Σ₁ definition of a
binary-weighted problem guesses.
Comparison by the highest differing position: one decoded number is
smaller than another exactly when there is a position carrying 0 in the
first and 1 in the second above which the two agree. Unlike the value
itself, this is a first-order reading of <, which is what a kernel
comparing two guessed numbers writes.