Exact two-margin matrix rounding
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.
workflow-assurance · Operation ID: cost-matrix-round
Choose this operation when
- Caller supplies both exact margins and requires the minimum absolute rounding error
Outside this profile
- Actual financial allocation, posting ledgers, payments or accounting advice
- Automatically choosing margins or unconstrained proportional apportionment
Exact release references
Static JSON contract · Markdown reference · Fixed example response
Complete input schema
{
"$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
}
Complete output-envelope schema
{
"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
}
Fixed example
One accepted fixed example, not a custom-input trial. No operation runs when this static page is requested.
Example input
{
"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"
]
}
Example response
{
"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
}
}
Bounds and precision
JavaScript IEEE-754 numbers; use strings for large integer IDs/exact decimals where the schema accepts strings. No lossless numeric parsing.
{
"global": {
"requestBytes": 131072,
"responseBytes": 524288,
"jsonDepth": 32,
"jsonNodes": 20000,
"requestsPerMinute": 60,
"paidAttemptsPerMinute": 20,
"idempotencyHours": 24
},
"operation": {
"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
}
}
Complete schemas, descriptions and cross-field validation may impose additional limits.
Proposed price and protocol definitions
{
"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."
}
Protocol definitions: x402, mpp. MPP uses Tempo charge. Paid MCP execution is unsupported. All runtime readiness is not evaluated in this build.
API path templates, not endpoints on this documentation host
{
"x402": "/v1/x402/cost-matrix-round",
"mpp": "/v1/mpp/cost-matrix-round"
}
Required headers
{
"Content-Type": "application/json",
"Idempotency-Key": "random 16–128 character operation identifier"
}
Actual SDK challenge amount, asset, network, recipient and wallet costs must pass independent authorization. Preserve identical key, body, protocol and credential on retries; on PAYMENT_UNCERTAIN stop and reconcile.
Execution profile and provider conditions
{
"deterministic": true,
"externalRequests": 0,
"maxExternalRequests": 0,
"resultSnapshotPersisted": false,
"fixedExampleIsIllustrativeSnapshot": false,
"requiresPayment": true,
"supportsMcpExecution": false
}
Deterministic supplied-input operation with no external requests or stored request/result bodies. Payment infrastructure retains payment metadata and hashes.
Failure handling
- HTTP 400: Malformed JSON, missing/invalid idempotency key, or payment identifier mismatch Correct the request before payment
- HTTP 402: Payment challenge or rejected payment Use official protocol SDK; inspect payment outcome before another payment
- HTTP 409: Idempotency conflict, duplicate proof, or PAYMENT_UNCERTAIN Keep original key, body, and proof; reconcile uncertainty with operator; never blindly repay
- HTTP 413: Input or generated output too large Reduce input; no payment attempted for validation failure
- HTTP 415: Unsupported media type or compression Send uncompressed application/json
- HTTP 422: Schema or service-specific semantic validation failure Correct input using returned error code; no payment attempted
- HTTP 429: Request/payment-attempt rate exceeded Wait for rate limit window; preserve existing payment identity
- HTTP 503: Payment configuration/provider/state unavailable, or live DNS preparation failed before settlement Check readiness; DNS preparation failures may retry the identical key/body/credential only; uncertainty requires reconciliation
Declared requirements
Before any paid call, refresh the live operation contract and POST the complete bounded budgeted plan to the separate API's /preflight. Unknown requirements block selection; compatible preflight is not permission to spend.