← All examples
14

Canonical Grid model

D'Hondt Apportionment

Auditable party-list seat allocation with pure quotient construction and native allocation.

Scale
Medium
Source
14-dhondt-apportionment.grid
Length
24 lines
Collection
Forecasting & decisions
Level
Intermediate
Runtime
Shipped module
Version
1.0.0

Watch it in Grid

See this model in motion.

Watch the model respond in the product, then inspect the exact source and checkpoints on this page.

Companion film

A chart worth sharing

Change one allocation input, refine the reactive Visuals chart, and export deterministic SVG and PNG output.

49 secGrid 0.63.2
Open film page

What this model gives you

An auditable six-seat D’Hondt allocation where a pure quotient table and the native APPORTION kernel independently produce the same seat vector.

20 min to study · Source reviewed 2026-08-26

Continue with guided practice

What to notice

  • Definitions-only shared modules
  • D’Hondt quotient construction
  • Deterministic cutoff and tie policy
  • Independent native-kernel comparison

Requirements

  • Grid 0.61 with shipped shared/politics.gs
  • Native APPORTION function
  • No connector or network

Expected checkpoint

A known state for this walkthrough.

With the shipped politics module and the authored vote vector [100000, 60000, 20000] allocating six seats. There is no cutoff tie; the current verification contract certifies compilation, while the cookbook independently documents the seat result.

Cutoff quotient
25,000H4, sixth-largest quotient
Pure allocation
[4, 2, 0]H6
Native allocation
[4, 2, 0]H8
Seats conserved
TRUEH9
Effective parties
81 / 35 ≈ 2.3143H10
01 · Import

Reuse policy as definitions, not hidden state

shared/politics.gs inlines the quotient and effective-number functions at compile time. The model still owns its votes, seat count, quotient table, and published audit trail.

02 · Construct

Make the quotient table visible

A4 crosses three parties with divisors one through six. LARGE selects the sixth-highest quotient, and BYROW counts each party’s entries at or above that cutoff.

03 · Compare

Ask a separate kernel the same question

APPORTION receives only the votes, seat count, and named method. H9 checks conservation, while the side-by-side summary makes disagreement between H6 and H8 visible during review.

04 · Audit

State the tie contract before a recount needs it

This fixture has no cutoff tie. For tied quotients, input order is the public deterministic tie-break, so preserve and document party ordering in any adapted model.

14-dhondt-apportionment.grid
MODEL "D'Hondt Apportionment"
DESCRIPTION "Auditable party-list seat allocation with pure quotient construction and native allocation."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "portable", "politics", "elections"

USE "shared/politics.gs" AS pol

# Party vote totals and a six-seat house. Input order is the public tie-break.
A1 = [100000, 60000, 20000]
A2 = 6

# Pure Grid quotient table: parties are rows, possible seats are columns.
A4 = [pol.dhondt_quotient(INDEX(A1, 1, party), divisor - 1) FOR party IN 1..3, divisor IN 1..6]
H4 = LARGE(A4, A2)
H6 = BYROW(A4, row => SUM(MAP(row, quotient => quotient >= H4 THEN 1 ELSE 0)))

# Native audited kernel. This result must match H6 for this no-cutoff-tie case.
H8 = APPORTION(A1, A2, "d'hondt")
H9 = SUM(H8) = A2
H10 = pol.effective_number(MAP(A1, votes => votes / SUM(A1)))
A12 = `pure={H6} native={H8} seats_conserved={H9} effective_parties={H10}`

END MODEL