Allocate by Largest Remainder
math.allocate_largest_remainder
Overview
Allocate a quantized total by Hamilton largest remainder with deterministic keyed ties. Inputs are bounded plain decimals, output order follows input order, and no currency, policy, materiality threshold, market data, or ambient default is inferred.
For Allocate by Largest Remainder, we publish the exact bounded decimal rule and audit fields so you do not have to trust approximate prompt arithmetic.
Reliability
Allocate by Largest Remainder is STRICT and stateless: the same bounded input produces the same normalized output. DECIMAL_INVALID means a value is malformed or outside the 100-digit/scale-40 ceilings; fix it before retrying. ITEM_LIMIT_EXCEEDED means an array exceeds 10,000 entries; split it. ZERO_DENOMINATOR means a denominator or weight sum is zero; change it or select the documented zero policy. ROUNDING_INVALID means mode, scale, or quantization is invalid; send a supported mode and scale. ALLOCATION_INVALID means weights, ids, or total violate the published allocation rules; correct the named structure.
Context footprint
For Allocate by Largest Remainder, one bounded call replaces an error-prone arithmetic prompt and returns normalized decimal strings. A successful call costs 1 execution credit.
When to use it
When a quantized total must be split into whole units with Hamilton remainders and keyed tie-breaks.
When you want a continuous pro-rata split, or unitScale and unique ids are still undecided.
Scope
Non-goals
- Does not infer a rounding, materiality, currency, or business policy
- Does not fetch market data or invoke another public skill
- Does not accept unbounded arrays or binary floating-point semantics
Properties
Capabilities
Cost & billing
Flat rate per invocation
File handling
How we handle your data
What this means
This skill may receive sensitive content, but it does not target sensitive data and returns only a structured non-sensitive result.
Squillify guarantees
- Runs inside Squillify
- This skill runs inside Squillify.
- Payloads are not sent to an external service by this skill.
- Squillify does not permanently store submitted payloads.
- Telemetry records metadata only, not submitted content.
- Submitted payloads are not used for training.
- Submitted payloads are not reviewed by humans.
- This skill does not target sensitive data.
- The response does not contain submitted content.
Your responsibility
Squillify does not determine whether submitted content is sensitive. Your application is responsible for deciding what data it is allowed to submit. Your application is responsible for securing the response.
Input schema
| Field | Type | Required | Description |
|---|---|---|---|
| total | string | Yes | Required non-negative total already quantized to unitScale; plain decimal, under 1E100. |
| weights | array | Yes | Required 1 to 10,000 objects {id, weight}; ids are unique tie-break keys and weights are non-negative plain decimals. |
| unitScale | integer | Yes | Required number of decimal places per allocatable unit, from 0 to 12. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| allocations | array | Yes | Rows in input order: {id, amount at unitScale, exactAmount before residual distribution}. |
| ranking | array | Yes | All ids ordered by descending fractional remainder, then id, then input position. |
| residualUnits | integer | Yes | Number of whole units assigned by the ranking. |
| unit | string | Yes | One allocatable unit at unitScale. |
API contract
POST /v1/executecurl -sS -X POST "$BASE/v1/execute" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"skillKey":"math.allocate_largest_remainder","input":{"total":"0.05","weights":[{"id":"B","weight":"1"},{"id":"A","weight":"1"},{"id":"C","weight":"1"}],"unitScale":2}}'import { Squillify } from "@squillify/sdk";
const sq = new Squillify({ apiKey: process.env.SQUILLIFY_API_KEY });
const { output } = await sq.execute("math.allocate_largest_remainder", {"weights":[{"id":"B","weight":"1"},{"id":"A","weight":"1"},{"id":"C","weight":"1"}],"unitScale":2,"total":"0.05"});Errors
| Code | HTTP | Retryable | Description |
|---|---|---|---|
| VALIDATION_ERROR | 400 | No | The request payload failed schema validation. |
| UNAUTHORIZED | 401 | No | Missing or invalid API key. |
| SKILL_NOT_ACCESSIBLE | 403 | No | The API key is not granted access to this skill. |
| SKILL_NOT_AVAILABLE_FOR_PLAN | 403 | No | This skill is not included in your current plan. |
| PLAN_ELIGIBILITY_UNAVAILABLE | 503 | Yes | Plan eligibility could not be decided. Retry after backoff. |
| SKILL_NOT_FOUND | 404 | No | The requested skill or version does not exist. |
| TENANT_RATE_LIMITED | 429 | Yes | Request rate limit exceeded. Retry after backoff. |
| QUOTA_EXCEEDED | 429 | Yes | Plan quota exhausted. Retryable once the quota period resets. |
| EXECUTION_TIMEOUT | 504 | Yes | Execution exceeded the allowed time budget. |
| DECIMAL_INVALID | 400 | No | The request payload failed this skill's input validation. |
| ITEM_LIMIT_EXCEEDED | 429 | No | A size, quota, rate, or time limit was exceeded. |
| ZERO_DENOMINATOR | 400 | No | The request payload failed this skill's input validation. |
| ROUNDING_INVALID | 400 | No | The request payload failed this skill's input validation. |
| ALLOCATION_INVALID | 400 | No | The request payload failed this skill's input validation. |
Other limits
| Limit | Value |
|---|---|
| Recommended inline bytes | 32 KiB |
Limitations
- Does not infer a rounding, materiality, currency, or business policy
- Does not fetch market data or invoke another public skill
- Does not accept unbounded arrays or binary floating-point semantics
- When you want a continuous pro-rata split, or unitScale and unique ids are still undecided.
- Do not use for approximate floating-point analytics or unbounded datasets
How to call
POST /v1/execute (requires authentication)
{
"skillKey": "math.allocate_largest_remainder",
"input": {
"weights": [
{
"id": "B",
"weight": "1"
},
{
"id": "A",
"weight": "1"
},
{
"id": "C",
"weight": "1"
}
],
"unitScale": 2,
"total": "0.05"
}
}Examples
Five cents across equal keyed weights
{
"weights": [
{
"id": "B",
"weight": "1"
},
{
"id": "A",
"weight": "1"
},
{
"id": "C",
"weight": "1"
}
],
"unitScale": 2,
"total": "0.05"
}{
"unit": "0.01",
"ranking": [
"A",
"B",
"C"
],
"residualUnits": 2,
"allocations": [
{
"id": "B",
"amount": "0.02",
"exactAmount": "0.01666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667"
},
{
"id": "A",
"amount": "0.02",
"exactAmount": "0.01666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667"
},
{
"id": "C",
"amount": "0.01",
"exactAmount": "0.01666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667"
}
]
}Whole units with an unequal weight
{
"weights": [
{
"id": "north",
"weight": "3"
},
{
"id": "south",
"weight": "1"
}
],
"unitScale": 0,
"total": "10"
}{
"unit": "1",
"ranking": [
"north",
"south"
],
"residualUnits": 1,
"allocations": [
{
"id": "north",
"amount": "8",
"exactAmount": "7.5"
},
{
"id": "south",
"amount": "2",
"exactAmount": "2.5"
}
]
}Recommended use cases
- When a quantized total must be split into whole units with Hamilton remainders and keyed tie-breaks.
- Use in auditable fund-accounting calculations that need normalized decimal output
Avoid for
- When you want a continuous pro-rata split, or unitScale and unique ids are still undecided.
- Do not use for approximate floating-point analytics or unbounded datasets
Related skills
Composable with
Safety & privacy
- Runs without calling any external service.
- Your payloads are never stored permanently.
- Telemetry captures metadata only — never your payload contents.
- We never train models on your payloads.
- No human reviews your payloads.