#!/usr/bin/env python3 """Independently compare raw Wick monomials with skeleton expansion. The raw side enumerates all normal-ordered involutions, retaining connected planar maps INCLUDING empty digons. It does not use the reduction algorithm or the closed positive-multiplicity formulas. The comparison side expands the supplied 115 reduced cells by positive edge multiplicities and predicts prod(J_i) raw labelled pairings for each cell/multiplicity assignment. """ from collections import Counter from itertools import combinations, permutations, product from pathlib import Path import json import math ROOT = Path(__file__).resolve().parent SKELETON_FILE = ROOT/'four_point_skeletons.json' if not SKELETON_FILE.exists(): SKELETON_FILE = ROOT.parent/'four_point_skeletons.json' PAIRS = tuple(combinations(range(4), 2)) INDEX = {pair: index for index, pair in enumerate(PAIRS)} def compositions(total, parts): if parts == 1: if total >= 1: yield (total,) return for value in range(1, total-parts+2): for rest in compositions(total-value, parts-1): yield (value,)+rest def raw_counter(degrees): total = sum(degrees) if total % 2: return Counter() owner, alpha = [], [] start = 0 for i, degree in enumerate(degrees): owner += [i]*degree alpha += list(range(start+1,start+degree))+[start] start += degree matching = [-1]*total answer = Counter() def collect(): seen = [False]*total faces = 0 for first in range(total): if seen[first]: continue faces += 1 h = first while not seen[h]: seen[h] = True h = alpha[matching[h]] if faces != total//2-2: return neighbours = [set() for _ in range(4)] powers = [0]*6 for h, partner in enumerate(matching): if h < partner: i,j = sorted((owner[h],owner[partner])) neighbours[i].add(j) neighbours[j].add(i) powers[INDEX[(i,j)]] += 1 reached, frontier = {0},[0] while frontier: i = frontier.pop() for j in neighbours[i]-reached: reached.add(j) frontier.append(j) if len(reached)==4: answer[tuple(powers)] += 1 def visit(unused): if not unused: collect() return first = unused[0] for p in range(1,len(unused)): second=unused[p] if owner[first]==owner[second]: continue matching[first],matching[second]=second,first visit(unused[1:p]+unused[p+1:]) visit(tuple(range(total))) return answer def prediction_table(cells,max_total): predictions = {} for cell in cells: edges = [(i-1,j-1) for i,j,copies in cell['adjacency'] for _ in range(copies)] for propagators in range(len(edges),max_total//2+1): for mult in compositions(propagators,len(edges)): degrees,powers=[0]*4,[0]*6 for (i,j),multiplicity in zip(edges,mult): degrees[i]+=multiplicity degrees[j]+=multiplicity powers[INDEX[(i,j)]]+=multiplicity key=tuple(degrees) predictions.setdefault(key,Counter())[tuple(powers)]+=math.prod(degrees) return predictions def reflection_check(cells): """Exhaust every vertex-labelled edge automorphism of each map. A candidate permutes the edges inside each fixed endpoint pair. Commutation with beta is automatic. It preserves ribbon orientation exactly when tau alpha=alpha tau and reverses it exactly when tau alpha=alpha^{-1} tau. No geometric rank information is used. """ records=[] summary=Counter() for cell in cells: size=2*cell['edge_count'] alpha=list(range(size)); inverse=list(range(size)); owner={} for i,cycle in enumerate(cell['alpha_cycles']): darts=[h-1 for h in cycle] for j,h in enumerate(darts): alpha[h]=darts[(j+1)%len(darts)] inverse[h]=darts[(j-1)%len(darts)] owner[h]=i groups={} for first,second in cell['beta_cycles']: first-=1;second-=1 if owner[first]>owner[second]: first,second=second,first groups.setdefault((owner[first],owner[second]),[]).append((first,second)) edge_groups=list(groups.values()) preserving=[];reversing=[] for images in product(*(permutations(edges) for edges in edge_groups)): tau=list(range(size)) for source_edges,image_edges in zip(edge_groups,images): for (a,b),(c,d) in zip(source_edges,image_edges): tau[a]=c;tau[b]=d if all(tau[alpha[h]]==alpha[tau[h]] for h in range(size)): preserving.append(tau) if all(tau[alpha[h]]==inverse[tau[h]] for h in range(size)): reversing.append(tau) expected=1 if cell['type'] in {'P','C','D_s','D_o','L','M'} else 0 assert len(preserving)==1,(cell['cell_id'],'orientation-preserving') assert len(reversing)==expected,(cell['cell_id'],'orientation-reversing') moved=[h+1 for h in range(size) if reversing and reversing[0][h]!=h] if expected: assert len(moved)==(0 if cell['type'] in {'P','C'} else 4) records.append({'cell_id':cell['cell_id'],'type':cell['type'], 'orientation_preserving_automorphisms':len(preserving), 'orientation_reversing_automorphisms':len(reversing), 'reflection_moved_darts':moved, 'reflection_dart_permutation_1based': [h+1 for h in reversing[0]] if reversing else None}) summary[(cell['type'],len(reversing))]+=1 return {'checked_cells':len(cells),'status':'all reflection classifications passed', 'by_type':[{'type':typ,'cells':count,'anti_automorphisms_per_cell':anti} for (typ,anti),count in sorted(summary.items())], 'records':records} def main(): cells=json.loads(SKELETON_FILE.read_text())['cells'] predicted=prediction_table(cells,12) degree_vectors=[d for total in range(4,13,2) for d in compositions(total,4)] records=[] monomial_checks=0 raw_pairings=0 for degrees in degree_vectors: actual=raw_counter(degrees) expected=predicted.get(degrees,Counter()) assert actual==expected,(degrees,actual-expected,expected-actual) monomial_checks+=len(set(actual)|set(expected)) raw_pairings+=sum(actual.values()) records.append({'degrees':degrees,'planar_connected_pairings':sum(actual.values()), 'spacetime_monomials':len(actual)}) payload={'status':'all raw Wick comparisons passed', 'maximum_total_degree':12,'ordered_even_total_degree_vectors':len(degree_vectors), 'spacetime_monomials_compared':monomial_checks, 'connected_planar_labelled_pairings':raw_pairings, 'ribbon_reflection_check':reflection_check(cells), 'records':records} (ROOT/'raw_wick_checks.json').write_text(json.dumps(payload,indent=2)+'\n') summary={k:v for k,v in payload.items() if k not in {'records','ribbon_reflection_check'}} summary['reflection_cells_checked']=payload['ribbon_reflection_check']['checked_cells'] summary['reflection_status']=payload['ribbon_reflection_check']['status'] print(json.dumps(summary,indent=2)) if __name__=='__main__': main()