Initial release: GCC-InvoiceMath-Verified v1
Browse files- CONTRACT.md +18 -0
- HUMAN_REVIEW.md +243 -0
- LICENSE +17 -0
- QA_REPORT.md +90 -0
- README.md +199 -0
- RELEASE_CHECKLIST.md +18 -0
- gcc_invoice_math_verified.jsonl +0 -0
- generator.py +118 -0
- manifest.json +50 -0
- sample.jsonl +0 -0
- schema.json +143 -0
- stats.json +51 -0
- validator.py +112 -0
CONTRACT.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Invoice math contract v1.0
|
| 2 |
+
|
| 3 |
+
This is an explicit software-testing contract, not a national tax rulebook.
|
| 4 |
+
|
| 5 |
+
The input is only `invoice` plus this contract. Do not feed expected labels, family, mutation or provenance to a model being evaluated. A challenge file strips these fields. `country` is research metadata; currency precision determines calculation.
|
| 6 |
+
|
| 7 |
+
1. Currency precision: SAR/AED/QAR two decimals; KWD/BHD/OMR three. Precision facts checked against SIX on 2026-09-30. These are the benchmark's arithmetic precision, not a statement that every e-invoice standard permits that precision in every field.
|
| 8 |
+
2. All quantities/prices/allowances/charges/rates are nonnegative; quantity > 0. Rate is an explicitly supplied fraction from 0 to 1; no jurisdiction-specific tax rate is inferred. Negative line net is forbidden.
|
| 9 |
+
3. Line net = round-half-up(quantity × unit_price − allowance + charge, currency precision).
|
| 10 |
+
4. Line tax = round-half-up(line net × rate, currency precision). Tax is rounded per line, NOT on an invoice group or subtotal. This choice is part of the synthetic contract and may differ from a real tax standard.
|
| 11 |
+
5. Net = sum(line net). Tax = sum(line tax). Gross = net + tax. Due = gross − prepaid. Prepaid must be an exact nonnegative currency amount no greater than gross.
|
| 12 |
+
6. Credit notes contain positive line magnitudes and zero prepaid. Negate the final net/tax/gross/due for credit notes. This sign convention is explicitly synthetic.
|
| 13 |
+
7. Output all four canonical ASCII decimal strings with exactly currency precision. `valid` means all claimed totals exactly equal these strings numerically. `error_fields` lists mismatched claimed fields in net,tax,gross,due order. A wrong net claim does not cascade into the expected gross: recompute each from original lines.
|
| 14 |
+
8. Numeric styles are ASCII with dot decimal, Arabic-Indic digits with U+066B decimal, and either with three-digit grouping (comma or U+066C). In grouped style the leading group is one to three digits and later groups exactly three. Minus is ASCII U+002D. No mixed digit alphabets, whitespace, bidi controls, exponent notation, currency symbols, or NaN/Infinity. These excluded parser cases are tested by controls, not claimed as coverage families in the dataset.
|
| 15 |
+
9. Ten designed families cover ties, per-line rounding, allowance, charge, prepayment, credit note, large precision stress, zero rate, mixed rates and zero due. Large-value stress is intentionally unrealistic to reveal binary floating-point errors. It is not an estimate of GCC invoice values.
|
| 16 |
+
10. Every positive/negative pair differs in one claimed total by one minor unit. Keep pairs together in splits. There are five parameter variations per currency/family, not 600 independent business processes. No dialect or natural-language authenticity claim.
|
| 17 |
+
|
| 18 |
+
The benchmark excludes XML/UBL schemas, signing, QR codes, identification, real tax semantics, regulatory certification, OCR, exchange rates, and payment reconciliation.
|
HUMAN_REVIEW.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GCC-InvoiceMath-Verified ? Human Review
|
| 2 |
+
|
| 3 |
+
20 records: one valid/invalid causal pair per scenario family.
|
| 4 |
+
|
| 5 |
+
## credit_note ? VALID
|
| 6 |
+
|
| 7 |
+
- ID: `49987f1529eeaa412c4bce17d4828418`
|
| 8 |
+
- Country: `SA`
|
| 9 |
+
- Currency: `SAR`
|
| 10 |
+
- Numeric style: `grouped_ascii`
|
| 11 |
+
- Document type: `credit_note`
|
| 12 |
+
- Claimed totals: `{"due": "-12,705.82", "gross": "-12,705.82", "net": "-12,100.78", "tax": "-605.04"}`
|
| 13 |
+
- Expected totals: `{"due": "-12705.82", "gross": "-12705.82", "net": "-12100.78", "tax": "-605.04"}`
|
| 14 |
+
- Error fields: `[]`
|
| 15 |
+
- Mutation: `None`
|
| 16 |
+
|
| 17 |
+
## credit_note ? INVALID
|
| 18 |
+
|
| 19 |
+
- ID: `0003524017ef7c5c80b41d416d2a10b7`
|
| 20 |
+
- Country: `SA`
|
| 21 |
+
- Currency: `SAR`
|
| 22 |
+
- Numeric style: `grouped_ascii`
|
| 23 |
+
- Document type: `credit_note`
|
| 24 |
+
- Claimed totals: `{"due": "-12,705.82", "gross": "-12,705.83", "net": "-12,100.78", "tax": "-605.04"}`
|
| 25 |
+
- Expected totals: `{"due": "-12705.82", "gross": "-12705.82", "net": "-12100.78", "tax": "-605.04"}`
|
| 26 |
+
- Error fields: `['gross']`
|
| 27 |
+
- Mutation: `{'delta': '-0.01', 'path': 'claimed_totals.gross', 'single_change': True}`
|
| 28 |
+
|
| 29 |
+
## line_allowance ? VALID
|
| 30 |
+
|
| 31 |
+
- ID: `004f85327f26174a16ff7dfedce2ff94`
|
| 32 |
+
- Country: `BH`
|
| 33 |
+
- Currency: `BHD`
|
| 34 |
+
- Numeric style: `grouped_ascii`
|
| 35 |
+
- Document type: `invoice`
|
| 36 |
+
- Claimed totals: `{"due": "6,857.355", "gross": "6,857.355", "net": "6,530.814", "tax": "326.541"}`
|
| 37 |
+
- Expected totals: `{"due": "6857.355", "gross": "6857.355", "net": "6530.814", "tax": "326.541"}`
|
| 38 |
+
- Error fields: `[]`
|
| 39 |
+
- Mutation: `None`
|
| 40 |
+
|
| 41 |
+
## line_allowance ? INVALID
|
| 42 |
+
|
| 43 |
+
- ID: `fd6cae9a38995dce4682dad331d1d4a5`
|
| 44 |
+
- Country: `BH`
|
| 45 |
+
- Currency: `BHD`
|
| 46 |
+
- Numeric style: `grouped_ascii`
|
| 47 |
+
- Document type: `invoice`
|
| 48 |
+
- Claimed totals: `{"due": "6,857.355", "gross": "6,857.356", "net": "6,530.814", "tax": "326.541"}`
|
| 49 |
+
- Expected totals: `{"due": "6857.355", "gross": "6857.355", "net": "6530.814", "tax": "326.541"}`
|
| 50 |
+
- Error fields: `['gross']`
|
| 51 |
+
- Mutation: `{'delta': '0.001', 'path': 'claimed_totals.gross', 'single_change': True}`
|
| 52 |
+
|
| 53 |
+
## half_up_tie ? VALID
|
| 54 |
+
|
| 55 |
+
- ID: `fe08cf71b7d524ff2abd95c666c0a083`
|
| 56 |
+
- Country: `KW`
|
| 57 |
+
- Currency: `KWD`
|
| 58 |
+
- Numeric style: `arabic_indic`
|
| 59 |
+
- Document type: `invoice`
|
| 60 |
+
- Claimed totals: `{"due": "٥٧٫٢٤٩", "gross": "٥٧٫٢٤٩", "net": "٥٧٫٢٤٩", "tax": "٠٫٠٠٠"}`
|
| 61 |
+
- Expected totals: `{"due": "57.249", "gross": "57.249", "net": "57.249", "tax": "0.000"}`
|
| 62 |
+
- Error fields: `[]`
|
| 63 |
+
- Mutation: `None`
|
| 64 |
+
|
| 65 |
+
## half_up_tie ? INVALID
|
| 66 |
+
|
| 67 |
+
- ID: `00c2e11379c8ad046c4794f9a1260624`
|
| 68 |
+
- Country: `KW`
|
| 69 |
+
- Currency: `KWD`
|
| 70 |
+
- Numeric style: `arabic_indic`
|
| 71 |
+
- Document type: `invoice`
|
| 72 |
+
- Claimed totals: `{"due": "٥٧٫٢٤٩", "gross": "٥٧٫٢٥٠", "net": "٥٧٫٢٤٩", "tax": "٠٫٠٠٠"}`
|
| 73 |
+
- Expected totals: `{"due": "57.249", "gross": "57.249", "net": "57.249", "tax": "0.000"}`
|
| 74 |
+
- Error fields: `['gross']`
|
| 75 |
+
- Mutation: `{'delta': '0.001', 'path': 'claimed_totals.gross', 'single_change': True}`
|
| 76 |
+
|
| 77 |
+
## zero_rate ? VALID
|
| 78 |
+
|
| 79 |
+
- ID: `2286aa7531e4e9a0bec94612f368f487`
|
| 80 |
+
- Country: `OM`
|
| 81 |
+
- Currency: `OMR`
|
| 82 |
+
- Numeric style: `arabic_indic`
|
| 83 |
+
- Document type: `invoice`
|
| 84 |
+
- Claimed totals: `{"due": "٨٥٧٩٫٥٨٠", "gross": "٨٥٧٩٫٥٨٠", "net": "٨٥٧٩٫٥٨٠", "tax": "٠٫٠٠٠"}`
|
| 85 |
+
- Expected totals: `{"due": "8579.580", "gross": "8579.580", "net": "8579.580", "tax": "0.000"}`
|
| 86 |
+
- Error fields: `[]`
|
| 87 |
+
- Mutation: `None`
|
| 88 |
+
|
| 89 |
+
## zero_rate ? INVALID
|
| 90 |
+
|
| 91 |
+
- ID: `00f69c4694801cfc80a130d7a425257d`
|
| 92 |
+
- Country: `OM`
|
| 93 |
+
- Currency: `OMR`
|
| 94 |
+
- Numeric style: `arabic_indic`
|
| 95 |
+
- Document type: `invoice`
|
| 96 |
+
- Claimed totals: `{"due": "٨٥٧٩٫٥٨٠", "gross": "٨٥٧٩٫٥٨٠", "net": "٨٥٧٩٫٥٧٩", "tax": "٠٫٠٠٠"}`
|
| 97 |
+
- Expected totals: `{"due": "8579.580", "gross": "8579.580", "net": "8579.580", "tax": "0.000"}`
|
| 98 |
+
- Error fields: `['net']`
|
| 99 |
+
- Mutation: `{'delta': '-0.001', 'path': 'claimed_totals.net', 'single_change': True}`
|
| 100 |
+
|
| 101 |
+
## line_charge ? VALID
|
| 102 |
+
|
| 103 |
+
- ID: `0130cb39479fd2ac755060cd1abc72c0`
|
| 104 |
+
- Country: `BH`
|
| 105 |
+
- Currency: `BHD`
|
| 106 |
+
- Numeric style: `ascii`
|
| 107 |
+
- Document type: `invoice`
|
| 108 |
+
- Claimed totals: `{"due": "4745.728", "gross": "4745.728", "net": "4519.741", "tax": "225.987"}`
|
| 109 |
+
- Expected totals: `{"due": "4745.728", "gross": "4745.728", "net": "4519.741", "tax": "225.987"}`
|
| 110 |
+
- Error fields: `[]`
|
| 111 |
+
- Mutation: `None`
|
| 112 |
+
|
| 113 |
+
## line_charge ? INVALID
|
| 114 |
+
|
| 115 |
+
- ID: `07ec5263854f8430ec3c811c5de72958`
|
| 116 |
+
- Country: `BH`
|
| 117 |
+
- Currency: `BHD`
|
| 118 |
+
- Numeric style: `ascii`
|
| 119 |
+
- Document type: `invoice`
|
| 120 |
+
- Claimed totals: `{"due": "4745.728", "gross": "4745.728", "net": "4519.740", "tax": "225.987"}`
|
| 121 |
+
- Expected totals: `{"due": "4745.728", "gross": "4745.728", "net": "4519.741", "tax": "225.987"}`
|
| 122 |
+
- Error fields: `['net']`
|
| 123 |
+
- Mutation: `{'delta': '-0.001', 'path': 'claimed_totals.net', 'single_change': True}`
|
| 124 |
+
|
| 125 |
+
## prepayment ? VALID
|
| 126 |
+
|
| 127 |
+
- ID: `ca193fc827f9a3eb5c35683778d28468`
|
| 128 |
+
- Country: `KW`
|
| 129 |
+
- Currency: `KWD`
|
| 130 |
+
- Numeric style: `grouped_ascii`
|
| 131 |
+
- Document type: `invoice`
|
| 132 |
+
- Claimed totals: `{"due": "4,274.217", "gross": "6,411.325", "net": "6,106.024", "tax": "305.301"}`
|
| 133 |
+
- Expected totals: `{"due": "4274.217", "gross": "6411.325", "net": "6106.024", "tax": "305.301"}`
|
| 134 |
+
- Error fields: `[]`
|
| 135 |
+
- Mutation: `None`
|
| 136 |
+
|
| 137 |
+
## prepayment ? INVALID
|
| 138 |
+
|
| 139 |
+
- ID: `022eefb2ca21eb4bbb483574e70cf5c4`
|
| 140 |
+
- Country: `KW`
|
| 141 |
+
- Currency: `KWD`
|
| 142 |
+
- Numeric style: `grouped_ascii`
|
| 143 |
+
- Document type: `invoice`
|
| 144 |
+
- Claimed totals: `{"due": "4,274.216", "gross": "6,411.325", "net": "6,106.024", "tax": "305.301"}`
|
| 145 |
+
- Expected totals: `{"due": "4274.217", "gross": "6411.325", "net": "6106.024", "tax": "305.301"}`
|
| 146 |
+
- Error fields: `['due']`
|
| 147 |
+
- Mutation: `{'delta': '-0.001', 'path': 'claimed_totals.due', 'single_change': True}`
|
| 148 |
+
|
| 149 |
+
## large_amount_stress ? VALID
|
| 150 |
+
|
| 151 |
+
- ID: `03e77757e020511ca9c512d1311cc1dc`
|
| 152 |
+
- Country: `SA`
|
| 153 |
+
- Currency: `SAR`
|
| 154 |
+
- Numeric style: `grouped_arabic_indic`
|
| 155 |
+
- Document type: `invoice`
|
| 156 |
+
- Claimed totals: `{"due": "٣١٥٬٠٠٠٬٠٠٠٬٣٠٧٬٧٤٨٫٤٨", "gross": "٣١٥٬٠٠٠٬٠٠٠٬٣٠٧٬٧٤٨٫٤٨", "net": "٣٠٠٬٠٠٠٬٠٠٠٬٢٩٣٬٠٩٣٫٧٩", "tax": "١٥٬٠٠٠٬٠٠٠٬٠١٤٬٦٥٤٫٦٩"}`
|
| 157 |
+
- Expected totals: `{"due": "315000000307748.48", "gross": "315000000307748.48", "net": "300000000293093.79", "tax": "15000000014654.69"}`
|
| 158 |
+
- Error fields: `[]`
|
| 159 |
+
- Mutation: `None`
|
| 160 |
+
|
| 161 |
+
## large_amount_stress ? INVALID
|
| 162 |
+
|
| 163 |
+
- ID: `24cf4d80fcb10e941f3c7d23b1912ed1`
|
| 164 |
+
- Country: `SA`
|
| 165 |
+
- Currency: `SAR`
|
| 166 |
+
- Numeric style: `grouped_arabic_indic`
|
| 167 |
+
- Document type: `invoice`
|
| 168 |
+
- Claimed totals: `{"due": "٣١٥٬٠٠٠٬٠٠٠٬٣٠٧٬٧٤٨٫٤٧", "gross": "٣١٥٬٠٠٠٬٠٠٠٬٣٠٧٬٧٤٨٫٤٨", "net": "٣٠٠٬٠٠٠٬٠٠٠٬٢٩٣٬٠٩٣٫٧٩", "tax": "١٥٬٠٠٠٬٠٠٠٬٠١٤٬٦٥٤٫٦٩"}`
|
| 169 |
+
- Expected totals: `{"due": "315000000307748.48", "gross": "315000000307748.48", "net": "300000000293093.79", "tax": "15000000014654.69"}`
|
| 170 |
+
- Error fields: `['due']`
|
| 171 |
+
- Mutation: `{'delta': '-0.01', 'path': 'claimed_totals.due', 'single_change': True}`
|
| 172 |
+
|
| 173 |
+
## mixed_rates ? VALID
|
| 174 |
+
|
| 175 |
+
- ID: `d25bf4a9c67725dc25ad673dec7f3232`
|
| 176 |
+
- Country: `QA`
|
| 177 |
+
- Currency: `QAR`
|
| 178 |
+
- Numeric style: `grouped_arabic_indic`
|
| 179 |
+
- Document type: `invoice`
|
| 180 |
+
- Claimed totals: `{"due": "١٦٬٤٩١٫٧٩", "gross": "١٦٬٤٩١٫٧٩", "net": "١٥٬٤٥٢٫٥٠", "tax": "١٬٠٣٩٫٢٩"}`
|
| 181 |
+
- Expected totals: `{"due": "16491.79", "gross": "16491.79", "net": "15452.50", "tax": "1039.29"}`
|
| 182 |
+
- Error fields: `[]`
|
| 183 |
+
- Mutation: `None`
|
| 184 |
+
|
| 185 |
+
## mixed_rates ? INVALID
|
| 186 |
+
|
| 187 |
+
- ID: `07dda1861f8819aee9f865f816cf32a6`
|
| 188 |
+
- Country: `QA`
|
| 189 |
+
- Currency: `QAR`
|
| 190 |
+
- Numeric style: `grouped_arabic_indic`
|
| 191 |
+
- Document type: `invoice`
|
| 192 |
+
- Claimed totals: `{"due": "١٦٬٤٩١٫٧٩", "gross": "١٦٬٤٩١٫٧٩", "net": "١٥٬٤٥٢٫٥٠", "tax": "١٬٠٣٩٫٢٨"}`
|
| 193 |
+
- Expected totals: `{"due": "16491.79", "gross": "16491.79", "net": "15452.50", "tax": "1039.29"}`
|
| 194 |
+
- Error fields: `['tax']`
|
| 195 |
+
- Mutation: `{'delta': '-0.01', 'path': 'claimed_totals.tax', 'single_change': True}`
|
| 196 |
+
|
| 197 |
+
## line_vs_document_rounding ? VALID
|
| 198 |
+
|
| 199 |
+
- ID: `12875e71d71f196da9074dd3e6008464`
|
| 200 |
+
- Country: `AE`
|
| 201 |
+
- Currency: `AED`
|
| 202 |
+
- Numeric style: `grouped_arabic_indic`
|
| 203 |
+
- Document type: `invoice`
|
| 204 |
+
- Claimed totals: `{"due": "٧٣٧٫٩٠", "gross": "٧٣٧٫٩٠", "net": "٧٣٧٫٩٠", "tax": "٠٫٠٠"}`
|
| 205 |
+
- Expected totals: `{"due": "737.90", "gross": "737.90", "net": "737.90", "tax": "0.00"}`
|
| 206 |
+
- Error fields: `[]`
|
| 207 |
+
- Mutation: `None`
|
| 208 |
+
|
| 209 |
+
## line_vs_document_rounding ? INVALID
|
| 210 |
+
|
| 211 |
+
- ID: `08d461285f815185f887e2f5cc88f70f`
|
| 212 |
+
- Country: `AE`
|
| 213 |
+
- Currency: `AED`
|
| 214 |
+
- Numeric style: `grouped_arabic_indic`
|
| 215 |
+
- Document type: `invoice`
|
| 216 |
+
- Claimed totals: `{"due": "٧٣٧٫٩٠", "gross": "٧٣٧٫٨٩", "net": "٧٣٧٫٩٠", "tax": "٠٫٠٠"}`
|
| 217 |
+
- Expected totals: `{"due": "737.90", "gross": "737.90", "net": "737.90", "tax": "0.00"}`
|
| 218 |
+
- Error fields: `['gross']`
|
| 219 |
+
- Mutation: `{'delta': '-0.01', 'path': 'claimed_totals.gross', 'single_change': True}`
|
| 220 |
+
|
| 221 |
+
## zero_due ? VALID
|
| 222 |
+
|
| 223 |
+
- ID: `60936a42fb6a223197e3845e1f77bdb1`
|
| 224 |
+
- Country: `KW`
|
| 225 |
+
- Currency: `KWD`
|
| 226 |
+
- Numeric style: `grouped_ascii`
|
| 227 |
+
- Document type: `invoice`
|
| 228 |
+
- Claimed totals: `{"due": "0.000", "gross": "10,201.088", "net": "9,715.322", "tax": "485.766"}`
|
| 229 |
+
- Expected totals: `{"due": "0.000", "gross": "10201.088", "net": "9715.322", "tax": "485.766"}`
|
| 230 |
+
- Error fields: `[]`
|
| 231 |
+
- Mutation: `None`
|
| 232 |
+
|
| 233 |
+
## zero_due ? INVALID
|
| 234 |
+
|
| 235 |
+
- ID: `1179c373a5da4964be96f9104923bf2f`
|
| 236 |
+
- Country: `KW`
|
| 237 |
+
- Currency: `KWD`
|
| 238 |
+
- Numeric style: `grouped_ascii`
|
| 239 |
+
- Document type: `invoice`
|
| 240 |
+
- Claimed totals: `{"due": "0.001", "gross": "10,201.088", "net": "9,715.322", "tax": "485.766"}`
|
| 241 |
+
- Expected totals: `{"due": "0.000", "gross": "10201.088", "net": "9715.322", "tax": "485.766"}`
|
| 242 |
+
- Error fields: `['due']`
|
| 243 |
+
- Mutation: `{'delta': '0.001', 'path': 'claimed_totals.due', 'single_change': True}`
|
LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
Copyright (c) 2026 RegalFire
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software, dataset metadata, and associated documentation files (the
|
| 5 |
+
"Software"), to deal in the Software without restriction, including without
|
| 6 |
+
limitation the rights to use, copy, modify, merge, publish, distribute,
|
| 7 |
+
sublicense, and/or sell copies of the Software, and to permit persons to whom
|
| 8 |
+
the Software is furnished to do so, subject to the following conditions:
|
| 9 |
+
The above copyright notice and this permission notice shall be included in all
|
| 10 |
+
copies or substantial portions of the Software.
|
| 11 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 12 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 13 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 14 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 15 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 16 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 17 |
+
SOFTWARE.
|
QA_REPORT.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GCC-InvoiceMath-Verified ? QA Report
|
| 2 |
+
Release status
|
| 3 |
+
PASS
|
| 4 |
+
Summary
|
| 5 |
+
Records: 600
|
| 6 |
+
Pairs: 300
|
| 7 |
+
Valid: 300
|
| 8 |
+
Invalid: 300
|
| 9 |
+
Independent validation result:
|
| 10 |
+
600 / 600 PASS
|
| 11 |
+
Coverage
|
| 12 |
+
Countries:
|
| 13 |
+
{
|
| 14 |
+
"SA": 100,
|
| 15 |
+
"AE": 100,
|
| 16 |
+
"BH": 100,
|
| 17 |
+
"KW": 100,
|
| 18 |
+
"OM": 100,
|
| 19 |
+
"QA": 100
|
| 20 |
+
}
|
| 21 |
+
Currencies:
|
| 22 |
+
{
|
| 23 |
+
"SAR": 100,
|
| 24 |
+
"AED": 100,
|
| 25 |
+
"BHD": 100,
|
| 26 |
+
"KWD": 100,
|
| 27 |
+
"OMR": 100,
|
| 28 |
+
"QAR": 100
|
| 29 |
+
}
|
| 30 |
+
Families:
|
| 31 |
+
{
|
| 32 |
+
"credit_note": 60,
|
| 33 |
+
"line_allowance": 60,
|
| 34 |
+
"half_up_tie": 60,
|
| 35 |
+
"zero_rate": 60,
|
| 36 |
+
"line_charge": 60,
|
| 37 |
+
"prepayment": 60,
|
| 38 |
+
"large_amount_stress": 60,
|
| 39 |
+
"mixed_rates": 60,
|
| 40 |
+
"line_vs_document_rounding": 60,
|
| 41 |
+
"zero_due": 60
|
| 42 |
+
}
|
| 43 |
+
Numeric styles:
|
| 44 |
+
{
|
| 45 |
+
"grouped_ascii": 150,
|
| 46 |
+
"arabic_indic": 150,
|
| 47 |
+
"ascii": 150,
|
| 48 |
+
"grouped_arabic_indic": 150
|
| 49 |
+
}
|
| 50 |
+
Splits:
|
| 51 |
+
{
|
| 52 |
+
"train": 360,
|
| 53 |
+
"validation": 120,
|
| 54 |
+
"test": 120
|
| 55 |
+
}
|
| 56 |
+
Error fields:
|
| 57 |
+
{
|
| 58 |
+
"gross": 75,
|
| 59 |
+
"net": 75,
|
| 60 |
+
"tax": 76,
|
| 61 |
+
"due": 74
|
| 62 |
+
}
|
| 63 |
+
Oracle independence
|
| 64 |
+
Generation:
|
| 65 |
+
Python Decimal + ROUND_HALF_UP
|
| 66 |
+
Validation:
|
| 67 |
+
Python Fraction with independently implemented rational rounding
|
| 68 |
+
The validator does not import the generator.
|
| 69 |
+
Integrity checks
|
| 70 |
+
PASS:
|
| 71 |
+
- schema validation
|
| 72 |
+
- unique record IDs
|
| 73 |
+
- fingerprints
|
| 74 |
+
- country/currency mapping
|
| 75 |
+
- deterministic ground truth
|
| 76 |
+
- pair integrity
|
| 77 |
+
- split isolation
|
| 78 |
+
- one valid + one invalid record per pair
|
| 79 |
+
- one-field causal mutations
|
| 80 |
+
- one-minor-unit mutation magnitude
|
| 81 |
+
- semantic source duplicate detection
|
| 82 |
+
- synthetic provenance
|
| 83 |
+
Human review status
|
| 84 |
+
Representative samples should be manually inspected before public release.
|
| 85 |
+
Automated validation does not constitute regulatory, accounting, or tax certification.
|
| 86 |
+
Classification
|
| 87 |
+
Technical quality: STRONG
|
| 88 |
+
Commercial demand: unconfirmed
|
| 89 |
+
Recommended release purpose:
|
| 90 |
+
public benchmark + lead generation for custom ERP/e-invoicing synthetic datasets.
|
README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
tags:
|
| 6 |
+
- synthetic-data
|
| 7 |
+
- gcc
|
| 8 |
+
- invoices
|
| 9 |
+
- ecommerce
|
| 10 |
+
- erp
|
| 11 |
+
- fintech
|
| 12 |
+
- testing
|
| 13 |
+
- data-quality
|
| 14 |
+
- arabic
|
| 15 |
+
- benchmark
|
| 16 |
+
pretty_name: GCC-InvoiceMath-Verified
|
| 17 |
+
size_categories:
|
| 18 |
+
- n<1K
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# GCC-InvoiceMath-Verified
|
| 22 |
+
|
| 23 |
+
A deterministic synthetic benchmark for testing invoice arithmetic, numeric parsing, rounding, and claimed-total validation across six GCC currencies.
|
| 24 |
+
|
| 25 |
+
## Overview
|
| 26 |
+
|
| 27 |
+
GCC-InvoiceMath-Verified contains **600 records / 300 causal pairs**.
|
| 28 |
+
|
| 29 |
+
Each pair contains:
|
| 30 |
+
|
| 31 |
+
- one mathematically correct invoice
|
| 32 |
+
- one counterfactual invoice where exactly one claimed total differs by one minor currency unit
|
| 33 |
+
|
| 34 |
+
The dataset is intended for:
|
| 35 |
+
|
| 36 |
+
- ERP QA
|
| 37 |
+
- e-invoicing integration testing
|
| 38 |
+
- financial software regression testing
|
| 39 |
+
- structured-output validation
|
| 40 |
+
- numerical reasoning evaluation
|
| 41 |
+
- synthetic data benchmarking
|
| 42 |
+
|
| 43 |
+
This benchmark is **not a tax-law compliance benchmark**.
|
| 44 |
+
|
| 45 |
+
It does not certify compliance with ZATCA, UAE e-invoicing rules, PINT, UBL, or any national tax regulation.
|
| 46 |
+
|
| 47 |
+
## Countries and currencies
|
| 48 |
+
|
| 49 |
+
| Country | Currency | Records |
|
| 50 |
+
|---|---|---:|
|
| 51 |
+
| Saudi Arabia | SAR | 100 |
|
| 52 |
+
| United Arab Emirates | AED | 100 |
|
| 53 |
+
| Qatar | QAR | 100 |
|
| 54 |
+
| Kuwait | KWD | 100 |
|
| 55 |
+
| Bahrain | BHD | 100 |
|
| 56 |
+
| Oman | OMR | 100 |
|
| 57 |
+
|
| 58 |
+
SAR, AED and QAR use two benchmark fractional digits.
|
| 59 |
+
|
| 60 |
+
KWD, BHD and OMR use three benchmark fractional digits.
|
| 61 |
+
|
| 62 |
+
## Scenario families
|
| 63 |
+
|
| 64 |
+
The benchmark contains 10 deterministic scenario families:
|
| 65 |
+
|
| 66 |
+
1. `half_up_tie`
|
| 67 |
+
2. `line_vs_document_rounding`
|
| 68 |
+
3. `line_allowance`
|
| 69 |
+
4. `line_charge`
|
| 70 |
+
5. `prepayment`
|
| 71 |
+
6. `credit_note`
|
| 72 |
+
7. `large_amount_stress`
|
| 73 |
+
8. `zero_rate`
|
| 74 |
+
9. `mixed_rates`
|
| 75 |
+
10. `zero_due`
|
| 76 |
+
|
| 77 |
+
Each family contains **60 records**.
|
| 78 |
+
|
| 79 |
+
## Numeric rendering
|
| 80 |
+
|
| 81 |
+
Four rendering styles are equally represented:
|
| 82 |
+
|
| 83 |
+
- ASCII
|
| 84 |
+
- grouped ASCII
|
| 85 |
+
- Arabic-Indic digits
|
| 86 |
+
- grouped Arabic-Indic digits
|
| 87 |
+
|
| 88 |
+
Each style contains **150 records**.
|
| 89 |
+
|
| 90 |
+
This makes it possible to test parsers handling both Western and Arabic-Indic numeric representations.
|
| 91 |
+
|
| 92 |
+
## Dataset structure
|
| 93 |
+
|
| 94 |
+
Important fields include:
|
| 95 |
+
|
| 96 |
+
```json
|
| 97 |
+
{
|
| 98 |
+
"id": "...",
|
| 99 |
+
"pair_id": "...",
|
| 100 |
+
"split": "train",
|
| 101 |
+
"country": "SA",
|
| 102 |
+
"family": "half_up_tie",
|
| 103 |
+
"contract_id": "gcc-invoice-math-1.0",
|
| 104 |
+
"invoice": {
|
| 105 |
+
"currency": "SAR",
|
| 106 |
+
"document_type": "invoice",
|
| 107 |
+
"numeric_style": "arabic_indic",
|
| 108 |
+
"lines": [],
|
| 109 |
+
"prepaid": "...",
|
| 110 |
+
"claimed_totals": {}
|
| 111 |
+
},
|
| 112 |
+
"expected": {
|
| 113 |
+
"valid": true,
|
| 114 |
+
"totals": {},
|
| 115 |
+
"error_fields": []
|
| 116 |
+
},
|
| 117 |
+
"mutation": null,
|
| 118 |
+
"fingerprint_sha256": "..."
|
| 119 |
+
}
|
| 120 |
+
Ground truth
|
| 121 |
+
Ground truth is generated procedurally using Python Decimal arithmetic with explicit ROUND_HALF_UP behavior.
|
| 122 |
+
Validation is performed independently using fractions.Fraction.
|
| 123 |
+
The validator does not import generator code.
|
| 124 |
+
This provides two different arithmetic implementations:
|
| 125 |
+
- generator oracle: Decimal
|
| 126 |
+
- validation oracle: rational arithmetic
|
| 127 |
+
Validation results
|
| 128 |
+
- Records generated: 600
|
| 129 |
+
- Records validated: 600
|
| 130 |
+
- Pass rate: 100%
|
| 131 |
+
- Valid examples: 300
|
| 132 |
+
- Invalid examples: 300
|
| 133 |
+
- Unique causal pairs: 300
|
| 134 |
+
The release also checks:
|
| 135 |
+
- JSON Schema compliance
|
| 136 |
+
- unique IDs
|
| 137 |
+
- unique semantic source invoices
|
| 138 |
+
- fingerprints
|
| 139 |
+
- country/currency consistency
|
| 140 |
+
- pair integrity
|
| 141 |
+
- train/validation/test pair isolation
|
| 142 |
+
- exactly one causal mutation per invalid record
|
| 143 |
+
- exactly one minor-unit difference
|
| 144 |
+
- generator/validator oracle agreement
|
| 145 |
+
Splits
|
| 146 |
+
- train: 360
|
| 147 |
+
- validation: 120
|
| 148 |
+
- test: 120
|
| 149 |
+
Positive and negative members of a causal pair are always kept in the same split.
|
| 150 |
+
Synthetic provenance
|
| 151 |
+
All records are procedurally generated.
|
| 152 |
+
- no real invoices
|
| 153 |
+
- no PII
|
| 154 |
+
- no copied commercial records
|
| 155 |
+
- no real tax identifiers
|
| 156 |
+
- no customer transaction data
|
| 157 |
+
External sources were used only for background research and currency-precision verification.
|
| 158 |
+
Important limitations
|
| 159 |
+
This dataset does not cover:
|
| 160 |
+
- XML / UBL validation
|
| 161 |
+
- digital signatures
|
| 162 |
+
- QR codes
|
| 163 |
+
- live tax submission
|
| 164 |
+
- regulatory certification
|
| 165 |
+
- real tax IDs
|
| 166 |
+
- OCR images
|
| 167 |
+
- exchange rates
|
| 168 |
+
- payment reconciliation
|
| 169 |
+
- jurisdiction-specific VAT interpretation
|
| 170 |
+
Tax rates used in the benchmark are synthetic testing parameters.
|
| 171 |
+
Intended use
|
| 172 |
+
Recommended uses:
|
| 173 |
+
- unit tests
|
| 174 |
+
- regression tests
|
| 175 |
+
- ERP adapter QA
|
| 176 |
+
- invoice parser evaluation
|
| 177 |
+
- financial-agent evaluation
|
| 178 |
+
- data-quality pipelines
|
| 179 |
+
- numeric-reasoning benchmarks
|
| 180 |
+
Commercial customization
|
| 181 |
+
Need a private benchmark matching your ERP, invoice schema, accounting rules, API, or failure modes?
|
| 182 |
+
Custom synthetic datasets can be generated with:
|
| 183 |
+
- client-specific field mappings
|
| 184 |
+
- custom currencies
|
| 185 |
+
- custom rounding behavior
|
| 186 |
+
- additional failure modes
|
| 187 |
+
- private held-out regression suites
|
| 188 |
+
- custom JSON / CSV / Parquet / SQL formats
|
| 189 |
+
- validation scripts
|
| 190 |
+
- QA reports
|
| 191 |
+
The commercial value is in adapting the benchmark to a real system, not simply generating more generic rows.
|
| 192 |
+
Reproducibility
|
| 193 |
+
The generator is deterministic and seed-based.
|
| 194 |
+
Default seed:
|
| 195 |
+
20260930
|
| 196 |
+
See generator.py and validator.py.
|
| 197 |
+
License
|
| 198 |
+
MIT License for the original benchmark code and synthetic fixtures.
|
| 199 |
+
See LICENSE.
|
RELEASE_CHECKLIST.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Release Checklist
|
| 2 |
+
- [x] 600 records generated
|
| 3 |
+
- [x] 600/600 independent validation PASS
|
| 4 |
+
- [x] 300 causal pairs
|
| 5 |
+
- [x] pair-safe splits
|
| 6 |
+
- [x] unique IDs
|
| 7 |
+
- [x] fingerprints verified
|
| 8 |
+
- [x] schema validation
|
| 9 |
+
- [x] provenance documented
|
| 10 |
+
- [x] no PII
|
| 11 |
+
- [x] no copied external records
|
| 12 |
+
- [x] generator included
|
| 13 |
+
- [x] validator included
|
| 14 |
+
- [x] contract included
|
| 15 |
+
- [x] stats included
|
| 16 |
+
- [x] representative sample manually reviewed
|
| 17 |
+
- [ ] Hugging Face repository published
|
| 18 |
+
|
gcc_invoice_math_verified.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generator.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Original procedural invoice arithmetic fixtures. Python >=3.11, standard library."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import argparse, copy, hashlib, json, random
|
| 4 |
+
from decimal import Decimal, ROUND_HALF_UP, localcontext
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
PROFILES = [('SA','SAR',2),('AE','AED',2),('QA','QAR',2),('KW','KWD',3),('BH','BHD',3),('OM','OMR',3)]
|
| 8 |
+
FAMILIES = ['half_up_tie','line_vs_document_rounding','line_allowance','line_charge','prepayment','credit_note','large_amount_stress','zero_rate','mixed_rates','zero_due']
|
| 9 |
+
STYLES = ['ascii','arabic_indic','grouped_ascii','grouped_arabic_indic']
|
| 10 |
+
SOURCES = ['https://zatca.gov.sa/en/E-Invoicing/Introduction/LawsAndRegulations/Pages/default.aspx','https://mof.gov.ae/en/about-us/initiatives/einvoicing/','https://www.six-group.com/en/products-services/financial-information/market-reference-data/data-standards.html','https://arxiv.org/abs/2602.18776']
|
| 11 |
+
|
| 12 |
+
def canonical(x): return json.dumps(x,sort_keys=True,separators=(',',':'),ensure_ascii=False)
|
| 13 |
+
def digest(x): return hashlib.sha256(canonical(x).encode()).hexdigest()
|
| 14 |
+
def fmt(x,scale): return format(x,f'.{scale}f')
|
| 15 |
+
def render(s,style):
|
| 16 |
+
sign = ''
|
| 17 |
+
if s.startswith('-'):
|
| 18 |
+
sign = '-'
|
| 19 |
+
s = s[1:]
|
| 20 |
+
|
| 21 |
+
if 'grouped' in style:
|
| 22 |
+
whole, sep, frac = s.partition('.')
|
| 23 |
+
whole = f'{int(whole):,}'
|
| 24 |
+
s = whole + (sep + frac if sep else '')
|
| 25 |
+
|
| 26 |
+
s = sign + s
|
| 27 |
+
|
| 28 |
+
if 'arabic' in style:
|
| 29 |
+
trans = str.maketrans({
|
| 30 |
+
'0': chr(0x0660), '1': chr(0x0661), '2': chr(0x0662),
|
| 31 |
+
'3': chr(0x0663), '4': chr(0x0664), '5': chr(0x0665),
|
| 32 |
+
'6': chr(0x0666), '7': chr(0x0667), '8': chr(0x0668),
|
| 33 |
+
'9': chr(0x0669), '.': chr(0x066B), ',': chr(0x066C)
|
| 34 |
+
})
|
| 35 |
+
s = s.translate(trans)
|
| 36 |
+
|
| 37 |
+
return s
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def calculate(lines,prepaid,scale,credit=False):
|
| 41 |
+
"""Generator oracle uses Decimal; validator must not import this function."""
|
| 42 |
+
step=Decimal(1).scaleb(-scale)
|
| 43 |
+
nets=[(l['quantity']*l['unit_price']-l['allowance']+l['charge']).quantize(step,rounding=ROUND_HALF_UP) for l in lines]
|
| 44 |
+
taxes=[(n*l['rate']).quantize(step,rounding=ROUND_HALF_UP) for n,l in zip(nets,lines)]
|
| 45 |
+
net=sum(nets,Decimal(0)); tax=sum(taxes,Decimal(0)); gross=net+tax
|
| 46 |
+
sign=-1 if credit else 1
|
| 47 |
+
return {k:fmt(v*sign,scale) for k,v in dict(net=net,tax=tax,gross=gross,due=gross-prepaid).items()}
|
| 48 |
+
|
| 49 |
+
def make_pair(currency_index,family_index,variation,seed):
|
| 50 |
+
country,currency,scale=PROFILES[currency_index]
|
| 51 |
+
family=FAMILIES[family_index]
|
| 52 |
+
unit=Decimal(1).scaleb(-scale)
|
| 53 |
+
local_seed=seed+currency_index*100000+family_index*1000+variation
|
| 54 |
+
rng=random.Random(local_seed)
|
| 55 |
+
lines=[dict(quantity=Decimal(rng.randint(1,9)),unit_price=Decimal(rng.randint(100000,900000))/1000,allowance=Decimal(0),charge=Decimal(0),rate=Decimal('0.05')) for _ in range(rng.randint(2,5))]
|
| 56 |
+
if family in ('half_up_tie','line_vs_document_rounding'):
|
| 57 |
+
# Even minor-unit base distinguishes half-up from ties-to-even.
|
| 58 |
+
lines=[dict(quantity=Decimal(1),unit_price=Decimal(rng.randrange(10000,90000,2))*unit+unit/2,allowance=Decimal(0),charge=Decimal(0),rate=Decimal(0)) for _ in range(2 if family=='line_vs_document_rounding' else 1)]
|
| 59 |
+
if family=='line_allowance':
|
| 60 |
+
for l in lines: l['allowance']=Decimal(rng.randint(1,900))*unit
|
| 61 |
+
if family=='line_charge':
|
| 62 |
+
for l in lines: l['charge']=Decimal(rng.randint(1,900))*unit
|
| 63 |
+
if family=='large_amount_stress':
|
| 64 |
+
lines[0]['unit_price']=Decimal(10**14+rng.randint(100,99999))+Decimal(7)*unit
|
| 65 |
+
if family=='zero_rate':
|
| 66 |
+
for l in lines: l['rate']=Decimal(0)
|
| 67 |
+
if family=='mixed_rates':
|
| 68 |
+
for i,l in enumerate(lines): l['rate']=[Decimal(0),Decimal('.05'),Decimal('.15')][i%3]
|
| 69 |
+
prepaid=Decimal(0)
|
| 70 |
+
totals=calculate(lines,prepaid,scale,False)
|
| 71 |
+
if family=='prepayment': prepaid=(Decimal(totals['gross'])/3).quantize(unit,rounding=ROUND_HALF_UP)
|
| 72 |
+
if family=='zero_due': prepaid=Decimal(totals['gross'])
|
| 73 |
+
totals=calculate(lines,prepaid,scale,family=='credit_note')
|
| 74 |
+
style=STYLES[(currency_index*50+family_index*5+variation)%4]
|
| 75 |
+
invoice=dict(currency=currency,document_type='credit_note' if family=='credit_note' else 'invoice',numeric_style=style,
|
| 76 |
+
lines=[{k:render(fmt(v,scale+3 if k=='unit_price' else scale if k in ('allowance','charge') else 2),style) for k,v in l.items()} for l in lines],
|
| 77 |
+
prepaid=render(fmt(prepaid,scale),style))
|
| 78 |
+
pair_id=digest(invoice)[:24]
|
| 79 |
+
split='train' if variation<3 else 'validation' if variation==3 else 'test'
|
| 80 |
+
field=['net','tax','gross','due'][(currency_index+family_index+variation)%4]
|
| 81 |
+
# Signed, one-minor-unit mutation. Both directions occur within each slice.
|
| 82 |
+
bad=copy.deepcopy(totals)
|
| 83 |
+
delta=unit * (-1 if (currency_index+variation)%2 else 1)
|
| 84 |
+
bad[field]=fmt(Decimal(bad[field])+delta,scale)
|
| 85 |
+
pair=[]
|
| 86 |
+
for claimed,valid in [(totals,True),(bad,False)]:
|
| 87 |
+
candidate=copy.deepcopy(invoice)
|
| 88 |
+
candidate['claimed_totals']={k:render(v,style) for k,v in claimed.items()}
|
| 89 |
+
record=dict(id=digest(candidate)[:32],pair_id=pair_id,seed=local_seed,split=split,country=country,family=family,
|
| 90 |
+
contract_id='gcc-invoice-math-1.0',invoice=candidate,
|
| 91 |
+
expected=dict(valid=valid,totals=totals,error_fields=[] if valid else [field]),
|
| 92 |
+
provenance=dict(synthetic=True,external_sources_used_for_research=SOURCES,copied_records=0,generation_method='procedural Decimal oracle plus single claimed-total perturbation',license_reviewed=True,license_review_scope='Original code and fixtures; no external records/code reused. Not a legal opinion.',model=None),
|
| 93 |
+
mutation=None if valid else dict(
|
| 94 |
+
path='claimed_totals.'+field,
|
| 95 |
+
delta=fmt(
|
| 96 |
+
Decimal(claimed[field]) - Decimal(totals[field]),
|
| 97 |
+
scale
|
| 98 |
+
),
|
| 99 |
+
single_change=True
|
| 100 |
+
))
|
| 101 |
+
record['fingerprint_sha256']=digest(record)
|
| 102 |
+
pair.append(record)
|
| 103 |
+
return pair
|
| 104 |
+
|
| 105 |
+
def generate(seed=20260930,variations=5):
|
| 106 |
+
if variations!=5: raise ValueError('v1 pilot is fixed at five parameter variants per currency/family; custom scaling requires new QA')
|
| 107 |
+
with localcontext() as ctx:
|
| 108 |
+
ctx.prec=50
|
| 109 |
+
rows=[r for c in range(6) for f in range(10) for v in range(variations) for r in make_pair(c,f,v,seed)]
|
| 110 |
+
return sorted(rows,key=lambda x:x['id'])
|
| 111 |
+
|
| 112 |
+
def write_jsonl(path,rows):
|
| 113 |
+
Path(path).write_text(''.join(canonical(r)+'\n' for r in rows),encoding='utf-8',newline='\n')
|
| 114 |
+
|
| 115 |
+
if __name__=='__main__':
|
| 116 |
+
p=argparse.ArgumentParser(); p.add_argument('--output',type=Path,required=True); p.add_argument('--seed',type=int,default=20260930)
|
| 117 |
+
a=p.parse_args(); a.output.parent.mkdir(parents=True,exist_ok=True); rows=generate(a.seed); write_jsonl(a.output,rows)
|
| 118 |
+
print(json.dumps(dict(records=len(rows),sha256=hashlib.sha256(a.output.read_bytes()).hexdigest())))
|
manifest.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"CONTRACT.md": {
|
| 3 |
+
"bytes": 2983,
|
| 4 |
+
"sha256": "24fc032fd1e662ac2ed0f9872c7db6b30eba395e683add1104f8fdaf6dfac0cc"
|
| 5 |
+
},
|
| 6 |
+
"gcc_invoice_math_verified.jsonl": {
|
| 7 |
+
"bytes": 985994,
|
| 8 |
+
"sha256": "c5fa3a9c0ccc1604660c30d3da81ca61594e338992e2a91edbad80a9593afdb9"
|
| 9 |
+
},
|
| 10 |
+
"generator.py": {
|
| 11 |
+
"bytes": 6911,
|
| 12 |
+
"sha256": "78f380e898ad65760f49f3a75eaa53dcd5837c7e429691f386a0fcf983d19456"
|
| 13 |
+
},
|
| 14 |
+
"HUMAN_REVIEW.md": {
|
| 15 |
+
"bytes": 9658,
|
| 16 |
+
"sha256": "d77b5600cd8869b1a25d4fccbc74a5dd6532bc1fc320c6d43dd21fbbca156692"
|
| 17 |
+
},
|
| 18 |
+
"LICENSE": {
|
| 19 |
+
"bytes": 1098,
|
| 20 |
+
"sha256": "689ec9660a76757dfac03df5b89e5ff8bd8251b484c30aafe9439e35b8211f07"
|
| 21 |
+
},
|
| 22 |
+
"QA_REPORT.md": {
|
| 23 |
+
"bytes": 1827,
|
| 24 |
+
"sha256": "49c012b6a98403a2b0c4587d087849e0f21e12f7f77abbb0d80f9728ff128cc2"
|
| 25 |
+
},
|
| 26 |
+
"README.md": {
|
| 27 |
+
"bytes": 5176,
|
| 28 |
+
"sha256": "27be7925d7b4e9401a150e149fde4c8f64e016f2e3dd0ab18e0b9ccf03857179"
|
| 29 |
+
},
|
| 30 |
+
"RELEASE_CHECKLIST.md": {
|
| 31 |
+
"bytes": 479,
|
| 32 |
+
"sha256": "eb2220a0ba284453264db4dafe86731c9bdc46c8064e5720f1aebb0c02d53d6a"
|
| 33 |
+
},
|
| 34 |
+
"sample.jsonl": {
|
| 35 |
+
"bytes": 207109,
|
| 36 |
+
"sha256": "8a8d20379bc4809d1ac5d7bdbc90c830b6593722ecd693b3db73387046a347e0"
|
| 37 |
+
},
|
| 38 |
+
"schema.json": {
|
| 39 |
+
"bytes": 3954,
|
| 40 |
+
"sha256": "1064be5d4d184f397fabc903f283419df521756627455205ee9d44ad1f3f6591"
|
| 41 |
+
},
|
| 42 |
+
"stats.json": {
|
| 43 |
+
"bytes": 924,
|
| 44 |
+
"sha256": "92740a0ab26ae3fb0c19163ccc3ba1aa55f50f7ae96cd59269d3b949a86e868a"
|
| 45 |
+
},
|
| 46 |
+
"validator.py": {
|
| 47 |
+
"bytes": 6733,
|
| 48 |
+
"sha256": "50f2b5b23f78cdc94b955871fda7f2c1c833b143907f208d5e3c77d6a6b6a38e"
|
| 49 |
+
}
|
| 50 |
+
}
|
sample.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
schema.json
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"type": "object",
|
| 4 |
+
"required": [
|
| 5 |
+
"id",
|
| 6 |
+
"pair_id",
|
| 7 |
+
"seed",
|
| 8 |
+
"split",
|
| 9 |
+
"country",
|
| 10 |
+
"family",
|
| 11 |
+
"contract_id",
|
| 12 |
+
"invoice",
|
| 13 |
+
"expected",
|
| 14 |
+
"provenance",
|
| 15 |
+
"mutation",
|
| 16 |
+
"fingerprint_sha256"
|
| 17 |
+
],
|
| 18 |
+
"properties": {
|
| 19 |
+
"id": { "type": "string", "minLength": 32, "maxLength": 32 },
|
| 20 |
+
"pair_id": { "type": "string", "minLength": 24, "maxLength": 24 },
|
| 21 |
+
"seed": { "type": "integer" },
|
| 22 |
+
"split": { "enum": ["train", "validation", "test"] },
|
| 23 |
+
"country": { "enum": ["SA", "AE", "QA", "KW", "BH", "OM"] },
|
| 24 |
+
"family": {
|
| 25 |
+
"enum": [
|
| 26 |
+
"half_up_tie",
|
| 27 |
+
"line_vs_document_rounding",
|
| 28 |
+
"line_allowance",
|
| 29 |
+
"line_charge",
|
| 30 |
+
"prepayment",
|
| 31 |
+
"credit_note",
|
| 32 |
+
"large_amount_stress",
|
| 33 |
+
"zero_rate",
|
| 34 |
+
"mixed_rates",
|
| 35 |
+
"zero_due"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
"contract_id": { "const": "gcc-invoice-math-1.0" },
|
| 39 |
+
"invoice": {
|
| 40 |
+
"type": "object",
|
| 41 |
+
"required": [
|
| 42 |
+
"currency",
|
| 43 |
+
"document_type",
|
| 44 |
+
"numeric_style",
|
| 45 |
+
"lines",
|
| 46 |
+
"prepaid",
|
| 47 |
+
"claimed_totals"
|
| 48 |
+
],
|
| 49 |
+
"properties": {
|
| 50 |
+
"currency": { "enum": ["SAR", "AED", "QAR", "KWD", "BHD", "OMR"] },
|
| 51 |
+
"document_type": { "enum": ["invoice", "credit_note"] },
|
| 52 |
+
"numeric_style": {
|
| 53 |
+
"enum": [
|
| 54 |
+
"ascii",
|
| 55 |
+
"arabic_indic",
|
| 56 |
+
"grouped_ascii",
|
| 57 |
+
"grouped_arabic_indic"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
"lines": {
|
| 61 |
+
"type": "array",
|
| 62 |
+
"minItems": 1,
|
| 63 |
+
"items": {
|
| 64 |
+
"type": "object",
|
| 65 |
+
"required": ["quantity", "unit_price", "allowance", "charge", "rate"],
|
| 66 |
+
"properties": {
|
| 67 |
+
"quantity": { "type": "string" },
|
| 68 |
+
"unit_price": { "type": "string" },
|
| 69 |
+
"allowance": { "type": "string" },
|
| 70 |
+
"charge": { "type": "string" },
|
| 71 |
+
"rate": { "type": "string" }
|
| 72 |
+
},
|
| 73 |
+
"additionalProperties": false
|
| 74 |
+
}
|
| 75 |
+
},
|
| 76 |
+
"prepaid": { "type": "string" },
|
| 77 |
+
"claimed_totals": {
|
| 78 |
+
"type": "object",
|
| 79 |
+
"required": ["net", "tax", "gross", "due"],
|
| 80 |
+
"properties": {
|
| 81 |
+
"net": { "type": "string" },
|
| 82 |
+
"tax": { "type": "string" },
|
| 83 |
+
"gross": { "type": "string" },
|
| 84 |
+
"due": { "type": "string" }
|
| 85 |
+
},
|
| 86 |
+
"additionalProperties": false
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
"additionalProperties": false
|
| 90 |
+
},
|
| 91 |
+
"expected": {
|
| 92 |
+
"type": "object",
|
| 93 |
+
"required": ["valid", "totals", "error_fields"],
|
| 94 |
+
"properties": {
|
| 95 |
+
"valid": { "type": "boolean" },
|
| 96 |
+
"totals": {
|
| 97 |
+
"type": "object",
|
| 98 |
+
"required": ["net", "tax", "gross", "due"],
|
| 99 |
+
"properties": {
|
| 100 |
+
"net": { "type": "string" },
|
| 101 |
+
"tax": { "type": "string" },
|
| 102 |
+
"gross": { "type": "string" },
|
| 103 |
+
"due": { "type": "string" }
|
| 104 |
+
},
|
| 105 |
+
"additionalProperties": false
|
| 106 |
+
},
|
| 107 |
+
"error_fields": {
|
| 108 |
+
"type": "array",
|
| 109 |
+
"items": { "enum": ["net", "tax", "gross", "due"] }
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
"additionalProperties": false
|
| 113 |
+
},
|
| 114 |
+
"provenance": {
|
| 115 |
+
"type": "object",
|
| 116 |
+
"required": [
|
| 117 |
+
"synthetic",
|
| 118 |
+
"external_sources_used_for_research",
|
| 119 |
+
"copied_records",
|
| 120 |
+
"generation_method",
|
| 121 |
+
"license_reviewed",
|
| 122 |
+
"license_review_scope",
|
| 123 |
+
"model"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
"mutation": {
|
| 127 |
+
"anyOf": [
|
| 128 |
+
{ "type": "null" },
|
| 129 |
+
{
|
| 130 |
+
"type": "object",
|
| 131 |
+
"required": ["path", "delta", "single_change"],
|
| 132 |
+
"properties": {
|
| 133 |
+
"path": { "type": "string" },
|
| 134 |
+
"delta": { "type": "string" },
|
| 135 |
+
"single_change": { "const": true }
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
]
|
| 139 |
+
},
|
| 140 |
+
"fingerprint_sha256": { "type": "string", "minLength": 64, "maxLength": 64 }
|
| 141 |
+
},
|
| 142 |
+
"additionalProperties": false
|
| 143 |
+
}
|
stats.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"records": 600,
|
| 3 |
+
"pairs": 300,
|
| 4 |
+
"valid_records": 300,
|
| 5 |
+
"invalid_records": 300,
|
| 6 |
+
"countries": {
|
| 7 |
+
"SA": 100,
|
| 8 |
+
"AE": 100,
|
| 9 |
+
"BH": 100,
|
| 10 |
+
"KW": 100,
|
| 11 |
+
"OM": 100,
|
| 12 |
+
"QA": 100
|
| 13 |
+
},
|
| 14 |
+
"currencies": {
|
| 15 |
+
"SAR": 100,
|
| 16 |
+
"AED": 100,
|
| 17 |
+
"BHD": 100,
|
| 18 |
+
"KWD": 100,
|
| 19 |
+
"OMR": 100,
|
| 20 |
+
"QAR": 100
|
| 21 |
+
},
|
| 22 |
+
"families": {
|
| 23 |
+
"credit_note": 60,
|
| 24 |
+
"line_allowance": 60,
|
| 25 |
+
"half_up_tie": 60,
|
| 26 |
+
"zero_rate": 60,
|
| 27 |
+
"line_charge": 60,
|
| 28 |
+
"prepayment": 60,
|
| 29 |
+
"large_amount_stress": 60,
|
| 30 |
+
"mixed_rates": 60,
|
| 31 |
+
"line_vs_document_rounding": 60,
|
| 32 |
+
"zero_due": 60
|
| 33 |
+
},
|
| 34 |
+
"splits": {
|
| 35 |
+
"train": 360,
|
| 36 |
+
"validation": 120,
|
| 37 |
+
"test": 120
|
| 38 |
+
},
|
| 39 |
+
"numeric_styles": {
|
| 40 |
+
"grouped_ascii": 150,
|
| 41 |
+
"arabic_indic": 150,
|
| 42 |
+
"ascii": 150,
|
| 43 |
+
"grouped_arabic_indic": 150
|
| 44 |
+
},
|
| 45 |
+
"error_fields": {
|
| 46 |
+
"gross": 75,
|
| 47 |
+
"net": 75,
|
| 48 |
+
"tax": 76,
|
| 49 |
+
"due": 74
|
| 50 |
+
}
|
| 51 |
+
}
|
validator.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent rational-arithmetic oracle. Never imports generator code."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import argparse, hashlib, json, re
|
| 4 |
+
from fractions import Fraction
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from collections import Counter, defaultdict
|
| 7 |
+
from jsonschema import Draft202012Validator
|
| 8 |
+
|
| 9 |
+
SCALES={'SAR':2,'AED':2,'QAR':2,'KWD':3,'BHD':3,'OMR':3}
|
| 10 |
+
COUNTRIES={'SAR':'SA','AED':'AE','QAR':'QA','KWD':'KW','BHD':'BH','OMR':'OM'}
|
| 11 |
+
FIELDS=('net','tax','gross','due')
|
| 12 |
+
|
| 13 |
+
def parse(text,style):
|
| 14 |
+
"""Reject mixed alphabets, malformed grouping, exponent notation and bidi controls."""
|
| 15 |
+
if not isinstance(text,str) or len(text)>80: raise ValueError('invalid number type/length')
|
| 16 |
+
arabic='arabic' in style
|
| 17 |
+
digits=''.join(chr(0x0660+i) for i in range(10)) if arabic else '0123456789'
|
| 18 |
+
dot=chr(0x066B) if arabic else '.'; group=chr(0x066C) if arabic else ','
|
| 19 |
+
integer=rf'[{digits}]{{1,3}}(?:{re.escape(group)}[{digits}]{{3}})*' if 'grouped' in style else rf'[{digits}]+'
|
| 20 |
+
pattern=rf'-?{integer}(?:{re.escape(dot)}[{digits}]+)?'
|
| 21 |
+
if re.fullmatch(pattern,text) is None: raise ValueError('number violates declared grammar')
|
| 22 |
+
# Decode each digit individually rather than sharing generator formatting helpers.
|
| 23 |
+
negative=text.startswith('-'); body=text[1:] if negative else text
|
| 24 |
+
sides=body.split(dot); whole=sides[0].replace(group,''); tail=sides[1] if len(sides)==2 else ''
|
| 25 |
+
n=0
|
| 26 |
+
for ch in whole+tail: n=n*10+digits.index(ch)
|
| 27 |
+
return Fraction(-n if negative else n,10**len(tail))
|
| 28 |
+
|
| 29 |
+
def rounded_minor(value,scale):
|
| 30 |
+
scaled=value*10**scale
|
| 31 |
+
a,b=abs(scaled.numerator),scaled.denominator
|
| 32 |
+
q,r=divmod(a,b)
|
| 33 |
+
return (-1 if scaled<0 else 1)*(q+(2*r>=b))
|
| 34 |
+
|
| 35 |
+
def money(n,scale):
|
| 36 |
+
sign='-' if n<0 else ''; n=abs(n); div=10**scale
|
| 37 |
+
return f'{sign}{n//div}.{n%div:0{scale}d}'
|
| 38 |
+
|
| 39 |
+
def oracle(invoice):
|
| 40 |
+
scale=SCALES[invoice['currency']]; style=invoice['numeric_style']; unit=10**scale
|
| 41 |
+
nets=[]; taxes=[]
|
| 42 |
+
for line in invoice['lines']:
|
| 43 |
+
q,p,a,c,r=[parse(line[k],style) for k in ['quantity','unit_price','allowance','charge','rate']]
|
| 44 |
+
if q<=0 or any(x<0 for x in (p,a,c,r)) or r>1: raise ValueError('impossible source line')
|
| 45 |
+
raw=q*p-a+c
|
| 46 |
+
if raw<0: raise ValueError('negative line net')
|
| 47 |
+
net=rounded_minor(raw,scale); nets.append(net)
|
| 48 |
+
taxes.append(rounded_minor(Fraction(net,unit)*r,scale))
|
| 49 |
+
net=sum(nets); tax=sum(taxes); gross=net+tax
|
| 50 |
+
pre=parse(invoice['prepaid'],style)*unit
|
| 51 |
+
if pre.denominator!=1 or pre<0 or pre>gross: raise ValueError('invalid prepaid')
|
| 52 |
+
if invoice['document_type']=='credit_note' and pre: raise ValueError('credit prepayment forbidden in this contract')
|
| 53 |
+
sign=-1 if invoice['document_type']=='credit_note' else 1
|
| 54 |
+
amounts=dict(net=sign*net,tax=sign*tax,gross=sign*gross,due=sign*(gross-int(pre)))
|
| 55 |
+
expected={k:money(v,scale) for k,v in amounts.items()}
|
| 56 |
+
errors=[]
|
| 57 |
+
for k in FIELDS:
|
| 58 |
+
obs=parse(invoice['claimed_totals'][k],style)*unit
|
| 59 |
+
if obs.denominator!=1 or obs!=amounts[k]: errors.append(k)
|
| 60 |
+
return dict(valid=not errors,totals=expected,error_fields=errors)
|
| 61 |
+
|
| 62 |
+
def canonical(x): return json.dumps(x,sort_keys=True,separators=(',',':'),ensure_ascii=False)
|
| 63 |
+
def sha(x): return hashlib.sha256(canonical(x).encode()).hexdigest()
|
| 64 |
+
|
| 65 |
+
def validate(rows,schema):
|
| 66 |
+
checker=Draft202012Validator(schema); ids=set(); content=set(); pairs=defaultdict(list); evidence=[]
|
| 67 |
+
for row in rows:
|
| 68 |
+
checker.validate(row)
|
| 69 |
+
if row['id'] in ids: raise ValueError('duplicate ID')
|
| 70 |
+
ids.add(row['id'])
|
| 71 |
+
d=sha(row['invoice'])
|
| 72 |
+
if d in content: raise ValueError('duplicate invoice')
|
| 73 |
+
content.add(d)
|
| 74 |
+
if row['id']!=d[:32]: raise ValueError('id mismatch')
|
| 75 |
+
body={k:v for k,v in row.items() if k!='fingerprint_sha256'}
|
| 76 |
+
if sha(body)!=row['fingerprint_sha256']: raise ValueError('fingerprint mismatch')
|
| 77 |
+
if row['country']!=COUNTRIES[row['invoice']['currency']]: raise ValueError('currency-country mismatch')
|
| 78 |
+
computed=oracle(row['invoice'])
|
| 79 |
+
if computed!=row['expected']: raise ValueError(f'oracle disagreement {row["id"]}')
|
| 80 |
+
if row['provenance']['copied_records']!=0 or not row['provenance']['synthetic']: raise ValueError('provenance mismatch')
|
| 81 |
+
pairs[row['pair_id']].append(row)
|
| 82 |
+
evidence.append(dict(id=row['id'],independent_oracle=computed,fingerprint_sha256=row['fingerprint_sha256'],pass_all=True))
|
| 83 |
+
# Validate pairing and leakage at semantic input level, beyond IDs.
|
| 84 |
+
base_hashes=set()
|
| 85 |
+
for pair_id,pair in pairs.items():
|
| 86 |
+
if len(pair)!=2 or sum(x['expected']['valid'] for x in pair)!=1: raise ValueError('pair label/count failure')
|
| 87 |
+
a,b=sorted(pair,key=lambda x:not x['expected']['valid'])
|
| 88 |
+
if a['split']!=b['split']: raise ValueError('split leakage')
|
| 89 |
+
src_a={k:v for k,v in a['invoice'].items() if k!='claimed_totals'}
|
| 90 |
+
src_b={k:v for k,v in b['invoice'].items() if k!='claimed_totals'}
|
| 91 |
+
if src_a!=src_b or sha(src_a)[:24]!=pair_id: raise ValueError('pair inputs differ')
|
| 92 |
+
changes=[k for k in FIELDS if a['invoice']['claimed_totals'][k]!=b['invoice']['claimed_totals'][k]]
|
| 93 |
+
if changes!=b['expected']['error_fields'] or len(changes)!=1: raise ValueError('not a causal single-field mutation')
|
| 94 |
+
field=changes[0]; style=a['invoice']['numeric_style']; scale=SCALES[a['invoice']['currency']]
|
| 95 |
+
delta=parse(b['invoice']['claimed_totals'][field],style)-parse(a['invoice']['claimed_totals'][field],style)
|
| 96 |
+
if abs(delta)!=Fraction(1,10**scale): raise ValueError('incorrect mutation delta')
|
| 97 |
+
if b['mutation']['path']!='claimed_totals.'+field or parse(b['mutation']['delta'],'ascii')!=delta: raise ValueError('mutation trace mismatch')
|
| 98 |
+
if a['mutation'] is not None: raise ValueError('valid record has mutation')
|
| 99 |
+
semantic=src_a.copy(); semantic.pop('numeric_style')
|
| 100 |
+
semantic['lines']=[{k:str(parse(v,style)) for k,v in l.items()} for l in semantic['lines']]
|
| 101 |
+
semantic['prepaid']=str(parse(semantic['prepaid'],style))
|
| 102 |
+
normalized=sha(semantic)
|
| 103 |
+
if normalized in base_hashes: raise ValueError('semantic duplicate source')
|
| 104 |
+
base_hashes.add(normalized)
|
| 105 |
+
return evidence
|
| 106 |
+
|
| 107 |
+
if __name__=='__main__':
|
| 108 |
+
p=argparse.ArgumentParser(); p.add_argument('dataset',type=Path); p.add_argument('--schema',type=Path,required=True); p.add_argument('--log',type=Path)
|
| 109 |
+
a=p.parse_args(); rows=[json.loads(x) for x in a.dataset.read_text(encoding='utf-8').splitlines()]
|
| 110 |
+
log=validate(rows,json.loads(a.schema.read_text(encoding='utf-8')))
|
| 111 |
+
if a.log: a.log.write_text(''.join(canonical(r)+'\n' for r in log),encoding='utf-8')
|
| 112 |
+
print(json.dumps(dict(validated=len(log),status='PASS')))
|