Standard posit comparisons and finite enumeration #
The Posit Standard (2022) defines comparisons by regarding the complete encoded words as
two's-complement signed integers. In particular, NaR compares as the least encoded value and two
NaR words compare equal. This is an ordering of posit values, including NaR; it is deliberately
not presented as an order embedding into Rat or Real, because NaR has no real denotation.
This module transports Lean's proved BitVec.toInt order to Model format. It also exposes the
exact equivalence with BitVec format.bits and derives Mathlib's FinEnum/Fintype
infrastructure from that equivalence. Exhaustive proofs can therefore enumerate the model without
maintaining a second list of encodings.
References #
- Posit Working Group, Standard for Posit Arithmetic (2022), March 2, 2022, Section 5.3, https://posithub.org/docs/posit_standard-2.pdf.
Canonical finite enumeration inherited from exact-width bit vectors.
The enumeration is by unsigned word, which is useful for encoding tables and exhaustive
conformance checks. The LinearOrder below is separately the standard's signed comparison order.
The number of posit words is exactly 2 ^ format.bits, including zero and NaR.
Interpret the complete posit word as a two's-complement signed integer.
Instances For
Signed-code interpretation is injective at a fixed width.
The standard total order on posit words.
This instance makes ordinary Lean notation (<, ≤, min, max, sorting, intervals) agree
with Posit Standard comparisons. NaR is included as the least word; numerical theorems that must
exclude NaR should state that premise explicitly or use toRat?.
The order is transported along signedCode, but the DecidableEq field reuses the derived
instance so that the model has a single decidable equality.
Standard equality comparison.
Instances For
Standard inequality comparison.
Instances For
Standard strict-less comparison, executed directly on the encoded words.
Instances For
Standard less-or-equal comparison, executed directly on the encoded words.
Instances For
Standard strict-greater comparison, executed by reversing strict-less.
Instances For
Standard greater-or-equal comparison, executed by reversing less-or-equal.
Instances For
Boolean equality agrees exactly with equality in the posit model.
Boolean inequality agrees exactly with inequality in the posit model.
Encoded strict-less comparison agrees with the standard signed-word order.
Encoded less-or-equal comparison agrees with the standard signed-word order.
Encoded strict-greater comparison agrees with the standard signed-word order.
Encoded greater-or-equal comparison agrees with the standard signed-word order.
Equality of NaR with itself follows the standard's encoded comparison rule.