Documentation

Linglib.Core.Scales.HasMeasure

Core/Scales/HasMeasure.lean — measurement typeclass + finite degree types #

HasMeasure E α is the formal-semantics "measure function" μ : E → α, parameterized over both the entity type and the codomain.

Renames the legacy HasDegree typeclass — HasDegree is preserved as a deprecation alias for one version, then removed in a later refactor.

Degree max and Threshold max are discretized scale types for gradable adjective RSA computations; they participate in the DirectedMeasure infrastructure via their LinearOrder/BoundedOrder instances.

This file is part of the Phase A decomposition of the legacy Core/Scales/Scale.lean dumping ground (master plan v4).

Multi-dim measurement #

No outParam on δ — multi-dim same-carrier (e.g. Entity measured by both height and weight) is supported via distinct (α, δ) instance signatures or newtype wrappers (mathlib Additive/Multiplicative precedent). This is a deliberate design choice per master plan v4.

Degree and Threshold types for finite scales #

Degree max wraps Fin (max + 1) with LinearOrder, BoundedOrder, Fintype. Threshold max wraps Fin max with coercion to Degree max.

structure Core.Scale.Degree (max : ) :

A degree on a scale from 0 to max. Represents discretized continuous values like height, temperature, etc.

  • value : Fin (max + 1)
Instances For
    def Core.Scale.instReprDegree.repr {max✝ : } :
    Degree max✝Std.Format
    Equations
    • Core.Scale.instReprDegree.repr x✝ prec✝ = Std.Format.bracket "{ " (Std.Format.nil ++ Std.Format.text "value" ++ Std.Format.text " := " ++ (Std.Format.nest 9 (repr x✝.value)).group) " }"
    Instances For
      @[implicit_reducible]
      instance Core.Scale.instReprDegree {max✝ : } :
      Repr (Degree max✝)
      Equations
      def Core.Scale.instDecidableEqDegree.decEq {max✝ : } (x✝ x✝¹ : Degree max✝) :
      Decidable (x✝ = x✝¹)
      Equations
      Instances For
        @[implicit_reducible]
        instance Core.Scale.instDecidableEqDegree {max✝ : } :
        DecidableEq (Degree max✝)
        Equations
        @[implicit_reducible]
        instance Core.Scale.instInhabitedDegree {n : } :
        Inhabited (Degree n)
        Equations
        @[implicit_reducible]
        instance Core.Scale.instLinearOrderDegree {max : } :
        LinearOrder (Degree max)

        Degree max inherits a linear order from Fin (max + 1).

        Equations
        @[implicit_reducible]
        instance Core.Scale.instBoundedOrderDegree {max : } :
        BoundedOrder (Degree max)

        Degree max is bounded: 0 is the minimum, max is the maximum.

        Equations
        def Core.Scale.allDegrees (max : ) :
        List (Degree max)

        All degrees from 0 to max

        Equations
        Instances For
          def Core.Scale.Degree.ofNat (max n : ) :
          Degree max

          Degree from Nat (clamped)

          Equations
          Instances For
            def Core.Scale.Degree.toNat {max : } (d : Degree max) :

            Get numeric value

            Equations
            Instances For
              structure Core.Scale.Threshold (max : ) :

              A threshold for a gradable adjective. x is "tall" iff degree(x) > threshold.

              • value : Fin max
              Instances For
                def Core.Scale.instReprThreshold.repr {max✝ : } :
                Threshold max✝Std.Format
                Equations
                • Core.Scale.instReprThreshold.repr x✝ prec✝ = Std.Format.bracket "{ " (Std.Format.nil ++ Std.Format.text "value" ++ Std.Format.text " := " ++ (Std.Format.nest 9 (repr x✝.value)).group) " }"
                Instances For
                  @[implicit_reducible]
                  instance Core.Scale.instReprThreshold {max✝ : } :
                  Repr (Threshold max✝)
                  Equations
                  def Core.Scale.instDecidableEqThreshold.decEq {max✝ : } (x✝ x✝¹ : Threshold max✝) :
                  Decidable (x✝ = x✝¹)
                  Equations
                  Instances For
                    @[implicit_reducible]
                    instance Core.Scale.instInhabitedThresholdOfAutoParamLtNatOfNat_auto_44 {n : } (h : 0 < n := by omega) :
                    Inhabited (Threshold n)
                    Equations
                    @[implicit_reducible]
                    instance Core.Scale.instLinearOrderThreshold {max : } :
                    LinearOrder (Threshold max)

                    Threshold max inherits a linear order from Fin max.

                    Equations
                    def Core.Scale.allThresholds (max : ) :
                    autoParam (0 < max) allThresholds._auto_1List (Threshold max)

                    All thresholds from 0 to max-1

                    Equations
                    Instances For
                      def Core.Scale.Threshold.toNat {max : } (t : Threshold max) :

                      Get numeric value

                      Equations
                      Instances For
                        @[implicit_reducible]
                        instance Core.Scale.instFintypeDegree {max : } :
                        Fintype (Degree max)
                        Equations
                        @[implicit_reducible]
                        instance Core.Scale.instFintypeThresholdOfNeZeroNat {max : } [NeZero max] :
                        Fintype (Threshold max)
                        Equations
                        @[implicit_reducible]
                        instance Core.Scale.instCoeThresholdDegree {max : } :
                        Coe (Threshold max) (Degree max)

                        Coercion: Threshold embeds into Degree via Fin.castSucc

                        Equations
                        theorem Core.Scale.coe_threshold_toNat {max : } (t : Threshold max) :
                        { value := t.value.castSucc }.toNat = t.toNat
                        @[reducible, inline]
                        abbrev Core.Scale.deg (n : ) {max : } (h : n max := by omega) :
                        Degree max

                        Construct a degree by literal: deg 5 : Degree 10.

                        Equations
                        Instances For
                          @[reducible, inline]
                          abbrev Core.Scale.thr (n : ) {max : } (h : n < max := by omega) :

                          Construct a threshold by literal: thr 5 : Threshold 10.

                          Equations
                          Instances For

                            Typeclass for entities that have a measurement on some scale. The formal semantics "measure function" μ : Entity → α.

                            The codomain α is polymorphic — heights might use ℚ (cm, exact), physical heights ℝ, durations ℕ (ticks), prices ℚ (USD), etc.

                            No outParam on α: master plan v4 deliberately drops outParam to support multi-dim same-carrier (e.g., Entity measured by BOTH height and weight). When an Entity has multiple measures, consumers disambiguate via explicit (α := ...) or named instances; mathlib Additive/Multiplicative newtype-wrapping is the canonical pattern for type-level disambiguation.

                            Renamed from HasDegree (legacy name) per master plan v4 Phase A.7. Field name kept as degree for one-version migration compatibility; HasMeasure.measure is provided as the v4-canonical alias.

                            • degree : Eα
                            Instances
                              @[reducible, inline]
                              abbrev Core.Scale.HasMeasure.measure {E α : Type} [HasMeasure E α] :
                              Eα

                              v4-canonical name for the measurement function. Aliased to the legacy field name degree for one-version migration.

                              Equations
                              Instances For
                                @[reducible, inline]
                                abbrev Core.Scale.HasDegree (E α : Type) :

                                Deprecation alias: HasDegree is the legacy name for HasMeasure. One-version migration alias; will be removed in a follow-up refactor.

                                Equations
                                Instances For
                                  @[reducible, inline]
                                  abbrev Core.Scale.HasDegree.degree {E α : Type} [HasDegree E α] :
                                  Eα

                                  Explicit alias for the legacy field projection HasDegree.degree. Needed because Lean does not auto-derive projection names through abbrevs.

                                  Equations
                                  Instances For