{
  "id": "cost-matrix-round",
  "name": "Exact two-margin matrix rounding",
  "description": "Round a supplied decimal allocation matrix to exact integer floor/ceiling cells while preserving both declared margins, minimizing absolute error and breaking ties lexicographically; return a verifiable optimum or infeasibility witness. No payments, accounting advice or execution.",
  "category": "workflow-assurance",
  "priceUsd": "0.01",
  "pricingStatus": "proposed-unverified",
  "pricing": {
    "unit": "one successful operation call",
    "proposedNominalUsd": "0.01",
    "sixDecimalTokenBaseUnits": "10000",
    "subscription": false,
    "includesPayerWalletOrNetworkFees": false,
    "liveQuoteVerified": false,
    "condition": "Actual SDK challenge is authoritative only within the caller's explicit authorization; configured six-decimal token peg is an operator assertion, not a conversion guarantee."
  },
  "intents": [
    "Round fractional allocations while preserving row and column totals",
    "Reconcile a supplied allocation matrix into integer minor units"
  ],
  "whenToUse": [
    "Caller supplies both exact margins and requires the minimum absolute rounding error"
  ],
  "whenNotToUse": [
    "Actual financial allocation, posting ledgers, payments or accounting advice",
    "Automatically choosing margins or unconstrained proportional apportionment"
  ],
  "capabilities": [
    "Exact decimal BigInt arithmetic with deterministic UTF-16 ID order",
    "Independent residual-potential optimum certificates or bounded infeasibility witnesses",
    "Well-formed infeasible inputs return no usable matrix; pure full evaluation before payment challenge"
  ],
  "related": [
    "integer-apportion",
    "gfm-table-compose"
  ],
  "limits": {
    "inputBytes": 100000,
    "outputBytes": 400000,
    "jsonNodes": 12000,
    "depth": 20,
    "rows": 8,
    "columns": 8,
    "cells": 64,
    "decimalIntegerDigits": 18,
    "decimalFractionDigits": 6,
    "targetDigits": 24,
    "vertices": 18,
    "residualArcs": 160,
    "augmentations": 64,
    "maximumRelaxationChecks": 176960
  },
  "errorCodes": [
    "INPUT_LIMIT",
    "OUTPUT_LIMIT",
    "COMPLEXITY_LIMIT",
    "INVALID_JSON",
    "INVALID_NUMBER",
    "INVALID_UNICODE",
    "UNSAFE_KEY",
    "DUPLICATE_ID",
    "MATRIX_DIMENSIONS",
    "MARGIN_TOTAL_MISMATCH",
    "INTERNAL_CERTIFICATE"
  ],
  "requirementsProfile": {
    "format": "declared-requirements-v1",
    "facts": {
      "execution.suppliedCode": false,
      "execution.remoteMutation": false,
      "execution.llmInference": false,
      "execution.paidMcp": false,
      "verification.semanticTruth": false,
      "verification.sourceAuthenticity": false,
      "verification.liveVulnerabilities": false,
      "numbers.arbitraryPrecisionJson": false,
      "numbers.model": "ieee754-binary64",
      "privacy.requestBodyPersisted": false,
      "execution.deterministic": true,
      "execution.networkAccess": false,
      "privacy.resultBodyPersisted": false,
      "payment.x402": true,
      "payment.mpp": true,
      "operation.id": "cost-matrix-round",
      "operation.category": "workflow-assurance",
      "limit.httpRequestBytes": 131072,
      "limit.requestBytes": 100000,
      "limit.responseBytes": 524288,
      "limit.resultBytes": 400000,
      "limit.jsonDepth": 20,
      "limit.jsonNodes": 12000,
      "matrixRound.profile": "exact-two-margin-round-v1",
      "matrixRound.maxRows": 8,
      "matrixRound.maxColumns": 8,
      "matrixRound.maxCells": 64,
      "matrixRound.maxDecimalIntegerDigits": 18,
      "matrixRound.maxDecimalFractionDigits": 6,
      "matrixRound.objective": "minimum-total-absolute-error",
      "matrixRound.tieBreak": "lexicographic-row-major-after-utf16-id-sort",
      "matrixRound.cellChoices": "floor-or-ceiling",
      "matrixRound.margins": "caller-declared-row-and-column-targets",
      "matrixRound.exactOptimality": true,
      "matrixRound.feasibilityGuaranteed": false,
      "matrixRound.binaryFloatAmounts": false,
      "matrixRound.executesAllocation": false,
      "matrixRound.accountingAdvice": false,
      "matrixRound.availabilityVerified": false,
      "input.rowIds.maxItems": 8,
      "input.rowIds.minItems": 1,
      "input.columnIds.maxItems": 8,
      "input.columnIds.minItems": 1,
      "input.values.maxItems": 8,
      "input.values.minItems": 1,
      "input.rowTargets.maxItems": 8,
      "input.rowTargets.minItems": 1,
      "input.columnTargets.maxItems": 8,
      "input.columnTargets.minItems": 1
    },
    "unknownPolicy": "Undeclared requirements are unknown, never compatible. Matching declared facts does not establish semantic fit or input validity.",
    "preflight": "/preflight"
  },
  "documentation": "/reference/tools/cost-matrix-round.md",
  "serviceContract": "/reference/services/cost-matrix-round.json",
  "errors": [
    {
      "status": 400,
      "meaning": "Malformed JSON, missing/invalid idempotency key, or payment identifier mismatch",
      "retry": "Correct the request before payment"
    },
    {
      "status": 402,
      "meaning": "Payment challenge or rejected payment",
      "retry": "Use official protocol SDK; inspect payment outcome before another payment"
    },
    {
      "status": 409,
      "meaning": "Idempotency conflict, duplicate proof, or PAYMENT_UNCERTAIN",
      "retry": "Keep original key, body, and proof; reconcile uncertainty with operator; never blindly repay"
    },
    {
      "status": 413,
      "meaning": "Input or generated output too large",
      "retry": "Reduce input; no payment attempted for validation failure"
    },
    {
      "status": 415,
      "meaning": "Unsupported media type or compression",
      "retry": "Send uncompressed application/json"
    },
    {
      "status": 422,
      "meaning": "Schema or service-specific semantic validation failure",
      "retry": "Correct input using returned error code; no payment attempted"
    },
    {
      "status": 429,
      "meaning": "Request/payment-attempt rate exceeded",
      "retry": "Wait for rate limit window; preserve existing payment identity"
    },
    {
      "status": 503,
      "meaning": "Payment configuration/provider/state unavailable, or live DNS preparation failed before settlement",
      "retry": "Check readiness; DNS preparation failures may retry the identical key/body/credential only; uncertainty requires reconciliation"
    }
  ],
  "numericPrecision": "JavaScript IEEE-754 numbers; use strings for large integer IDs/exact decimals where the schema accepts strings. No lossless numeric parsing.",
  "paymentWorkflow": {
    "discoveryOnly": false,
    "supportedProtocols": [
      "x402",
      "mpp"
    ],
    "x402": {
      "credentialHeader": "PAYMENT-SIGNATURE",
      "challengeHeader": "PAYMENT-REQUIRED",
      "receiptHeader": "PAYMENT-RESPONSE",
      "version": 2,
      "scheme": "exact",
      "paymentIdentifier": "payment-identifier extension MUST equal the HTTP Idempotency-Key",
      "sdk": "@x402/core with @x402/evm"
    },
    "mpp": {
      "supported": true,
      "credentialHeader": "Authorization",
      "challengeHeader": "WWW-Authenticate",
      "receiptHeader": "Payment-Receipt",
      "method": "tempo",
      "intent": "charge",
      "sdk": "mppx",
      "tokenDecimals": 6
    },
    "steps": [
      "Check configured readiness and the exact service schema",
      "Generate a fresh random Idempotency-Key for this operation; never use a discovery probe fixture for purchases",
      "Send valid input without a credential to obtain the official protocol challenge",
      "Use the official SDK and authorized wallet to fulfill the challenge",
      "Retry only with identical key, body, protocol and credential",
      "On PAYMENT_UNCERTAIN stop and request operator reconciliation; never blindly pay again"
    ],
    "versionedRetries": "Request fingerprint includes service release version. Retries across a version upgrade can conflict; coordinate upgrades outside the 24-hour replay window and reconcile pending attempts.",
    "docs": "/llms.txt"
  },
  "method": "POST",
  "paths": {
    "x402": "/v1/x402/cost-matrix-round",
    "mpp": "/v1/mpp/cost-matrix-round"
  },
  "inputSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "rowIds": {
        "minItems": 1,
        "maxItems": 8,
        "type": "array",
        "items": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      },
      "columnIds": {
        "minItems": 1,
        "maxItems": 8,
        "type": "array",
        "items": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      },
      "values": {
        "minItems": 1,
        "maxItems": 8,
        "type": "array",
        "items": {
          "minItems": 1,
          "maxItems": 8,
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(?:0|[1-9][0-9]{0,17})(?:\\.[0-9]{1,6})?$"
          }
        }
      },
      "rowTargets": {
        "minItems": 1,
        "maxItems": 8,
        "type": "array",
        "items": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,23})$"
        }
      },
      "columnTargets": {
        "minItems": 1,
        "maxItems": 8,
        "type": "array",
        "items": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,23})$"
        }
      }
    },
    "required": [
      "rowIds",
      "columnIds",
      "values",
      "rowTargets",
      "columnTargets"
    ],
    "additionalProperties": false
  },
  "outputSchema": {
    "type": "object",
    "required": [
      "operation",
      "version",
      "result",
      "provenance"
    ],
    "properties": {
      "operation": {
        "const": "cost-matrix-round",
        "type": "string"
      },
      "version": {
        "const": "0.29.0",
        "type": "string"
      },
      "result": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "profile": {
                "type": "string",
                "const": "exact-two-margin-round-v1"
              },
              "externalRequests": {
                "type": "number",
                "const": 0
              },
              "execution": {
                "type": "boolean",
                "const": false
              },
              "availabilityVerified": {
                "type": "boolean",
                "const": false
              },
              "rowIds": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              },
              "columnIds": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              },
              "rowTargets": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "columnTargets": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "status": {
                "type": "string",
                "const": "optimal"
              },
              "matrix": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "minItems": 1,
                  "maxItems": 8,
                  "type": "array",
                  "items": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  }
                }
              },
              "rowTotals": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "columnTotals": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "grandTotal": {
                "type": "string",
                "pattern": "^(?:0|[1-9][0-9]*)$"
              },
              "absoluteError": {
                "type": "object",
                "properties": {
                  "numerator": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  },
                  "denominator": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]*$"
                  }
                },
                "required": [
                  "numerator",
                  "denominator"
                ],
                "additionalProperties": false
              },
              "cells": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "minItems": 1,
                  "maxItems": 8,
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "floor": {
                        "type": "string",
                        "pattern": "^(?:0|[1-9][0-9]*)$"
                      },
                      "fraction": {
                        "type": "object",
                        "properties": {
                          "numerator": {
                            "type": "string",
                            "pattern": "^(?:0|[1-9][0-9]*)$"
                          },
                          "denominator": {
                            "type": "string",
                            "pattern": "^[1-9][0-9]*$"
                          }
                        },
                        "required": [
                          "numerator",
                          "denominator"
                        ],
                        "additionalProperties": false
                      },
                      "increment": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 1
                      }
                    },
                    "required": [
                      "floor",
                      "fraction",
                      "increment"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "certificate": {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "min-cost-flow-potentials"
                  },
                  "scale": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  },
                  "primaryMultiplier": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  },
                  "combinedCost": {
                    "type": "string",
                    "pattern": "^(?:0|[1-9][0-9]*)$"
                  },
                  "vertexPotentials": {
                    "minItems": 4,
                    "maxItems": 18,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^(?:0|-?[1-9][0-9]*)$"
                    }
                  },
                  "requiredFlow": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 64
                  },
                  "achievedFlow": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 64
                  }
                },
                "required": [
                  "kind",
                  "scale",
                  "primaryMultiplier",
                  "combinedCost",
                  "vertexPotentials",
                  "requiredFlow",
                  "achievedFlow"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "profile",
              "externalRequests",
              "execution",
              "availabilityVerified",
              "rowIds",
              "columnIds",
              "rowTargets",
              "columnTargets",
              "status",
              "matrix",
              "rowTotals",
              "columnTotals",
              "grandTotal",
              "absoluteError",
              "cells",
              "certificate"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "profile": {
                "type": "string",
                "const": "exact-two-margin-round-v1"
              },
              "externalRequests": {
                "type": "number",
                "const": 0
              },
              "execution": {
                "type": "boolean",
                "const": false
              },
              "availabilityVerified": {
                "type": "boolean",
                "const": false
              },
              "rowIds": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              },
              "columnIds": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              },
              "rowTargets": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "columnTargets": {
                "minItems": 1,
                "maxItems": 8,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]*)$"
                }
              },
              "status": {
                "type": "string",
                "const": "infeasible"
              },
              "matrix": {
                "type": "null"
              },
              "witness": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "margin-bound"
                      },
                      "axis": {
                        "type": "string",
                        "enum": [
                          "row",
                          "column"
                        ]
                      },
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100
                      },
                      "target": {
                        "type": "string",
                        "pattern": "^(?:0|[1-9][0-9]*)$"
                      },
                      "minimum": {
                        "type": "string",
                        "pattern": "^(?:0|[1-9][0-9]*)$"
                      },
                      "maximum": {
                        "type": "string",
                        "pattern": "^(?:0|[1-9][0-9]*)$"
                      }
                    },
                    "required": [
                      "kind",
                      "axis",
                      "id",
                      "target",
                      "minimum",
                      "maximum"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "residual-min-cut"
                      },
                      "reachableRowIds": {
                        "maxItems": 8,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        }
                      },
                      "reachableColumnIds": {
                        "maxItems": 8,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        }
                      },
                      "requiredFlow": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 64
                      },
                      "achievedFlow": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 64
                      },
                      "cutCapacity": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 64
                      },
                      "partialIncrements": {
                        "minItems": 1,
                        "maxItems": 8,
                        "type": "array",
                        "items": {
                          "minItems": 1,
                          "maxItems": 8,
                          "type": "array",
                          "items": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 1
                          }
                        }
                      }
                    },
                    "required": [
                      "kind",
                      "reachableRowIds",
                      "reachableColumnIds",
                      "requiredFlow",
                      "achievedFlow",
                      "cutCapacity",
                      "partialIncrements"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            },
            "required": [
              "profile",
              "externalRequests",
              "execution",
              "availabilityVerified",
              "rowIds",
              "columnIds",
              "rowTargets",
              "columnTargets",
              "status",
              "matrix",
              "witness"
            ],
            "additionalProperties": false
          }
        ]
      },
      "provenance": {
        "type": "object",
        "required": [
          "inputSha256",
          "outputSha256",
          "deterministic",
          "externalRequests"
        ],
        "properties": {
          "inputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "outputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "deterministic": {
            "const": true
          },
          "externalRequests": {
            "const": 0
          }
        }
      }
    },
    "additionalProperties": false
  },
  "exampleInput": {
    "rowIds": [
      "r1",
      "r2"
    ],
    "columnIds": [
      "a",
      "b",
      "c"
    ],
    "values": [
      [
        "0.6",
        "0.6",
        "0.8"
      ],
      [
        "0.4",
        "0.4",
        "0.2"
      ]
    ],
    "rowTargets": [
      "2",
      "1"
    ],
    "columnTargets": [
      "1",
      "1",
      "1"
    ]
  },
  "exampleResponse": {
    "operation": "cost-matrix-round",
    "version": "0.29.0",
    "result": {
      "profile": "exact-two-margin-round-v1",
      "externalRequests": 0,
      "execution": false,
      "availabilityVerified": false,
      "rowIds": [
        "r1",
        "r2"
      ],
      "columnIds": [
        "a",
        "b",
        "c"
      ],
      "rowTargets": [
        "2",
        "1"
      ],
      "columnTargets": [
        "1",
        "1",
        "1"
      ],
      "status": "optimal",
      "matrix": [
        [
          "0",
          "1",
          "1"
        ],
        [
          "1",
          "0",
          "0"
        ]
      ],
      "rowTotals": [
        "2",
        "1"
      ],
      "columnTotals": [
        "1",
        "1",
        "1"
      ],
      "grandTotal": "3",
      "absoluteError": {
        "numerator": "12",
        "denominator": "5"
      },
      "cells": [
        [
          {
            "floor": "0",
            "fraction": {
              "numerator": "3",
              "denominator": "5"
            },
            "increment": 0
          },
          {
            "floor": "0",
            "fraction": {
              "numerator": "3",
              "denominator": "5"
            },
            "increment": 1
          },
          {
            "floor": "0",
            "fraction": {
              "numerator": "4",
              "denominator": "5"
            },
            "increment": 1
          }
        ],
        [
          {
            "floor": "0",
            "fraction": {
              "numerator": "2",
              "denominator": "5"
            },
            "increment": 1
          },
          {
            "floor": "0",
            "fraction": {
              "numerator": "2",
              "denominator": "5"
            },
            "increment": 0
          },
          {
            "floor": "0",
            "fraction": {
              "numerator": "1",
              "denominator": "5"
            },
            "increment": 0
          }
        ]
      ],
      "certificate": {
        "kind": "min-cost-flow-potentials",
        "scale": "10",
        "primaryMultiplier": "64",
        "combinedCost": "1564",
        "vertexPotentials": [
          "-772",
          "-530",
          "-772",
          "0",
          "-2",
          "0",
          "0"
        ],
        "requiredFlow": 3,
        "achievedFlow": 3
      }
    },
    "provenance": {
      "inputSha256": "15594a17c74c1a6c9b7cd6f0f74ea731fd6a8c6a10f59eab883541f893d56dfa",
      "outputSha256": "ac4a933060b7d1d3b3d7d2bb32f7a9a4ef7ba15111ac766bb16a59be2976ee2a",
      "deterministic": true,
      "externalRequests": 0
    }
  },
  "requiredHeaders": {
    "Content-Type": "application/json",
    "Idempotency-Key": "random 16–128 character operation identifier"
  },
  "fixedExample": "/reference/examples/cost-matrix-round.json",
  "execution": {
    "deterministic": true,
    "externalRequests": 0,
    "maxExternalRequests": 0,
    "resultSnapshotPersisted": false,
    "fixedExampleIsIllustrativeSnapshot": false,
    "requiresPayment": true,
    "supportsMcpExecution": false
  },
  "releaseSnapshot": {
    "format": "static-release-reference-v1",
    "sourceVersion": "0.29.0",
    "sourceRegistrySha256": "a2b5ec09bf6c38b9d2879d746a4fded374f5928b445377b0270ef6aa8e6cac65",
    "generatedAt": "2026-10-06T15:38:00Z",
    "releaseAcceptance": "not-verified-by-generator",
    "runtimeReadiness": "not-evaluated",
    "livePaymentsVerified": false,
    "indexingVerified": false,
    "apiOrigin": null,
    "notice": "Build-time release reference. Runtime readiness, deployment, payment settlement and external indexing are not evaluated here. Prices are proposed; this file cannot authorize execution or payment."
  }
}
