Ranks in a finite linear order and the BIT predicate
Lax895169.BitPredicate · concepts/Lax895169/BitPredicate.lean · lax-895169
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
In a finite linear order, the rank of an element is the number of elements strictly below it, so that the elements are numbered . The number of bit positions of the order is , enough to write every rank in binary. The predicate BIT holds when the bit of weight is set in the binary expansion of the rank of , where is the rank of : an element names a position by its rank.
A quantifier prefix over variables is given by a polarity per variable, existential or universal; it holds of a property of -tuples when the variables, quantified in order with the first outermost, make the property true.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Data.Set.Card |
| 2 | import Mathlib.Data.Nat.Bitwise |
| 3 | import Mathlib.Data.Nat.Log |
| 4 | import Mathlib.Data.Fin.Tuple.Basic |
| 5 | import Mathlib.Order.Basic |
| 6 | |
| 7 | /-! |
| 8 | --- |
| 9 | title: Ranks in a finite linear order and the BIT predicate |
| 10 | type: definition |
| 11 | --- |
| 12 | In a finite linear order, the rank of an element is the number of elements |
| 13 | strictly below it, so that the elements are numbered . The |
| 14 | number of bit positions of the order is , enough |
| 15 | to write every rank in binary. The predicate BIT holds when the bit |
| 16 | of weight is set in the binary expansion of the rank of , where |
| 17 | is the rank of : an element names a position by its rank. |
| 18 | |
| 19 | A quantifier prefix over variables is given by a polarity per variable, |
| 20 | existential or universal; it holds of a property of -tuples when the |
| 21 | variables, quantified in order with the first outermost, make the property |
| 22 | true. |
| 23 | -/ |
| 24 | |
| 25 | namespace Lax895169.BitPredicate |
| 26 | |
| 27 | /-- The rank of an element of a finite linear order: the number of its strict |
| 28 | predecessors. -/ |
| 29 | noncomputable def orank {A : Type} [LinearOrder A] (z : A) : ℕ := |
| 30 | {y : A | y < z}.ncard |
| 31 | |
| 32 | /-- **The number of bit positions** of the ranks of `A`: the ranks are the |
| 33 | numbers below `Nat.card A`, so they are exactly the numbers whose bits live |
| 34 | below `Nat.clog 2 (Nat.card A)`. -/ |
| 35 | noncomputable def posCount (A : Type) [LinearOrder A] [Finite A] : ℕ := |
| 36 | Nat.clog 2 (Nat.card A) |
| 37 | |
| 38 | /-- **The bit of `x` at the index `i`**: the `BIT` of the classical vocabulary |
| 39 | `FO(≤, BIT)`, the position being named by the element whose *rank* is the |
| 40 | exponent. Total, and with no guard – above the bit positions of the universe |
| 41 | every bit is simply clear. -/ |
| 42 | def BitIx {A : Type} [LinearOrder A] (i x : A) : Prop := |
| 43 | (orank x).testBit (orank i) = true |
| 44 | |
| 45 | /-- A quantifier prefix, peeled from the innermost variable outwards: the |
| 46 | variable of index `0` is quantified outermost, existentially when its polarity |
| 47 | is `true`. -/ |
| 48 | def prefixHolds {A : Type} : (m : ℕ) → (Fin m → Bool) → ((Fin m → A) → Prop) → Prop |
| 49 | | 0, _, P => P Fin.elim0 |
| 50 | | m + 1, pol, P => |
| 51 | prefixHolds m (fun j => pol j.castSucc) |
| 52 | (fun v => if pol (Fin.last m) = true then ∃ a, P (Fin.snoc v a) |
| 53 | else ∀ a, P (Fin.snoc v a)) |
| 54 | |
| 55 | end Lax895169.BitPredicate |
| 56 |
Builds on
none
Used by
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments