Ranks in a finite linear order and the BIT predicate

Lax895169.BitPredicate · concepts/Lax895169/BitPredicate.lean · lax-895169

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural 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 0,…,n−10, \dots, n - 1. The number of bit positions of the order is ⌈log⁡2n⌉\lceil \log_2 n \rceil, enough to write every rank in binary. The predicate BIT(i,x)(i, x) holds when the bit of weight 2r2^{r} is set in the binary expansion of the rank of xx, where rr is the rank of ii: an element names a position by its rank.

    A quantifier prefix over mm variables is given by a polarity per variable, existential or universal; it holds of a property of mm-tuples when the variables, quantified in order with the first outermost, make the property true.

    Concept map
    1 concept; 10 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Data.Set.Card
    2import Mathlib.Data.Nat.Bitwise
    3import Mathlib.Data.Nat.Log
    4import Mathlib.Data.Fin.Tuple.Basic
    5import Mathlib.Order.Basic
    6
    7/-!
    8---
    9title: Ranks in a finite linear order and the BIT predicate
    10type: definition
    11---
    12In a finite linear order, the rank of an element is the number of elements
    13strictly below it, so that the elements are numbered 0,…,n−10, \dots, n - 1. The
    14number of bit positions of the order is ⌈log⁡2n⌉\lceil \log_2 n \rceil, enough
    15to write every rank in binary. The predicate BIT(i,x)(i, x) holds when the bit
    16of weight 2r2^{r} is set in the binary expansion of the rank of xx, where
    17rr is the rank of ii: an element names a position by its rank.
    18
    19A quantifier prefix over mm variables is given by a polarity per variable,
    20existential or universal; it holds of a property of mm-tuples when the
    21variables, quantified in order with the first outermost, make the property
    22true.
    23-/
    24
    25namespace Lax895169.BitPredicate
    26
    27/-- The rank of an element of a finite linear order: the number of its strict
    28predecessors. -/
    29noncomputable 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
    33numbers below `Nat.card A`, so they are exactly the numbers whose bits live
    34below `Nat.clog 2 (Nat.card A)`. -/
    35noncomputable 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
    40exponent. Total, and with no guard – above the bit positions of the universe
    41every bit is simply clear. -/
    42def 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
    46variable of index `0` is quantified outermost, existentially when its polarity
    47is `true`. -/
    48def 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
    55end Lax895169.BitPredicate
    56

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…