TorchLean API

FloatLib.Numerics.Operation.Semantics

Contracts for numerical operations #

Relations between executable functions and their denotations, starting with indexed inputs and specializing to unary, binary, and ternary functions. The contracts distinguish total, finite, checked, cast, and quantizer semantics. They live in Prop and add no runtime data.

See Operation.Status for result flags, Operation.Context for rounding policies, and Operation.Entropy for explicit randomness. Operation.Proof contains application and composition lemmas.

Indexed input contracts #

@[reducible, inline]
abbrev FloatLib.Numerics.Operation.InputCodes {ι : Type u} (inputs : ιNumericalSystem) :
Type (max u u_1)

Runtime inputs indexed by their numerical systems.

Instances For
    @[reducible, inline]
    abbrev FloatLib.Numerics.Operation.InputValues {ι : Type u} (inputs : ιNumericalSystem) :
    Type (max u u_2)

    Complete denotations of indexed numerical inputs.

    Instances For
      @[reducible, inline]
      abbrev FloatLib.Numerics.Operation.InputScalars {ι : Type u} (inputs : ιNumericalSystem) :
      Type (max u u_2)

      Ordinary finite scalar values indexed by their numerical systems.

      Instances For
        def FloatLib.Numerics.Operation.InputsRepresent {ι : Type u} (inputs : ιNumericalSystem) (codes : InputCodes inputs) (values : InputScalars inputs) :

        Every indexed runtime input represents its corresponding finite scalar.

        Instances For
          def FloatLib.Numerics.Operation.Refines {ι : Type u} (inputs : ιNumericalSystem) {Result : Type v} (run : InputCodes inputsResult) (post : InputValues inputsResultProp) :

          An executable operation satisfies a relational contract over the complete denotations of all inputs.

          Result is deliberately unconstrained: it may be a code, an Option, a status-bearing result, an entropy-producing computation, or a block value.

          Instances For
            def FloatLib.Numerics.Operation.RefinesFinite {ι : Type u} (inputs : ιNumericalSystem) {Result : Type v} (run : InputCodes inputsResult) (post : InputScalars inputsResultProp) :

            An executable operation satisfies a relational contract on represented finite inputs.

            Instances For

              Unary, binary, and ternary relations #

              def FloatLib.Numerics.Operation.Refines1 (A : NumericalSystem) {Result : Type u} (run : A.CodeResult) (post : NumericalValue A.ScalarResultProp) :

              A unary executable operation satisfies a relation on complete input denotations.

              Instances For
                def FloatLib.Numerics.Operation.Refines2 (A : NumericalSystem) (B : NumericalSystem) {Result : Type u} (run : A.CodeB.CodeResult) (post : NumericalValue A.ScalarNumericalValue B.ScalarResultProp) :

                A two-input executable operation satisfies a relation on complete input denotations.

                Instances For
                  def FloatLib.Numerics.Operation.Refines3 (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) {Result : Type u} (run : A.CodeB.CodeC.CodeResult) (post : NumericalValue A.ScalarNumericalValue B.ScalarNumericalValue C.ScalarResultProp) :

                  A three-input executable operation satisfies a relation on complete input denotations.

                  Instances For
                    def FloatLib.Numerics.Operation.RefinesFinite1 (A : NumericalSystem) {Result : Type u} (run : A.CodeResult) (post : A.ScalarResultProp) :

                    A unary executable operation satisfies a relation on represented finite inputs.

                    Instances For
                      def FloatLib.Numerics.Operation.RefinesFinite2 (A : NumericalSystem) (B : NumericalSystem) {Result : Type u} (run : A.CodeB.CodeResult) (post : A.ScalarB.ScalarResultProp) :

                      A two-input executable operation satisfies a relation on represented finite inputs.

                      Instances For
                        def FloatLib.Numerics.Operation.RefinesFinite3 (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) {Result : Type u} (run : A.CodeB.CodeC.CodeResult) (post : A.ScalarB.ScalarC.ScalarResultProp) :

                        A three-input executable operation satisfies a relation on represented finite inputs.

                        Instances For

                          Total, finite, checked, and quantizer semantics #

                          Correctness of a unary total operation, including exceptional values.

                          Instances For

                            Correctness of a two-input total operation, including exceptional values.

                            Instances For

                              Correctness of a three-input total operation, including exceptional values.

                              Instances For

                                Correctness of a unary operation on represented finite inputs.

                                Instances For
                                  def FloatLib.Numerics.Operation.Finite2 (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (run : A.CodeB.CodeC.Code) (spec : A.ScalarB.ScalarC.Scalar) :

                                  Correctness of a two-input operation on represented finite inputs.

                                  Instances For
                                    def FloatLib.Numerics.Operation.Finite3 (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (D : NumericalSystem) (run : A.CodeB.CodeC.CodeD.Code) (spec : A.ScalarB.ScalarC.ScalarD.Scalar) :

                                    Correctness of a three-input operation on represented finite inputs.

                                    Instances For
                                      def FloatLib.Numerics.Operation.Finite1If (A : NumericalSystem) (B : NumericalSystem) (run : A.CodeB.Code) (spec : A.ScalarB.Scalar) (accept : A.CodeB.CodeProp) :

                                      Correctness of a unary operation when a predicate on the concrete input and result holds.

                                      The predicate captures executable side conditions such as a floating-point result remaining finite. It is proof-only and does not change the direct runtime function.

                                      Instances For
                                        def FloatLib.Numerics.Operation.Finite2If (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (run : A.CodeB.CodeC.Code) (spec : A.ScalarB.ScalarC.Scalar) (accept : A.CodeB.CodeC.CodeProp) :

                                        Correctness of a two-input operation when a predicate on its concrete inputs and result holds.

                                        Instances For
                                          def FloatLib.Numerics.Operation.Finite3If (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (D : NumericalSystem) (run : A.CodeB.CodeC.CodeD.Code) (spec : A.ScalarB.ScalarC.ScalarD.Scalar) (accept : A.CodeB.CodeC.CodeD.CodeProp) :

                                          Correctness of a three-input operation when a predicate on its concrete inputs and result holds.

                                          Instances For

                                            Correctness of a checked unary operation on represented finite inputs.

                                            Instances For

                                              Correctness of a checked two-input operation on represented finite inputs.

                                              Instances For

                                                Correctness of a checked three-input operation on represented finite inputs.

                                                Instances For

                                                  A checked unary operation is correct whenever its scalar precondition holds.

                                                  Instances For
                                                    def FloatLib.Numerics.Operation.Checked2On (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (run : A.CodeB.CodeOption C.Code) (spec : A.ScalarB.ScalarNumericalValue C.Scalar) (pre : A.ScalarB.ScalarProp) :

                                                    A checked two-input operation is correct whenever its scalar precondition holds.

                                                    Instances For
                                                      def FloatLib.Numerics.Operation.Checked3On (A : NumericalSystem) (B : NumericalSystem) (C : NumericalSystem) (D : NumericalSystem) (run : A.CodeB.CodeC.CodeOption D.Code) (spec : A.ScalarB.ScalarC.ScalarNumericalValue D.Scalar) (pre : A.ScalarB.ScalarC.ScalarProp) :

                                                      A checked three-input operation is correct whenever its scalar precondition holds.

                                                      Instances For
                                                        def FloatLib.Numerics.Operation.CastFiniteOn (A : NumericalSystem) (B : NumericalSystem) (run : A.CodeB.Code) (embed : A.ScalarB.Scalar) (pre : A.ScalarProp) :

                                                        A conversion implements embed on every represented value accepted by pre.

                                                        Instances For
                                                          def FloatLib.Numerics.Operation.QuantizerOn (S : NumericalSystem) (quantize : S.ScalarS.Code) (round : S.ScalarS.Scalar) (pre : S.ScalarProp) :

                                                          A quantizer implements a named rounding map on values satisfying pre.

                                                          Instances For