<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc [
  <!ENTITY nbsp "&#160;">
]>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     category="exp"
     docName="draft-dutta-gcmf-01"
     ipr="trust200902"
     obsoletes="" updates="" submissionType="independent"
     xml:lang="en" version="3">

  <front>
    <title abbrev="GCMF">General-Purpose Compression via Mathematical Functions (GCMF)</title>

    <author fullname="Srijal Dutta" initials="S." surname="Dutta">
      <organization>The ZSMC Co.</organization>
      <address>
        <postal>
          <city>Gurugram</city>
          <region>Haryana</region>
          <country>India</country>
        </postal>
        <email>srijal@thezsmc.co</email>
      </address>
    </author>

    <date year="2026" month="August" day="29"/>

    <area>Independent Submission</area>
    <workgroup>Independent Research</workgroup>

    <keyword>compression</keyword>
    <keyword>lossless</keyword>
    <keyword>mathematical functions</keyword>
    <keyword>binary format</keyword>

    <abstract>
      <t>
        This document specifies General-Purpose Compression via Mathematical
        Functions (GCMF), a lossless compression format that represents
        sequences of data using mathematical functions and associated
        parameters.
      </t>
      <t>
        GCMF attempts to represent a sequence using a compact mathematical
        representation rather than storing every value explicitly. This
        document defines the GCMF data format, function types, encoding
        rules, decoding procedure, and interoperability requirements.
      </t>
    </abstract>
  </front>

  <middle>

    <section anchor="intro" numbered="true" toc="default">
      <name>Introduction</name>
      <t>
        General-Purpose Compression via Mathematical Functions (GCMF) is a
        lossless compression method that represents data using mathematical
        functions.
      </t>
      <t>
        Instead of storing every value in a sequence explicitly, GCMF may
        store a function and a range over which the function can reproduce
        the original values.
      </t>
      <t>
        The objective of GCMF is to reduce the amount of information required
        to represent sequences that exhibit mathematical regularity, in the
        spirit of minimum-description-length approaches to modeling such as
        <xref target="J_RISSANEN_1978"/>.
      </t>
      <t>
        A GCMF encoder <bcp14>MUST</bcp14> evaluate a set of valid candidate
        representations supported by the implementation and
        <bcp14>SHOULD</bcp14> select the candidate having the minimum
        complete encoded length, as described in <xref target="model"/>.
      </t>

      <section anchor="terminology" numbered="true" toc="default">
        <name>Terminology</name>
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
          "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
          "OPTIONAL" in this document are to be interpreted as described in
          BCP&nbsp;14 <xref target="RFC2119"/> when, and only when, they
          appear in all capitals, as shown here.
        </t>
        <t>
          This document also uses "OPTIONAL" as a structural label within
          binary layout diagrams (<xref target="binfmt"/>) to mark a field
          that is absent under some, but not all, values of a preceding
          discriminant field (for example, a Function Address or a
          predefined-function identity). A field so marked is still
          mandatory whenever the applicable discriminant requires it;
          "OPTIONAL" in a diagram never means an implementation may omit the
          field at its own discretion. <xref target="filestruct"/> identifies,
          for each representation, which fields are conditional and on what.
        </t>
      </section>
    </section>

    <section anchor="mime" numbered="true" toc="default">
      <name>File Extension and MIME Type</name>
      <t>
        GCMF currently utilizes a working MIME type of
        <tt>application/gcmf</tt>. This is not an officially registered MIME
        type under <xref target="RFC2046"/>, or under any current standard
        or working group as of the publication of this document. It is
        intended only to identify the file type to adopting implementations.
      </t>
      <t>
        GCMF also currently utilizes a working file extension of
        <tt>.gcmf</tt>. Until formal registration occurs, this extension
        <bcp14>SHOULD</bcp14> be treated with the same significance as the
        MIME type above.
      </t>
    </section>

    <section anchor="model" numbered="true" toc="default">
      <name>Function Representation Model</name>
      <t>
        GCMF represents a numerical data sequence as the evaluation of a
        mathematical function over a finite domain, optionally augmented by
        a residual function. The original sequence <bcp14>MUST</bcp14> be:
      </t>
      <artwork><![CDATA[
D = d0, d1, ..., d(n-1)
]]></artwork>
      <t>
        A GCMF encoder <bcp14>MUST</bcp14> attempt to determine a function
        (f), a domain sequence (X = x0, x1, ..., x(n-1)), and
        <bcp14>MAY</bcp14> also determine a residual function. For a
        generalized representation:
      </t>
      <artwork><![CDATA[
d(i) = f(x(i))
]]></artwork>
      <t>For an exact representation:</t>
      <artwork><![CDATA[
d(i) = f(x(i)) + r(x(i))
]]></artwork>
      <t>
        The exact representation is therefore a special case of the
        generalized representation for which:
      </t>
      <artwork><![CDATA[
r(x) = 0
]]></artwork>
      <t>
        Let C be the theoretical set of all valid GCMF candidate
        representations, and let C_I be the subset of candidates that a
        particular implementation is capable of generating, where C_I is a
        subset of C. Because a real implementation can only search C_I, its
        encoder optimization objective is:
      </t>
      <artwork><![CDATA[
C*_I = arg min L(C), for C in C_I
]]></artwork>
      <t>
        where L(C) is the complete encoded length of candidate C in bytes,
        as defined in <xref target="sizecomp"/>.
      </t>
      <t>
        An implementation <bcp14>MAY</bcp14> use heuristic, statistical,
        symbolic, or other candidate-discovery methods. An implementation is
        not required to discover every mathematically valid representation;
        consequently an implementation is not required to find C*, the
        theoretical global optimum over C, and is only required to find
        C*_I, the best candidate it is able to construct.
      </t>
      <t>
        A candidate is considered compressive only when its complete
        encoded representation is smaller than the original input under the
        source-size comparison defined in <xref target="sizecomp"/>.
      </t>

      <section anchor="sizecomp" numbered="true" toc="default">
        <name>Source Size Comparison</name>
        <t>
          For the purpose of determining whether a GCMF representation is
          compressive, the original input is considered as a sequence of N
          bytes and has a source size of N bytes.
        </t>
        <t>A GCMF representation is compressive if and only if:</t>
        <artwork><![CDATA[
L(C) < N
]]></artwork>
        <t>
          where L(C) is the complete physical size of the GCMF
          representation in bytes.
        </t>
        <t>
          All GCMF structural overhead <bcp14>MUST</bcp14> be included in
          L(C), including magic numbers, version information, function
          addresses, parameters, domains, residual data, padding, and all
          other encoded fields.
        </t>
        <t>
          An implementation <bcp14>MUST NOT</bcp14> claim compression solely
          because the mathematical description of the data is shorter than
          the original data.
        </t>
      </section>
    </section>

    <section anchor="binfmt" numbered="true" toc="default">
      <name>GCMF Binary Format Specification</name>
      <t>
        This section defines the binary representation of GCMF. A
        conforming GCMF decoder <bcp14>MUST</bcp14> be capable of parsing
        all mandatory structure defined in this specification. Unless
        otherwise stated, all bit fields are packed from the
        most-significant bit to the least-significant bit.
      </t>
      <t>
        GCMF is a lossless representation format. A valid GCMF stream
        <bcp14>MUST</bcp14> decode to exactly the byte sequence represented
        by the encoded data.
      </t>
      <t>
        Every GCMF representation is one of exactly two kinds: a LITERAL
        representation (<xref target="literal"/>) or a mathematical
        representation (<xref target="customfn"/> through
        <xref target="residcont"/>). A mathematical representation is
        further one of exactly two kinds: a CUSTOM function representation,
        in which the function is defined inline by bytecode, or a
        PREDEFINED function representation, in which the function is
        identified by Function Address alone and looked up in the registry
        of <xref target="predef"/>. These branches are mutually exclusive:
        a single representation never contains both a CUSTOM bytecode body
        and a PREDEFINED parameter body, and never contains both a
        mathematical body and a LITERAL payload. The field tables in
        <xref target="customfn"/>, <xref target="predef"/>, and
        <xref target="literal"/> give the exact, non-overlapping field
        sequence for each of these three branches; the combined view in
        <xref target="canonlayout"/> shows them side by side for comparison
        only and is not itself a fourth, independent layout.
      </t>

      <section anchor="filestruct" numbered="true" toc="default">
        <name>File Structure</name>
        <t>
          A GCMF file consists of a fixed header followed by a
          representation-specific payload. The general structure is:
        </t>
        <artwork><![CDATA[
+--------------------------------+
| Magic                | 4 bytes |
+--------------------------------+
| Version               | 1 byte |
+--------------------------------+
| Function Address      | 5 bits |
+--------------------------------+
| Representation Data   | variable, see Sections 4.8, 4.9, 4.18 |
+--------------------------------+
| Physical EOF                   |
+--------------------------------+
]]></artwork>
        <t>
          The Function Address determines the interpretation of
          Representation Data. For mathematical representations,
          Representation Data consists of the function body (either inline
          CUSTOM bytecode or PREDEFINED parameters), X_start, X_end, BASE,
          and, when the residual flag is set, the residual representation.
          For LITERAL, Representation Data consists entirely of the
          original source bytes after the required alignment padding.
        </t>
        <t>
          Physical EOF is not encoded as a field or byte; it is the point
          at which the physical GCMF stream ends, and it terminates the
          final representation. There is exactly one Magic field and one
          Physical EOF per file: unlike some of the illustrative field
          tables later in this section, the file as a whole never repeats
          the Magic field or contains an in-band EOF marker (see
          <xref target="eof"/>).
        </t>
        <t>
          The exact fields present after the Function Address depend on
          the selected function type. The LITERAL function type is an
          exception and terminates the structured portion of the stream
          after three padding bits.
        </t>
      </section>

      <section anchor="magic" numbered="true" toc="default">
        <name>Magic Number</name>
        <t>
          Every GCMF file <bcp14>MUST</bcp14> begin with the following 4
          bytes: 0x47 0x43 0x4D 0x46. These bytes correspond to the ASCII
          string "GCMF". A decoder <bcp14>MUST</bcp14> reject a file whose
          first 4 bytes do not equal 0x47 0x43 0x4D 0x46.
        </t>
      </section>

      <section anchor="version" numbered="true" toc="default">
        <name>Version</name>
        <t>
          Immediately following the magic number is an 8-bit unsigned
          version field. The version number assigned to this publication is
          Version 0, written as 0x00.
        </t>
        <t>
          Future versions <bcp14>MAY</bcp14> use additional version values.
          A decoder encountering an unsupported version
          <bcp14>MUST NOT</bcp14> attempt to interpret the remainder of the
          stream according to an unsupported specification.
        </t>
      </section>

      <section anchor="funcaddr" numbered="true" toc="default">
        <name>Function Address</name>
        <t>The function address is a 5-bit field defined as:</t>
        <artwork><![CDATA[
+---+---------+
| 1 |    4    | BITS
+---+---------+
| R | A A A A |
+---+---------+
]]></artwork>
        <t>where R is the residual flag and AAAA is the function type address.</t>

        <section anchor="residflag" numbered="true" toc="default">
          <name>Residual Flag</name>
          <t>
            The most-significant bit <bcp14>MUST</bcp14> be the residual
            flag, where 0 indicates no residual function is present and 1
            indicates a residual function is present.
          </t>
          <t>
            If R = 1, the residual representation immediately follows the
            primary mathematical representation according to the residual
            encoding rules in <xref target="residrep"/>. R
            <bcp14>MUST</bcp14> be 0 for LITERAL (<xref target="literal"/>).
          </t>
        </section>

        <section anchor="functypeaddr" numbered="true" toc="default">
          <name>Function Type Address</name>
          <t>
            The four-bit function type address AAAA selects one of the
            sixteen function types listed in <xref target="tab-ftypes"/>.
            LITERAL with the residual flag set (address 10001) is reserved
            and <bcp14>MUST</bcp14> be rejected by a conforming decoder
            unless a future GCMF version explicitly defines semantics for
            it.
          </t>
        </section>
      </section>

      <section anchor="bitpack" numbered="true" toc="default">
        <name>Bit Packing</name>
        <t>
          The Function Address occupies exactly five bits and
          <bcp14>MUST NOT</bcp14> automatically consume a complete byte.
        </t>
        <t>
          The bit immediately following the Function Address is the first
          bit of the next field unless alignment is explicitly required by
          the representation.
        </t>
        <t>
          GCMF-VLI units <bcp14>MAY</bcp14> begin at any bit offset within a
          bit-packed structure. Implementations <bcp14>MUST</bcp14>
          therefore provide a bit-level reader and writer for structured
          GCMF fields.
        </t>
        <t>
          Where a field is explicitly required to be byte-aligned,
          zero-valued padding bits <bcp14>MUST</bcp14> be inserted before
          that field. Padding bits <bcp14>MUST NOT</bcp14> be interpreted as
          data and <bcp14>MUST</bcp14> be zero.
        </t>
        <t>
          Unless explicitly specified otherwise, no implicit alignment is
          performed.
        </t>
      </section>

      <section anchor="vli" numbered="true" toc="default">
        <name>Variable Length Integer Encoding</name>
        <t>
          GCMF uses a variable-length integer representation called
          GCMF-VLI. Each encoded unit contains:
        </t>
        <artwork><![CDATA[
+---+-------+
| 1 |   7   | BITS
+---+-------+
| C | VALUE |
+---+-------+
]]></artwork>
        <t>
          where C = 1 indicates that another VLI unit follows, C = 0
          indicates the final VLI unit, and VALUE contains 7 bits of the
          integer.
        </t>
        <t>
          The first unit contains the most significant portion of the
          value. Therefore, GCMF-VLI is a big-endian base-128
          representation.
        </t>
        <t>
          A decoder <bcp14>MUST</bcp14> continue reading VLI units until a
          unit with C=0 is encountered. A VLI <bcp14>MUST NOT</bcp14>
          contain unnecessary leading zero payload groups.
        </t>
      </section>

      <section anchor="zigzag" numbered="true" toc="default">
        <name>Signed Integer Encoding</name>
        <t>
          Where a mathematical parameter may be negative, GCMF uses ZigZag
          encoding before GCMF-VLI encoding. For a signed integer n:
        </t>
        <artwork><![CDATA[
Z(n) = 2n,        n >= 0
Z(n) = -2n - 1,   n < 0
]]></artwork>
        <t>
          The resulting non-negative integer is then encoded using
          GCMF-VLI. This allows small negative and positive values to have
          similarly compact representations.
        </t>
      </section>

      <section anchor="customfn" numbered="true" toc="default">
        <name>CUSTOM Function</name>
        <t>A CUSTOM function has Function Type Address:</t>
        <artwork><![CDATA[
0000
]]></artwork>
        <t>or, when residual data is present:</t>
        <artwork><![CDATA[
10000
]]></artwork>
        <t>
          A CUSTOM representation always carries an inline function body;
          the Function Length and Function Bytecode fields below are
          therefore mandatory whenever Function Address selects CUSTOM, and
          are never present under any other function type. The structure
          is:
        </t>
        <artwork><![CDATA[
+--------------------------------------------------------------+
| Magic                | 4 bytes (0x47434D46)                  |
+--------------------------------------------------------------+
| Version               | 1 byte (0x00)                        |
+--------------------------------------------------------------+
| Function Address      | 5 bits                                |
+--------------------------------------------------------------+
| Function Length       | variable VLI                         |
+--------------------------------------------------------------+
| Function Bytecode     | Function Length bits                 |
+--------------------------------------------------------------+
| X_start               | variable VLI                         |
+--------------------------------------------------------------+
| X_end                 | variable VLI                         |
+--------------------------------------------------------------+
| Base                  | variable VLI                         |
+--------------------------------------------------------------+
| [Residual]            | present iff R = 1, see Section 4.17  |
+--------------------------------------------------------------+
]]></artwork>
        <t>
          Physical EOF follows the final field; per <xref target="eof"/> no
          additional Magic or EOF field is encoded at the end of the
          representation.
        </t>
        <t>
          The Function Length specifies the number of bits occupied by the
          function bytecode, including opcode bits, operand bits, and the
          END instruction.
        </t>
        <t>
          The Function Length <bcp14>MUST</bcp14> be sufficient to contain
          a complete bytecode sequence ending in an END instruction.
        </t>
        <t>
          The decoder <bcp14>MUST NOT</bcp14> read beyond the declared
          function length while executing the function.
        </t>
        <t>
          Any unused bits between the final END instruction and the
          declared function boundary <bcp14>MUST</bcp14> be zero. A
          canonical encoder <bcp14>SHOULD</bcp14> emit no unused bits after
          END.
        </t>
        <t>
          The function bytecode <bcp14>MUST</bcp14> contain a valid END
          instruction within the specified function length.
        </t>
      </section>

      <section anchor="predef" numbered="true" toc="default">
        <name>Predefined Functions</name>
        <t>
          A predefined function does not contain its mathematical
          definition in the file. The Function Address identifies the
          mathematical function through the GCMF predefined-function
          registry. The decoder obtains the function definition from the
          version-specific registry.
        </t>
        <t>
          A predefined representation never carries a Function Length or
          Function Bytecode field; those fields are exclusive to CUSTOM
          (<xref target="customfn"/>). Depending on which predefined
          function is selected, the Function Parameters field itself may
          be empty: <xref target="predefparams"/> defines five predefined
          functions (FIBONACCI, FACTORIAL, TRIANGULAR, SQUARE, CUBE) that
          take no parameters, in which case this field is zero-length and
          X_start immediately follows the Function Address. A predefined
          function therefore has the general structure:
        </t>
        <artwork><![CDATA[
+--------------------------------------------------------------+
| Magic                | 4 bytes (0x47434D46)                  |
+--------------------------------------------------------------+
| Version               | 1 byte (0x00)                        |
+--------------------------------------------------------------+
| Function Address      | 5 bits                                |
+--------------------------------------------------------------+
| [Function Parameters] | OPTIONAL, variable -- empty for the   |
|                        | zero-parameter functions listed      |
|                        | above, otherwise per Section 4.9.1   |
+--------------------------------------------------------------+
| X_start               | variable VLI                         |
+--------------------------------------------------------------+
| X_end                 | variable VLI                         |
+--------------------------------------------------------------+
| Base                  | variable VLI                         |
+--------------------------------------------------------------+
| [Residual]            | present iff R = 1, see Section 4.17  |
+--------------------------------------------------------------+
]]></artwork>
        <t>
          Physical EOF follows the final field; per <xref target="eof"/> no
          additional Magic or EOF field is encoded at the end of the
          representation.
        </t>
        <t>
          Each predefined function <bcp14>MUST</bcp14> have a precisely
          defined parameter encoding.
        </t>

        <section anchor="predefparams" numbered="true" toc="default">
          <name>Predefined Function Parameter Encoding</name>
          <t>
            Unless otherwise specified, all integer parameters of
            predefined functions are encoded using GCMF-VLI. Parameters
            that may be negative <bcp14>MUST</bcp14> use ZigZag encoding
            before GCMF-VLI encoding.
          </t>
          <t>The predefined functions use the following parameter encodings:</t>
          <artwork><![CDATA[
CONSTANT:     c
LINEAR:       a, b
ARITHMETIC:   a, d
GEOMETRIC:    a, r
POLYNOMIAL:   n, a0, a1, ..., an
EXPONENTIAL:  a, b
LOGARITHMIC:  a, b, c
POWER:        a, b, c
MODULAR:      G(x), m
FIBONACCI:    no parameters
FACTORIAL:    no parameters
TRIANGULAR:   no parameters
SQUARE:       no parameters
CUBE:         no parameters
]]></artwork>
          <t>
            For MODULAR, G(x) is a mathematical function defined by a
            nested GCMF function representation and m is a positive integer
            modulus. The nested function G(x) <bcp14>MUST</bcp14> be
            encoded using the same function representation rules defined by
            this specification, excluding residual encoding.
          </t>
          <t>
            The modulus m <bcp14>MUST</bcp14> be encoded as an unsigned
            GCMF-VLI integer and <bcp14>MUST</bcp14> satisfy m &gt;= 1.
          </t>
          <t>
            For every domain value x, the decoder first evaluates G(x) and
            then computes:
          </t>
          <artwork><![CDATA[
F(x) = G(x) mod m
]]></artwork>
          <t>
            The result of the modulo operation <bcp14>MUST</bcp14> be the
            unique integer r satisfying 0 &lt;= r &lt; m, where
            G(x) = qm + r for some integer q.
          </t>
          <t>
            The MODULAR function <bcp14>MUST NOT</bcp14> contain a residual
            representation within its nested G(x) function. Recursive
            MODULAR functions <bcp14>MAY</bcp14> be permitted, provided
            that the implementation-defined maximum nesting depth is not
            exceeded.
          </t>
          <t>
            A decoder <bcp14>MUST</bcp14> reject a MODULAR representation
            if G(x) is invalid, m is zero, or evaluation of G(x) produces a
            value outside the supported numerical domain.
          </t>
          <t>
            All parameters <bcp14>MUST</bcp14> appear in the order
            specified above. A decoder <bcp14>MUST</bcp14> reject a
            representation containing missing, malformed, or unexpected
            parameter data.
          </t>
        </section>
      </section>

      <section anchor="bytecode" numbered="true" toc="default">
        <name>Function Bytecode</name>
        <t>
          GCMF mathematical functions use a stack-based bytecode. Each
          opcode occupies exactly five bits.
        </t>
        <t>
          The opcode is immediately followed by its operand, if the opcode
          requires one. No implicit byte alignment is performed between an
          opcode and its operand.
        </t>
        <t>
          For CONST, the operand is a signed GCMF-VLI value. For
          instructions that do not require an operand, no operand bits are
          present.
        </t>
        <t>
          The Function Length counts every bit occupied by the bytecode,
          including five-bit opcodes and all operand bits. A decoder
          <bcp14>MUST NOT</bcp14> read beyond the declared Function Length
          while decoding instructions.
        </t>
        <t>
          The bytecode <bcp14>MUST</bcp14> contain exactly one terminating
          END instruction as its logical terminator. A canonical bytecode
          representation <bcp14>MUST NOT</bcp14> contain instructions after
          END.
        </t>
        <t>
          Because opcodes are bit-packed, an operand begins at the bit
          immediately following the opcode.
        </t>
      </section>

      <section anchor="stackmachine" numbered="true" toc="default">
        <name>Stack Machine Requirements</name>
        <t>
          A custom function is evaluated independently for every value of
          x. Before evaluating a new x, the evaluation stack
          <bcp14>MUST</bcp14> be empty. Each instruction operates on the
          stack.
        </t>
        <t>For binary operators: [a, b] becomes [a OP b].</t>
        <t>For unary operators: [a] becomes [OP(a)].</t>
        <t>DUP transforms: [a] becomes [a, a].</t>
        <t>X pushes the current domain value.</t>
        <t>CONST pushes its encoded constant.</t>
        <t>END terminates execution.</t>
        <t>
          At END, the stack <bcp14>MUST</bcp14> contain exactly one value.
          That value is the output of the function.
        </t>
        <t>
          A function that underflows the stack; executes an invalid
          operation; reaches the declared function boundary without END;
          contains an invalid operand; or terminates with anything other
          than exactly one stack value <bcp14>MUST</bcp14> be considered
          invalid.
        </t>

        <section anchor="numeval" numbered="true" toc="default">
          <name>Numerical Evaluation</name>
          <t>
            GCMF v1 mathematical evaluation <bcp14>MUST</bcp14> use exact
            integer arithmetic unless a specific operation is explicitly
            defined to use another numerical domain.
          </t>
          <t>
            An operation whose mathematical result is undefined within the
            applicable numerical domain <bcp14>MUST</bcp14> cause decoding
            to fail. Examples include division by zero, logarithms outside
            their valid domain, square roots of invalid values, and other
            undefined operations.
          </t>
          <t>
            A decoder <bcp14>MUST</bcp14> reject a representation if
            evaluation produces a value that cannot be represented by the
            numerical domain defined for the representation.
          </t>
          <t>
            Implementations <bcp14>MUST NOT</bcp14> silently round,
            truncate, saturate, wrap, or otherwise alter a mathematical
            result unless such behavior is explicitly defined by the
            applicable GCMF version.
          </t>
          <t>
            All conforming implementations of the same GCMF version
            <bcp14>MUST</bcp14> produce the same mathematical result for
            the same valid input.
          </t>
        </section>
      </section>

      <section anchor="customex" numbered="true" toc="default">
        <name>Example Custom Function</name>
        <t>The function f(x) = 3x + 10 can be represented as:</t>
        <artwork><![CDATA[
CONST 3 X MUL CONST 10 ADD END
]]></artwork>
        <t>The logical execution is:</t>
        <artwork><![CDATA[
CONST 3   -> [3]
X         -> [3, x]
MUL       -> [3x]
CONST 10  -> [3x, 10]
ADD       -> [3x + 10]
END       -> result
]]></artwork>
      </section>

      <section anchor="xstartend" numbered="true" toc="default">
        <name>X_start and X_end</name>
        <t>
          For all non-LITERAL representations, the domain is specified
          using two unsigned GCMF-VLI fields:
        </t>
        <artwork><![CDATA[
+----------------+
| X_START        | GCMF-VLI
+----------------+
| X_END          | GCMF-VLI
+----------------+
]]></artwork>
        <t>
          X_start and X_end <bcp14>MUST</bcp14> be non-negative integers.
          The default domain is the integer sequence:
        </t>
        <artwork><![CDATA[
X = X_start, X_start + 1, ..., X_end
]]></artwork>
        <t>The number of generated values is:</t>
        <artwork><![CDATA[
N = X_end - X_start + 1
]]></artwork>
        <t>
          X_end <bcp14>MUST</bcp14> be greater than or equal to X_start. A
          decoder <bcp14>MUST</bcp14> reject a representation whose domain
          would require an invalid, negative, or implementation-prohibited
          number of values.
        </t>
        <t>
          The number of generated values <bcp14>MUST</bcp14> also be
          consistent with the number of source values represented by the
          GCMF stream.
        </t>
      </section>

      <section anchor="baseenc" numbered="true" toc="default">
        <name>Base Encoding</name>
        <t>
          The BASE field specifies the numerical radix associated with the
          domain representation. BASE is encoded as an unsigned GCMF-VLI
          integer. The base <bcp14>MUST</bcp14> be greater than or equal
          to 2.
        </t>
        <t>
          A conforming implementation <bcp14>SHOULD</bcp14> support at
          least bases 2 through 36.
        </t>
        <t>
          The BASE field does not alter the binary encoding of GCMF-VLI
          values, function opcodes, function bytecode, or other binary
          fields.
        </t>
      </section>

      <section anchor="baseinterp" numbered="true" toc="default">
        <name>Base Interpretation</name>
        <t>
          BASE specifies the radix used for the interpretation of X_start
          and X_end when a representation requires base-dependent numerical
          interpretation.
        </t>
        <t>
          The mathematical values represented by X_start and X_end are
          independent of the selected radix. For example, a domain value of
          decimal 16 has the same mathematical value regardless of whether
          BASE is 10 or 16.
        </t>
        <t>
          BASE therefore <bcp14>MUST NOT</bcp14> change the numerical value
          of X_start or X_end.
        </t>
        <t>
          An encoder <bcp14>MAY</bcp14> evaluate multiple BASE values when
          selecting a representation if the selected base affects the
          representation length of the domain under the encoding rules
          defined by this specification.
        </t>
        <t>
          If BASE does not affect the encoded length or interpretation of
          a candidate, changing BASE <bcp14>MUST NOT</bcp14> be used as a
          basis for selecting that candidate.
        </t>
      </section>

      <section anchor="residrep" numbered="true" toc="default">
        <name>Residual Representation</name>
        <t>
          If the Residual Flag is 1, a residual representation follows the
          primary function representation. The residual represents the
          difference between the original datum and the primary
          mathematical output. For every value:
        </t>
        <artwork><![CDATA[
r(i) = d(i) - f(x(i))
]]></artwork>
        <t>The original datum is reconstructed using:</t>
        <artwork><![CDATA[
d(i) = f(x(i)) + r(i)
]]></artwork>
        <t>
          The residual representation <bcp14>MUST</bcp14> itself be
          encoded using a valid GCMF function representation. Therefore a
          residual <bcp14>MAY</bcp14> be a predefined function or a custom
          function, subject to the restrictions imposed by this version of
          GCMF (see <xref target="residcont"/>, which prohibits a residual
          from itself carrying a further nested residual).
        </t>
        <t>
          The residual representation does not independently require a
          second Function Address byte; it uses the four-bit Residual
          Function Type defined in <xref target="residcont"/> instead.
        </t>
      </section>

      <section anchor="residcont" numbered="true" toc="default">
        <name>Residual Function Container</name>
        <t>
          When R = 1, the residual representation immediately follows the
          complete primary mathematical representation. The residual
          section is encoded as:
        </t>
        <artwork><![CDATA[
+----------------------------------------------------------+
| Residual Function Type | 4 bits                          |
+----------------------------------------------------------+
| Residual Function Data | variable, mandatory -- see below |
+----------------------------------------------------------+
]]></artwork>
        <t>
          The Residual Function Type uses the same function-type address
          table as the primary function (<xref target="tab-ftypes"/>),
          excluding the residual flag. The residual function therefore
          contains exactly four function-type bits, and Residual Function
          Data is always present: a custom residual's data is its Function
          Length and Function Bytecode, and a predefined residual's data is
          its parameter fields, which may be zero-length for the
          parameterless functions of <xref target="predefparams"/> but the
          field itself is never omitted outright.
        </t>
        <t>
          For a custom residual, 0000 is used as the Residual Function
          Type. A custom residual <bcp14>MUST</bcp14> contain its Function
          Length followed by its Function Bytecode according to the CUSTOM
          function encoding rules.
        </t>
        <t>
          A predefined residual <bcp14>MUST</bcp14> contain the parameter
          fields specified for its function type.
        </t>
        <t>
          The Residual Function Type <bcp14>MUST NOT</bcp14> encode LITERAL
          (0001): a residual is always a mathematical representation, never
          a literal payload.
        </t>
        <t>
          The residual function <bcp14>MUST NOT</bcp14> contain a residual
          flag and <bcp14>MUST NOT</bcp14> contain another residual
          representation. Recursive residual nesting is therefore
          prohibited in GCMF v1.
        </t>
        <t>
          The residual representation <bcp14>MUST</bcp14> generate exactly
          the same number of values as the primary representation.
        </t>
      </section>

      <section anchor="literal" numbered="true" toc="default">
        <name>Literal</name>
        <t>The LITERAL function has Function Type Address:</t>
        <artwork><![CDATA[
0001
]]></artwork>
        <t>
          and <bcp14>MUST NOT</bcp14> have the Residual Flag set. Its
          complete Function Address is therefore:
        </t>
        <artwork><![CDATA[
00001
]]></artwork>
        <t>
          LITERAL is a terminal representation. Immediately following the
          Function Address, the decoder <bcp14>MUST</bcp14> consume three
          zero-valued padding bits. These three padding bits align the
          stream to the next byte boundary. The remainder of the GCMF
          stream is then interpreted as raw source bytes.
        </t>
        <artwork><![CDATA[
+--------------------------+
| Magic                    |
+--------------------------+
| Version                  |
+--------------------------+
| Function Address         |
+--------------------------+
| Zero padding (3 bits)    |
+--------------------------+
| Raw source bytes         |
+--------------------------+
| Physical EOF             |
+--------------------------+
]]></artwork>
        <t>
          No function length is stored. No X_start is stored. No X_end is
          stored. No BASE field is stored. No residual representation is
          stored. There is no trailing Magic field or in-band EOF field;
          per <xref target="eof"/>, the physical end of the stream is the
          only termination condition.
        </t>
        <t>
          The decoder <bcp14>MUST</bcp14> copy the literal payload directly
          to the output without interpretation or transformation.
        </t>
      </section>

      <section anchor="eof" numbered="true" toc="default">
        <name>Physical End Of File</name>
        <t>
          The physical end of the GCMF file is the termination condition
          for the final field. No EOF byte or other in-band EOF marker is
          defined by GCMF, and the Magic field defined in
          <xref target="magic"/> is never repeated within a representation.
        </t>
        <t>
          This is particularly important for LITERAL, because every byte
          value from 0x00 through 0xFF is valid source data. Consequently,
          no byte value <bcp14>MAY</bcp14> be reserved as an EOF marker.
        </t>
        <t>
          For LITERAL, EOF is the physical end of the GCMF stream. The
          final byte of the file is therefore the final literal source
          byte.
        </t>
        <t>
          A transport or container system embedding GCMF
          <bcp14>MUST</bcp14> preserve the exact file length.
        </t>
      </section>

      <section anchor="canonlayout" numbered="true" toc="default">
        <name>Complete Canonical Layout</name>
        <t>
          This section restates, side by side and for reference only, the
          three mutually exclusive field sequences already given in full
          and without ambiguity in <xref target="customfn"/> (CUSTOM),
          <xref target="predef"/> (PREDEFINED), and
          <xref target="literal"/> (LITERAL). A single GCMF representation
          always matches exactly one of these three sequences; the
          bracketed items below are conditional exactly as specified in the
          section cited, not independently optional.
        </t>
        <t>CUSTOM mathematical representation (<xref target="customfn"/>):</t>
        <artwork><![CDATA[
GCMF
VERSION
FUNCTION ADDRESS
FUNCTION LENGTH
FUNCTION BYTECODE
X_START
X_END
BASE
[RESIDUAL FUNCTION TYPE, RESIDUAL FUNCTION DATA]   -- iff R = 1
EOF
]]></artwork>
        <t>PREDEFINED mathematical representation (<xref target="predef"/>):</t>
        <artwork><![CDATA[
GCMF
VERSION
FUNCTION ADDRESS
[FUNCTION PARAMETERS]   -- zero-length for the parameterless
                           functions listed in Section 4.9.1
X_START
X_END
BASE
[RESIDUAL FUNCTION TYPE, RESIDUAL FUNCTION DATA]   -- iff R = 1
EOF
]]></artwork>
        <t>LITERAL representation (<xref target="literal"/>):</t>
        <artwork><![CDATA[
GCMF
VERSION
00001
ZERO PADDING (3 BITS)
RAW DATA
EOF
]]></artwork>
      </section>

      <section anchor="encex" numbered="true" toc="default">
        <name>Encoding Example</name>
        <t>Consider the sequence:</t>
        <artwork><![CDATA[
10, 13, 16, 19, 22, 25
]]></artwork>
        <t>
          It can be represented by the linear function f(x) = 3x + 10 over
          the domain X = 0, 1, 2, 3, 4, 5. This is a PREDEFINED
          representation (LINEAR), so it follows the PREDEFINED field
          sequence of <xref target="predef"/> with Function Parameters =
          (a=3, b=10) and no residual. The logical GCMF representation is
          therefore:
        </t>
        <artwork><![CDATA[
MAGIC
VERSION
FUNCTION ADDRESS = LINEAR, R = 0
a = 3
b = 10
X_START = 0
X_END = 5
BASE
PHYSICAL EOF
]]></artwork>
        <t>The decoder evaluates:</t>
        <artwork><![CDATA[
f(0) = 10
f(1) = 13
f(2) = 16
f(3) = 19
f(4) = 22
f(5) = 25
]]></artwork>
        <t>The resulting sequence exactly reproduces the source sequence.</t>
      </section>

      <section anchor="encsel" numbered="true" toc="default">
        <name>Encoder Selection Algorithm</name>
        <t>
          The encoder <bcp14>SHOULD</bcp14> construct multiple candidate
          representations. Candidates <bcp14>MAY</bcp14> differ in function
          type, function parameters, custom bytecode, domain, numerical
          base, or residual representation.
        </t>
        <t>
          For every candidate C, the encoder computes L(C), the total
          encoded length in bytes. The encoder selects:
        </t>
        <artwork><![CDATA[
C* = arg min L(C)
]]></artwork>
        <t>
          The encoder <bcp14>MUST</bcp14> include all structural overhead
          in this calculation. Therefore the cost of a candidate includes
          magic, version, function address, function length where
          applicable, function bytecode, parameters, domain, base, residual
          data, and any required alignment.
        </t>
        <t>
          The encoder <bcp14>MUST NOT</bcp14> select a mathematical
          representation merely because the function itself is shorter.
        </t>
      </section>

      <section anchor="litsel" numbered="true" toc="default">
        <name>Literal Selection</name>
        <t>
          The encoder <bcp14>MUST</bcp14> be permitted to select LITERAL
          when no mathematical representation provides sufficient
          compression.
        </t>
        <t>
          The encoder <bcp14>SHOULD</bcp14> compare the best mathematical
          candidate against the LITERAL representation:
        </t>
        <artwork><![CDATA[
arg min (L(C_best_math), L(C_literal))
]]></artwork>
        <t>
          This prevents the creation of deliberately inflated mathematical
          representations for incompressible data.
        </t>
      </section>

      <section anchor="decsm" numbered="true" toc="default">
        <name>Decoder State Machine</name>
        <t>A conforming decoder can conceptually operate as follows:</t>
        <artwork><![CDATA[
START
  |
  v
READ MAGIC
  |
  v
READ VERSION
  |
  v
READ FUNCTION ADDRESS
  |
  +-----> LITERAL --> SKIP 3 PADDING BITS --> COPY REMAINDER --> END
  |
  v
[not LITERAL]
  |
  v
READ FUNCTION (CUSTOM: length + bytecode; PREDEFINED: parameters)
  |
  v
READ X_start
  |
  v
READ X_end
  |
  v
READ BASE
  |
  +-----> R = 0 -----> EVALUATE -----> END
  |
  +-----> R = 1 -----> READ RESIDUAL
                          |
                          v
                     EVALUATE RESIDUAL
                          |
                          v
                     RECONSTRUCT
                          |
                          v
                         END
]]></artwork>
      </section>

      <section anchor="decval" numbered="true" toc="default">
        <name>Decoder Validation</name>
        <t>
          A decoder <bcp14>MUST</bcp14> reject a GCMF stream if any of the
          following occurs:
        </t>
        <ul spacing="normal">
          <li>The magic number is invalid.</li>
          <li>The version is unsupported.</li>
          <li>
            The Function Address is invalid, including LITERAL with the
            residual flag set (<xref target="functypeaddr"/>).
          </li>
          <li>A required VLI is truncated.</li>
          <li>A VLI is malformed.</li>
          <li>A custom function exceeds its declared length.</li>
          <li>A custom function lacks a valid END.</li>
          <li>A function causes stack underflow.</li>
          <li>A function terminates with an invalid stack state.</li>
          <li>X_end is less than X_start.</li>
          <li>BASE is less than 2.</li>
          <li>A required function parameter is missing.</li>
          <li>
            A residual representation is malformed, including a Residual
            Function Type of LITERAL (<xref target="residcont"/>).
          </li>
          <li>A prohibited recursive residual is encountered.</li>
          <li>
            The mathematical evaluation produces a value that cannot be
            represented by the selected numerical representation.
          </li>
          <li>The stream terminates before all mandatory fields are read.</li>
        </ul>
        <t>
          A decoder <bcp14>SHOULD</bcp14> also impose implementation-defined
          limits on:
        </t>
        <ul spacing="normal">
          <li>maximum function length;</li>
          <li>maximum domain size;</li>
          <li>maximum stack depth;</li>
          <li>maximum numerical magnitude;</li>
          <li>maximum execution time.</li>
        </ul>
        <t>
          Such limits are important because GCMF functions are executable
          mathematical expressions and should not be permitted to consume
          unbounded computational resources.
        </t>
      </section>

      <section anchor="canonenc" numbered="true" toc="default">
        <name>Canonical Encoding</name>
        <t>
          A GCMF encoder <bcp14>SHOULD</bcp14> produce canonical encodings.
          A canonical representation <bcp14>MUST</bcp14>:
        </t>
        <ul spacing="normal">
          <li>use the shortest valid GCMF-VLI representation;</li>
          <li>avoid unnecessary leading VLI groups;</li>
          <li>use the minimum required function length;</li>
          <li>terminate bytecode with exactly one END;</li>
          <li>avoid unnecessary residual representations;</li>
          <li>avoid unnecessary domain extension;</li>
          <li>avoid unnecessary padding;</li>
          <li>
            select the smallest valid complete representation when
            deterministic encoding is required.
          </li>
        </ul>
        <t>
          Canonicalization permits byte-for-byte comparison of equivalent
          GCMF representations.
        </t>
      </section>

      <section anchor="versioning" numbered="true" toc="default">
        <name>Versioning</name>
        <t>
          The version byte identifies the binary interpretation rules. A
          future version <bcp14>MAY</bcp14>:
        </t>
        <ul spacing="normal">
          <li>add predefined functions;</li>
          <li>add bytecode instructions;</li>
          <li>modify residual semantics;</li>
          <li>add new representation modes;</li>
          <li>define previously reserved fields.</li>
        </ul>
        <t>
          Existing function addresses <bcp14>MUST NOT</bcp14> be silently
          reassigned within a compatible version. A new incompatible
          interpretation <bcp14>MUST</bcp14> use a new version number.
        </t>
      </section>

      <section anchor="reserved" numbered="true" toc="default">
        <name>Reserved Space</name>
        <t>
          The initial GCMF function address space has no unused
          base-function address because all 16 four-bit values are
          assigned. Future extensions <bcp14>SHOULD</bcp14> therefore use
          one of the following mechanisms:
        </t>
        <ul spacing="normal">
          <li>a new GCMF version;</li>
          <li>extension instructions;</li>
          <li>additional extension containers;</li>
          <li>
            a future extension mechanism explicitly defined by the
            specification.
          </li>
        </ul>
        <t>
          The five-bit address space itself <bcp14>MUST NOT</bcp14> be
          silently expanded within GCMF v1. The bytecode instruction space
          is similarly fully allocated.
        </t>
      </section>

      <section anchor="lossless" numbered="true" toc="default">
        <name>Losslessness Requirement</name>
        <t>
          For every valid GCMF representation G, decoding
          <bcp14>MUST</bcp14> satisfy:
        </t>
        <artwork><![CDATA[
Decode(G) = D
]]></artwork>
        <t>
          where D is the exact original input byte sequence. For
          mathematical representations:
        </t>
        <artwork><![CDATA[
d(i) = f(x(i)) + r(x(i))
]]></artwork>
        <t>For exact mathematical representations, r(x(i)) = 0. For LITERAL:</t>
        <artwork><![CDATA[
Decode(G) = LiteralPayload(G)
]]></artwork>
        <t>
          No rounding, approximation, or numerical loss is permitted unless
          explicitly introduced by a future GCMF version.
        </t>
      </section>

      <section anchor="grammar" numbered="true" toc="default">
        <name>Summary of Binary Grammar</name>
        <t>The logical grammar of GCMF v1 is:</t>
        <artwork><![CDATA[
GCMF_FILE :=
    MAGIC
    VERSION
    FUNCTION_ADDRESS
    REPRESENTATION

REPRESENTATION :=
      LITERAL_REPRESENTATION
    | MATHEMATICAL_REPRESENTATION

LITERAL_REPRESENTATION :=
    LITERAL_FUNCTION_ADDRESS
    ZERO_PADDING_3_BITS
    RAW_BYTES

MATHEMATICAL_REPRESENTATION :=
    FUNCTION
    X_START
    X_END
    BASE
    [RESIDUAL]

FUNCTION :=
      CUSTOM_FUNCTION
    | PREDEFINED_FUNCTION

CUSTOM_FUNCTION :=
    FUNCTION_LENGTH
    FUNCTION_BYTECODE

PREDEFINED_FUNCTION :=
    [FUNCTION_PARAMETERS]

RESIDUAL :=
    RESIDUAL_FUNCTION_TYPE
    RESIDUAL_FUNCTION_DATA

RESIDUAL_FUNCTION_DATA :=
      CUSTOM_RESIDUAL_DATA
    | PREDEFINED_RESIDUAL_DATA

CUSTOM_RESIDUAL_DATA :=
    FUNCTION_LENGTH
    FUNCTION_BYTECODE

PREDEFINED_RESIDUAL_DATA :=
    [FUNCTION_PARAMETERS]

PHYSICAL_EOF :=
    END_OF_PHYSICAL_GCMF_STREAM
]]></artwork>
        <t>The fundamental mathematical decoding equation is:</t>
        <artwork><![CDATA[
d(i) = f(x(i)) + r(x(i))
]]></artwork>
        <t>
          where r(x(i)) = 0 for representations without residuals. For
          LITERAL, Decode(G) = LiteralPayload(G). No additional EOF field
          is encoded.
        </t>
      </section>
    </section>

    <section anchor="iana" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <t>
        This document defines a working, unregistered MIME type,
        <tt>application/gcmf</tt>, as described in <xref target="mime"/>.
        This document does not request any registration action from IANA
        at this time. Should GCMF advance toward broader adoption, a future
        document <bcp14>MAY</bcp14> request registration of
        <tt>application/gcmf</tt> in accordance with the procedures of
        <xref target="RFC2046"/> and BCP&nbsp;13.
      </t>
    </section>

    <section anchor="security" numbered="true" toc="default">
      <name>Security Considerations</name>
      <t>
        GCMF CUSTOM function representations embed executable stack-based
        bytecode within the file format, as described in
        <xref target="bytecode"/>. A decoder that evaluates untrusted GCMF
        input therefore executes untrusted, attacker-supplied instructions.
        Implementations <bcp14>MUST</bcp14> treat GCMF decoding of CUSTOM
        and MODULAR functions as execution of untrusted code and
        <bcp14>SHOULD</bcp14> apply appropriate sandboxing.
      </t>
      <t>
        Because GCMF functions are evaluated over a domain that can be
        specified independently of the resulting output size, a
        maliciously crafted file can specify an extremely large [X_start,
        X_end] domain, or a MODULAR or POLYNOMIAL function with a large
        nesting or degree, in order to force a decoder to perform an
        excessive amount of computation or produce an excessive volume of
        output from a very small input file. This is a form of
        decompression-bomb risk analogous to those found in other
        compression formats. Implementations <bcp14>SHOULD</bcp14> impose
        configurable limits on maximum domain size, maximum function
        length, maximum stack depth, maximum recursive MODULAR nesting
        depth, maximum numerical magnitude, and maximum decode execution
        time, as noted in <xref target="decval"/>.
      </t>
      <t>
        Certain bytecode operations, such as DIV, MOD, LOG, LOG10, and
        SQRT, are undefined for some operand values (for example, division
        by zero or the logarithm of a non-positive number). Implementations
        <bcp14>MUST</bcp14> reject such evaluations rather than
        substituting an implementation-defined or platform-defined result,
        as required in <xref target="numeval"/>, since inconsistent
        handling of undefined operations across implementations could
        otherwise be leveraged to produce divergent decoded output from the
        same input.
      </t>
      <t>
        Because GCMF-VLI and the bit-packed Function Address are
        variable-width fields that need not be byte-aligned, a
        non-conforming or naive decoder implementation is at heightened
        risk of buffer over-read or integer overflow when parsing malformed
        or truncated input. Implementations <bcp14>MUST</bcp14> validate
        that sufficient input remains before consuming any field and
        <bcp14>MUST</bcp14> reject truncated streams as described in
        <xref target="decval"/>.
      </t>
      <t>
        GCMF does not itself provide authentication, integrity protection,
        or confidentiality for encoded data. Applications that require
        these properties for GCMF streams transmitted or stored in
        untrusted environments <bcp14>SHOULD</bcp14> apply them at another
        layer.
      </t>
    </section>

  </middle>

  <back>
    <references>
      <name>Normative References</name>
      <reference anchor="RFC2046" target="https://www.rfc-editor.org/rfc/rfc2046">
        <front>
          <title>Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types</title>
          <author initials="N." surname="Freed" fullname="Ned Freed"/>
          <author initials="N." surname="Borenstein" fullname="Nathaniel S. Borenstein"/>
          <date month="November" year="1996"/>
        </front>
        <seriesInfo name="RFC" value="2046"/>
        <seriesInfo name="DOI" value="10.17487/RFC2046"/>
      </reference>
      <reference anchor="RFC2119" target="https://www.rfc-editor.org/rfc/rfc2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author initials="S." surname="Bradner" fullname="Scott Bradner"/>
          <date month="March" year="1997"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
        <seriesInfo name="DOI" value="10.17487/RFC2119"/>
      </reference>
    </references>

    <references>
      <name>Informative References</name>
      <reference anchor="J_RISSANEN_1978">
        <front>
          <title>Modeling by shortest data description</title>
          <author initials="J." surname="Rissanen" fullname="Jorma Rissanen"/>
          <date year="1978"/>
        </front>
        <seriesInfo name="Automatica" value="vol. 14, no. 5, pp. 465-471"/>
      </reference>
    </references>

    <section anchor="app-example" numbered="true" toc="default">
      <name>Example GCMF Representation</name>
      <t>
        This appendix reproduces, for reference, the worked example of
        <xref target="encex"/> in a single consolidated view.
      </t>
      <t>
        Given the source sequence 10, 13, 16, 19, 22, 25 (six 8-bit
        unsigned values, a 6-byte source), an encoder implementing this
        specification could produce a LINEAR representation with a = 3,
        b = 10, X_start = 0, X_end = 5, discovering that:
      </t>
      <artwork><![CDATA[
f(x) = 3x + 10

f(0) = 10
f(1) = 13
f(2) = 16
f(3) = 19
f(4) = 22
f(5) = 25
]]></artwork>
      <t>
        which exactly reproduces the six-value source sequence with an
        exact (residual-free) representation, per <xref target="model"/>.
        Per <xref target="encsel"/>, the encoder would compare the total
        encoded length of this LINEAR representation, including all
        structural overhead, against the LITERAL representation of the
        same six bytes, and select whichever candidate yields the smaller
        value of L(C).
      </t>

      <table anchor="tab-ftypes">
        <name>Function Type Addresses</name>
        <thead>
          <tr>
            <th>AAAA</th>
            <th>Function</th>
            <th>Formula</th>
          </tr>
        </thead>
        <tbody>
          <tr><td>0000</td><td>CUSTOM</td><td>User-defined</td></tr>
          <tr><td>0001</td><td>LITERAL</td><td>N/A -- raw bytes, see Section 4.18</td></tr>
          <tr><td>0010</td><td>CONSTANT</td><td>F(x) = c</td></tr>
          <tr><td>0011</td><td>LINEAR</td><td>F(x) = ax + b</td></tr>
          <tr><td>0100</td><td>ARITHMETIC</td><td>F(x) = a + xd</td></tr>
          <tr><td>0101</td><td>GEOMETRIC</td><td>F(x) = a r^x</td></tr>
          <tr><td>0110</td><td>POLYNOMIAL</td><td>F(x) = sum_(i=0)^n a_i x^i</td></tr>
          <tr><td>0111</td><td>EXPONENTIAL</td><td>F(x) = a b^x</td></tr>
          <tr><td>1000</td><td>LOGARITHMIC</td><td>F(x) = a log_b(x) + c</td></tr>
          <tr><td>1001</td><td>POWER</td><td>F(x) = a x^b + c</td></tr>
          <tr><td>1010</td><td>MODULAR</td><td>F(x) = G(x) mod m</td></tr>
          <tr><td>1011</td><td>FIBONACCI</td><td>F(x)=F(x-1)+F(x-2), x&gt;=2, F(0)=0, F(1)=1</td></tr>
          <tr><td>1100</td><td>FACTORIAL</td><td>F(x) = x!</td></tr>
          <tr><td>1101</td><td>TRIANGULAR</td><td>F(x) = x(x+1)/2</td></tr>
          <tr><td>1110</td><td>SQUARE</td><td>F(x) = x^2</td></tr>
          <tr><td>1111</td><td>CUBE</td><td>F(x) = x^3</td></tr>
        </tbody>
      </table>
      <t>
        NOTE: the LITERAL row was previously listed with the formula
        "F(x) = x", which incorrectly implied LITERAL evaluates a function.
        Per <xref target="literal"/>, LITERAL stores no function, domain,
        or base; the decoded output is the raw payload copied verbatim
        (<xref target="lossless"/>).
      </t>

      <table anchor="tab-opcodes">
        <name>Function Bytecode Opcodes</name>
        <thead>
          <tr>
            <th>OPCODE</th>
            <th>MNEMONIC</th>
            <th>STACK OPERATION</th>
          </tr>
        </thead>
        <tbody>
          <tr><td>00000</td><td>CONST</td><td>Push constant</td></tr>
          <tr><td>00001</td><td>X</td><td>Push current x</td></tr>
          <tr><td>00010</td><td>ADD</td><td>a + b</td></tr>
          <tr><td>00011</td><td>SUB</td><td>a - b</td></tr>
          <tr><td>00100</td><td>MUL</td><td>a * b</td></tr>
          <tr><td>00101</td><td>DIV</td><td>a / b</td></tr>
          <tr><td>00110</td><td>MOD</td><td>a mod b</td></tr>
          <tr><td>00111</td><td>POW</td><td>a ^ b</td></tr>
          <tr><td>01000</td><td>NEG</td><td>-a</td></tr>
          <tr><td>01001</td><td>ABS</td><td>|a|</td></tr>
          <tr><td>01010</td><td>SQRT</td><td>sqrt(a)</td></tr>
          <tr><td>01011</td><td>LOG</td><td>ln(a)</td></tr>
          <tr><td>01100</td><td>LOG10</td><td>log10(a)</td></tr>
          <tr><td>01101</td><td>EXP</td><td>e^a</td></tr>
          <tr><td>01110</td><td>SIN</td><td>sin(a)</td></tr>
          <tr><td>01111</td><td>COS</td><td>cos(a)</td></tr>
          <tr><td>10000</td><td>TAN</td><td>tan(a)</td></tr>
          <tr><td>10001</td><td>ASIN</td><td>arcsin(a)</td></tr>
          <tr><td>10010</td><td>ACOS</td><td>arccos(a)</td></tr>
          <tr><td>10011</td><td>ATAN</td><td>arctan(a)</td></tr>
          <tr><td>10100</td><td>FLOOR</td><td>floor(a)</td></tr>
          <tr><td>10101</td><td>CEIL</td><td>ceil(a)</td></tr>
          <tr><td>10110</td><td>ROUND</td><td>round(a)</td></tr>
          <tr><td>10111</td><td>MIN</td><td>min(a, b)</td></tr>
          <tr><td>11000</td><td>MAX</td><td>max(a, b)</td></tr>
          <tr><td>11001</td><td>AND</td><td>a &amp; b</td></tr>
          <tr><td>11010</td><td>OR</td><td>a | b</td></tr>
          <tr><td>11011</td><td>XOR</td><td>a xor b (bitwise)</td></tr>
          <tr><td>11100</td><td>SHL</td><td>a &lt;&lt; b</td></tr>
          <tr><td>11101</td><td>SHR</td><td>a &gt;&gt; b</td></tr>
          <tr><td>11110</td><td>DUP</td><td>Duplicate top stack value</td></tr>
          <tr><td>11111</td><td>END</td><td>End function</td></tr>
        </tbody>
      </table>
    </section>

    <section anchor="app-changes" numbered="true" toc="default">
      <name>Changes from draft-dutta-gcmf-00</name>
      <t>
        This appendix is non-normative and summarizes the corrections made
        relative to draft-dutta-gcmf-00; it will be removed before this
        document advances.
      </t>
      <ul spacing="normal">
        <li>
          <xref target="customfn"/> (CUSTOM Function): the layout table
          previously marked Function Length and Function Bytecode as
          OPTIONAL, which contradicted the surrounding prose (Function
          Length "MUST be sufficient", bytecode "MUST contain a valid
          END"). These fields are mandatory for every CUSTOM
          representation; the table has been corrected and an explanatory
          sentence added.
        </li>
        <li>
          <xref target="predef"/> (Predefined Functions): the layout table
          previously showed Function Parameters as an unmarked,
          unconditionally present field, even though
          <xref target="predefparams"/> defines five predefined functions
          that take no parameters. The field is now correctly marked
          OPTIONAL/zero-length for those functions, with a cross-reference
          to <xref target="predefparams"/>.
        </li>
        <li>
          <xref target="customfn"/> and <xref target="predef"/>: the layout
          tables previously repeated a trailing "Magic | 4 bytes" and "EOF"
          field at the end of each representation. This contradicted
          <xref target="filestruct"/> (one Magic field per file) and
          <xref target="eof"/> (no in-band EOF marker is ever encoded). The
          trailing Magic/EOF rows have been removed and replaced with an
          explicit forward reference to <xref target="eof"/>.
        </li>
        <li>
          <xref target="canonlayout"/> (Complete Canonical Layout):
          previously presented a single combined diagram with FUNCTION
          LENGTH, FUNCTION BYTECODE, and FUNCTION PARAMETERS all bracketed
          as independently optional, which incorrectly implied a single
          representation could mix CUSTOM and PREDEFINED fields, or omit
          them freely. The section now presents the CUSTOM, PREDEFINED,
          and LITERAL field sequences as three separate, mutually
          exclusive layouts, consistent with the grammar in
          <xref target="grammar"/>.
        </li>
        <li>
          <xref target="literal"/> (Literal): the layout table previously
          omitted the 3-bit zero-padding field shown in the surrounding
          prose, and retained a trailing bare "EOF" row. The table now
          shows the padding field explicitly and labels the terminal row
          "Physical EOF" for consistency with <xref target="eof"/>.
        </li>
        <li>
          <xref target="filestruct"/>: added an explicit statement that the
          file contains exactly one Magic field and no in-band EOF marker,
          to prevent the per-representation layout tables from being read
          as implying otherwise.
        </li>
        <li>
          <xref target="functypeaddr"/>: clarified that AAAA selects among
          the sixteen entries of <xref target="tab-ftypes"/>, and gave the
          reserved LITERAL+RESIDUAL combination its explicit 5-bit encoding
          (10001) rather than leaving it as a bare 4-bit function-type
          value inconsistent with the 5-bit Function Address field defined
          in <xref target="funcaddr"/>.
        </li>
        <li>
          <xref target="residcont"/>: clarified that Residual Function Data
          is always present when R = 1 (it is never itself optional), that
          it may be zero-length only for a parameterless predefined
          function, and added an explicit prohibition on a Residual
          Function Type of LITERAL, consistent with
          <xref target="residrep"/>'s statement that a residual is always a
          mathematical representation.
        </li>
        <li>
          <xref target="decsm"/> (Decoder State Machine): the LITERAL
          branch previously omitted the padding-skip step shown in
          <xref target="literal"/>'s prose, and the non-LITERAL path had no
          explicit branch label. Both have been added, and an END state was
          added after EVALUATE to match the END state already present on
          the residual path.
        </li>
        <li>
          <xref target="grammar"/> (Summary of Binary Grammar):
          PREDEFINED_FUNCTION previously expanded to an unconditional
          FUNCTION_PARAMETERS, inconsistent with
          <xref target="predefparams"/>. It is now bracketed as optional.
          RESIDUAL_FUNCTION_DATA was added as an explicit production
          distinguishing CUSTOM_RESIDUAL_DATA from
          PREDEFINED_RESIDUAL_DATA, since <xref target="residcont"/>
          defines both but the previous grammar only gave a production for
          the custom case.
        </li>
        <li>
          <xref target="terminology"/> (Terminology): added a paragraph
          defining how the structural label "OPTIONAL" is used inside
          binary layout diagrams in <xref target="binfmt"/>, as distinct
          from the RFC 2119 keyword OPTIONAL, to prevent the ambiguity that
          produced the defects above.
        </li>
        <li>
          <xref target="tab-ftypes"/> (Function Type Addresses): the
          LITERAL row previously listed a formula, "F(x) = x", which is
          incorrect: <xref target="literal"/> states that LITERAL stores no
          function, domain, or base, and Decode(G) for LITERAL is defined
          in <xref target="lossless"/> as the raw payload, not a function
          evaluation. The row has been corrected to read "N/A -- raw
          bytes, see Section 4.18".
        </li>
        <li>
          <xref target="model"/>: removed a duplicated statement of the
          global optimization objective (arg min over C) that repeated,
          almost verbatim, the implementation-level objective (arg min
          over C_I) given immediately before it, and clarified in prose why
          the two objectives differ (C_I is what an implementation can
          search; C is the theoretical optimum it is not required to
          find).
        </li>
      </ul>
    </section>

  </back>
</rfc>