2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 static char rcsid[]= "$Id: hall.c,v 0.4 1994/06/24 10:37:23 ceriel Exp $";
15 * This file implements the marriage thesis from Hall.
16 * The thesis says that given a number, say N, of subsets from
17 * a finite set, it is possible to create a set with cardinality N,
18 * that contains one member for each of the subsets,
19 * iff for each number, say M, of subsets from 2 to N the union of
20 * each M-tuple sets has cardinality >= M.
22 * So what, you might say. As indeed I did.
23 * But this is actually used here to check the possibility of each
24 * code rule. If a code rule has a number of token_sets in the with
25 * clause and a number of properties in the uses rule it must be
26 * possible to do this from an empty fakestack. Hall helps.
29 #define MAXHALL (TOKPATMAX+MAXALLREG)
30 short hallsets[MAXHALL][SETSIZE];
32 int hallfreq[MAXHALL][2];
38 fprintf(stderr,"Table of hall frequencies\n # pre post\n");
39 for (max=MAXHALL-1;hallfreq[max][0]==0 && hallfreq[max][1]==0;max--)
42 fprintf(stderr,"%3d%6d%6d\n",i,hallfreq[i][0],hallfreq[i][1]);
47 assert(nhallsets == -1);
51 nexthall(sp) register short *sp; {
55 for(i=0;i<SETSIZE;i++)
56 hallsets[nhallsets][i] = sp[i];
60 card(sp) register short *sp; {
64 for(i=0;i<8*sizeof(short)*SETSIZE;i++)
74 error("Hall says: \"You can't have those registers\"");
81 hallfreq[nhallsets][0]++;
83 * If a set has cardinality >= nhallsets it can never be the cause
84 * of the hall algorithm failing. So it can be thrown away.
85 * But then nhallsets is less, so this step can be re-applied.
90 for(i=0;i<nhallsets;i++)
91 if (card(hallsets[i])>=nhallsets) {
92 for (j=i+1;j<nhallsets;j++)
93 for(k=0;k<SETSIZE;k++)
103 * Now all sets have cardinality < nhallsets
106 hallfreq[nhallsets][1]++;
107 ok=recurhall(nhallsets,hallsets);
112 recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
113 short copysets[MAXHALL][SETSIZE];
114 short setsum[SETSIZE];
115 register i,j,k,ncopys;
118 * First check cardinality of union of all
120 for(k=0;k<SETSIZE;k++)
122 for(i=0;i<nhallsets;i++)
123 unite(hallsets[i],setsum);
124 if (card(setsum)<nhallsets)
127 * Now check the hall property of everything but one set,
130 for(i=0;i<nhallsets;i++) {
132 for(j=0;j<nhallsets;j++) if (j!=i) {
133 for(k=0;k<SETSIZE;k++)
134 copysets[ncopys][k] = hallsets[j][k];
137 assert(ncopys == nhallsets-1);
138 if (!recurhall(ncopys,copysets))
144 unite(sp,into) register short *sp,*into; {
147 for(i=0;i<SETSIZE;i++)
154 * N zngurzngvpvna anzrq Unyy
155 * Unf n urknurqebavpny onyy,
156 * Naq gur phor bs vgf jrvtug
157 * Gvzrf uvf crpxre'f, cyhf rvtug
158 * Vf uvf cubar ahzore -- tvir uvz n pnyy..