Documentation

Complexity.Computability.Ram.Source.Value

Typed views of source value fields #

Word, array-reference and unit values are represented by one, two and zero words respectively. Encoding and decoding identify those same fields; they neither allocate arrays nor load mathematical data into source memory. The source syntax and callable-function proof interfaces share this representation.

Source value shape; arrays have two word fields and Unit has none.

Instances For

    Number of physical words in a source value.

    Equations
    Instances For

      Ordinary Lean value represented by the declared result fields.

      Equations
      Instances For
        def Ram.DSL.ValueKind.encode {w : Nat} (kind : ValueKind) :
        kind.Value w → List (Word w)

        The actual fields of a typed value, without allocation or memory access.

        Equations
        Instances For
          @[simp]
          theorem Ram.DSL.ValueKind.encode_word {w : Nat} (value : Word w) :
          word.encode value = [value]
          @[simp]
          theorem Ram.DSL.ValueKind.encode_array {w : Nat} (value : ArrayRef w) :
          array.encode value = [value.base, value.length]
          @[simp]
          theorem Ram.DSL.ValueKind.encode_unit {w : Nat} (value : Unit) :
          unit.encode value = []
          @[simp]
          theorem Ram.DSL.ValueKind.length_encode {w : Nat} (kind : ValueKind) (value : kind.Value w) :
          (kind.encode value).length = kind.width

          Each value has exactly its declared number of fields.

          def Ram.DSL.ValueKind.decode {w : Nat} (kind : ValueKind) (fields : List (Word w)) (shape : fields.length = kind.width) :
          kind.Value w

          Project actual fields with a proved shape. No missing field is replaced by a default.

          Equations
          Instances For
            @[simp]
            theorem Ram.DSL.ValueKind.decode_word {w : Nat} (value : Word w) (shape : [value].length = word.width) :
            word.decode [value] shape = value
            @[simp]
            theorem Ram.DSL.ValueKind.decode_array {w : Nat} (base length : Word w) (shape : [base, length].length = array.width) :
            array.decode [base, length] shape = { base := base, length := length }
            @[simp]
            theorem Ram.DSL.ValueKind.decode_unit {w : Nat} (fields : List (Word w)) (shape : fields.length = unit.width) :
            unit.decode fields shape = ()
            @[simp]
            theorem Ram.DSL.ValueKind.decode_encode {w : Nat} (kind : ValueKind) (value : kind.Value w) (shape : (kind.encode value).length = kind.width) :
            kind.decode (kind.encode value) shape = value

            Decoding the actual representation recovers the typed value.

            @[simp]
            theorem Ram.DSL.ValueKind.encode_decode {w : Nat} (kind : ValueKind) (fields : List (Word w)) (shape : fields.length = kind.width) :
            kind.encode (kind.decode fields shape) = fields

            Typed observation retains every field of the original return value.

            theorem Ram.DSL.ValueKind.decode_eq_of_eq_encode {w : Nat} (kind : ValueKind) {fields : List (Word w)} {value : kind.Value w} (shape : fields.length = kind.width) (equal : fields = kind.encode value) :
            kind.decode fields shape = value

            A raw result equation transfers to a typed value without decomposing its fields.

            Distinct typed values cannot have the same actual fields.

            @[simp]
            theorem Ram.DSL.ValueKind.encode_inj {w : Nat} (kind : ValueKind) (left right : kind.Value w) :
            kind.encode left = kind.encode right ↔ left = right