Documentation

Init.Data.Char.Ordinal

Bijection between Char and Fin Char.numCodePoints #

In this file, we construct a bijection between Char and Fin Char.numCodePoints and show that it is compatible with various operations. Since Fin is simpler than Char due to being based on natural numbers instead of UInt32 and not having a hole in the middle (surrogate code points), this is sometimes useful to simplify reasoning about Char.

We use these declarations in the construction of Char ranges, see the module Init.Data.Range.Polymorphic.Char.

@[reducible, inline]

The number of surrogate code points.

Equations
    Instances For
      @[reducible, inline]

      The size of the Char type.

      Equations
        Instances For

          Packs Char bijectively into Fin Char.numCodePoints by shifting code points which are greater than the surrogate code points by the number of surrogate code points.

          The inverse of this function is called Char.ofOrdinal.

          Equations
            Instances For

              Unpacks Fin Char.numCodePoints bijectively to Char by shifting code points which are greater than the surrogate code points by the number of surrogate code points.

              The inverse of this function is called Char.ordinal.

              Equations
                Instances For

                  Computes the next Char, skipping over surrogate code points (which are not valid Chars) as necessary.

                  This function is specified by its interaction with Char.ordinal, see Char.succ?_eq.

                  Equations
                    Instances For
                      def Char.succMany? (m : Nat) (c : Char) :

                      Computes the m-th next Char, skipping over surrogate code points (which are not valid Chars) as necessary.

                      This function is specified by its interaction with Char.ordinal, see Char.succMany?_eq.

                      Equations
                        Instances For
                          @[simp]
                          theorem Char.ordinal_zero :
                          '\x00'.ordinal = 0
                          theorem Char.val_ofOrdinal {f : Fin numCodePoints} :
                          (ofOrdinal f).val = if h : f < 55296 then UInt32.ofNatLT f else UInt32.ofNatLT (f + numSurrogates)
                          @[simp]
                          theorem Char.ordinal_inj {c d : Char} :
                          theorem Char.ordinal_le_of_le {c d : Char} (h : c d) :