5 typedef struct formula fmla;
19 static void putf(fmla *a)
42 static void duf(fmla *f)
48 static inline fmla *newf(int op, fmla *l, fmla *r)
50 fmla *f = malloc(sizeof(fmla));
57 f->key = 313*l->key + 17*r->key + 2;
60 f->key = 1733*l->key + 5;
68 static inline int match(fmla *a, fmla *b)
72 if (a->op != b->op || a->key != b->key)
77 if (!match(a->arg[1], b->arg[1]))
80 if (!match(a->arg[0], b->arg[0]))
88 fmla *head_depth[G_DEPTH+1];
96 duf(head_depth[1] = newf(OP_X, NULL, NULL));
97 duf(head_depth[1]->next = newf(OP_Y, NULL, NULL));
98 for(i=2; i<=G_DEPTH; i++) {
99 printf("### depth %d\n", i);
103 z = newf(OP_NOT, x, NULL);
114 z = newf(OP_IMP, x, y);
137 for(i=1; i<=G_DEPTH; i++)
138 for(j=1; j<=G_DEPTH; j++)
139 if (2*i+j+2 <= A_DEPTH)
140 for(x = head_depth[i]; x; x=x->next)
141 for(y = head_depth[j]; y; y=y->next) {
142 z = newf(OP_IMP, x, newf(OP_IMP, y, x));
149 /* (A->(B->C)) -> ((A->B) -> (A->C)) */
150 for(i=1; i<=G_DEPTH; i++)
151 for(j=1; j<=G_DEPTH; j++)
152 for(k=1; k<=G_DEPTH; k++)
153 if (3*i+2*j+2*k+6 <= A_DEPTH)
154 for(x=head_depth[i]; x; x=x->next)
155 for(y=head_depth[j]; y; y=y->next)
156 for(z=head_depth[k]; z; z=z->next) {
158 newf(OP_IMP, x, newf(OP_IMP, y, z)),
161 newf(OP_IMP, x, z)));
168 /* (^A->^B)->(B->A) */
169 for(i=1; i<=G_DEPTH; i++)
170 for(j=1; j<=G_DEPTH; j++)
171 if (2*i+2*j+5 <= A_DEPTH)
172 for(x = head_depth[i]; x; x=x->next)
173 for(y = head_depth[j]; y; y=y->next) {
175 newf(OP_IMP, newf(OP_NOT, x, NULL), newf(OP_NOT, y, NULL)),
185 fmla *x, *y, *last, *z;
189 for(last=flist; last->next; last=last->next)
194 /* Modus Ponens: A, A->B =] B */
195 for(x=flist; x; x=x->next)
196 for(y=flist; y; y=y->next) {
197 if (x->op == OP_IMP &&
198 match(x->arg[0], y)) {
200 if (!z->next && z != last) {