"""J.VIP original synthetic football counterexamples; Python 3 stdlib only. Not real match results, predictions, a complete competition-rule engine or betting settlement. Official-rule inputs are individually documented in evidence-ledger.json. Run: python reproduce_football_cases.py --output-dir PATH """ from __future__ import annotations import argparse, csv, json from collections import Counter from datetime import date from itertools import combinations from pathlib import Path def table(matches, teams=None): teams = sorted(teams or {t for m in matches for t in m[:2]}) out = {t: dict(played=0, points=0, gf=0, ga=0, gd=0, wins=0) for t in teams} for home, away, hg, ag in matches: assert home != away and isinstance(hg, int) and isinstance(ag, int) and min(hg, ag) >= 0 for t, f, a in [(home, hg, ag), (away, ag, hg)]: r = out[t]; r['played'] += 1; r['gf'] += f; r['ga'] += a r['points'] += 3 if f > a else 1 if f == a else 0 r['wins'] += int(f > a); r['gd'] = r['gf'] - r['ga'] assert sum(r['gf'] for r in out.values()) == sum(r['ga'] for r in out.values()) return out def mini(matches, teams): return table([m for m in matches if m[0] in teams and m[1] in teams], teams) def write_csv(path, rows, fields): with path.open('w', newline='', encoding='utf-8-sig') as f: w = csv.DictWriter(f, fields); w.writeheader(); w.writerows(rows) def league_schedule(n, scenario): assert n in (18, 20) and scenario in (1, 2) teams = ['U', 'V', 'A', 'B', 'C', 'D'] + [f'R{i:02}' for i in range(1, n-5)] fixed = {('A','B'):(0,1),('B','A'):(0,0),('A','C'):(4,0),('C','A'):(0,1), ('A','D'):(1,0),('D','A'):(0,0),('B','C'):(1,0),('C','B'):(1,0), ('B','D'):(1,0),('D','B'):(0,0),('C','D'):(0,0),('D','C'):(0,0)} if scenario == 2: fixed[('A','C')] = (5,1) fixed[('B','D')] = (4,0) matches = [] for h in teams: for a in teams: if h == a: continue if 'U' in (h,a): score = (1,0) if h == 'U' else (0,1) elif 'V' in (h,a): score = (1,0) if h == 'V' else (0,1) else: score = fixed.get((h,a),(0,0)) matches.append((h,a,*score)) assert len(matches) == n*(n-1) assert len(set((m[0], m[1]) for m in matches)) == n*(n-1) t = table(matches, teams) assert all(v['played'] == 2*(n-1) for v in t.values()) assert t['A']['points'] == t['B']['points'] assert set(k for k,v in t.items() if v['points'] == t['A']['points']) == {'A','B'} assert sorted(t, key=lambda k:t[k]['points'], reverse=True)[:2] == ['U','V'] h = mini(matches, ['A','B']) assert h['A']['points'] == 1 and h['B']['points'] == 4 assert h['B']['gd'] == 1 if scenario == 1: assert t['A']['gd'] > t['B']['gd'] else: assert t['A']['gd'] == t['B']['gd'] assert t['A']['gf'] > t['B']['gf'] # Prefixes stop at the first decisive criterion. We never invent fallbacks. rank = { 'Premier League C.4-C.6': sorted(['A','B'], key=lambda k:(t[k]['points'],t[k]['gd'],t[k]['gf']), reverse=True), 'Bundesliga SpOL 2.3(c) prefix': sorted(['A','B'], key=lambda k:(t[k]['points'],t[k]['gd'],t[k]['gf']), reverse=True), 'LaLiga Art10 two clubs': sorted(['A','B'], key=lambda k:(t[k]['points'],h[k]['gd']), reverse=True), 'Ligue1 Art518ter prefix': sorted(['A','B'], key=lambda k:(t[k]['points'],t[k]['gd'],h[k]['points'],h[k]['gd'],t[k]['gf']), reverse=True), 'SerieA ordinary positions 244A': sorted(['A','B'], key=lambda k:(t[k]['points'],h[k]['points'],h[k]['gd'],t[k]['gd'],t[k]['gf']), reverse=True) } return matches, {'teams':n,'scenario':scenario,'total_matches':len(matches),'A':t['A'],'B':t['B'],'mini_AB':h,'order_AB':rank,'full_table':t} def worldcup_case(): matches=[('A','B',1,1),('A','C',0,0),('B','C',0,0),('A','D',1,0),('B','D',5,0),('C','D',9,0)] t=table(matches); small=mini(matches,['A','B','C']); rem=mini(matches,['A','B']) assert t['A']['points']==t['B']['points']==t['C']['points']==5 assert small['A']['points']==small['B']['points']==small['C']['points']==2 assert small['A']['gd']==small['B']['gd']==small['C']['gd']==0 assert small['A']['gf']==small['B']['gf']==1 and small['C']['gf']==0 assert rem['A']==rem['B'] def rank_h2_prefix(teams): """Article13 prefix sufficient for this input; unsupported ties fail closed.""" m=mini(matches,teams) groups={} for team in teams: key=(m[team]['points'],m[team]['gd'],m[team]['gf']) groups.setdefault(key,[]).append(team) if len(groups)==1: # Remaining H2 subset is still equal: only full-group GD/GF needed here. keys=[(t[k]['gd'],t[k]['gf']) for k in teams] assert len(set(keys))==len(keys), 'disciplinary/ranking inputs required; not implemented' return sorted(teams,key=lambda k:(t[k]['gd'],t[k]['gf']),reverse=True) result=[] for key in sorted(groups,reverse=True): subset=groups[key] result.extend(subset if len(subset)==1 else rank_h2_prefix(subset)) return result order=rank_h2_prefix(['A','B','C'])+['D'] assert order==['B','A','C','D'] assert t['B']['gd']>t['A']['gd'] and t['C']['gd']>t['B']['gd'] return matches, {'table':t,'initial_mini_ABC':small,'remaining_mini_AB':rem,'article13_group_order':order, 'incorrect_total_GD_first':sorted(t,key=lambda k:(t[k]['points'],t[k]['gd'],t[k]['gf']),reverse=True), 'best_third_boundary':'C is selected as this group third before cross-group Article13 comparison; not automatically first or qualified.'} def euro_cases(): previous=[('A','C',0,0),('A','D',1,1),('B','C',1,1),('B','D',0,0)] before=table(previous) assert before['A']==before['B'] results=[] for other in [(1,0),(0,0)]: matches=previous+[('A','B',0,0),('C','D',*other)] t=table(matches) tied=[k for k in t if t[k]['points']==t['A']['points']] gate=(before['A']['points']==before['B']['points'] and before['A']['gf']==before['B']['gf'] and before['A']['ga']==before['B']['ga'] and len(tied)==2) results.append({'other_match':f'C {other[0]}-{other[1]} D','table':t,'teams_level_with_AB':tied,'article20_02_penalty_gate':gate,'matches':matches}) assert [r['article20_02_penalty_gate'] for r in results]==[True,False] return {'before_last_round':before,'last_round_matches':['A-B','C-D'],'cases':results} def olympic_cases(): rows=[] for edition, cutoff, when in [(2024,date(2001,1,1),date(2024,7,24)),(2028,date(2005,1,1),date(2028,7,10))]: for born in [date(cutoff.year-1,12,31), cutoff]: age=when.year-born.year-((when.month,when.day)<(born.month,born.day)) rows.append({'edition':edition,'illustrative_date':when.isoformat(),'birth_date':born.isoformat(),'whole_year_age':age, 'FIFA_birth_date_threshold_met':born>=cutoff, 'men_final_age_role':'within threshold' if born>=cutoff else 'overage slot required (max3)', 'men_preliminary_base_age':('not examined in 2024 article' if edition==2024 else 'not determined from final-cutoff alone; specific confederation competition eligibility rules required'), 'women_age_restriction':'none in cited FIFA provisions; other eligibility not evaluated'}) assert all(r['whole_year_age']==23 for r in rows) assert [r['FIFA_birth_date_threshold_met'] for r in rows]==[False,True,False,True] # Illustrative chosen list size is not a claim about LA28 final official quota. count_cases=[{'hypothetical_list_size':18,'overage_birth_dates':3,'only_max3_constraint':True}, {'hypothetical_list_size':18,'overage_birth_dates':4,'only_max3_constraint':False}] return {'date_cases':rows,'list_count_cases':count_cases,'scope':'age sub-check only, not nationality, release, registration, suspensions, selection or full eligibility certification'} def main(): p=argparse.ArgumentParser();p.add_argument('--output-dir',default='results');args=p.parse_args();out=Path(args.output_dir);out.mkdir(parents=True,exist_ok=True) all_results={'method':'exact integer deterministic synthetic examples; no simulation or real-match measurements','league':[]} for n in (20,18): for s in (1,2): matches,record=league_schedule(n,s);all_results['league'].append(record) write_csv(out/f'league-{n}-scenario{s}-matches.csv',[dict(zip(['home','away','home_goals','away_goals'],m)) for m in matches],['home','away','home_goals','away_goals']) matches,wc=worldcup_case();all_results['worldcup_2026']=wc write_csv(out/'worldcup-2026-synthetic-group.csv',[dict(zip(['team1','team2','goals1','goals2'],m)) for m in matches],['team1','team2','goals1','goals2']) all_results['euro_2026_28']=euro_cases();all_results['olympic']=olympic_cases() (out/'football-case-results.json').write_text(json.dumps(all_results,ensure_ascii=False,indent=2),encoding='utf8') print(json.dumps({'league_AB':[{k:v for k,v in r.items() if k!='full_table'} for r in all_results['league']], 'worldcup_2026':wc,'euro_gates':[r['article20_02_penalty_gate'] for r in all_results['euro_2026_28']['cases']],'olympic':all_results['olympic']},ensure_ascii=False,indent=2)) if __name__=='__main__': main()