LADR-2009-11A/0000755000175000017500000000000011274373356012031 5ustar mccunemccuneLADR-2009-11A/Makefile0000644000175000017500000000272410707213430013460 0ustar mccunemccunehelp: @echo See README.make all: cd ladr && $(MAKE) lib cd mace4.src && $(MAKE) all cd provers.src && $(MAKE) all cd apps.src && $(MAKE) all /bin/cp -p utilities/* bin @echo "" @echo "**** Now try 'make test1'. ****" @echo "" ladr lib: cd ladr && $(MAKE) lib test1: bin/prover9 -f prover9.examples/x2.in | bin/prooftrans parents_only @echo "" @echo "**** If you see a proof, prover9 is probably okay. ****" @echo "**** Next try 'make test2'. ****" @echo "" test2: bin/mace4 -v0 -f mace4.examples/group2.in | bin/interpformat tabular @echo "" @echo "**** If you see a group table, mace4 is probably okay. ****" @echo "**** Next try 'make test3'. ****" @echo "" test3: bin/mace4 -n3 -m -1 < apps.examples/qg.in | bin/interpformat | bin/isofilter @echo "" @echo "*** If you see 5 interpretations, the apps are probably okay. ***" @echo "" @echo "*** All of the programs are in ./bin, and they can be copied anywhere you like. ***" @echo "" clean: cd ladr && $(MAKE) realclean cd apps.src && $(MAKE) realclean cd mace4.src && $(MAKE) realclean cd provers.src && $(MAKE) realclean realclean: $(MAKE) clean /bin/rm -f bin/* # The following cleans up, then makes a .tar.gz file of the current # directory, leaving it in the parent directory. (Gnu make only.) DIR = $(shell basename $(PWD)) dist: $(MAKE) realclean cd .. && tar cvf $(DIR).tar $(DIR) gzip -f ../$(DIR).tar ls -l ../$(DIR).tar.gz LADR-2009-11A/manpages/0000755000175000017500000000000010736071641013616 5ustar mccunemccuneLADR-2009-11A/manpages/prover9.10000644000175000017500000000254310736071612015310 0ustar mccunemccune.TH PROVER9 1 "August 12, 2007" .SH NAME prover9 \- resolution/paramodulation theorem prover .SH SYNOPSIS .B prover9 .RI [ options ] < .I input-file > .I output-file .br .B prover9 .RI [ options ] -f .I input-file > .I output-file .SH DESCRIPTION This manual page documents briefly the .B prover9 command. .PP \fBprover9\fP is an automated theorem prover for first-order and equational logic. It is a successor of the .BR otter (1) prover. \fBprover9\fP uses the inference techniques of ordered resolution and paramodulation with literal selection. .SH OPTIONS A summary of options is included below. .TP .B \-h View a list of command-line options. .TP .B \-x Enables an experimental enhanced auto-mode. For more information consult the \fBprover9\fP manual. .TP .B \-p Fully parenthesize output. .TP .B \-t \fIn Constrain the search to last about \fIn\fP seconds. For UNIX-like systems, the `user CPU' time is used. .TP .B \-f \fIfiles Take input from \fIfiles\fP instead of from standard input. .SH SEE ALSO .BR mace4 (1), .BR otter (1). .br On Debian systems, the manual is found in the \fIprover9-doc\fP package, at \fI/usr/share/doc/prover9-doc/manual/index.html\fP. .SH AUTHOR \fBprover9\fP ws written by William McCune .PP This manual page was written by Peter Collingbourne , for the Debian project (but may be used by others). LADR-2009-11A/manpages/mace4.10000644000175000017500000001033510736071612014671 0ustar mccunemccune.TH MACE4 1 "August 12, 2007" .SH NAME mace4 \- searches for finite countermodels of first-order statements .SH SYNOPSIS .B mace4 .RI [ options ] < .I input-file > .I output-file .SH DESCRIPTION This manual page documents briefly the .B mace4 command. .PP The program \fBmace4\fP searches for finite structures satisfying first-order and equational statements, the same kind of statement that .BR prover9 (1) accepts. If the statement is the denial of some conjecture, any structures found by \fBmace4\fP are counterexamples to the conjecture. \fBmace4\fP can be a valuable complement to .BR prover9 (1), looking for counterexamples before (or at the same time as) using .BR prover9 (1) to search for a proof. It can also be used to help debug input clauses and formulas for .BR prover9 (1). .SH OPTIONS A summary of options is included below. Options override the equivalent settings given in the input file. To set or clear a flag, you must give 1 or 0 as the value. .TP .B \-help This tells \fBmace4\fP to print a summary of these command-line options. .TP .B \-n \fIn This gives the starting domain size for the search. The default value is 2. If you also give an \fB-N\fP option, \fBmace4\fP will iterate domain sizes up through the \fB-N\fP value, using an increment given by the \fB-I\fP value. Otherwise, \fBmace4\fP will search only for the \fB-n\fP value. .TP .B \-N \fIn This gives the ending domain size for the search. The default is 10. .TP .B \-i \fIn This gives the domain size increment for the search. The default is 1. .TP .B \-q \fIn This flag overrides the parameter iterate. It says to try the sizes that are prime numbers, from \fB-n\fP up through \fB-N\fP. .TP .B \-m \fIn Stop searching when the \fIn\fPth structure has been found. The default is 1. .TP .B \-t \fIn Stop searching after \fIn\fP seconds. .TP .B \-s \fIn Allow at most \fIn\fP seconds for each domain size. The parameter can be used (together with \fB-t\fP) to give an overall time limit. .TP .B \-b \fIn Stop searching when (about) \fIn\fP megabytes of memory have been used. .TP .B \-V \fIn A rule is needed for distinguishing variables from constants in clauses and formulas with free variables. If this flag is clear, variables start with (lower case) `u' through `z'. If this flag is set, variables in clauses start with (upper case) `A' through `Z' or `_'. .TP .B \-P \fIn If this flag is set, all structures that are found are printed in `standard' form, which means they are suitable as input to other LADR programs such as .BR isofilter (1) and .BR interpformat (1). .TP .B \-p \fIn If this flag is set, and if \fB-P\fP is clear, all structures that are found are printed in a tabular form. .TP .B \-R \fIn If this flag is set, a ring structure is is applied to the search. The operations {+,-,*} are assumed to be the ring of integers (mod domain_size). This method puts a tight constraint on the search, allowing much larger structures to be investigated. .TP .B \-v \fIn If this flag is set, the output file receives information about the search, including the initial partial model (the part of the model that can be determined before backtracking starts) and timing and other statistics for each domain size. (It does not give a trace of the backtracking, so it does not consume a lot of file space.) .TP .B \-T \fIn If the trace flag is set, detailed information about the search, including a trace of all assignments and backtracking, is printed to the standard output. This flag causes a lot of output, so it should be used only on small searches. .PP There also exist a number of advanced options, which are used for experimentation with search methods. They can be ignored by nearly all users. For descriptions of these options, see the original \fBmace4\fP manual. .SH SEE ALSO .BR prover9 (1). .br Full documentation for \fBmace4\fP is found in the \fBprover9\fP manual, available on Debian systems in the \fIprover9-doc\fP package at \fI/usr/share/doc/prover9-doc/manual/index.html\fP. .br The original \fBmace4\fP manual, which can be downloaded at http://www.cs.unm.edu/~mccune/prover9/mace4.pdf .SH AUTHOR \fBmace4\fP ws written by William McCune .PP This manual page was written by Peter Collingbourne , for the Debian project (but may be used by others). LADR-2009-11A/README.make0000644000175000017500000000114210741776342013623 0ustar mccunemccuneCompiling Prover9, Mace4, and related programs. (Tested with Gnu make and GCC 3.3.3, 3.3.5, 4.0.0, 4.0.2., 4.1.1) % make all This compiles ladr library mace4 library mace4 prover9 (and related provers) miscellaneous apps (clausefilter, prooftrans, isofilter, etc) then it moves all the programs and utilities to ./bin. Quick tests: % make test1 % make test2 % make test3 Building a package for Debian. The file libtoolize.patch (contributed by Peter Collingbourne) can be used to update the Makefiles so that they build and use a shared LADR library. LADR-2009-11A/mace4.src/0000755000175000017500000000000011274373242013602 5ustar mccunemccuneLADR-2009-11A/mace4.src/ordercells.c0000644000175000017500000001045411133704150016076 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "../ladr/order.h" extern int Number_of_cells; extern struct cell *Cells; extern struct cell **Ordered_cells; /* Permutation of Cells. */ extern BOOL Skolems_last; extern int First_skolem_cell; /************* * * sum_indexes(t) * * Tssume t is an eterm, that is, nonvariable with variable arguments. * *************/ static int sum_indexes(Term t) { if (ARITY(t) == 0) return -1; else { int sum = 0; int i; for (i = 0; i < ARITY(t); i++) sum += VARNUM(ARG(t,i)); return sum; } } /* sum_indexes */ /************* * * compare_cells() * * For example, if a < b < g < f, this gives the following order: * * a. g(2). 0 = 0. * b. f(0,2). 0 = 1. * g(0). f(2,0). 0 = 2. * f(0,0). f(1,2). 1 = 0. * g(1). f(2,1). 1 = 1. * f(0,1). f(2,2). 1 = 2. * f(1,0). 2 = 0. * f(1,1). 2 = 1. * 2 = 2. * * Equality cells are greatest, * * If (Skolems_last) Skolem cells are next greatest, * * . */ static Ordertype compare_cells(struct cell *a, struct cell *b) { if (a->symbol->attribute == EQUALITY_SYMBOL && b->symbol->attribute != EQUALITY_SYMBOL) return GREATER_THAN; else if (a->symbol->attribute != EQUALITY_SYMBOL && b->symbol->attribute == EQUALITY_SYMBOL) return LESS_THAN; else if (Skolems_last && a->symbol->attribute == SKOLEM_SYMBOL && b->symbol->attribute != SKOLEM_SYMBOL) return GREATER_THAN; else if (Skolems_last && a->symbol->attribute != SKOLEM_SYMBOL && b->symbol->attribute == SKOLEM_SYMBOL) return LESS_THAN; else if (a->max_index < b->max_index) return LESS_THAN; else if (a->max_index > b->max_index) return GREATER_THAN; else if (a->symbol->mace_sn < b->symbol->mace_sn) return LESS_THAN; else if (a->symbol->mace_sn > b->symbol->mace_sn) return GREATER_THAN; else if (sum_indexes(a->eterm) < sum_indexes(b->eterm)) return LESS_THAN; else if (sum_indexes(a->eterm) > sum_indexes(b->eterm)) return GREATER_THAN; else return SAME_AS; /* For now, let f(0,1) be the same as f(1,0), etc. */ } /* compare_cells */ /************* * * order_cells() * *************/ void order_cells(BOOL verbose) { int i; for (i = 0; i < Number_of_cells; i++) Ordered_cells[i] = Cells + i; merge_sort((void **) Ordered_cells, Number_of_cells, (Ordertype (*) (void*,void*)) compare_cells); if (Skolems_last) { for (i = 0; i < Number_of_cells; i++) if (Ordered_cells[i]->symbol->attribute == SKOLEM_SYMBOL) break; First_skolem_cell = i; /* if none, set to Number_of_cells */ } else First_skolem_cell = Number_of_cells; if (verbose) { /* print the Ordered_cells */ printf("\n%% Cell selection order:\n\n"); for (i = 0; i < Number_of_cells; i++) { Term t = Ordered_cells[i]->eterm; if (!is_eq_symbol(SYMNUM(t))) fwrite_term_nl(stdout, t); } fflush(stdout); } } /* order_cells */ LADR-2009-11A/mace4.src/help20000644000175000017500000000414211107053123014524 0ustar mccunemccuneDivision by zero The new built-in integer arithmetic in Mace4 suppoorts integer division and remainder operations (/ and mod). I want to run by you how it is handling division by zero. First, it can't just fail (fatal error) like programming languages do, because Mace4 is going to be plugging in zeros all the time and trying to evaluate expressions involving division by zero (including mod). Second, when evaluating an expression containing division by zero, it can't just result in some special value "undefined", with all relations that get "undefined" as an argument evaluate to FALSE. The reason: 3/0 = 3/0 has to evaluate to TRUE (because it's an instance of x=x). So the problem is that we have a ground atomic formula involving integers and operations (+ * - / mod) with one of the relations (< <= > >= =) at the root. We have to evaluate it to TRUE or to FALSE. If it has no division by zero, it's trivial. Otherwise, we evaluate as much as possible, and then simplify with ring identities. Simplification might get rid of some division by zero by applying rules that eliminate terms (e.g., x * 0 = 0 and x-x=0.) Then, put the result in a canonial form. Assume some division by zero remains (otherwise, we have just TRUE or FALSE). If it is an equality in which the two sides are identical, it evaluates to TRUE. Otherwise, it is FALSE. But, I don't think there is a unique canonical form for expressions like this, such that two terms are equal iff their canonical forms are identical. Also, trichotomy fails for expressions involving division by zero: e.g., for 3/0 and 2/0, none of < > = holds. I suppose, technically, that expressions involving division by zero shouldn't evaluate to FALSE, because that can't be proved formally in the theory. But Mace4 has to think of it that way, because it either has to go forward (TRUE) or backtrack and try something else (FALSE). Maybe we should think of it as "maybe" and solutions can't depend on "maybe", so it is essentially the same as FALSE. I'd like to get this right. (I've ridiculed Wolfram many times for getting division by zero wrong in Mathematica.) Bill LADR-2009-11A/mace4.src/Makefile0000644000175000017500000000175111172113126015234 0ustar mccunemccune# LADR/mace4.src CC = gcc # XFLAGS can be specified on the command line (see XFLAGS below) CFLAGS = $(XFLAGS) -O -Wall # CFLAGS = $(XFLAGS) -O6 -Wall # CFLAGS = $(XFLAGS) -g -O -Wall # CFLAGS = $(XFLAGS) -g -Wall # CFLAGS = $(XFLAGS) -pg -O -Wall # CFLAGS = $(XFLAGS) -Wall -pedantic OBJECTS = estack.o util.o print.o syms.o ground.o arithmetic.o select.o \ propagate.o mstate.o negpropindex.o negprop.o ordercells.o \ commandline.o msearch.o all: ladr lib mace4 install libmace4.a: $(OBJECTS) $(AR) rs libmace4.a $(OBJECTS) ############################################################################## lib libmace4: $(MAKE) libmace4.a ladr: cd ../ladr && $(MAKE) libladr.a $(MAKE) clean mace4: libmace4.a mace4.o $(OBJECTS) $(CC) $(CFLAGS) -o mace4 mace4.o libmace4.a ../ladr/libladr.a $(OBJECTS): estack.h syms.h ground.h propagate.h mstate.h msearch.h tags: etags *.c ../ladr/*.c clean: /bin/rm -f *.o realclean: /bin/rm -f *.o *.a mace4 install: /bin/mv mace4 ../bin LADR-2009-11A/mace4.src/pub0000644000175000017500000000004210140245551014277 0ustar mccunemccune/* DOCUMENTATION */ /* PUBLIC */ LADR-2009-11A/mace4.src/r1.in0000644000175000017500000000042711171221161014443 0ustar mccunemccuneset(arithmetic). assngn(max_models, -1). lex([A,E,P1,P2,K,a,p]). formulas(assumptions). A + E + P1 + P2 = a + p + 1. A + E + P1 + P2 + a + p + K > 1. A + E + P1 + P2 + a + p + K <= domain_size. %BEGIN a > 0. K > 0. A > 0. E > 0. p > 0. P1 > 0 | P2 > 0. END% end_of_list. LADR-2009-11A/mace4.src/h1.in0000644000175000017500000000212611156471200014433 0ustar mccunemccune% Language Options op(500, infix, "+"). %addition op(490, infix, ";"). %multiplication op(490, infix, "*"). %concurrent op(480, postfix, "^"). %omega op(490, infix, "||"). %disjoint parallel op(490, infix, "/\"). %meet op(490, infix, "!!"). %alternation if(Prover9). % Options for Prover9 assign(max_seconds, 60). end_if. if(Mace4). % Options for Mace4 assign(max_seconds, 60). end_if. formulas(assumptions). %commutative additive monoid x + y = y + x. x + 0 = x. x+(y+z) = (x+y)+z. %multiplicative monoid x;1 = x & 1;x = x. x;(y;z) = (x;y);z. %multiplicative monoid x*1 = x & 1*x = x. x*(y*z) = (x*y)*z. %distributivity (x + y);z = x;z + y;z. (x + y)*z = x*z + y*z. z;(x + y) = z;x + z;y. z*(x + y) = z*x + z*y. %annihilation 0;x = 0. x;0 = 0. 0*x = 0. x*0 = 0. %idempotence x + x = x. %subsumption order x <= y <-> x+y=y. %exchange (x*x1);(y*y1) <= (x1;y)*(x;y1). %meet x/\y <= x. x/\y <= y. z <= x & z<= y -> z<= x/\y. x||y = (x;y)/\(y;x). x!!y = (x/\1);y + x;(y/\1). end_of_list. formulas(goals). x!!y=y!!x. end_of_list. LADR-2009-11A/mace4.src/util.c0000644000175000017500000000356210607745010014724 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "../ladr/header.h" /************* * * random_permutation() * *************/ void random_permutation(int *a, int n) { int i, t, k; for (i = 0; i < n; i++) a[i] = i; for (i = n-1; i >= 0; i--) { /* Get a random number k in [0,...,i], then swap a[i] and a[k]. */ k = rand() % (i+1); t = a[i]; a[i] = a[k]; a[k] = t; } } /* random_permutation */ #define MAX_PRIME 1000 /************* * * prime() * *************/ BOOL prime(int n) { /* Is n a prime number? If n is too big, a fatal error occurs. */ /* On the first call, use the sieve of Eratosthenes to set up an array. */ static BOOL a[MAX_PRIME+1]; static BOOL initialized = FALSE; if (!initialized) { int i, p; for (i = 2; i <= MAX_PRIME; i++) a[i] = TRUE; p = 2; while (p*p < MAX_PRIME) { int j = p*p; while (j < MAX_PRIME) { a[j] = FALSE; j = j + p; } do p++; while (a[p] == FALSE); } initialized = TRUE; } if (n > MAX_PRIME) exit(1); /* fatal_error("prime: n out of range"); */ else if (n < 2) return FALSE; else return a[n]; } /* prime */ LADR-2009-11A/mace4.src/estack.c0000644000175000017500000000776710607745010015234 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "estack.h" /* Estack */ #define ESTACK_SIZE 400 /* size of each chunk */ struct estack { void **p[ESTACK_SIZE]; void *v[ESTACK_SIZE]; int n; Estack next; }; static Estack Estack_avail; static unsigned Estack_gets, Estack_frees, Estack_avails; /************* * * Estack get_estack() * *************/ static Estack get_estack(void) { Estack p; Estack_gets++; if (Estack_avail == NULL) p = malloc(sizeof(struct estack)); else { Estack_avails--; p = Estack_avail; Estack_avail = Estack_avail->next; } /* no initialization */ return(p); } /* get_estack */ /************* * * free_estack() * *************/ static void free_estack(Estack p) { Estack_frees++; Estack_avails++; p->next = Estack_avail; Estack_avail = p; } /* free_estack */ /************* * * fprint_estack_mem() * *************/ void fprint_estack_mem(FILE *fp, int heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct estack); fprintf(fp, "estack (%4d) %11u%11u%11u%9.1f K (avail=%u, %.1f K)\n", n, Estack_gets, Estack_frees, Estack_gets - Estack_frees, ((Estack_gets - Estack_frees) * n) / 1024., Estack_avails, (Estack_avails * n) / 1024.); /* end of printing for each type */ } /* fprint_estack_mem */ /************* * * p_estack_mem() * *************/ void p_estack_mem() { fprint_estack_mem(stdout, 1); } /* p_estack_mem */ /************* * * free_estack_memory() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_estack_memory(void) { Estack a = Estack_avail; while (a) { Estack b = a; a = a->next; free(b); Estack_avails--; } Estack_avail = NULL; } /* free_estack_memory */ /************* * * estack_bytes() * *************/ /* DOCUMENTATION Return the number of bytes allocated for Estacks. */ /* PUBLIC */ int estack_bytes(void) { return ((Estack_gets - Estack_frees) + Estack_avails) * sizeof(struct estack); } /* estack_bytes */ /************* * * update_and_push() * *************/ Estack update_and_push(void **p, void *new, Estack stack) { if (stack == NULL || stack->n == ESTACK_SIZE) { Estack s = get_estack(); /* allocate a stack entry */ s->n = 0; s->next = stack; stack = s; } /* printf("ZZ update: %p, %p\n", p, *p); */ stack->p[stack->n] = p; /* record the location */ stack->v[stack->n] = *p; /* record the old value */ *p = new; /* make the assignment */ stack->n++; return stack; /* return the updated stack */ } /* update_and_push */ /************* * * restore_from_stack() * *************/ void restore_from_stack(Estack stack) { while (stack != NULL) { int i; Estack s = stack; stack = stack->next; for (i = s->n-1; i >= 0; i--) { /* printf("ZZ restore: %p, %p\n", s->p[i], *(s->p[i])); */ *(s->p[i]) = s->v[i]; /* restore */ } free_estack(s); } } /* restore_from_stack */ /************* * * zap_estack() * *************/ void zap_estack(Estack stack) { while (stack != NULL) { Estack s = stack; stack = stack->next; free_estack(s); } } /* zap_estack */ LADR-2009-11A/mace4.src/msearch.c0000644000175000017500000006314711274054067015404 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "../ladr/banner.h" // #define DEBUG /*****************************************************************************/ /* Variables -- most are used (extern) by other source files */ /* Options and Statistics */ Mace_options Opt; struct mace_stats Mstats; /* List of symbols and associated data */ Symbol_data Symbols; /* This maps OPS symbol IDs to MACE symbol IDs, which start with 0. */ static int Sn_map_size; Symbol_data *Sn_to_mace_sn; /* Cell table is indexed by eterm IDs. */ int Number_of_cells; struct cell *Cells; /* the table of cells (dynamically allocated) */ struct cell **Ordered_cells; /* (pointers to) permutation of Cells */ int First_skolem_cell; /* Misc Variables*/ int Domain_size; Term *Domain; /* array of terms representing (shared) domain elements */ BOOL Skolems_last; Plist Ground_clauses; /* Mclauses (see ground.h) */ int Relation_flag; /* term flag */ int Negation_flag; /* term flag */ int Eq_sn; int Or_sn; int Not_sn; static int Max_domain_element_in_input; /* For Least Number Heuristic */ static Plist Models; /* in case we collect models as terms */ Clock Mace4_clock; /* stats for entire run */ unsigned Total_models; static double Start_seconds; static double Start_domain_seconds; static int Start_megs; /* end of variables */ /*****************************************************************************/ /* search return codes */ enum { SEARCH_GO_MODELS, /* continue: model(s) found on current path */ SEARCH_GO_NO_MODELS, /* continue: no models found on current path */ SEARCH_MAX_MODELS, /* stop */ SEARCH_MAX_MEGS, /* stop */ SEARCH_MAX_TOTAL_SECONDS, /* stop */ SEARCH_MAX_DOMAIN_SECONDS, /* stop */ SEARCH_DOMAIN_OUT_OF_RANGE /* stop */ }; /* Ground terms. MACE4 operates on ground clauses, which are represented by the structure mclause. Ground terms (and atoms) are represented with ordinary LADR terms. There are a few tricks: (1) We use upward pointers from terms to superterms and from atoms to clauses. (2) We need to mark atoms with a termflag, so that we know when to stop when following the upward pointers. Also, a termflag is used to indicate that an atom is negated. (3) Domain elements are represented by variables (sorry, but it is very convenient to do so). Also, there is only one actual copy of each domain element (structure sharing of domain elements). Global array *Domain contains them. IDs. If all of the arguments of a term (including atoms) are domain elements, that term is called an eterm. For example, f(3,4), a, P(0), and Q. Each eterm has a unique ID which is used as an index into the cell table, for example, when a new eterm is obtained by evaluating a subterm to a domain element, we have to quickly check if this new eterm can be evaluated. We do this by calculating its ID and looking up in Cells[ID].value. And when we have a new assignment, say f(3,4)=2, we find the list of occurrences of f(3,4) by looking in Cells[ID].occurrences. */ /************* * * init_mace_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_mace_options(Mace_options opt) { opt->domain_size = init_parm("domain_size", 0, 0, INT_MAX); opt->start_size = init_parm("start_size", 2, 2, INT_MAX); opt->end_size = init_parm("end_size", -1, -1, INT_MAX); opt->iterate_up_to = init_parm("iterate_up_to", -1, -1, INT_MAX); opt->max_models = init_parm("max_models", 1, -1, INT_MAX); opt->max_seconds = init_parm("max_seconds", -1, -1, INT_MAX); opt->max_seconds_per = init_parm("max_seconds_per", -1, -1, INT_MAX); opt->selection_order = init_parm("selection_order", 2, 0, 2); opt->selection_measure = init_parm("selection_measure",4, 0, 4); opt->increment = init_parm("increment", 1, 1, INT_MAX); opt->max_megs = init_parm("max_megs", 500, -1, INT_MAX); opt->report_stderr = init_parm("report_stderr", -1, -1, INT_MAX); opt->print_models = init_flag("print_models", TRUE); opt->print_models_tabular = init_flag("print_models_tabular", FALSE); opt->lnh = init_flag("lnh", TRUE); opt->trace = init_flag("trace", FALSE); opt->negprop = init_flag("negprop", TRUE); opt->neg_assign = init_flag("neg_assign", TRUE); opt->neg_assign_near = init_flag("neg_assign_near", TRUE); opt->neg_elim = init_flag("neg_elim", TRUE); opt->neg_elim_near = init_flag("neg_elim_near", TRUE); opt->verbose = init_flag("verbose", FALSE); opt->integer_ring = init_flag("integer_ring", FALSE); opt->order_domain = init_flag("order_domain", FALSE); opt->arithmetic = init_flag("arithmetic", FALSE); opt->iterate_primes = init_flag("iterate_primes", FALSE); opt->iterate_nonprimes = init_flag("iterate_nonprimes", FALSE); opt->skolems_last = init_flag("skolems_last", FALSE); opt->return_models = init_flag("return_models", FALSE); opt->iterate = init_stringparm("iterate", 5, "all", "evens", "odds", "primes", "nonprimes"); /* dependencies */ flag_flag_dependency(opt->print_models_tabular,TRUE,opt->print_models,FALSE); flag_flag_dependency(opt->print_models,TRUE,opt->print_models_tabular,FALSE); flag_flag_dependency(opt->iterate_primes, TRUE,opt->iterate_nonprimes,FALSE); flag_flag_dependency(opt->iterate_nonprimes, TRUE,opt->iterate_primes,FALSE); parm_parm_dependency(opt->domain_size, opt->start_size, 1, TRUE); parm_parm_dependency(opt->domain_size, opt->end_size, 1, TRUE); parm_parm_dependency(opt->iterate_up_to, opt->end_size, 1, TRUE); flag_stringparm_dependency(opt->iterate_primes,TRUE,opt->iterate,"primes"); flag_stringparm_dependency(opt->iterate_nonprimes,TRUE,opt->iterate,"nonprimes"); flag_flag_dependency(opt->integer_ring, TRUE, opt->lnh, FALSE); flag_flag_dependency(opt->order_domain, TRUE, opt->lnh, FALSE); flag_flag_dependency(opt->arithmetic, TRUE, opt->lnh, FALSE); flag_parm_dependency(opt->arithmetic,TRUE,opt->selection_order,0); } /* init_mace_options */ /************* * * exit_string() * *************/ static char *exit_string(int code) { char *message; switch (code) { case MAX_MODELS_EXIT: message = "max_models"; break; case ALL_MODELS_EXIT: message = "all_models"; break; case EXHAUSTED_EXIT: message = "exhausted"; break; case MAX_MEGS_YES_EXIT: message = "max_megs_yes"; break; case MAX_MEGS_NO_EXIT: message = "max_megs_no" ; break; case MAX_SEC_YES_EXIT: message = "max_sec_yes"; break; case MAX_SEC_NO_EXIT: message = "max_sec_no"; break; case MACE_SIGINT_EXIT: message = "mace_sigint"; break; case MACE_SIGSEGV_EXIT: message = "mace_sigsegv"; break; default: message = "???"; } return message; } /* exit_string */ /************* * * mace4_exit() * *************/ void mace4_exit(int exit_code) { if (Opt && flag(Opt->verbose)) p_mem(); if (Opt && parm(Opt->report_stderr) > 0) fprintf(stderr, "Domain_size=%d. Models=%d. User_CPU=%.2f.\n", Domain_size, Total_models, user_seconds()); printf("\nUser_CPU=%.2f, System_CPU=%.2f, Wall_clock=%d.\n", user_seconds(), system_seconds(), wallclock()); if (Total_models == 0) printf("\nExiting with failure.\n"); else printf("\nExiting with %d model%s.\n", Total_models, Total_models == 1 ? "" : "s"); fprintf(stderr, "\n------ process %d exit (%s) ------\n", my_process_id(), exit_string(exit_code)); printf("\nProcess %d exit (%s) %s", my_process_id(), exit_string(exit_code), get_date()); printf("The process finished %s", get_date()); exit(exit_code); } /* mace4_exit */ /************* * * initialize_for_search() * * This is the initialization that has to be done only once * for a given set of clauses. It is independent of the * domain size. * *************/ static void initialize_for_search(Plist clauses) { int max, i; Symbol_data s; Mace4_clock = clock_init("Mace4"); /* In ground clauses, VARIABLEs represent domain elements, so from here on, print variables as integers. */ // set_variable_style(INTEGER_STYLE); /* These flags are for ground clause (mclause) literals. */ Relation_flag = claim_term_flag(); Negation_flag = claim_term_flag(); /* Cache some symbol numbers. */ Eq_sn = str_to_sn(eq_sym(), 2); Or_sn = str_to_sn(or_sym(), 2); Not_sn = str_to_sn(not_sym(), 1); /* Set up Symbols list. */ init_built_in_symbols(); /* =/2 (and maybe others) */ /* Maybe initialize for arithmetic. */ if (flag(Opt->arithmetic)) init_arithmetic(); Skolems_last = flag(Opt->skolems_last); /* Collect data for each symbol. */ Max_domain_element_in_input = -1; i = collect_mace4_syms(clauses, flag(Opt->arithmetic)); Max_domain_element_in_input = MAX(Max_domain_element_in_input, i); if (Max_domain_element_in_input == -1) printf("\n%% There are no natural numbers in the input.\n"); else printf("\n%% The largest natural number in the input is %d.\n", Max_domain_element_in_input); /* Set up map from ordinary symnums to mace symnums. */ max = 0; i = 0; for (s = Symbols; s != NULL; s = s->next) { s->mace_sn = i++; /* printf("mace symbol: %s/%d\n", sn_to_str(s->sn), sn_to_arity(s->sn)); */ max = (s->sn > max ? s->sn : max); } Sn_map_size = max+1; Sn_to_mace_sn = malloc(Sn_map_size * sizeof(void *)); for (i = 0; i < Sn_map_size; i++) Sn_to_mace_sn[i] = NULL; for (s = Symbols; s != NULL; s = s->next) { Sn_to_mace_sn[s->sn] = s; } } /* initialize_for_search */ /************* * * init_for_domain_size() * * Given the list of (general) clauses, set up the various data * structures that will be needed for a given domain size. * *************/ static void init_for_domain_size(void) { int i, j, nextbase, id; Symbol_data s; /* Give each symbol its "base" value, which is used to index cells. */ nextbase = 0; for (s = Symbols; s != NULL; s = s->next) { s->base = nextbase; nextbase += int_power(Domain_size, s->arity); } /* Set up the array of domain terms. All ground terms refer to these. */ Domain = malloc(Domain_size * sizeof(void *)); for (i = 0; i < Domain_size; i++) Domain[i] = get_variable_term(i); /* Set up the table of cells. */ Number_of_cells = nextbase; Cells = malloc(Number_of_cells * sizeof(struct cell)); Ordered_cells = malloc(Number_of_cells * sizeof(void *)); for (id = 0; id < Number_of_cells; id++) { struct cell *c = Cells + id; int n; c->id = id; c->occurrences = NULL; c->value = NULL; c->symbol = find_symbol_node(id); c->eterm = decode_eterm_id(id); c->max_index = max_index(id, c->symbol); n = id_to_domain_size(id); c->possible = malloc(n * sizeof(void *)); for (j = 0; j < n; j++) c->possible[j] = Domain[j]; /* really just a flag */ } order_cells(flag(Opt->verbose)); if (flag(Opt->negprop)) init_negprop_index(); } /* init_for_domain_size */ /************* * * built_in_assignments() * *************/ static void built_in_assignments(void) { Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { if (s->attribute == EQUALITY_SYMBOL) { int i, j; for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[i==j ? 1 : 0]); } } } /* built_in_assignments */ /************* * * special_assignments() * *************/ static void special_assignments(void) { if (flag(Opt->integer_ring)) { /* Fix [+,-,*] as the ring of integers mod domain_size. */ /* If any of those operations doesn't exist, then ignore it.*/ Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { int i, j; if (is_symbol(s->sn, "+", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[(i + j) % Domain_size]; } else if (is_symbol(s->sn, "*", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[(i * j) % Domain_size]; } else if (is_symbol(s->sn, "-", 1)) { for (i = 0; i < Domain_size; i++) Cells[X1(s->base,i)].value = Domain[(Domain_size - i) % Domain_size]; } else if (is_symbol(s->sn, "--", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[((i + Domain_size) - j) % Domain_size]; } } } if (flag(Opt->order_domain)) { Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { int i, j; if (is_symbol(s->sn, "<", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[isn, "<=", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[i<=j ? 1 : 0]); } } } } /* special_assignments */ /************* * * check_that_ground_clauses_are_true() * *************/ static BOOL check_that_ground_clauses_are_true(void) { Plist g; BOOL ok = TRUE; for (g = Ground_clauses; g != NULL; g = g->next) { Mclause c = g->v; if (!c->subsumed) { fprintf(stderr, "ERROR, model reported, but clause not true!\n"); fprintf(stdout, "ERROR, model reported, but clause not true! "); p_mclause(c); ok = FALSE; } } return ok; } /* check_that_ground_clauses_are_true */ /************* * * possible_model() * *************/ static int possible_model(void) { if (flag(Opt->arithmetic)) { if (!check_with_arithmetic(Ground_clauses)) return SEARCH_GO_NO_MODELS; } else if (!check_that_ground_clauses_are_true()) fatal_error("possible_model, bad model found"); { static int next_message = 1; Total_models++; Mstats.current_models++; if (flag(Opt->return_models)) { Term modelterm = interp_term(); Interp model = compile_interp(modelterm, FALSE); zap_term(modelterm); Models = plist_append(Models, model); } if (flag(Opt->print_models)) print_model_standard(stdout, TRUE); else if (flag(Opt->print_models_tabular)) p_model(FALSE); else if (next_message == Total_models) { printf("\nModel %d has been found.\n", Total_models); next_message *= 10; } fflush(stdout); if (parm(Opt->max_models) != -1 && Total_models >= parm(Opt->max_models)) return SEARCH_MAX_MODELS; else return SEARCH_GO_MODELS; } } /* possible_model */ /************* * * mace_megs() * *************/ static int mace_megs(void) { return (megs_malloced() - Start_megs) + (estack_bytes() / (1024*1024)); } /* mace_megs */ /************* * * check_time_memory() * *************/ static int check_time_memory(void) { static int Next_report; double seconds = user_seconds(); int max_seconds = parm(Opt->max_seconds); int max_seconds_per = parm(Opt->max_seconds_per); int max_megs = parm(Opt->max_megs); int report = parm(Opt->report_stderr); if (max_seconds != -1 && seconds - Start_seconds > max_seconds) return SEARCH_MAX_TOTAL_SECONDS; else if (max_seconds_per != -1 && seconds - Start_domain_seconds > parm(Opt->max_seconds_per)) return SEARCH_MAX_DOMAIN_SECONDS; else if (max_megs != -1 && mace_megs() > parm(Opt->max_megs)) return SEARCH_MAX_MEGS; else { if (report > 0) { if (Next_report == 0) Next_report = parm(Opt->report_stderr); if (seconds >= Next_report) { fprintf(stderr, "Domain_size=%d. Models=%d. User_CPU=%.2f.\n", Domain_size, Total_models, seconds); fflush(stderr); while (seconds >= Next_report) Next_report += report; } } return SEARCH_GO_NO_MODELS; } } /* check_time_memory */ /************* * * mace4_skolem_check() * *************/ static BOOL mace4_skolem_check(int id) { /* Should we keep going w.r.t. the Skolem restriction? */ if (!flag(Opt->skolems_last)) return TRUE; else if (Cells[id].symbol->attribute == SKOLEM_SYMBOL) { printf("pruning\n"); return FALSE; } else return TRUE; } /* mace4_skolem_check */ /************* * * p_possible_values() * *************/ #if 0 static void p_possible_values(void) { int i; for (i = 0; i < Number_of_cells; i++) { if (Cells[i].symbol->attribute == ORDINARY_SYMBOL) { int j; printf("Cell %d: ", i); for (j = 0; j < id_to_domain_size(i); j++) { if (Cells[i].possible[j] != NULL) printf(" %d", j); } printf("\n"); } } } /* p_possible_values */ #endif /************* * * search() * * Max_constrained is the maximum constrained domain element * (or -1 is none is constrained). Greater domain elements * can all be considered symmetric. An element can become * constrained in two ways: (1) it is an index of some selected * cell, or (2) it is the value assigned to some selected cell. * (Propagation does not constrain elements. This might need * careful justification.) * * To apply the least number heuristic, we consider values * 0 ... MIN(max_constrained+1, Domain_size-1). * * To make this effective, we should keep max_constrained as low as * possible by selecting cells with maximum index <= max_constrained. * * return: * SEARCH_GO_MODELS * SEARCH_GO_NO_MODELS * SEARCH_MAX_MODELS * SEARCH_MAX_MEGS * SEARCH_MAX_TOTAL_SECONDS * SEARCH_MAX_DOMAIN_SECONDS * *************/ static int search(int max_constrained, int depth) { int id; BOOL go; int rc = check_time_memory(); if (rc != SEARCH_GO_NO_MODELS) return rc; else { id = select_cell(max_constrained); if (id == -1) { rc = possible_model(); return rc; } else { int i, last; /* we'll do 0 .. last */ int x = Cells[id].max_index; max_constrained = MAX(max_constrained, x); Mstats.selections++; if (flag(Opt->trace)) { printf("select: "); p_model(FALSE); /* p_possible_values(); */ } if (Cells[id].symbol->type == RELATION) last = 1; else if (flag(Opt->lnh)) last = MIN(max_constrained+1, Domain_size-1); else last = Domain_size-1; for (i = 0, go = TRUE; i <= last && go; i++) { Estack stk; Mstats.assignments++; if (flag(Opt->trace)) { printf("assign: "); fwrite_term(stdout, Cells[id].eterm); printf("=%d (%d) depth=%d\n", i, last, depth); } stk = assign_and_propagate(id, Domain[i]); if (stk != NULL) { /* no contradiction found during propagation, so we recurse */ rc = search(MAX(max_constrained, i), depth+1); /* undo assign_and_propagate changes */ restore_from_stack(stk); if (rc == SEARCH_GO_MODELS) go = mace4_skolem_check(id); else go = (rc == SEARCH_GO_NO_MODELS); } } return rc; } } } /* search */ /************* * * mace4n() -- look for a model of a specific size * *************/ static int mace4n(Plist clauses, int order) { Plist p, g; int i, rc; Mstate initial_state = get_mstate(); Variable_style save_style = variable_style(); set_variable_style(INTEGER_STYLE); if (Max_domain_element_in_input >= order) { if (flag(Opt->arithmetic)) { if (!ok_for_arithmetic(clauses, order)) return SEARCH_DOMAIN_OUT_OF_RANGE; } else return SEARCH_DOMAIN_OUT_OF_RANGE; } Domain_size = order; init_for_domain_size(); built_in_assignments(); /* Fill out equality table (and maybe others). */ special_assignments(); /* assignments determined by options */ /* Instantiate clauses over the domain. This also (1) makes any domain element constants into real domain elements, (2) applies OR, NOT, and EQ simplification, and (3) does unit propagation (which pushes events onto initial_state->stack). Do the units first, then the 2-clauses, then the rest. */ for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) < 2) generate_ground_clauses(p->v, initial_state); for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) == 2) generate_ground_clauses(p->v, initial_state); for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) > 2) generate_ground_clauses(p->v, initial_state); /* The preceding calls push propagation events onto initial_state->stack. We won't have to undo those initial events during the search, but we can undo them after the search. */ if (flag(Opt->verbose)) { printf("\nInitial partial model:\n"); p_model(FALSE); fflush(stdout); } /* Here we go! */ if (initial_state->ok) rc = search(Max_domain_element_in_input, 0); else rc = SEARCH_GO_NO_MODELS; /* contradiction in initial state */ /* Free all of the memory associated with the current domain size. */ restore_from_stack(initial_state->stack); free_mstate(initial_state); if (flag(Opt->negprop)) free_negprop_index(); free(Ordered_cells); Ordered_cells = NULL; for (i = 0; i < Number_of_cells; i++) { zap_mterm(Cells[i].eterm); free(Cells[i].possible); } free(Cells); Cells = NULL; for (i = 0; i < Domain_size; i++) zap_term(Domain[i]); free(Domain); Domain = NULL; for (g = Ground_clauses; g != NULL; g = g->next) zap_mclause(g->v); zap_plist(Ground_clauses); Ground_clauses = NULL; set_variable_style(save_style); return rc; } /* mace4n */ /************* * * iterate_ok() * *************/ static BOOL iterate_ok(int n, char *class) { if (str_ident(class, "all")) return TRUE; else if (str_ident(class, "evens")) return n % 2 == 0; else if (str_ident(class, "odds")) return n % 2 == 1; else if (str_ident(class, "primes")) return prime(n); else if (str_ident(class, "nonprimes")) return !prime(n); else { fatal_error("iterate_ok, unknown class"); return FALSE; /* to please compiler */ } } /* iterate_ok */ /************* * * next_domain_size() * *************/ static int next_domain_size(n) { int top = (parm(Opt->end_size) == -1 ? INT_MAX : parm(Opt->end_size)); if (n == 0) n = parm(Opt->start_size); /* first call */ else n += parm(Opt->increment); while (!iterate_ok(n, stringparm1(Opt->iterate))) n += parm(Opt->increment); return (n > top ? -1 : n); } /* next_domain_size */ /************* * * mace4() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Mace_results mace4(Plist clauses, Mace_options opt) { int n, rc; Mace_results results = malloc(sizeof(struct mace_results)); disable_max_megs(); /* mace4 does its own max_megs check */ Start_seconds = user_seconds(); Start_megs = megs_malloced(); Opt = opt; /* put options into a global variable */ initialize_for_search(clauses); n = next_domain_size(0); /* returns -1 if we're done */ rc = SEARCH_GO_NO_MODELS; while (n >= 2 && (rc == SEARCH_GO_NO_MODELS || rc == SEARCH_GO_MODELS)) { char str[20]; sprintf(str, "DOMAIN SIZE %d", n); print_separator(stdout, str, TRUE); fflush(stdout); fprintf(stderr,"\n=== Mace4 starting on domain size %d. ===\n",n); Start_domain_seconds = user_seconds(); clock_start(Mace4_clock); rc = mace4n(clauses, n); if (rc == SEARCH_MAX_DOMAIN_SECONDS) { printf("\n====== Domain size %d terminated by max_seconds_per. ======\n",n); rc = SEARCH_GO_NO_MODELS; } else if (rc == SEARCH_DOMAIN_OUT_OF_RANGE) { printf("\n====== Domain size %d skipped because domain elememt too big. ======\n",n); rc = SEARCH_GO_NO_MODELS; } clock_stop(Mace4_clock); p_stats(); reset_current_stats(); clock_reset(Mace4_clock); n = next_domain_size(n); /* returns -1 if we're done */ } /* free memory used for all domain sizes */ free_estack_memory(); free(Sn_to_mace_sn); Sn_to_mace_sn = NULL; results->success = Total_models != 0; results->models = Models; /* NULL if no models or not collecting models */ results->user_seconds = user_seconds() - Start_seconds; if (rc == SEARCH_MAX_MODELS) results->return_code = MAX_MODELS_EXIT; else if (rc == SEARCH_GO_MODELS || rc == SEARCH_GO_NO_MODELS) results->return_code = Total_models==0 ? EXHAUSTED_EXIT : ALL_MODELS_EXIT; else if (rc == SEARCH_MAX_TOTAL_SECONDS) results->return_code = Total_models==0 ? MAX_SEC_NO_EXIT : MAX_SEC_YES_EXIT; else if (rc == SEARCH_MAX_MEGS) results->return_code = Total_models==0 ? MAX_MEGS_NO_EXIT : MAX_MEGS_YES_EXIT; else fatal_error("mace4: unknown return code"); enable_max_megs(); return results; } /* mace4 */ LADR-2009-11A/mace4.src/syms.h0000644000175000017500000000333011105134010014722 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef MACE4_SYMS_H #define MACE4_SYMS_H /* INTRODUCTION */ /* Public definitions */ /* Symbol types */ enum { FUNCTION, RELATION }; /* Symbol attributes */ enum { ORDINARY_SYMBOL, EQUALITY_SYMBOL, SKOLEM_SYMBOL }; typedef struct symbol_data * Symbol_data; struct symbol_data { /* SORT */ int sn; /* ordinary symbol ID */ int mace_sn; /* MACE symbol ID */ int arity; int type; /* FUNCTION or RELATION */ int base; int attribute; /* ORDINARY_SYMBOL or EQUALITY_SYMBOL */ Symbol_data next; }; /* End of public definitions */ /* Public function prototypes from syms.c */ Symbol_data get_symbol_data(void); Symbol_data find_symbol_data(int sn); void init_built_in_symbols(void); int collect_mace4_syms(Plist clauses, BOOL arithmetic); void p_symbol_data(Symbol_data s); Symbol_data find_symbol_node(int id); int id_to_domain_size(int id); int max_index(int id, Symbol_data s); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/arithmetic.h0000644000175000017500000000265211107445562016111 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_ARITHMETIC_H #define TP_ARITHMETIC_H /* #include "" */ /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from arithmetic.c */ void init_arithmetic(void); BOOL domain_term(Term t, int domain_size); BOOL arith_op_sn(int i); BOOL arith_rel_sn(int i); BOOL arith_op_term(Term t); BOOL arith_rel_term(Term t); BOOL arith_term(Term t); BOOL arith_quasi_evaluable(Term t); int arith_evaluate(Term t, BOOL *evaluated); int arith_eval(Term t, BOOL *evaluated); BOOL ok_for_arithmetic(Plist clauses, int domain_size); BOOL check_with_arithmetic(Plist ground_clauses); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/temp0000644000175000017500000053607011171220574014500 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2009-02A, February 2009. Process 15418 was started by mccune on cleo, Tue Apr 14 17:51:22 2009 The command was "./mace4 -m -1 -n7 -f r1.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file r1.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. lex([A,E,P1,P2,K,a,p]). formulas(assumptions). A + E + P1 + P2 = a + p + 1. A + E + P1 + P2 + a + p + K > 1. A + E + P1 + P2 + a + p + K <= domain_size. end_of_list. % From the command line: assign(max_models, -1). % assign(domain_size, 7) -> assign(start_size, 7). % assign(domain_size, 7) -> assign(end_size, 7). % From the command line: assign(domain_size, 7). ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). A + E + P1 + P2 = a + p + 1. A + E + P1 + P2 + a + p + K > 1. A + E + P1 + P2 + a + p + K <= domain_size. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 1. ============================== DOMAIN SIZE 7 ========================= ============================== MODEL ================================= interpretation( 7, [number=1, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=2, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=3, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=4, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=5, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 5 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=6, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 6 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=7, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=8, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=9, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=10, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=11, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=12, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=13, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=14, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=15, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=16, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=17, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=18, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=19, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=20, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=21, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=22, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=23, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=24, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=25, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=26, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 4 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=27, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 4 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=28, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 4 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=29, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 4 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=30, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=31, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=32, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=33, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=34, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 5 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=35, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 6 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=36, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=37, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=38, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=39, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=40, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=41, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=42, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=43, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=44, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=45, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=46, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=47, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=48, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=49, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=50, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=51, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=52, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=53, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=54, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=55, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=56, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=57, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=58, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=59, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=60, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=61, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=62, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=63, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=64, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=65, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=66, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=67, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=68, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=69, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=70, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=71, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=72, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=73, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=74, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=75, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=76, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=77, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=78, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=79, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=80, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=81, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=82, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=83, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=84, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=85, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=86, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=87, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=88, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=89, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=90, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=91, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=92, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=93, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=94, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=95, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 4 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=96, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 4 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=97, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 4 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=98, seconds=0], [ function(A, [ 0 ]), function(E, [ 0 ]), function(P1, [ 4 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=99, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=100, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=101, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=102, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=103, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 5 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=104, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 6 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=105, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=106, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=107, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=108, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=109, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=110, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=111, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=112, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=113, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=114, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=115, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=116, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=117, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=118, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=119, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=120, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=121, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=122, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=123, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=124, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=125, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=126, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=127, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=128, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=129, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=130, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=131, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=132, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=133, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=134, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=135, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=136, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=137, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=138, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=139, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=140, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=141, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=142, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=143, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=144, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=145, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=146, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=147, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=148, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=149, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=150, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=151, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=152, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=153, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=154, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=155, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=156, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=157, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=158, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=159, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=160, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=161, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=162, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=163, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=164, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=165, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=166, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=167, seconds=0], [ function(A, [ 0 ]), function(E, [ 1 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=168, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=169, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=170, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=171, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=172, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=173, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=174, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=175, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=176, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=177, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=178, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=179, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=180, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=181, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=182, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=183, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=184, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=185, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=186, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=187, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=188, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=189, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=190, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=191, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=192, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=193, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=194, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=195, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=196, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=197, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=198, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=199, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=200, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=201, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=202, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=203, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=204, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=205, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=206, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=207, seconds=0], [ function(A, [ 0 ]), function(E, [ 2 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=208, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=209, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=210, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=211, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=212, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=213, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=214, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=215, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=216, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=217, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=218, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=219, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=220, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=221, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=222, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=223, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=224, seconds=0], [ function(A, [ 0 ]), function(E, [ 3 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=225, seconds=0], [ function(A, [ 0 ]), function(E, [ 4 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=226, seconds=0], [ function(A, [ 0 ]), function(E, [ 4 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=227, seconds=0], [ function(A, [ 0 ]), function(E, [ 4 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=228, seconds=0], [ function(A, [ 0 ]), function(E, [ 4 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=229, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=230, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=231, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=232, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=233, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 5 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=234, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 6 ]), function(a, [ 0 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=235, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=236, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=237, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=238, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=239, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=240, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=241, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=242, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=243, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=244, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=245, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=246, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=247, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=248, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=249, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=250, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=251, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=252, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=253, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=254, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=255, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=256, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=257, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 3 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=258, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=259, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=260, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=261, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=262, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=263, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=264, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=265, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=266, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=267, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=268, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=269, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=270, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=271, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=272, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=273, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=274, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=275, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=276, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=277, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=278, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=279, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=280, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=281, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=282, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=283, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=284, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=285, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=286, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=287, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=288, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=289, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=290, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=291, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=292, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=293, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=294, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=295, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=296, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=297, seconds=0], [ function(A, [ 1 ]), function(E, [ 0 ]), function(P1, [ 3 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=298, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=299, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=300, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=301, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=302, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=303, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=304, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=305, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=306, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=307, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=308, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=309, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=310, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=311, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=312, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=313, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=314, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=315, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=316, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=317, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=318, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=319, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=320, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=321, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=322, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=323, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=324, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=325, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=326, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=327, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=328, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=329, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=330, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=331, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=332, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=333, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=334, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=335, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=336, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=337, seconds=0], [ function(A, [ 1 ]), function(E, [ 1 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=338, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=339, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=340, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=341, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=342, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=343, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=344, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=345, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=346, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=347, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=348, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=349, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=350, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=351, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=352, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=353, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=354, seconds=0], [ function(A, [ 1 ]), function(E, [ 2 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=355, seconds=0], [ function(A, [ 1 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=356, seconds=0], [ function(A, [ 1 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=357, seconds=0], [ function(A, [ 1 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=358, seconds=0], [ function(A, [ 1 ]), function(E, [ 3 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=359, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=360, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=361, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=362, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=363, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=364, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=365, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=366, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 3 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=367, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 0 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=368, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 4 ]), function(a, [ 1 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=369, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=370, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=371, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=372, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=373, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=374, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=375, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=376, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=377, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=378, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=379, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=380, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=381, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 2 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=382, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=383, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=384, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=385, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=386, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=387, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=388, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=389, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=390, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=391, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=392, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=393, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=394, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=395, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=396, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=397, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=398, seconds=0], [ function(A, [ 2 ]), function(E, [ 0 ]), function(P1, [ 2 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=399, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=400, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=401, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=402, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=403, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=404, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=405, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=406, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=407, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=408, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=409, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=410, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=411, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=412, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=413, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=414, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=415, seconds=0], [ function(A, [ 2 ]), function(E, [ 1 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=416, seconds=0], [ function(A, [ 2 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=417, seconds=0], [ function(A, [ 2 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=418, seconds=0], [ function(A, [ 2 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=419, seconds=0], [ function(A, [ 2 ]), function(E, [ 2 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=420, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=421, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=422, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=423, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=424, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=425, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 1 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=426, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 0 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=427, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 1 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=428, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 2 ]), function(a, [ 2 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=429, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=430, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=431, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=432, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 1 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=433, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=434, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=435, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=436, seconds=0], [ function(A, [ 3 ]), function(E, [ 0 ]), function(P1, [ 1 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=437, seconds=0], [ function(A, [ 3 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=438, seconds=0], [ function(A, [ 3 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=439, seconds=0], [ function(A, [ 3 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=440, seconds=0], [ function(A, [ 3 ]), function(E, [ 1 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=441, seconds=0], [ function(A, [ 4 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 0 ]), function(p, [ 3 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=442, seconds=0], [ function(A, [ 4 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 1 ]), function(p, [ 2 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=443, seconds=0], [ function(A, [ 4 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 2 ]), function(p, [ 1 ]) ]). ============================== end of model ========================== ============================== MODEL ================================= interpretation( 7, [number=444, seconds=0], [ function(A, [ 4 ]), function(E, [ 0 ]), function(P1, [ 0 ]), function(P2, [ 0 ]), function(K, [ 0 ]), function(a, [ 3 ]), function(p, [ 0 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 7. Current CPU time: 0.00 seconds (total CPU time: 1.30 seconds). Ground clauses: seen=3, kept=3. Selections=137257, assignments=960799, propagations=0, current_models=444. Rewrite_terms=1225346, rewrite_bools=830385, indexes=0. Rules_from_neg_clauses=0, cross_offs=0. ============================== end of statistics ===================== User_CPU=1.30, System_CPU=0.03, Wall_clock=2. Exiting with 444 models. Process 15418 exit (all_models) Tue Apr 14 17:51:24 2009 The process finished Tue Apr 14 17:51:24 2009 LADR-2009-11A/mace4.src/propagate.c0000644000175000017500000003736211107452044015734 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" /* External variables defined in mace4.c. */ extern Mace_options Opt; extern Symbol_data *Sn_to_mace_sn; extern struct cell *Cells; extern int Domain_size; extern Term *Domain; /* array of terms representing (shared) domain elements */ extern int Relation_flag; /* term flag */ extern int Negation_flag; /* term flag */ extern int Eq_sn; extern int Or_sn; extern int Not_sn; extern struct mace_stats Mstats; /************* * * eterm() * * Check if a term is evaluable. If so, set the id. * For example, f(k,j,i) gives k*n*n + j*n + i + base. * If the term is not evaluable, set the id to -1. * *************/ BOOL eterm(Term t, int *pid) { *pid = -1; /* We must return -1 if the term is not evaluable. */ if (t == NULL || VARIABLE(t) || arith_rel_term(t) || arith_op_term(t)) return FALSE; else { int i; int mult = 1; int id = Sn_to_mace_sn[SYMNUM(t)]->base; for (i = ARITY(t)-1; i >= 0; i--) { if (!VARIABLE(ARG(t,i))) return FALSE; else id += VARNUM(ARG(t,i)) * mult; mult *= Domain_size; } *pid = id; return TRUE; } } /* eterm */ /************* * * decode_eterm_id() * * Build and return the e-term corresponding to the given ID. * This inverse of eterm_id. If it is temporary, make sure * to call zap_mterm(t) when finished with it. * *************/ Term decode_eterm_id(int id) { /* Assume the id is in range. */ Symbol_data s = Cells[id].symbol; Term t = get_rigid_term_dangerously(s->sn, s->arity); int n = Domain_size; int x = id - s->base; int i; for (i = s->arity - 1; i >= 0; i--) { int p = int_power(n, i); int e = x / p; ARG(t, (s->arity-1) - i) = Domain[e]; x = x % p; } return t; } /* decode_eterm_id */ /************* * * pvalues_check() * * If there is exactly 1 possible value, return it; else return NULL; * *************/ static Term pvalues_check(Term *a, int n) { Term b = NULL; int i; for (i = 0; i < n; i++) { if (a[i] != NULL) { if (b != NULL) return NULL; else b = a[i]; } } if (b == NULL) fatal_error("pvalues_check: no possible values\n"); return b; } /* pvalues_check */ /************* * * nterm_check_and_process() * * Given a new unit (which is not an ASSIGNMENT or ELIMINATION), * check to see if it is a NEAR_ASSIGNMENT or NEAR_ELIMINATION. * If so, insert it into the index (which updates the stack), * and put it into the job list. * * Note that these operations occur even if the some of the * individual operations are disbaled. However, this routine * should not be called if all negative propagation is disabled. * *************/ static void nterm_check_and_process(Term lit, Mstate state) { int pos; int id; int neg = NEGATED(lit); int eq = EQ_TERM(lit); int type = (neg && eq ? NEAR_ELIMINATION : NEAR_ASSIGNMENT); if (eq) { Term a0 = ARG(lit,0); Term a1 = ARG(lit,1); if (VARIABLE(a1) && nterm(a0, &pos, &id)) { insert_negprop_eq(lit, a0, VARNUM(a1), state); job_prepend(state, type, id, a0, a1, pos); } else if (VARIABLE(a0) && nterm(a1, &pos, &id)) { insert_negprop_eq(lit, a1, VARNUM(a0), state); job_prepend(state, type, id, a1, a0, pos); } } else if (nterm(lit, &pos, &id)) { insert_negprop_noneq(lit, state); job_prepend(state, NEAR_ASSIGNMENT, id, lit, (neg ? Domain[0] : Domain[1]), pos); } } /* nterm_check_and_process */ /************* * * new_assignment() * * If a contradiction is found, set state->ok to FALSE. * *************/ static void new_assignment(int id, Term value, Mstate state) { if (Cells[id].value == NULL) { /* Note that alpha of the new rule is indexed, so the rule will rewrite itself. That IS what we want. */ state->stack = update_and_push((void **) &(Cells[id].value), value, state->stack); if (flag(Opt->trace)) { printf("\t\t\t\t\t"); fwrite_term(stdout, Cells[id].eterm); printf(" = %d\n", VARNUM(value)); } job_prepend(state, ASSIGNMENT, id, NULL, NULL, -1); Mstats.propagations++; return; } else if (Cells[id].value == value) return; /* ok: we already have the rule */ else { /* contradiction: we have an incompatible rule */ if (flag(Opt->trace)) { printf("\t\t\t\t\t"); fwrite_term(stdout, Cells[id].eterm); printf(" = %d BACKUP!\n", VARNUM(value)); } state->ok = FALSE; return; } } /* new_assignment */ /************* * * new_elimination() * * If a contradiction is found, set state->ok to FALSE. * *************/ void new_elimination(int id, Term beta, Mstate state) { if (Cells[id].value == beta) { if (flag(Opt->trace)) { printf("\t\t\t\t\t"); fwrite_term(stdout, Cells[id].eterm); printf(" != %d BACKUP!\n", VARNUM(beta)); } state->ok = FALSE; /* contradiction: cell already has that value! */ return; } else if (Cells[id].value != NULL) return; /* ok: cell already has a (different) value */ else if (Cells[id].possible[VARNUM(beta)] == NULL) return; /* ok: already crossed off */ else { /* New unit f(1,2) != 3. Cross it off and push for negprop. */ Term value; Mstats.cross_offs++; state->stack=update_and_push((void **) &(Cells[id].possible[VARNUM(beta)]), NULL, state->stack); if (flag(Opt->trace)) { printf("\t\t\t\t\t"); fwrite_term(stdout, Cells[id].eterm); printf(" != %d\n", VARNUM(beta)); } if (flag(Opt->negprop)) job_prepend(state, ELIMINATION, id, NULL, beta, -1); value = pvalues_check(Cells[id].possible, Domain_size); if (value == NULL) return; /* ok: nothing more to do */ else { Mstats.rules_from_neg++; new_assignment(id, value, state); } } } /* new_elimination */ /************* * * process_clause() -- process new unit clauses * * There are several things to check for: * (1) contradiction in the form of a FALSE clause; * (2) contradiction in the form of a rule inconsistent with an existing * rule (this would eventually produce a FALSE clause, but why wait?); * (3) a new assignment, e.g., f(1,2)=3, P(4), ~P(5); * (4) a new elimination, e.g., f(1,2)!=3; * (5) near assignment, near elimination (for negative propagation). * * If a contradiction is found, set state->ok to FALSE. * *************/ static void process_clause(Mclause c, Mstate state) { if (c->subsumed) return; else if (c->u.active == 0) { if (flag(Opt->trace)) printf("\t\t\t\t\t** BACKUP **\n"); state->ok = FALSE; return; } else if (c->u.active != 1) return; /* nonunit, so do nothing */ else { /* OK, we have a nonsubsumed unit. */ Term lit, beta; BOOL negated, eq; int id; int i = 0; while (FALSE_TERM(LIT(c,i))) i++; lit = LIT(c,i); negated = NEGATED(lit); eq = EQ_TERM(lit); #if 0 printf("process_clause 1: "); p_matom(lit); #endif if (!eq && eterm(lit, &id)) beta = Domain[negated ? 0 : 1]; /* P(1,2,3) or ~P(1,2,3) */ else if (eq && eterm(ARG(lit,0),&id) && VARIABLE(ARG(lit,1))) beta = ARG(lit,1); /* f(1,2)=3 or f(1,2)!=3 */ else if (eq && eterm(ARG(lit,1),&id) && VARIABLE(ARG(lit,0))) beta = ARG(lit,0); /* 3=f(1,2) or 3!=f(1,2) */ else { if (flag(Opt->negprop)) /* If it is an nterm, index and insert into job list. */ nterm_check_and_process(lit, state); return; /* We cannot do anything else with the unit. */ } if (eq && negated) new_elimination(id, beta, state); /* f(1,2) != 3 */ else new_assignment(id, beta, state); /* f(1,2) = 3, P(0), ~P(0) */ } } /* process_clause */ /************* * * handle_literal() * *************/ static Mclause handle_literal(Term lit, Term result, Mstate state) { Mclause clause_to_process = NULL; Mclause parent_clause = lit->container; /* evaluable eterm literal -- this will rewrite to TRUE or FALSE */ int pos = lit_position(parent_clause, lit); BOOL negated = NEGATED(lit); Mstats.rewrite_bools++; /* Result should be either 0 or 1, because lit is a literal. if the literal is negated, negate the result. */ if (negated) result = (result == Domain[0] ? Domain[1] : Domain[0]); state->stack = update_and_push((void **) &(LIT(parent_clause,pos)), result, state->stack); /* Now we have to update fields in the clause. */ if (FALSE_TERM(result)) { /* decrement the count of active literals */ state->stack = update_and_push((void **) &(parent_clause->u.active), (void *) (parent_clause->u.active-1), state->stack); clause_to_process = parent_clause; } else /* mark clause as subsumed */ state->stack = update_and_push((void **) &(parent_clause->subsumed), (void *) TRUE, state->stack); return clause_to_process; } /* handle_literal */ /************* * * propagate_positive() * * Propagate a positive assignment. This includes negated non-equality * atoms. For example, ~P(1,2,3) is thought of as p(1,2,3) = FALSE. * * If a contradiction is found, set state->ok to FALSE. * *************/ static void propagate_positive(int id, Mstate state) { Term t; #if 0 printf("propagage_positive: "); p_term(Cells[id].eterm); #endif for (t = Cells[id].occurrences; t != NULL; t = t->u.vp) { /* foreach term the rule applies to */ Term curr = t; Mclause clause_to_process; BOOL index_it; /* The following loop iterates up toward the root of the clause, rewriting terms. We stop when we get to a literal, an eterm that cannot be rewritten (we then index the eterm in this case), or when we get to a non-eterm. */ #if 0 printf("rewriting: "); p_mclause(containing_mclause(curr)); #endif while (!LITERAL(curr) && /* stop if literal */ !arith_op_term(curr) && /* stop if arithmetic term */ eterm(curr, &id) && /* stop if not eterm */ Cells[id].value != NULL) { /* stop if eterm not evaluable*/ Term result = Cells[id].value; Term parent = curr->container; int pos = arg_position(parent, curr); state->stack = update_and_push((void **) &(ARG(parent,pos)), result, state->stack); Mstats.rewrite_terms++; curr = parent; } /* while rewriting upward */ #if 0 printf("done: "); p_mclause(containing_mclause(curr)); #endif clause_to_process = NULL; /* set to possible new rule */ index_it = FALSE; /* should curr be indexed? */ if (arith_rel_term(curr) || arith_op_term(curr)) { Term parent_lit = containing_mliteral(curr); Mclause parent_clause = parent_lit->container; if (!parent_clause->subsumed) { BOOL evaluated; int b = arith_eval(parent_lit, &evaluated); if (evaluated) { Term result; if (b != 0 && b != 1) fatal_error("propagate_positive, arith_eval should be Boolean"); result = (b ? Domain[1] : Domain[0]); clause_to_process = handle_literal(parent_lit, result, state); } else if (EQ_TERM(curr)) clause_to_process = parent_clause; } } else if (!LITERAL(curr)) { /* curr is a term */ Term parent = curr->container; if (id != -1) index_it = TRUE; /* curr is a non-evaluable eterm */ /* If curr is 1 or 2 steps away from a literal, process it. */ if (LITERAL(parent)) clause_to_process = parent->container; else { parent = parent->container; if (LITERAL(parent)) clause_to_process = parent->container; } } else { /* curr is a literal (equality or nonquality, positive or negative) */ Mclause parent_clause = curr->container; if (!eterm(curr, &id)) /* non-eterm literal */ clause_to_process = parent_clause; else if (Cells[id].value == NULL) { /* non-evaluable eterm literal */ index_it = TRUE; clause_to_process = parent_clause; } else if (!parent_clause->subsumed) { clause_to_process = handle_literal(curr, Cells[id].value, state); } } /* literal */ if (index_it) { /* curr is an evaluable term or literal, e.g., f(1,2), but there is no rule for it. Therefore, we index it so that it can be found in case a rule appears later. */ Mstats.indexes++; state->stack = update_and_push((void **) &(curr->u.vp), Cells[id].occurrences, state->stack); state->stack = update_and_push((void **) &(Cells[id].occurrences), curr, state->stack); } if (clause_to_process != NULL) { process_clause(clause_to_process, state); if (!state->ok) return; } } /* foreach occurrence (container) of the cell just assigned */ } /* propagate_positive */ /************* * * propagate() * * Do all of the jobs in the Mstate. If a contradiction is found, * clean up the Mstate by flushing any undone jobs and restoring * from the stack. * *************/ static void propagate(Mstate state) { while (state->ok && state->first_job != NULL) { /* Negative propagation is applied to all types. Positive propagation is applied to ASSIGNMENT only. */ int type = state->first_job->type; int id = state->first_job->id; Term alpha = state->first_job->alpha; Term beta = state->first_job->beta; int pos = state->first_job->pos; job_pop(state); if (type == ASSIGNMENT) propagate_positive(id, state); if (state->ok && flag(Opt->negprop)) propagate_negative(type, id, alpha, beta, pos, state); } if (!state->ok) { zap_jobs(state); restore_from_stack(state->stack); state->stack = NULL; } } /* propagate */ /************* * * assign_and_propagate() * * Make an assignment, and propagate its effects. * Return the stack of events that occur. If the propagation * gives a contradiction, return NULL. * *************/ Estack assign_and_propagate(int id, Term value) { Estack tmp_stack; Mstate state = get_mstate(); if (Cells[id].value == value) fatal_error("assign_and_propagate: repeated assignment"); if (Cells[id].value != NULL) fatal_error("assign_and_propagate: contradictory assignment"); /* First make the assignment and initialize the job list. */ state->stack = update_and_push((void **) &(Cells[id].value), value, NULL); job_prepend(state, ASSIGNMENT, id, NULL, NULL, -1); /* Process the job list (which can grow during propagation). */ propagate(state); /* Return the stack (which is NULL iff we have a contradiction). */ tmp_stack = state->stack; free_mstate(state); return tmp_stack; } /* assign_and_propagate */ /************* * * process_initial_clause() * * This routine processes the initial ground clauses. This includes * checking for the empty clause, checking for unit conflicts, and * unit propagation. If a contradiction is found, state->ok is set * to FALSE. * *************/ void process_initial_clause(Mclause c, Mstate state) { process_clause(c, state); /* handles empty clause and nonsubsumed units */ if (state->ok && state->first_job != NULL) propagate(state); /* Process_clause pushed a job, so we propagate it. */ } /* process_initial_clause */ LADR-2009-11A/mace4.src/README.memory0000644000175000017500000000222110215411704015754 0ustar mccunemccuneONCE FOR ALL DOMAIN SIZES GET Sn_to_mace_sn = malloc(Sn_map_size * sizeof(void *)); FREE ONCE FOR EACH DOMAIN SIZE: GET Domain = malloc(Domain_size * sizeof(void *)); for (i = 0; i < Domain_size; i++) Domain[i] = get_variable_term(i); Cells = malloc(Number_of_cells * sizeof(struct cell)); Ordered_cells = malloc(Number_of_cells * sizeof(void *)); for (id = 0; id < Number_of_cells; id++) { c->eterm = decode_eterm_id(id); /* builds an mterm */ c->possible = malloc(n * sizeof(void *)); } if (flag(Opt->negprop)) init_negprop_index(); (Ground_clauses get constructed) FREE for (i = 0; i < Domain_size; i++) zap_term(Domain[i]); free(Domain); free(Ordered_cells); free(Cells); for (i = 0; i < Number_of_cells; i++) { zap_mterm(Cells[i].eterm); free(Cells[i].possible); } if (flag(Opt->negprop)) free_negprop_index(); for (g = Ground_clauses; g != NULL; g = g->next) zap_mclause(g->v); zap_plist(Ground_clauses); /* Free all of the memory associated with the current domain size. */ restore_from_stack(initial_state->stack); free_mstate(initial_state); LADR-2009-11A/mace4.src/arithmetic.c0000644000175000017500000003412111171151212016063 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" extern int Negation_flag; /* for dealing with mclause */ extern Term *Domain; extern int Domain_size; /* Private definitions and types */ static int Sum_sn; static int Prod_sn; static int Neg_sn; static int Div_sn; static int Mod_sn; static int Min_sn; static int Max_sn; static int Abs_sn; static int Domain_size_sn; static int Lt_sn; static int Le_sn; static int Gt_sn; static int Ge_sn; static int Eq_sn; static BOOL *Arith_op_sn; /* array to know if sn is arithmetic operation */ static BOOL *Arith_rel_sn; /* array to know if sn is arithmetic relation */ static int Arith_sn_size = 0; /* size of array */ /************* * * init_arithmetic() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_arithmetic(void) { Arith_sn_size = greatest_symnum() + 20; Arith_op_sn = calloc(Arith_sn_size, sizeof(BOOL)); Arith_rel_sn = calloc(Arith_sn_size, sizeof(BOOL)); Arith_op_sn[Sum_sn = str_to_sn("+", 2)] = TRUE; Arith_op_sn[Prod_sn = str_to_sn("*", 2)] = TRUE; Arith_op_sn[Neg_sn = str_to_sn("-", 1)] = TRUE; Arith_op_sn[Div_sn = str_to_sn("/", 2)] = TRUE; Arith_op_sn[Mod_sn = str_to_sn("mod", 2)] = TRUE; Arith_op_sn[Min_sn = str_to_sn("min", 2)] = TRUE; Arith_op_sn[Max_sn = str_to_sn("max", 2)] = TRUE; Arith_op_sn[Abs_sn = str_to_sn("abs", 1)] = TRUE; Arith_op_sn[Domain_size_sn = str_to_sn("domain_size", 0)] = TRUE; Arith_rel_sn[Le_sn = str_to_sn("<=", 2)] = TRUE; Arith_rel_sn[Lt_sn = str_to_sn("<", 2)] = TRUE; Arith_rel_sn[Ge_sn = str_to_sn(">=", 2)] = TRUE; Arith_rel_sn[Gt_sn = str_to_sn(">", 2)] = TRUE; Arith_rel_sn[Eq_sn = str_to_sn("=", 2)] = TRUE; set_assoc_comm("+", TRUE); set_assoc_comm("*", TRUE); declare_parse_type("+", 490, INFIX_RIGHT); declare_parse_type("*", 470, INFIX_RIGHT); declare_parse_type("/", 460, INFIX); declare_parse_type("mod", 460, INFIX); } /* init_arithmetic */ /************* * * modulo() * *************/ /* DOCUMENTATION In C, the % (remainder) operation is not defined for negative operands. Also there is a distinction between the "remainder" and "modulo" operations for negative operands: A B A/B A rem B A mod B 14 5 2 4 4 -14 5 -2 -4 1 14 -5 -2 4 -1 -14 -5 2 -4 -4 */ /* PUBLIC */ int modulo(int a, int b) { if (b == 0) return INT_MAX; else if (b > 0) { if (a >= 0) return a % b; /* a >= 0, b > 0 */ else return -(abs(a) % b) + b; /* a < 0, b > 0 */ } else { if (a >= 0) return (a % abs(b)) + b; /* a >= 0, b < 0 */ else return -(abs(a) % abs(b)); /* a < 0, b < 0 */ } } /* modulo */ /************* * * domain_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL domain_term(Term t, int domain_size) { return VARIABLE(t) && VARNUM(t) < domain_size; } /* domain_term */ /************* * * arith_op_sn() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL arith_op_sn(int i) { if (i >= Arith_sn_size) return FALSE; else return Arith_op_sn[i]; } /* arith_op_sn */ /************* * * arith_rel_sn() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL arith_rel_sn(int i) { if (i >= Arith_sn_size) return FALSE; else return Arith_rel_sn[i]; } /* arith_rel_sn */ /************* * * arith_op_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL arith_op_term(Term t) { return !VARIABLE(t) && arith_op_sn(SYMNUM(t)); } /* arith_op_term */ /************* * * arith_rel_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL arith_rel_term(Term t) { return !VARIABLE(t) && arith_rel_sn(SYMNUM(t)); } /* arith_rel_term */ /************* * * arith_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL arith_term(Term t) { if (VARIABLE(t)) return TRUE; else return arith_op_term(t) || arith_rel_term(t); } /* arith_term */ /************* * * arith_quasi_evaluable() * *************/ /* DOCUMENTATION Similar to arith_evaluable(), except that division by 0 is not checked. */ /* PUBLIC */ BOOL arith_quasi_evaluable(Term t) { if (!arith_term(t)) return FALSE; else if (VARIABLE(t)) return TRUE; else { int i; for (i = 0; i < ARITY(t); i++) if (!arith_quasi_evaluable(ARG(t,i))) return FALSE; return TRUE; } } /* arith_quasi_evaluable */ /************* * * arith_evaluate() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int arith_evaluate(Term t, BOOL *evaluated) { if (!arith_term(t)) { *evaluated = FALSE; return 0; } if (VARIABLE(t)) return VARNUM(t); else { int sn = SYMNUM(t); if (sn == Div_sn || sn == Mod_sn) { int d = arith_evaluate(ARG(t,1), evaluated); if (d == 0) { *evaluated = FALSE; return 0; } else if (sn == Div_sn) return arith_evaluate(ARG(t,0), evaluated) / d; else return modulo(arith_evaluate(ARG(t,0), evaluated), d); } else if (sn == Sum_sn) return arith_evaluate(ARG(t,0), evaluated) + arith_evaluate(ARG(t,1), evaluated); else if (sn == Prod_sn) return arith_evaluate(ARG(t,0), evaluated) * arith_evaluate(ARG(t,1), evaluated); else if (sn == Neg_sn) return -arith_evaluate(ARG(t,0), evaluated); else if (sn == Abs_sn) return abs(arith_evaluate(ARG(t,0), evaluated)); else if (sn == Domain_size_sn) return Domain_size; else if (sn == Min_sn) { int a0 = arith_evaluate(ARG(t,0), evaluated); int a1 = arith_evaluate(ARG(t,1), evaluated); return IMIN(a0,a1); } else if (sn == Max_sn) { int a0 = arith_evaluate(ARG(t,0), evaluated); int a1 = arith_evaluate(ARG(t,1), evaluated); return IMAX(a0,a1); } else if (sn == Lt_sn) return arith_evaluate(ARG(t,0), evaluated) < arith_evaluate(ARG(t,1), evaluated); else if (sn == Le_sn) return arith_evaluate(ARG(t,0), evaluated) <= arith_evaluate(ARG(t,1), evaluated); else if (sn == Gt_sn) return arith_evaluate(ARG(t,0), evaluated) > arith_evaluate(ARG(t,1), evaluated); else if (sn == Ge_sn) return arith_evaluate(ARG(t,0), evaluated) >= arith_evaluate(ARG(t,1), evaluated); else if (sn == Eq_sn) return arith_evaluate(ARG(t,0), evaluated) == arith_evaluate(ARG(t,1), evaluated); else { fatal_error("arith_evaluate, operation not handled"); return INT_MIN; } } } /* arith_evaluate */ /************* * * arith_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int arith_eval(Term t, BOOL *evaluated) { *evaluated = TRUE; return arith_evaluate(t, evaluated); } /* arith_eval */ /************* * * top_safe() -- for clauses whose nats are constants * *************/ static BOOL top_safe(Term t, int domain_size) { if (VARIABLE(t)) return TRUE; else if (CONSTANT(t)) return natural_constant_term(t) < domain_size; else if (arith_op_term(t) || arith_rel_term(t)) return FALSE; else return TRUE; } /* top_safe */ /************* * * all_safe() - nothing in the term or any of the subterms involves * arithmetic or nats out of range. * - for clauses whose nats are constants * *************/ static BOOL all_safe(Term t, int domain_size) { if (VARIABLE(t)) return TRUE; else if (!top_safe(t, domain_size)) return FALSE; else { int i; for (i = 0; i < ARITY(t); i++) { if (!all_safe(ARG(t,i), domain_size)) return FALSE; } return TRUE; } } /* all_safe */ /************* * * all_ordinary_nodes_safe() -- for clauses whose nats are constants * *************/ static BOOL all_ordinary_nodes_safe(Term t, int domain_size) { if (VARIABLE(t) || CONSTANT(t)) return TRUE; else if (arith_rel_term(t) || arith_op_term(t)) { int i; for (i = 0; i < ARITY(t); i++) { if (!all_ordinary_nodes_safe(ARG(t,i), domain_size)) return FALSE; } return TRUE; } else return all_safe(t, domain_size); } /* all_ordinary_nodes_safe */ /************* * * non_arith() -- for clauses whose nats are constants * *************/ static BOOL non_arith(Term t) { if (VARIABLE(t)) return FALSE; else if (CONSTANT(t)) return natural_constant_term(t) < 0; else if (arith_rel_term(t) || arith_op_term(t)) return FALSE; else return TRUE; } /* non_arith */ /************* * * atom_safe() -- for clauses whose nats are constants * *************/ static BOOL atom_safe(Term atom, int domain_size) { if (SYMNUM(atom) == Eq_sn) { /* special case, because = is sometimes arith, sometimes not */ Term a = ARG(atom,0); Term b = ARG(atom,1); if (non_arith(a) && natural_constant_term(b) >= domain_size) return FALSE; else if (non_arith(b) && natural_constant_term(a) >= domain_size) return FALSE; else return all_ordinary_nodes_safe(atom, domain_size); } else return all_ordinary_nodes_safe(atom, domain_size); } /* atom_safe */ /************* * * ok_for_arithmetic() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ok_for_arithmetic(Plist clauses, int domain_size) { /* Domain elements and other integers are CONSTANTS!!! */ Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; Literals lit; for (lit = c->literals; lit; lit = lit->next) { if (!atom_safe(lit->atom, domain_size)) return FALSE; } } return TRUE; } /* ok_for_arithmetic */ /************* * * distrib() * *************/ static Term distrib(Term t) { if (VARIABLE(t)) return t; else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = distrib(ARG(t,i)); if (SYMNUM(t) != Prod_sn) return t; else { if (SYMNUM(ARG(t,1)) == Sum_sn) { /* a*(b+c) */ Term a = ARG(t,0); Term b = ARG(ARG(t,1),0); Term c = ARG(ARG(t,1),1); free_term(ARG(t,1)); free_term(t); return build_binary_term(Sum_sn, distrib(build_binary_term(Prod_sn, a, b)), distrib(build_binary_term(Prod_sn, copy_term(a), c))); } else if (SYMNUM(ARG(t,0)) == Sum_sn) { /* (b+c)*a */ Term a = ARG(t,1); Term b = ARG(ARG(t,0),0); Term c = ARG(ARG(t,0),1); free_term(ARG(t,0)); free_term(t); return build_binary_term(Sum_sn, distrib(build_binary_term(Prod_sn, b, a)), distrib(build_binary_term(Prod_sn, c, copy_term(a)))); } else return t; } } } /* distrib */ /************* * * qsimp() * *************/ static Term qsimp(Term t) { if (VARIABLE(t)) return t; else { int i; BOOL all_args_ints = TRUE; for (i = 0; i < ARITY(t); i++) { ARG(t,i) = qsimp(ARG(t,i)); if (!(VARIABLE(ARG(t,i)) || (SYMNUM(ARG(t,i)) == Neg_sn && VARIABLE(ARG(ARG(t,i),0))))) all_args_ints = FALSE; } if (all_args_ints) { BOOL evaluated; int i = arith_eval(t, &evaluated); if (evaluated) { zap_term(t); if (i >= 0) return get_variable_term(i); else return build_unary_term(Neg_sn, get_variable_term(-i)); } else return t; } else { if (SYMNUM(t) != Prod_sn && VARIABLE(ARG(t,0)) && VARNUM(ARG(t,0)) == 0) { /* 0*x to 0 */ zap_term(t); return get_variable_term(0); } else if (SYMNUM(t) != Sum_sn && SYMNUM(ARG(t,1)) == Neg_sn && term_ident(ARG(t,0),ARG(ARG(t,1),0))) { /* x + -x to 0 */ zap_term(t); return get_variable_term(0); } else return t; } } } /* qsimp */ /************* * * arith_rel_quasi_eval() * *************/ static BOOL arith_rel_quasi_eval(Term atom) { /* This is an initial version for testing only. */ if (SYMNUM(atom) == Eq_sn) { BOOL negated = NEGATED(atom); Term atom2 = copy_term(atom); BOOL val; atom2 = distrib(atom2); // printf("after distrib: "); fwrite_term_nl(stdout, atom2); ac_canonical2(atom2, -1, term_compare_vcp); // printf("after AC canon: "); fwrite_term_nl(stdout, atom2); ARG(atom2,0) = qsimp(ARG(atom2,0)); ARG(atom2,1) = qsimp(ARG(atom2,1)); // printf("after qsimp: "); fwrite_term_nl(stdout, atom2); if (term_ident(ARG(atom2,0), ARG(atom2,1))) val = negated ? FALSE : TRUE; else val = FALSE; zap_term(atom2); return val; } else return FALSE; } /* arith_rel_quasi_eval */ /************* * * check_with_arithmetic() * *************/ /* DOCUMENTATION Return TRUE iff all clauses are true. There can be arithmeic terms that need to be evaluated. */ /* PUBLIC */ BOOL check_with_arithmetic(Plist ground_clauses) { Plist p; for (p = ground_clauses; p; p = p->next) { Mclause c = p->v; if (!c->subsumed) { /* look for an arithmetic term and evaluate it */ BOOL clause_is_true = FALSE; int i; for (i = 0; i < c->numlits && !clause_is_true; i++) { Term atom = LIT(c, i); if (arith_quasi_evaluable(atom)) { if (arith_rel_quasi_eval(atom)) clause_is_true = TRUE; } else if (!FALSE_TERM(atom) && !TRUE_TERM(atom)) { /* non-arithmetic lits should have been reduced to TRUE or FALSE */ fprintf(stderr, "ERROR, model reported, but clause not true!\n"); fprintf(stdout, "ERROR, model reported, but clause not true! "); p_mclause(c); fatal_error("check_with_arithmetic, clause not reduced"); } } /* literals loop */ if (!clause_is_true) return FALSE; } /* non-subsumed clause */ } /* clauses loop */ return TRUE; } /* check_with_arithmetic */ LADR-2009-11A/mace4.src/mstate.h0000644000175000017500000000307410607745010015247 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_MSTATE_H #define TP_MSTATE_H /* Public definitions */ typedef struct jnode * Jnode; typedef struct mstate * Mstate; struct mstate { Estack stack; Jnode first_job; Jnode last_job; BOOL ok; }; struct jnode { int type; int id; Term alpha; Term beta; int pos; Jnode prev; Jnode next; }; /* End of public definitions */ /* Public function prototypes from mstate.c */ Mstate get_mstate(void); void free_mstate(Mstate p); Jnode get_jnode(void); void free_jnode(Jnode p); void fprint_mstate_mem(FILE *fp, BOOL heading); void p_mstate_mem(void); void job_append(Mstate s, int type, int id, Term atom, Term beta, int pos); void job_prepend(Mstate s, int type, int id, Term atom, Term beta, int pos); void job_pop(Mstate s); void zap_jobs(Mstate s); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/TAGS0000644000175000017500000024066311151265435014274 0ustar mccunemccune arithmetic.c,1050 static int Sum_sn;27,1004 static int Prod_sn;28,1023 static int Neg_sn;29,1043 static int Div_sn;30,1062 static int Mod_sn;31,1081 static int Min_sn;32,1100 static int Max_sn;33,1119 static int Abs_sn;34,1138 static int Lt_sn;35,1157 static int Le_sn;36,1175 static int Gt_sn;37,1193 static int Ge_sn;38,1211 static int Eq_sn;39,1229 static BOOL *Arith_op_sn;41,1248 static BOOL *Arith_rel_sn;42,1325 static int Arith_sn_size 43,1401 void init_arithmetic(55,1549 int modulo(107,3087 BOOL domain_term(135,3571 BOOL arith_op_sn(150,3777 BOOL arith_rel_sn(168,3995 BOOL arith_op_term(186,4217 BOOL arith_rel_term(201,4413 BOOL arith_term(216,4608 BOOL arith_quasi_evaluable(235,4921 int arith_evaluate(260,5300 int arith_eval(329,7305 BOOL top_safe(342,7529 BOOL all_safe(363,8012 BOOL all_ordinary_nodes_safe(386,8423 BOOL non_arith(409,8911 BOOL atom_safe(428,9252 BOOL ok_for_arithmetic(455,9874 Term distrib(477,10306 Term qsimp(524,11260 BOOL arith_rel_quasi_eval(577,12313 BOOL check_with_arithmetic(619,13279 commandline.c,158 BOOL member_args(28,854 void command_line_flag(44,1105 void command_line_parm(65,1613 void usage_message(78,1880 void process_command_line_args(158,4605 estack.c,510 #define ESTACK_SIZE 23,790 struct estack estack25,841 static Estack Estack_avail;32,934 static unsigned Estack_gets,33,962 static unsigned Estack_gets, Estack_frees,33,962 static unsigned Estack_gets, Estack_frees, Estack_avails;33,962 Estack get_estack(42,1092 void free_estack(67,1438 void fprint_estack_mem(81,1635 void p_estack_mem(106,2213 void free_estack_memory(121,2388 int estack_bytes(144,2728 Estack update_and_push(155,2919 void restore_from_stack(179,3554 void zap_estack(199,3937 ground.c,851 #define PTRS_MCLAUSE 38,1050 static unsigned Mclause_gets,39,1117 static unsigned Mclause_gets, Mclause_frees;39,1117 static unsigned Mclause_use,40,1162 static unsigned Mclause_use, Mclause_high;40,1162 Mclause get_mclause(49,1283 void free_mclause(81,2043 void fprint_mclause_mem(96,2334 void p_mclause_mem(117,2843 void zap_mterm(130,3041 void zap_mclause(146,3260 int lit_position(160,3458 void set_parent_pointers(179,3783 void check_parent_pointers(202,4242 Mclause containing_mclause(228,4746 Term containing_mliteral(241,4944 void eterm_index_term(257,5213 BOOL member(284,5687 Term merge(298,5955 Term simp_term(317,6276 Term simp_tv(335,6579 Plist term_to_lits(426,8426 Mclause term_to_mclause(442,8702 Term subst_domain_elements_term(475,9320 void instances_recurse(507,9954 void generate_ground_clauses(570,11699 mace4.c,146 void init_attrs(31,883 void mace4_sig_handler(54,1446 Plist process_distinct_terms(84,1976 Plist read_mace4_input(119,2777 int main(198,5045 msearch.c,1545 Mace_options Opt;29,998 struct mace_stats Mstats;30,1016 Symbol_data Symbols;34,1086 static int Sn_map_size;38,1180 Symbol_data *Sn_to_mace_sn;39,1204 int Number_of_cells;43,1276 struct cell *Cells;44,1297 struct cell **Ordered_cells;45,1376 int First_skolem_cell;46,1447 int Domain_size;50,1492 Term *Domain;51,1509 BOOL Skolems_last;52,1586 Plist Ground_clauses;54,1606 int Relation_flag;56,1660 int Negation_flag;57,1696 int Eq_sn;59,1733 int Or_sn;60,1744 int Not_sn;61,1755 static int Max_domain_element_in_input;63,1768 static Plist Models;65,1843 Clock Mace4_clock;67,1907 unsigned Total_models;71,1955 static double Start_seconds;73,1979 static double Start_domain_seconds;74,2008 static int Start_megs;75,2044 SEARCH_GO_MODELS,83,2206 SEARCH_GO_NO_MODELS,84,2283 SEARCH_MAX_MODELS,85,2361 SEARCH_MAX_MEGS,86,2402 SEARCH_MAX_TOTAL_SECONDS,87,2443 SEARCH_MAX_DOMAIN_SECONDS,88,2484 SEARCH_DOMAIN_OUT_OF_RANGE 89,2525 void init_mace_options(132,3983 char *exit_string(203,7449 void mace4_exit(227,8182 void initialize_for_search(265,9213 void init_for_domain_size(344,11144 void built_in_assignments(397,12472 void special_assignments(417,12881 BOOL check_that_ground_clauses_are_true(472,14518 int possible_model(495,15010 int mace_megs(539,16092 int check_time_memory(551,16278 BOOL mace4_skolem_check(590,17347 void p_possible_values(611,17725 int search(657,19000 int mace4n(724,20461 BOOL iterate_ok(825,23079 int next_domain_size(850,23604 Mace_results mace4(875,24037 mstate.c,487 #define PTRS_MSTATE 25,806 static unsigned Mstate_gets,26,871 static unsigned Mstate_gets, Mstate_frees;26,871 #define PTRS_JNODE 28,915 static unsigned Jnode_gets,29,978 static unsigned Jnode_gets, Jnode_frees;29,978 Mstate get_mstate(37,1083 void free_mstate(51,1270 Jnode get_jnode(63,1428 void free_jnode(76,1591 void fprint_mstate_mem(95,1965 void p_mstate_mem(127,2788 void job_append(142,2961 void job_prepend(171,3454 void job_pop(200,3948 void zap_jobs(221,4299 negprop.c,181 int nterm_id(47,1251 void negprop_elim(70,1709 void negprop_assign(117,2908 void negprop_near_elim(212,5450 void negprop_near_assign(245,6243 void propagate_negative(332,8856 negpropindex.c,403 void ****Index;28,935 void *init_recurse(55,1815 void init_negprop_index(75,2166 void free_recurse(113,3055 void free_negprop_index(131,3313 void p_recurse(169,4131 void p_negprop_index(200,4666 void insert_recurse(236,5490 void insert_negprop_eq(269,6555 void insert_negprop_noneq(297,7221 BOOL nterm(330,8093 static Term negprop_find_near_recurse(362,8625 Term negprop_find_near(371,8887 ordercells.c,85 int sum_indexes(38,1123 Ordertype compare_cells(75,1978 void order_cells(117,3612 print.c,351 static int id2val(48,1165 int f0_val(54,1284 int f1_val(61,1373 int f2_val(68,1471 void p_model(80,1624 void print_model_standard(181,3810 Term interp_term(244,5279 void p_matom(283,6323 void p_mclause(308,6745 int eterms_count(336,7244 void p_eterms(341,7328 void p_stats(372,7969 void p_mem(409,9483 void reset_current_stats(433,10039 propagate.c,381 BOOL eterm(51,1414 Term decode_eterm_id(82,2154 Term pvalues_check(108,2696 void nterm_check_and_process(141,3494 void new_assignment(177,4398 void new_elimination(215,5438 void process_clause(271,7264 Mclause handle_literal(328,8662 void propagate_positive(370,10070 void propagate(485,13835 Estack assign_and_propagate(522,14776 void process_initial_clause(559,15825 select.c,544 #define SELECT_LINEAR 37,1175 #define SELECT_CONCENTRIC 38,1235 #define SELECT_CONCENTRIC_BAND 39,1271 #define NO_MEASURE 41,1308 #define MOST_OCCURRENCES 42,1370 #define MOST_PROPAGATIONS 43,1406 #define MOST_CONTRADICTIONS 44,1442 #define MOST_CROSSED 45,1478 int num_contradictions(60,1867 int num_propagations(93,2636 int num_crossed(117,3161 int num_occurrences(136,3482 void selection_measure(152,3710 int select_linear(174,4310 int select_concentric(207,5042 int select_concentric_band(236,5723 int select_cell(263,6379 syms.c,305 Symbol_data get_symbol_data(32,932 Symbol_data find_symbol_data(52,1268 void init_built_in_symbols(66,1492 Symbol_data insert_mace4_sym(86,1813 int collect_mace4_syms(114,2379 void p_symbol_data(159,3513 Symbol_data find_symbol_node(173,3814 int id_to_domain_size(192,4219 int max_index(208,4586 util.c,79 void random_permutation(27,848 #define MAX_PRIME 41,1148 BOOL prime(49,1223 ../ladr/ac_redun.c,440 static Ilist C_symbols 21,778 static Ilist A1_symbols 22,833 static Ilist A2_symbols 23,905 static Ilist AC_symbols 24,977 BOOL same_top(39,1200 int commutativity(59,1569 int associativity(91,2262 int c_associativity(132,3207 int associativity3(179,4198 int associativity4(231,5386 Ordertype can_compare(272,6474 Term canon(293,6928 BOOL cac_redundant_atom(342,7960 BOOL cac_tautology(387,9107 BOOL cac_redundancy(425,10067 ../ladr/accanon.c,142 void flatten(36,1030 void right_associate(69,1748 void ac_canonical2(121,2627 void ac_canonical(180,4499 int check_ac_canonical(234,5902 ../ladr/attrib.c,1700 struct attribute attribute25,875 #define MAX_ATTRIBUTE_NAMES 37,1170 } Attribute_names[43,1482 static int Next_attribute_name 45,1523 #define PTRS_ATTRIBUTE 51,1589 static unsigned Attribute_gets,52,1643 static unsigned Attribute_gets, Attribute_frees;52,1643 Attribute get_attribute(61,1769 void free_attribute(75,1968 void fprint_attrib_mem(94,2362 void p_attrib_mem(120,2992 Attribute_type attribute_type(136,3176 char *attribute_name(148,3351 int register_attribute(166,3693 void declare_term_attribute_inheritable(195,4526 BOOL inheritable(209,4840 Attribute set_int_attribute(228,5206 int get_int_attribute(261,5911 BOOL exists_attribute(287,6465 Attribute set_term_attribute(312,6950 void replace_term_attribute(346,7713 void replace_int_attribute(378,8531 Term get_term_attribute(410,9327 Term get_term_attributes(441,10052 Attribute set_string_attribute(477,10858 char *get_string_attribute(512,11717 BOOL string_attribute_member(542,12414 void zap_attributes(567,12990 Attribute delete_attributes(589,13421 Attribute cat_att(619,14026 Term build_attr_term(644,14497 Term attributes_to_term(689,15504 Attribute cat_attributes(709,15928 int attribute_name_to_id(732,16387 Attribute term_to_attributes(762,17061 Attribute inheritable_att_instances(814,18323 Attribute copy_attributes(840,18889 void instantiate_inheritable_attributes(869,19513 void renumber_vars_attributes(892,20006 void set_vars_attributes(913,20429 Plist vars_in_attributes(935,20868 int label_att(959,21280 BOOL attributes_contain_variables(982,21725 Attribute copy_int_attribute(1009,22234 Attribute copy_string_attribute(1030,22613 Attribute copy_term_attribute(1051,22993 ../ladr/avltree.c,964 struct avl_node avl_node24,832 static BOOL Debug 31,1046 #define PTRS_AVL_NODE 37,1103 static unsigned Avl_node_gets,38,1155 static unsigned Avl_node_gets, Avl_node_frees;38,1155 Avl_node get_avl_node(47,1277 void free_avl_node(61,1468 void fprint_avltree_mem(80,1859 void p_avltree_mem(106,2486 int avl_height(126,2753 int avl_size(142,2972 void set_height_and_size(154,3126 BOOL balance_ok(167,3383 Avl_node rotate_left(179,3563 Avl_node rotate_right(198,3893 Avl_node avl_fix(217,4220 Avl_node avl_insert(262,5260 Avl_node remove_and_return_largest(295,6105 Avl_node remove_and_return_smallest(315,6512 Avl_node avl_delete(342,7133 Avl_node avl_lookup(383,8118 void *avl_find(414,8891 void *avl_smallest(432,9226 void *avl_largest(453,9575 int avl_place(476,10045 double avl_position(510,10853 void *avl_nth_item(529,11236 void *avl_item_at_position(556,11890 void avl_zap(580,12406 void avl_check(604,12878 void p_avl(646,14150 ../ladr/backdemod.c,234 void index_term_back_demod(30,890 void index_clause_back_demod(51,1303 BOOL rewritable_term(70,1684 BOOL rewritable_clause(99,2257 Plist back_demod_linear(129,2996 BOOL lex_rewritable(149,3404 Plist back_demod_indexed(177,4113 ../ladr/banner.c,57 void print_separator(40,1020 void print_banner(66,1615 ../ladr/basic.c,453 static BOOL Basic_paramodulation 64,2487 static int Nonbasic_flag 65,2561 void init_basic_paramod(77,2744 void set_basic_paramod(95,3090 BOOL basic_paramod(111,3311 void mark_term_nonbasic(126,3491 void mark_all_nonbasic(143,3781 BOOL nonbasic_term(165,4200 BOOL basic_term(181,4448 int nonbasic_flag(196,4627 Term apply_basic(213,4932 Term apply_basic_substitute(258,6220 void clear_all_nonbasic_marks(287,6842 void p_term_basic(308,7218 ../ladr/btm.c,1920 typedef struct ac_match_pos * Ac_match_pos;Ac_match_pos23,810 typedef struct ac_match_free_vars_pos * Ac_match_free_vars_pos;Ac_match_free_vars_pos24,854 struct btm_state btm_state26,919 struct ac_match_pos ac_match_pos47,1586 struct ac_match_free_vars_pos ac_match_free_vars_pos70,2776 #define POP 81,3224 #define BACKTRACK 82,3244 #define GO 83,3264 #define SUCCESS 84,3284 #define FAILURE 85,3304 #define BIND_BT(BIND_BT89,3378 #define PTRS_AC_MATCH_POS 101,3681 static unsigned Ac_match_pos_gets,102,3741 static unsigned Ac_match_pos_gets, Ac_match_pos_frees;102,3741 #define PTRS_AC_MATCH_FREE_VARS_POS 104,3797 static unsigned Ac_match_free_vars_pos_gets,105,3877 static unsigned Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees;105,3877 #define PTRS_BTM_STATE 107,3953 static unsigned Btm_state_gets,108,4007 static unsigned Btm_state_gets, Btm_state_frees;108,4007 Ac_match_pos get_ac_match_pos(117,4139 void free_ac_match_pos(131,4359 Ac_match_free_vars_pos get_ac_match_free_vars_pos(144,4588 void free_ac_match_free_vars_pos(158,4878 Btm_state get_btm_state(171,5131 void free_btm_state(187,5375 void fprint_btm_mem(206,5763 void p_btm_mem(244,7007 void flatten_mult(265,7447 int macbv_rec(302,8180 int match_ac_bound_vars(340,9232 void set_up_free_vars(382,10517 void unbind_free_var(442,11941 int free_var_match(477,12690 Term build_partial_term(591,15486 void clear_partial_term(621,16054 #define GO_FUNCTORS 637,16348 #define GO_BOUND_VARS 638,16372 #define GO_FREE_VARS 639,16396 #define SUCCESS 640,16420 #define FAILURE 641,16444 int match_ac(661,16973 void match_ac_cancel(860,22259 Btm_state match_bt_backup(888,22838 Btm_state match_bt_guts(932,23563 int match_commute(1081,26575 void p_acm(1134,27766 void p_btm_state(1177,28734 Btm_state match_bt_first(1234,30497 Btm_state match_bt_next(1259,30987 void match_bt_cancel(1294,31787 ../ladr/btu.c,1356 #define MAX_ACU_ARGS 23,810 typedef struct ac_position * Ac_position;Ac_position25,836 struct ac_position ac_position27,879 struct btu_state btu_state45,1792 #define GO 67,2411 #define SUCCESS 68,2431 #define EXHAUSTED 69,2451 #define FAILURE 70,2471 #define POP 71,2491 #define BACKTRACK 72,2511 #define BIND_BT(BIND_BT76,2598 #define PTRS_BTU_STATE 88,2836 static unsigned Btu_state_gets,89,2890 static unsigned Btu_state_gets, Btu_state_frees;89,2890 #define PTRS_AC_POSITION 91,2940 static unsigned Ac_position_gets,92,2998 static unsigned Ac_position_gets, Ac_position_frees;92,2998 Btu_state get_btu_state(101,3128 void free_btu_state(116,3345 Ac_position get_ac_position(129,3537 void free_ac_position(143,3750 void fprint_btu_mem(162,4148 void p_btu_mem(194,5020 void p_binding(210,5195 void flatten_deref(244,6222 int compare_ncv_context(287,7062 void sort_ac(345,8378 void elim_con_context(382,9030 void ac_mult_context(411,9681 void ac_prepare(466,10784 void set_up_basis_terms(514,12013 int unify_ac(560,13210 void unify_ac_cancel(897,22343 void p_ac_position(956,23602 Btu_state unify_bt_backup(986,24303 int unify_commute(1040,25430 Btu_state unify_bt_first(1152,28803 Btu_state unify_bt_next(1175,29320 void unify_bt_cancel(1208,30123 Btu_state unify_bt_guts(1246,30927 void p_bt_tree(1434,34834 ../ladr/clash.c,438 #define PTRS_CLASH 27,841 static unsigned Clash_gets,28,887 static unsigned Clash_gets, Clash_frees;28,887 Clash get_clash(37,997 void free_clash(51,1168 void fprint_clash_mem(70,1540 void p_clash_mem(96,2138 Clash append_clash(116,2451 void zap_clash(136,2773 Literals atom_to_literal(158,3124 Literals apply_lit(179,3547 int lit_position(191,3732 Topform resolve(212,4064 void clash_recurse(272,5622 void clash(356,8078 ../ladr/clause_eval.c,1430 enum { CL_EVAL_AND,39,1420 CL_EVAL_OR,40,1440 CL_EVAL_NOT,41,1459 CL_EVAL_ALL,42,1479 CL_EVAL_LESS,44,1500 CL_EVAL_LESS_EQUAL,45,1521 CL_EVAL_GREATER,46,1548 CL_EVAL_GREATER_EQUAL,47,1572 CL_EVAL_EQUAL,48,1602 CL_EVAL_POSITIVE,50,1625 CL_EVAL_NEGATIVE,51,1650 CL_EVAL_MIXED,52,1675 CL_EVAL_HINT,54,1698 CL_EVAL_TRUE,56,1720 CL_EVAL_FALSE,57,1741 CL_EVAL_HAS_EQUALITY,59,1764 CL_EVAL_HORN,60,1793 CL_EVAL_DEFINITE,61,1814 CL_EVAL_UNIT,62,1839 CL_EVAL_INITIAL,64,1861 CL_EVAL_RESOLVENT,65,1885 CL_EVAL_UR_RESOLVENT,66,1911 CL_EVAL_HYPER_RESOLVENT,67,1940 CL_EVAL_FACTOR,68,1972 CL_EVAL_PARAMODULANT,69,1995 CL_EVAL_BACK_DEMODULANT,70,2024 CL_EVAL_SUBSUMER,71,2056 CL_EVAL_WEIGHT,73,2082 CL_EVAL_VARIABLES,74,2105 CL_EVAL_DEPTH,75,2131 CL_EVAL_LITERALS,76,2153 CL_EVAL_LEVEL77,2178 struct clause_eval clause_eval82,2300 #define PTRS_EVAL_RULE 94,2608 static unsigned Clause_eval_gets,95,2682 static unsigned Clause_eval_gets, Clause_eval_frees;95,2682 Clause_eval get_clause_eval(104,2816 void free_clause_eval(118,3027 void zap_clause_eval_rule(138,3280 Clause_eval compile_clause_eval_rule(160,3685 BOOL eval_clause_in_rule(284,7091 BOOL rule_contains_semantics(384,9884 ../ladr/clause_misc.c,317 Clist clist_copy(39,1033 Clist copy_clauses_to_clist(64,1527 Clist move_clauses_to_clist(90,2067 Plist input_clauses(115,2549 void delete_clause(145,3153 void delete_clist(169,3732 Topform copy_clause_ija(199,4222 Plist copy_clauses_ija(220,4687 void delete_clauses(244,5109 void make_clause_basic(264,5419 ../ladr/clauseid.c,421 #define CLAUSE_ID_TAB_SIZE 23,815 static Plist Topform_id_tab[25,850 static unsigned Topform_id_count 26,903 int next_clause_id(35,1010 int clause_ids_assigned(51,1236 void assign_clause_id(70,1642 void unassign_clause_id(97,2232 Topform find_clause_by_id(135,3043 void fprint_clause_id_tab(161,3524 void p_clause_id_tab(184,3955 Plist insert_clause_into_plist(204,4377 BOOL clause_plist_member(239,5183 ../ladr/clauses.c,437 Topform clause_member_plist(38,1022 Plist intersect_clauses(62,1485 int max_clause_weight(87,1954 int max_clause_symbol_count(110,2355 Plist nonneg_clauses(132,2776 BOOL all_clauses_horn(155,3173 BOOL all_clauses_unit(177,3512 BOOL all_clauses_positive(199,3855 int neg_nonunit_clauses(221,4219 int negative_clauses(244,4615 int most_literals(268,4988 BOOL pos_equality_in_clauses(291,5389 BOOL equality_in_clauses(315,5835 ../ladr/clausify.c,280 Literals formula_to_literal(39,1157 Literals formula_to_literals(59,1553 Topform formula_to_clause(91,2367 Plist formula_to_clauses(117,2962 Plist clausify_formula(147,3746 Term vars_to_names(170,4123 Formula literal_to_formula(207,4852 Formula clause_to_formula(231,5263 ../ladr/clist.c,1622 #define PTRS_CLIST_POS 27,841 static unsigned Clist_pos_gets,28,895 static unsigned Clist_pos_gets, Clist_pos_frees;28,895 #define PTRS_CLIST 30,945 static unsigned Clist_gets,31,991 static unsigned Clist_gets, Clist_frees;31,991 Clist_pos get_clist_pos(40,1109 void free_clist_pos(54,1308 Clist get_clist(67,1488 void free_clist(81,1659 void fprint_clist_mem(100,2031 void p_clist_mem(132,2871 Clist clist_init(155,3359 void name_clist(178,3714 void clist_free(201,4068 void clist_append(223,4378 void clist_prepend(255,4847 void clist_insert_before(287,5333 void clist_insert_after(319,5861 void clist_remove(353,6518 void clist_remove_all_clauses(397,7384 int clist_remove_all(415,7735 int clist_member(436,8061 void fprint_clist(461,8549 void p_clist(486,8968 void clist_zap(504,9279 void clist_check(532,9736 void clist_append_all(570,10469 BOOL clist_empty(589,10852 int clist_length(604,11025 int max_wt_in_clist(620,11248 BOOL horn_clist(641,11587 BOOL unit_clist(661,11901 BOOL equality_in_clist(681,12244 BOOL neg_nonunit_in_clist(701,12592 Plist clauses_in_clist(722,13005 void clist_swap(746,13489 void clist_move_clauses(772,14011 Plist move_clist_to_plist(791,14285 Plist copy_clist_to_plist_shallow(814,14637 Clist plist_to_clist(833,14955 void clist_reverse(854,15260 Clist_pos pos_in_clist(879,15637 void clist_append_plist(896,15894 Plist prepend_clist_to_plist(914,16159 int clist_number_of_weight(936,16490 Ordertype compare_clause_ids(958,16827 void sort_clist_by_id(978,17126 Plist neg_clauses_in_clist(1008,17641 void fprint_clause_clist(1031,18092 ../ladr/clock.c,937 struct clock clock23,812 static BOOL Clocks_enabled 30,1081 static unsigned Clock_starts 31,1146 static unsigned Wall_start;33,1203 #define CPU_TIME(CPU_TIME42,1527 #define CPU_TIME(CPU_TIME45,1674 #define PTRS_CLOCK 52,1761 static unsigned Clock_gets,53,1807 static unsigned Clock_gets, Clock_frees;53,1807 Clock get_clock(62,1917 void free_clock(79,2115 Clock clock_init(107,2663 void clock_start(127,2968 void clock_stop(151,3396 unsigned clock_milliseconds(179,3912 double clock_seconds(207,4372 BOOL clock_running(234,4808 void clock_reset(251,5106 void fprint_clock(270,5325 char * get_date(287,5644 unsigned user_time(305,5933 double user_seconds(329,6331 unsigned system_time(356,6877 double system_seconds(383,7425 unsigned absolute_wallclock(405,7739 void init_wallclock(422,8004 unsigned wallclock(439,8293 void disable_clocks(454,8474 void enable_clocks(469,8646 BOOL clocks_enabled(484,8816 ../ladr/cnf.c,1177 static jmp_buf Jump_env;41,1433 static unsigned Fid_call_limit 43,1491 static unsigned Fid_calls 44,1534 Formula share_formula(53,1632 Formula consolidate_formula(90,2386 BOOL formula_ident_share(115,2931 Formula formula_copy_share(152,3804 BOOL complementary_share(180,4399 BOOL contains_complements_share(197,4738 BOOL prop_member_share(216,5099 BOOL prop_subset_share(232,5423 BOOL prop_subsume_share(250,5741 Formula remove_subsumed_share(274,6226 Formula bbt(316,7052 Formula balanced_binary(338,7474 Formula disjoin_flatten_simplify(360,7885 Formula simplify_and_share(407,9049 Formula distribute_top(436,9582 Formula distribute(473,10375 Formula cnf(502,10907 Formula dnf(535,11490 Formula skolem(547,11617 Formula skolemize(621,13568 Ilist unique_qvars(634,13719 Formula unique_quantified_vars(679,14878 void mark_free_vars_formula(697,15195 Formula remove_uni_quant(717,15650 Formula remove_universal_quantifiers(751,16407 Formula clausify_prepare(781,17249 Formula ms_free_vars(811,17860 Formula miniscope(871,19356 typedef void (*sighandler_t)sighandler_t932,20765 Formula miniscope_formula(938,20835 int cnf_max_clauses(990,22135 ../ladr/complex.c,399 #define IMAX(IMAX24,936 double complexity1(51,1570 double complexity2(111,2721 double complexity3(152,3498 Term complex4_devar(185,4140 Term complex4_revar(207,4566 void complex4_compare(229,4954 BOOL complex4_p2(249,5423 void complex4_p1(271,5813 double complex4(302,6749 void term_to_ints(335,7465 double term_complexity(358,7801 double clause_complexity(390,8370 int main(401,8659 ../ladr/compress.c,192 Term uncompress_term(33,910 void compress_term_recurse(55,1319 char *compress_term(78,1696 void compress_clause(103,2153 void uncompress_clause(132,2862 void uncompress_clauses(162,3508 ../ladr/definitions.c,379 BOOL is_definition(37,940 Term subst_terms(78,1936 void subst_free_vars(112,2782 Formula subst_atomic_formula(135,3358 Formula strip_quantifiers(174,4541 BOOL definition_applies(188,4735 Formula expand_with_definition(210,5158 Topform first_definition(236,5869 void process_definitions(260,6261 void expand_with_definitions(303,7215 void separate_definitions(344,8150 ../ladr/demod.c,397 static int Demod_attempts 26,866 static int Demod_rewrites 27,897 int demodulator_type(40,1100 void idx_demodulator(90,2289 int demod_attempts(117,2927 int demod_rewrites(133,3167 Term demod(147,3324 Term contract_bt(207,4875 Term demod_bt(242,5761 Term demodulate(288,6961 Term demod1_recurse(312,7536 void demod1(372,8902 Term part_recurse(403,9616 void particular_demod(468,11105 ../ladr/di_tree.c,869 static int Nonunit_fsub_tests;23,814 static int Nonunit_bsub_tests;24,845 static unsigned Sub_calls 26,877 static unsigned Sub_calls_overflows 27,908 #define BUMP_SUB_CALLS 28,949 int nonunit_fsub_tests(40,1133 int nonunit_bsub_tests(55,1324 #define PTRS_DI_TREE 64,1442 static unsigned Di_tree_gets,65,1492 static unsigned Di_tree_gets, Di_tree_frees;65,1492 Di_tree get_di_tree(77,1637 void free_di_tree(94,1849 void fprint_di_tree_mem(113,2235 void p_di_tree_mem(139,2855 Di_tree init_di_tree(160,3152 void di_tree_insert(175,3322 BOOL di_tree_delete(215,4094 void zap_di_tree(256,4984 void p_di_tree(281,5358 BOOL subsume_di_literals(311,5899 BOOL subsumes_di(343,6538 Topform di_tree_forward(359,6817 Topform forward_feature_subsume(395,7566 void di_tree_back(412,7903 Plist back_feature_subsume(448,8685 unsigned mega_sub_calls(469,9075 ../ladr/dioph.c,641 int gcd(28,860 int lcm(44,1095 int less_vec(57,1316 int var_check_1(79,1794 int var_check_2(105,2379 int add_solution(131,2924 int a_in_bounds(158,3623 int b_in_bounds(199,4664 int dio(242,5899 #define ADD_TO_SUM(ADD_TO_SUM359,8409 #define SUBTRACT_FROM_SUM(SUBTRACT_FROM_SUM362,8507 int next_combo_a(391,9547 int next_combo_b(451,10916 #define DOWN 514,12188 #define OVER 515,12206 #define BACKUP 516,12224 #define SUCCESS 517,12242 #define FAILURE 518,12260 int next_combo_c(527,12463 int superset_degree(615,14638 int next_combo_ss(661,16079 void p_ac_basis(722,17305 int all_combos(745,17807 int main(790,18715 ../ladr/discrim.c,598 #define PTRS_DISCRIM 27,843 static unsigned Discrim_gets,28,893 static unsigned Discrim_gets, Discrim_frees;28,893 #define PTRS_DISCRIM_POS 30,939 static unsigned Discrim_pos_gets,31,997 static unsigned Discrim_pos_gets, Discrim_pos_frees;31,997 Discrim get_discrim(43,1150 void free_discrim(60,1362 Discrim_pos get_discrim_pos(77,1605 void free_discrim_pos(94,1867 void fprint_discrim_mem(113,2273 void p_discrim_mem(145,3149 Discrim discrim_init(166,3480 void discrim_dealloc(182,3717 void zap_discrim_tree(198,3950 void destroy_discrim_tree(235,4636 BOOL discrim_empty(252,4937 ../ladr/discrimb.c,913 typedef struct flat2 * Flat2;Flat227,844 struct flat2 flat229,875 #define GO 38,1079 #define BACKTRACK 39,1099 #define SUCCESS 40,1119 #define FAILURE 41,1139 #define PTRS_FLAT2 47,1189 static unsigned Flat2_gets,48,1235 static unsigned Flat2_gets, Flat2_frees;48,1235 Flat2 get_flat2(57,1345 void free_flat2(71,1516 void fprint_discrimb_mem(90,1894 void p_discrimb_mem(116,2504 void print_discrim_bind_tree(132,2724 void fprint_discrim_bind_index(176,3623 void p_discrim_bind_index(192,3913 Discrim discrim_bind_insert_rec(207,4231 void discrim_bind_insert(279,5800 Discrim discrim_bind_end(313,6725 void discrim_bind_delete(364,7795 void discrim_bind_update(447,9650 Flat2 check_flat2(462,9927 void p_flat2(489,10403 Plist discrim_bind_retrieve_leaf(512,10803 void *discrim_bind_retrieve_first(681,14446 void *discrim_bind_retrieve_next(721,15400 void discrim_bind_cancel(758,16255 ../ladr/discrimw.c,1022 typedef struct flat * Flat;Flat23,815 struct flat flat25,844 #define GO 38,1324 #define BACKTRACK 39,1344 #define SUCCESS 40,1364 #define FAILURE 41,1384 #define PTRS_FLAT 47,1434 static unsigned Flat_gets,48,1478 static unsigned Flat_gets, Flat_frees;48,1478 Flat get_flat(57,1584 void free_flat(85,1982 void fprint_discrimw_mem(104,2355 void p_discrimw_mem(130,2958 Flat check_flat(146,3145 void p_flat(173,3612 void flip_flat(193,3918 int num_ac_args(230,4647 int num_ac_nv_args(246,4937 void print_discrim_wild_tree(262,5259 void fprint_discrim_wild_index(313,6394 void p_discrim_wild_index(329,6685 Discrim discrim_wild_insert_ac(341,6876 Discrim discrim_wild_insert_rec(390,7938 void discrim_wild_insert(459,9393 Discrim discrim_wild_end(493,10311 void discrim_wild_delete(568,11780 void discrim_wild_update(650,13625 Plist discrim_wild_retrieve_leaf(665,13937 void *discrim_wild_retrieve_first(895,19451 void *discrim_wild_retrieve_next(932,20234 void discrim_wild_cancel(968,20980 ../ladr/dollar.c,1127 struct rule rule26,963 SUM_OP=35,1067 SUM_OP=1, PROD_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP, MAX_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP, MAX_OP, ABS_OP,35,1067 NEG_OP,36,1128 LT_OP,37,1138 LT_OP, LE_OP,37,1138 LT_OP, LE_OP, GT_OP,37,1138 LT_OP, LE_OP, GT_OP, GE_OP,37,1138 LLT_OP,38,1201 LLT_OP, LLE_OP,38,1201 LLT_OP, LLE_OP, LGT_OP,38,1201 LLT_OP, LLE_OP, LGT_OP, LGE_OP,38,1201 AND_OP,39,1261 AND_OP, OR_OP,39,1261 AND2_OP,40,1278 AND2_OP, OR2_OP,40,1278 IF_OP,41,1297 ID_OP,42,1306 ID_OP, NID_OP,42,1306 VAR_OP,43,1381 VAR_OP, CONST_OP,43,1381 VAR_OP, CONST_OP, GROUND_OP}43,1381 static int Symbols_size;45,1414 static int *Op_codes;46,1439 static struct rule **Rules;47,1461 static int Local_evals;48,1489 void init_dollar_eval(64,1639 BOOL evaluable_predicate(167,4724 Term dollar_eval(189,5046 Term rewrite_top(364,8968 Term rewrite(419,10202 void rewrite_with_eval(510,11971 ../ladr/fastparse.c,354 static int Arity[23,816 static int Symnum[24,883 static int Pos;26,951 #define MAX_LINE 28,1003 void fast_set_symbol(48,1442 void fast_set_defaults(79,2054 Term fast_parse(105,2556 Term fast_read_term(169,4110 void fast_fwrite_term(201,4733 void fast_fwrite_term_nl(245,5761 Topform fast_read_clause(271,6328 void fast_fwrite_clause(305,7065 ../ladr/fatal.c,146 static int Fatal_exit_code 23,812 void bell(36,971 int get_fatal_exit_code(53,1223 void set_fatal_exit_code(70,1517 void fatal_error(88,1880 ../ladr/features.c,384 static Ilist Feature_symbols;23,815 static int Work_size;30,1078 static int *Pos_occurrences;31,1139 static int *Neg_occurrences;32,1168 static int *Pos_maxdepth;33,1197 static int *Neg_maxdepth;34,1223 void init_features(46,1343 void fill_in_arrays(66,1852 Ilist features(114,2905 int feature_length(161,3850 BOOL features_less_or_equal(185,4281 void p_features(204,4544 ../ladr/flatdemod.c,528 static int Fdemod_attempts 23,816 static int Fdemod_rewrites 24,848 Flatterm fapply_demod(45,1284 enum { GO,75,1854 enum { GO, BACKTRACK 75,1854 void maybe_unbind(85,1964 #define MAYBE_UNBIND(MAYBE_UNBIND94,2152 Plist discrim_flat_retrieve_leaf(100,2309 void *discrim_flat_retrieve_first(187,3981 void *discrim_flat_retrieve_next(217,4536 void discrim_flat_cancel(250,5155 Flatterm fdemod(272,5561 Term fdemodulate(387,8548 int fdemod_attempts(426,9492 int fdemod_rewrites(442,9721 void fdemod_clause(462,10083 ../ladr/flatterm.c,646 #define PTRS_FLATTERM 27,844 static unsigned Flatterm_gets,28,896 static unsigned Flatterm_gets, Flatterm_frees;28,896 Flatterm get_flatterm(40,1045 void free_flatterm(63,1450 void fprint_flatterm_mem(82,1843 void p_flatterm_mem(108,2474 BOOL flatterm_ident(127,2691 void zap_flatterm(146,3031 Flatterm term_to_flatterm(166,3302 Term flatterm_to_term(204,3921 Flatterm copy_flatterm(230,4367 void print_flatterm(264,4906 int flatterm_symbol_count(300,5563 void p_flatterm(326,5941 BOOL flat_occurs_in(342,6123 I2list flat_multiset_vars(361,6434 BOOL flat_variables_multisubset(381,6778 int flatterm_count_without_vars(401,7167 ../ladr/formula.c,2323 #define PTRS_FORMULA 27,843 static unsigned Formula_gets,28,893 static unsigned Formula_gets, Formula_frees;28,893 static unsigned Arg_mem;30,939 Formula get_formula(39,1081 void free_formula(59,1367 void fprint_formula_mem(82,1891 void p_formula_mem(111,2630 unsigned formula_megs(131,2917 Formula formula_get(151,3208 void zap_formula(170,3576 BOOL logic_term(200,4042 void gather_symbols_in_term(220,4455 void gather_symbols_in_formula_term(248,5073 void gather_symbols_in_formula(277,5701 void gather_symbols_in_formulas(305,6386 Ilist function_symbols_in_formula(322,6699 Ilist relation_symbols_in_formula(344,7080 BOOL relation_symbol_in_formula(366,7460 Formula term_to_formula(386,7870 Term formula_to_term(459,9600 void fprint_formula(533,11467 void p_formula(602,13310 unsigned hash_formula(621,13611 BOOL formula_ident(652,14307 Formula formula_copy(682,14976 BOOL dual_type(708,15395 Formula dual(730,15755 Formula and(750,16001 Formula or(768,16221 Formula imp(786,16439 Formula impby(804,16662 Formula not(819,16862 Formula negate(836,17057 BOOL quant_form(851,17241 Formula flatten_top(866,17466 Formula formula_flatten(922,18562 Formula nnf2(949,19247 Formula nnf(1069,22166 Formula make_conjunction(1085,22381 Formula make_disjunction(1107,22721 void formula_canon_eq(1130,23122 int formula_size(1161,23679 int greatest_qvar(1189,24231 int greatest_symnum_in_formula(1222,24937 void subst_free_var(1256,25698 Formula elim_rebind(1277,26210 Formula eliminate_rebinding(1332,27677 Plist free_vars(1345,27850 BOOL closed_formula(1374,28407 Formula get_quant_form(1392,28686 Formula uni_close(1407,28935 Formula universal_closure(1430,29364 BOOL free_var(1445,29616 BOOL free_variable(1472,30064 Formula formulas_to_conjunction(1495,30575 Formula formulas_to_disjunction(1522,31168 Plist copy_plist_of_formulas(1544,31530 BOOL literal_formula(1567,31927 BOOL clausal_formula(1587,32226 void formula_set_vars_recurse(1608,32559 void formula_set_variables(1639,33407 BOOL positive_formula(1697,34792 BOOL formula_contains_attributes(1726,35312 BOOL subformula_contains_attributes(1752,35792 Ilist constants_in_formula(1775,36170 BOOL relation_in_formula(1792,36426 void rename_all_bound_vars(1815,36815 void rename_these_bound_vars(1843,37364 ../ladr/fpa.c,2247 static unsigned Fpa_id_count 23,810 static unsigned Next_calls 25,845 static unsigned Next_calls_overflows 26,877 #define BUMP_NEXT_CALLS 27,919 typedef struct fpa_trie * Fpa_trie;Fpa_trie29,1005 struct fpa_trie fpa_trie31,1042 struct fpa_index fpa_index40,1180 struct fpa_state fpa_state46,1261 struct path path61,1661 enum { LEAF,66,1708 enum { LEAF, UNION,66,1708 enum { LEAF, UNION, INTERSECT 66,1708 #define PTRS_FPA_TRIE 77,1963 static unsigned Fpa_trie_gets,78,2015 static unsigned Fpa_trie_gets, Fpa_trie_frees;78,2015 #define PTRS_FPA_STATE 80,2063 static unsigned Fpa_state_gets,81,2117 static unsigned Fpa_state_gets, Fpa_state_frees;81,2117 #define PTRS_FPA_INDEX 83,2167 static unsigned Fpa_index_gets,84,2221 static unsigned Fpa_index_gets, Fpa_index_frees;84,2221 Fpa_trie get_fpa_trie(93,2345 void free_fpa_trie(108,2554 Fpa_state get_fpa_state(121,2737 void free_fpa_state(135,2936 Fpa_index get_fpa_index(148,3124 void free_fpa_index(163,3340 void fprint_fpa_mem(182,3728 void p_fpa_mem(220,4823 void fprint_path(240,5096 void p_path(271,5602 void fprint_fpa_trie(284,5785 void fprint_fpa_index(326,6666 void p_fpa_index(345,7117 Fpa_trie fpa_trie_member_insert(360,7486 Fpa_trie fpa_trie_member(400,8533 void fpa_trie_possible_delete(430,9371 void path_insert(457,9995 void path_delete(479,10475 Ilist path_push(506,11060 void path_restore(529,11490 void fpa_paths(548,11912 Fpa_index fpa_init_index(591,12904 void fpa_update(616,13461 Fpa_state query_leaf_full(645,14164 Fpa_state query_leaf(663,14497 Fpa_state query_intersect(690,14941 Fpa_state query_union(707,15219 Fpa_state query_special(729,15561 void zap_fpa_state(779,16950 Fpa_state union_commuted(798,17226 BOOL var_in_context(846,18193 BOOL all_args_vars_in_context(859,18379 Fpa_state build_query(878,18691 void fprint_fpa_state(961,21085 void p_fpa_state(1007,22033 void p_fpa_query(1023,22283 Term next_term(1063,23565 Term fpa_next_answer(1180,26140 Term fpa_first_answer(1206,26777 void fpa_cancel(1229,27278 void zap_fpa_trie(1241,27415 void zap_fpa_index(1273,27873 BOOL fpa_empty(1290,28131 void fpa_density(1302,28304 void p_fpa_density(1325,28682 unsigned mega_next_calls(1340,28864 ../ladr/fpalist.c,985 #define F_INITIAL_SIZE 48,1970 #define F_MAX_SIZE 49,2050 #define PTRS_FPA_CHUNK 55,2135 static unsigned Fpa_chunk_gets,56,2189 static unsigned Fpa_chunk_gets, Fpa_chunk_frees;56,2189 #define PTRS_FPA_LIST 58,2239 static unsigned Fpa_list_gets,59,2291 static unsigned Fpa_list_gets, Fpa_list_frees;59,2291 static unsigned Chunk_mem;61,2339 Fpa_chunk get_fpa_chunk(70,2493 void free_fpa_chunk(87,2748 Fpa_list get_fpa_list(105,3012 void free_fpa_list(120,3233 void fprint_fpalist_mem(139,3624 void p_fpalist_mem(173,4613 #define FLAST(FLAST184,4799 #define FFIRST(FFIRST185,4838 Fpa_chunk double_chunksize(194,4953 Fpa_chunk flist_insert(232,5850 void fpalist_insert(314,7782 Fpa_chunk consolidate(344,8542 Fpa_chunk flist_delete(367,8977 void fpalist_delete(413,9894 struct fposition first_fpos(433,10232 struct fposition next_fpos(448,10440 void zap_fpa_chunks(474,10917 void zap_fpalist(492,11143 BOOL fpalist_empty(508,11338 void p_fpa_list(523,11519 ../ladr/glist.c,3091 #define PTRS_ILIST 25,804 static unsigned Ilist_gets,26,850 static unsigned Ilist_gets, Ilist_frees;26,850 #define PTRS_PLIST 28,892 static unsigned Plist_gets,29,938 static unsigned Plist_gets, Plist_frees;29,938 #define PTRS_I2LIST 31,980 static unsigned I2list_gets,32,1028 static unsigned I2list_gets, I2list_frees;32,1028 #define PTRS_I3LIST 34,1072 static unsigned I3list_gets,35,1120 static unsigned I3list_gets, I3list_frees;35,1120 Ilist get_ilist(47,1259 void free_ilist(65,1474 Plist get_plist(81,1661 void free_plist(99,1876 I2list get_i2list(115,2065 void free_i2list(133,2287 I3list get_i3list(149,2481 void free_i3list(167,2703 void fprint_glist_mem(186,3080 void p_glist_mem(224,4113 Plist plist_cat(251,4747 Plist plist_cat2(282,5266 Plist plist_pop(299,5589 int plist_count(318,5830 Plist rev_app_plist(332,6009 Plist reverse_plist(361,6506 Plist copy_plist(377,6752 void zap_plist(408,7226 Plist plist_append(432,7563 Plist plist_prepend(458,7987 BOOL plist_member(477,8269 Plist plist_subtract(500,8630 BOOL plist_subset(523,8978 Plist plist_remove(544,9317 Plist plist_remove_string(572,9760 Plist sort_plist(599,10177 Plist plist_remove_last(624,10653 int position_of_string_in_plist(649,11055 BOOL string_member_plist(674,11454 int longest_string_in_plist(690,11714 void *ith_in_plist(711,12022 void *plist_last(731,12298 Ilist ilist_cat(759,12990 Ilist ilist_cat2(788,13481 Ilist ilist_pop(810,13878 int ilist_count(829,14119 Ilist rev_app_ilist(843,14298 Ilist reverse_ilist(872,14795 Ilist copy_ilist(888,15041 void zap_ilist(918,15461 Ilist ilist_append(942,15799 Ilist ilist_prepend(968,16222 Ilist ilist_last(986,16442 BOOL ilist_member(1009,16859 Ilist ilist_subtract(1032,17218 Ilist ilist_removeall(1058,17629 Ilist ilist_intersect(1086,18078 Ilist ilist_union(1114,18550 Ilist ilist_set(1137,19085 Ilist ilist_rem_dups(1163,19488 BOOL ilist_is_set(1190,19851 BOOL ilist_subset(1210,20128 void fprint_ilist(1232,20497 void p_ilist(1255,20899 Ilist ilist_copy(1272,21092 Ilist ilist_remove_last(1294,21386 int ilist_occurrences(1319,21769 Ilist ilist_insert_up(1337,22034 int position_in_ilist(1362,22431 void zap_i2list(1392,23069 I2list i2list_append(1416,23415 I2list i2list_prepend(1443,23879 I2list i2list_removeall(1465,24190 I2list i2list_member(1490,24565 void p_i2list(1512,24930 int i2list_count(1534,25272 BOOL i3list_member(1556,25786 I3list i3list_append(1578,26196 I3list i3list_prepend(1606,26684 void zap_i3list(1627,26995 I3list rev_app_i3list(1646,27243 I3list reverse_i3list(1675,27751 I3list copy_i3list(1691,28005 int i3list_count(1723,28469 I2list alist_insert(1750,29242 int assoc(1766,29456 I3list alist2_insert(1793,30040 int assoc2a(1809,30265 int assoc2b(1831,30591 I3list alist2_remove(1852,30904 BOOL i2list_multimember(1889,31720 BOOL i2list_multisubset(1909,32029 I2list multiset_add_n(1930,32385 I2list multiset_add(1955,32761 I2list multiset_union(1973,33095 Ilist multiset_to_set(1992,33369 int multiset_occurrences(2014,33674 ../ladr/hash.c,644 struct hashtab hashtab23,811 struct hashnode hashnode28,868 #define PTRS_HASHTAB 37,952 static unsigned Hashtab_gets,38,1002 static unsigned Hashtab_gets, Hashtab_frees;38,1002 #define PTRS_HASHNODE 40,1048 static unsigned Hashnode_gets,41,1100 static unsigned Hashnode_gets, Hashnode_frees;41,1100 Hashtab get_hashtab(50,1220 void free_hashtab(64,1405 Hashnode get_hashnode(77,1581 void free_hashnode(91,1773 void fprint_hash_mem(110,2158 void p_hash_mem(142,3001 Hashtab hash_init(161,3256 void hash_insert(180,3502 void *hash_lookup(199,3796 void hash_delete(220,4134 void hash_destroy(255,4798 void hash_info(280,5152 ../ladr/hints.c,647 static Lindex Hints_idx 23,812 static Clist Redundant_hints 24,876 static Mindex Back_demod_idx;25,946 static int Bsub_wt_attr;26,1026 static BOOL Back_demod_hints;27,1051 static BOOL Collect_labels;28,1081 static int Hint_id_count 36,1258 static int Active_hints_count 37,1288 static int Redundant_hints_count 38,1323 void init_hints(50,1452 void done_with_hints(76,2040 int redundant_hints(99,2474 Topform find_equivalent_hint(111,2641 Topform find_matching_hint(139,3373 void index_hint(168,4042 void unindex_hint(208,5136 void adjust_weight_with_hints(232,5571 void keep_hint_matcher(300,7373 void back_demod_hints(316,7586 ../ladr/ibuffer.c,317 Ibuffer ibuf_init(39,1002 void ibuf_free(60,1356 void ibuf_write(77,1562 void ibuf_write_block(106,2183 void ibuf_rewind(124,2447 int ibuf_read(141,2725 int ibuf_xread(165,3175 int ibuf_length(185,3499 int *ibuf_buffer(200,3675 #define ISIZE 211,3811 Ibuffer fd_read_to_ibuf(217,3864 void p_ibuf(254,4562 ../ladr/int_code.c,374 void put_ilist_to_ibuf(30,885 Ilist get_ilist_from_ibuf(45,1158 void put_i3list_to_ibuf(63,1473 I3list get_i3list_from_ibuf(81,1814 void put_term_to_ibuf(103,2226 Term get_term_from_ibuf(123,2563 void put_just_to_ibuf(150,3118 Just get_just_from_ibuf(208,4462 void put_clause_to_ibuf(277,6069 Topform get_clause_from_ibuf(312,6775 void check_ibuf_clause(348,7493 ../ladr/interp.c,2821 struct interp interp28,878 #define ISWAP(ISWAP50,1726 #define I2(I254,1828 #define I3(I355,1868 #define UNDEFINED 57,1927 #define FUNCTION 58,1947 #define RELATION 59,1967 #define MAX_VARS_EVAL 61,1988 static long unsigned Iso_checks 65,2033 static long unsigned Iso_perms 66,2070 #define PTRS_INTERP 72,2136 static unsigned Interp_gets,73,2184 static unsigned Interp_gets, Interp_frees;73,2184 Interp get_interp(82,2298 void free_interp(96,2476 void fprint_interp_mem(115,2855 void p_interp_mem(141,3464 int *trivial_permutation(157,3653 int int_power(179,4009 Interp compile_interp(219,4800 void transpose_binary(355,8547 void zap_interp(394,9407 void fprint_interp_tex(436,10153 void compute_args(535,12726 void fprint_interp_xml(558,13122 void fprint_interp_standard(669,16515 void fprint_interp_standard2(727,17968 static void portable_indent(785,19409 void portable_recurse(800,19634 void fprint_interp_portable(834,20417 void p_interp(891,21744 void fprint_interp_cooked(908,22019 void fprint_interp_tabular(979,23652 void fprint_interp_raw(1065,25522 int eval_term_ground(1120,26821 BOOL eval_literals_ground(1169,27986 BOOL all_recurse(1195,28581 BOOL eval_literals(1238,29798 int all_recurse2(1263,30229 int eval_literals_true_instances(1295,31009 int eval_literals_false_instances(1322,31558 int eval_fterm_ground(1340,32021 BOOL eval_form(1390,33153 BOOL eval_formula(1483,35753 Term interp_remove_constants_recurse(1524,36471 void interp_remove_constants(1552,37072 Term interp_remove_others_recurse(1568,37362 void interp_remove_others(1596,38002 Interp copy_interp(1612,38304 Interp permute_interp(1697,40420 BOOL ident_interp_perm(1765,42087 Interp normal_interp(1846,44462 BOOL iso_interp_recurse(1890,45364 BOOL isomorphic_interps(1931,46353 int interp_size(1969,47049 Term interp_comments(1985,47257 int *interp_table(2001,47488 long unsigned iso_checks(2022,47898 long unsigned iso_perms(2038,48128 BOOL evaluable_term(2053,48294 BOOL evaluable_atom(2084,48896 BOOL evaluable_literals(2115,49511 BOOL evaluable_formula(2134,49818 BOOL evaluable_topform(2157,50192 void update_interp_with_constant(2175,50497 BOOL eval_topform(2201,51060 Ordertype compare_interp(2221,51416 BOOL ident_interp(2254,52054 Ordertype compare_ints(2260,52165 void invert_perm(2271,52339 void copy_perm(2279,52462 Ordertype compare_permed_interps(2301,52814 void canon_recurse(2376,54556 Interp canon_interp(2426,55803 void assign_discriminator_counts(2460,56579 BOOL same_discriminator_counts(2484,57099 void update_profile(2503,57518 void create_profile(2538,58246 void p_interp_profile(2573,59022 Interp normal3_interp(2625,60257 BOOL same_profiles(2695,61897 long unsigned perms_required(2715,62230 long unsigned factorial(2750,62758 ../ladr/ioutil.c,1118 void fwrite_formula(39,1187 Topform read_clause(66,1781 Topform parse_clause_from_string(89,2167 BOOL end_of_list_clause(108,2509 Clist read_clause_clist(139,3248 Plist read_clause_list(168,3865 void sb_write_clause_jmap(185,4223 void sb_write_clause(245,5407 void sb_xml_write_clause_jmap(262,5747 void sb_tagged_write_clause_jmap(328,7779 void fwrite_clause_jmap(372,8576 void fwrite_clause(405,9332 void f_clause(421,9601 void fwrite_clause_clist(444,9974 void fwrite_demod_clist(470,10547 void fwrite_clause_list(510,11400 void f_clauses(535,11865 Formula read_formula(554,12238 BOOL end_of_list_formula(576,12553 Plist read_formula_list(605,13137 void fwrite_formula_list(639,13751 void zap_formula_list(665,14232 BOOL end_of_list_term(687,14559 BOOL end_of_commands_term(708,14905 Plist read_term_list(735,15512 void fwrite_term_list(769,16107 Term term_reader(801,16807 void term_writer(823,17271 Topform clause_reader(847,17767 void clause_writer(863,18187 Topform term_to_topform2(882,18466 Topform read_clause_or_formula(912,19033 Plist read_clause_or_formula_list(934,19379 ../ladr/ivy.c,790 #define DICT_SIZE 23,810 static char *Dict[27,895 char *dict_lookup(40,1177 void ivy_term_trans(57,1422 void ivy_clause_trans(78,1779 void sb_ivy_write_term(93,2012 void sb_ivy_write_pair(118,2462 void sb_ivy_write_pairs(136,2784 void sb_ivy_write_position(155,3113 void sb_ivy_write_lit(174,3445 void sb_ivy_write_literals(192,3766 void sb_ivy_write_just(217,4228 void sb_ivy_write_clause_jmap(275,5687 Topform instantiate_inference(299,6422 Topform renumber_inference(316,6902 Ilist ivy_lit_position(339,7358 Ilist ivy_para_position(368,8198 Plist paramod2_instances(396,8920 Topform flip_inference(481,11512 Plist resolve2_instances(524,12674 Plist factor2_instances(621,15016 Plist copy_proof_and_rename_symbols_for_ivy(682,16548 Plist expand_proof_ivy(704,16948 ../ladr/just.c,2701 #define PTRS_JUST 27,840 static unsigned Just_gets,28,884 static unsigned Just_gets, Just_frees;28,884 #define PTRS_PARAJUST 30,924 static unsigned Parajust_gets,31,976 static unsigned Parajust_gets, Parajust_frees;31,976 #define PTRS_INSTANCEJUST 33,1024 static unsigned Instancejust_gets,34,1084 static unsigned Instancejust_gets, Instancejust_frees;34,1084 #define PTRS_IVYJUST 36,1140 static unsigned Ivyjust_gets,37,1190 static unsigned Ivyjust_gets, Ivyjust_frees;37,1190 Just get_just(49,1329 void free_just(63,1493 Parajust get_parajust(79,1681 void free_parajust(93,1873 Instancejust get_instancejust(109,2089 void free_instancejust(123,2309 Ivyjust get_ivyjust(136,2508 void free_ivyjust(150,2692 void fprint_just_mem(169,3072 void p_just_mem(213,4385 Just ivy_just(232,4584 Just input_just(260,5122 Just goal_just(279,5399 Just deny_just(298,5672 Just clausify_just(318,5979 Just expand_def_just(338,6306 Just copy_just(358,6686 Just propositional_just(378,7011 Just new_symbol_just(398,7376 Just back_demod_just(418,7719 Just back_unit_deletion_just(438,8078 Just binary_res_just(460,8541 Just binary_res_just_by_id(484,9082 Just factor_just(508,9609 Just xxres_just(528,10030 Just resolve_just(549,10454 Just demod_just(568,10749 Just para_just(588,11095 Just instance_just(616,11650 Just para_just_rev_copy(640,12131 Just unit_del_just(660,12557 Just flip_just(680,12966 Just xx_just(700,13286 Just merge_just(721,13641 Just eval_just(741,13959 Just append_just(760,14220 Just copy_justification(781,14502 char *jstring(859,16592 int jstring_to_jtype(907,18115 char itoc(974,19897 int ctoi(993,20130 int jmap1(1015,20486 char *jmap2(1039,20998 void sb_append_id(1065,21403 void sb_write_res_just(1081,21733 void sb_write_position(1120,22565 void sb_write_ids(1142,22947 void sb_write_just(1164,23346 void sb_xml_write_just(1324,27317 void p_just(1371,28377 void zap_parajust(1387,28617 void zap_instancejust(1401,28813 void zap_ivyjust(1414,29000 void zap_just(1433,29300 Ilist get_parents(1491,30600 Topform first_negative_parent(1586,33386 Plist get_clanc(1607,33826 Plist get_clause_ancestors(1643,34667 int proof_length(1659,34894 int map_id(1671,35037 void map_just(1688,35301 int just_count(1780,37903 void mark_parents_as_used(1797,38119 I2list cl_level(1815,38451 int clause_level(1849,39245 int lit_string_to_int(1864,39488 Ilist args_to_ilist(1882,39739 Just term_to_just(1914,40333 BOOL primary_just_type(2078,43902 BOOL has_input_just(2094,44174 BOOL has_copy_just(2110,44409 BOOL has_copy_flip_just(2126,44670 void sb_tagged_write_res_just(2148,45325 void sb_tagged_write_just(2183,46015 ../ladr/lindex.c,409 #define PTRS_LINDEX 27,842 static unsigned Lindex_gets,28,890 static unsigned Lindex_gets, Lindex_frees;28,890 Lindex get_lindex(37,1004 void free_lindex(51,1182 void fprint_lindex_mem(70,1561 void p_lindex_mem(96,2170 Lindex lindex_init(126,2904 void lindex_destroy(149,3447 void lindex_update(167,3737 void lindex_update_first(189,4181 BOOL lindex_empty(212,4636 BOOL lindex_backtrack(229,4949 ../ladr/listterm.c,413 #define CONS_SYM 23,815 #define NIL_SYM 24,841 Term get_nil_term(37,998 Term listterm_cons(54,1249 BOOL cons_term(74,1584 BOOL nil_term(91,1856 BOOL proper_listterm(109,2165 Term listterm_append(137,2839 int listterm_length(158,3208 Term listterm_i(179,3547 BOOL listterm_member(200,3896 Plist listterm_to_tlist(224,4321 void listterm_zap(249,4709 Term rev2(266,4914 Term listterm_reverse(286,5279 ../ladr/literals.c,1875 #define PTRS_LITERALS 27,844 static unsigned Literals_gets,28,896 static unsigned Literals_gets, Literals_frees;28,896 Literals get_literals(40,1045 void free_literals(57,1264 void fprint_literals_mem(76,1655 void p_literals_mem(102,2284 void zap_literal(122,2527 void zap_literals(139,2754 Literals new_literal(159,3063 Literals copy_literal(177,3308 Literals append_literal(193,3572 Literals term_to_literals(213,3864 Term literal_to_term(248,4584 Term literals_to_term(270,4892 Term lits_to_term(297,5513 void free_lits_to_term(327,6046 int positive_literals(349,6449 int negative_literals(370,6832 BOOL positive_clause(391,7217 BOOL any_clause(407,7485 BOOL negative_clause(423,7719 BOOL mixed_clause(440,8008 int number_of_literals(457,8298 BOOL unit_clause(476,8604 BOOL horn_clause(492,8861 BOOL definite_clause(508,9129 int greatest_variable_in_clause(525,9443 Plist vars_in_clause(547,9888 Ilist varnums_in_clause(566,10233 int number_of_variables(590,10686 BOOL ground_clause(608,10947 Literals copy_literals(626,11272 Literals copy_literals_with_flags(652,11785 Literals copy_literals_with_flag(678,12334 int literal_number(704,12938 int atom_number(729,13444 Literals ith_literal(753,13853 BOOL true_clause(775,14233 BOOL complementary_scan(792,14506 BOOL tautology(815,15004 int symbol_occurrences_in_clause(839,15441 Literals remove_null_literals(859,15797 Literals first_literal_of_sign(885,16191 Ilist constants_in_clause(906,16590 BOOL clause_ident(927,16968 int clause_symbol_count(952,17478 int clause_depth(972,17872 BOOL pos_eq(995,18305 BOOL neg_eq(1012,18588 BOOL pos_eq_unit(1029,18899 BOOL neg_eq_unit(1047,19191 BOOL contains_pos_eq(1066,19539 BOOL contains_eq(1089,19959 BOOL only_eq(1111,20321 int literals_depth(1133,20707 Term term_at_position(1154,21010 Ilist pos_predicates(1175,21354 ../ladr/maximal.c,539 int Maximal_flag 23,814 int Maximal_signed_flag 24,886 int Selected_flag 25,961 void init_maximal(37,1118 BOOL greater_literals(53,1434 BOOL max_lit_test(83,2124 BOOL max_signed_lit_test(110,2672 void mark_maximal_literals(134,3148 BOOL maximal_literal(164,3873 BOOL maximal_signed_literal(184,4301 int number_of_maximal_literals(203,4706 void mark_selected_literal(224,5045 void mark_selected_literals(239,5265 BOOL selected_literal(270,5924 BOOL exists_selected_literal(285,6138 void copy_selected_literal_marks(304,6448 ../ladr/memory.c,816 #define MALLOC_MEGS 21,776 #define DEFAULT_MAX_MEGS 22,847 #define MAX_MEM_LISTS 23,912 static void ** M[25,985 static BOOL Max_megs_check 27,1019 static int Max_megs 28,1054 static int Malloc_calls 31,1206 static unsigned Bytes_palloced 33,1280 static void *Block 35,1317 static void *Block_pos 36,1397 static unsigned Mem_calls 38,1464 static unsigned Mem_calls_overflows 39,1495 #define BUMP_MEM_CALLS 41,1537 void *palloc(50,1728 void *get_cmem(96,2788 void *get_mem(134,3421 void free_mem(166,4013 int mlist_length(190,4401 void memory_report(207,4598 int megs_malloced(233,5277 void set_max_megs(251,5617 void set_max_megs_proc(268,5900 int bytes_palloced(285,6189 void *tp_alloc(302,6468 unsigned mega_mem_calls(321,6786 void disable_max_megs(338,7026 void enable_max_megs(353,7204 ../ladr/mindex.c,948 struct mindex_pos mindex_pos23,813 #define PTRS_MINDEX 53,1371 static unsigned Mindex_gets,54,1419 static unsigned Mindex_gets, Mindex_frees;54,1419 #define PTRS_MINDEX_POS 56,1463 static unsigned Mindex_pos_gets,57,1519 static unsigned Mindex_pos_gets, Mindex_pos_frees;57,1519 Mindex get_mindex(66,1641 void free_mindex(82,1862 Mindex_pos get_mindex_pos(95,2037 void free_mindex_pos(110,2265 void fprint_mindex_mem(129,2664 void p_mindex_mem(161,3522 Mindex mindex_init(204,4833 BOOL mindex_empty(234,5560 void mindex_free(263,6056 void mindex_destroy(295,6675 void linear_insert(324,7230 void linear_delete(343,7538 void linear_update(375,8158 void mindex_update(398,8628 Term mindex_retrieve_first(465,10746 Term next_candidate(510,11865 Term retrieve_next_backtrack(565,13185 Term mindex_retrieve_next(643,15321 void mindex_retrieve_cancel(733,17311 void fprint_linear_index(765,18162 void fprint_mindex(787,18560 ../ladr/multiset.c,98 int num_occurrences(30,883 Plist set_of_more_occurrences(48,1211 BOOL greater_multiset(83,2083 ../ladr/nonport.c,98 char *username(42,1117 char *hostname(64,1471 int my_process_id(87,1826 int get_bits(107,2093 ../ladr/options.c,2570 typedef enum { FLAGT,28,892 typedef enum { FLAGT, PARMT,28,892 typedef enum { FLAGT, PARMT, FLOATPARMT,28,892 typedef enum { FLAGT, PARMT, FLOATPARMT, STRINGPARMT 28,892 typedef enum { FLAGT, PARMT, FLOATPARMT, STRINGPARMT } Opttype;Opttype28,892 typedef struct optdep * Optdep;Optdep29,956 struct optdep optdep31,989 struct flag flag42,1544 struct parm parm49,1671 struct floatparm floatparm57,1858 struct stringparm stringparm65,2063 static struct flag Flags[74,2414 static struct parm Parms[75,2451 static struct floatparm Floatparms[76,2488 static struct stringparm Stringparms[77,2540 static int Next_flag 79,2596 static int Next_parm 80,2622 static int Next_floatparm 81,2648 static int Next_stringparm 82,2679 static int Option_updates 84,2712 static BOOL Ignore_dependencies 86,2774 #define PTRS_OPTDEP 92,2845 static unsigned Optdep_gets,93,2893 static unsigned Optdep_gets, Optdep_frees;93,2893 Optdep get_optdep(102,3007 void free_optdep(117,3191 void fprint_options_mem(137,3579 void p_options_mem(163,4192 void enable_option_dependencies(182,4418 void disable_option_dependencies(197,4633 BOOL option_dependencies_state(212,4847 int init_flag(232,5286 int init_parm(269,6140 int init_floatparm(304,6932 int init_stringparm(343,7903 void fprint_options(380,8848 void p_options(433,10186 int flag(451,10449 int parm(468,10715 BOOL at_parm_limit(484,10918 BOOL over_parm_limit(504,11245 double floatparm(525,11646 BOOL stringparm(542,11938 char *stringparm1(559,12207 void update_flag(576,12495 void set_flag(654,14482 void clear_flag(672,14825 void assign_parm(691,15219 void assign_floatparm(753,16903 void assign_stringparm(788,18079 int str_to_flag_id(827,19037 int str_to_parm_id(848,19417 int str_to_floatparm_id(869,19802 int str_to_stringparm_id(890,20214 char *flag_id_to_str(910,20562 char *parm_id_to_str(928,20873 char *floatparm_id_to_str(946,21199 char *stringparm_id_to_str(964,21553 Optdep append_dep(978,21803 void flag_flag_dependency(1001,22217 void flag_flag_dep_default(1024,22759 void flag_parm_dependency(1047,23298 void flag_floatparm_dependency(1070,23840 void flag_parm_dep_default(1093,24394 void flag_floatparm_dep_default(1116,24941 void parm_flag_dependency(1139,25497 void parm_parm_dependency(1160,25974 void flag_stringparm_dependency(1183,26530 void flag_stringparm_dep_default(1206,27104 int option_updates(1227,27582 int flag_default(1242,27751 int parm_default(1257,27935 int floatparm_default(1272,28124 char *stringparm1_default(1287,28340 ../ladr/order.c,116 void merge_sort_recurse(49,1403 void merge_sort(110,2752 Ordertype compare_vecs(129,3112 void copy_vec(151,3428 ../ladr/paramod.c,839 static BOOL Ordered_inference 23,814 static BOOL Positive_inference 24,854 static BOOL Para_from_vars 25,895 static BOOL Para_into_vars 26,931 static BOOL Para_from_small 27,968 static BOOL Check_instances 28,1006 static int Para_instance_prunes 30,1077 static int Basic_prunes 31,1132 void paramodulation_options(44,1291 int para_instance_prunes(73,1977 int basic_paramodulation_prunes(89,2248 BOOL basic_check(101,2413 Literals apply_lit_para(118,2656 Term apply_substitute_para(134,2960 Topform paramodulate(156,3402 BOOL para_from_right(200,4715 BOOL from_parent_test(221,5098 BOOL into_parent_test(245,5699 BOOL check_instance(287,6779 BOOL check_instances(319,7529 void para_into(341,7989 void para_into_lit(391,9296 void para_from_into(442,10931 Topform para_pos(479,11980 Topform para_pos2(529,13395 ../ladr/parautil.c,719 int Oriented_flag 23,815 int Renamable_flip_flag 24,893 void init_paramod(36,1064 void mark_renamable_flip(55,1452 BOOL renamable_flip_eq(74,1898 BOOL renamable_flip_eq_test(95,2333 void mark_oriented_eq(126,2933 BOOL oriented_eq(145,3347 BOOL same_term_structure(168,3792 void flip_eq(194,4304 void orient_equalities(218,4878 BOOL eq_tautology(295,7028 Term top_flip(320,7539 void zap_top_flip(343,7906 Literals literal_flip(358,8065 void zap_literal_flip(377,8355 Topform clause_with_new_constant(390,8537 Topform new_constant(422,9495 Topform fold_denial(453,10163 BOOL equational_def_2(486,10939 int equational_def(504,11256 Ordertype unfold_order(530,11691 Topform build_reflex_eq(555,12146 ../ladr/parse.c,3210 #define COMMENT_CHAR 23,812 static char Cons_char 25,838 static char Quote_char 26,867 static int Quantifier_precedence 27,898 static BOOL Parenthesize 29,978 static BOOL Check_for_illegal_symbols 30,1012 typedef enum {TOK_UNKNOWN,34,1078 TOK_ORDINARY,35,1143 TOK_SPECIAL,36,1190 TOK_STRING,37,1236 TOK_COMMENT,38,1280 TOK_PUNC 39,1326 } Toktype;Toktype40,1377 typedef enum {READ_BUF_OK,44,1425 typedef enum {READ_BUF_OK,READ_BUF_EOF,44,1425 READ_BUF_ERROR,45,1465 READ_BUF_ERROR,READ_BUF_QUOTE_ERROR}45,1465 READ_BUF_ERROR,READ_BUF_QUOTE_ERROR} Read_rc;Read_rc45,1465 typedef struct token * Token;Token49,1543 struct token token51,1574 typedef struct pterm * Pterm;Pterm61,1848 struct pterm pterm63,1879 typedef struct tok_pos *Tok_pos;Tok_pos71,2017 struct tok_pos tok_pos73,2051 static BOOL Translate_neg_equalities 81,2163 static Plist Multiple_char_special_syms 82,2211 #define PTRS_TOKEN 88,2290 static unsigned Token_gets,89,2336 static unsigned Token_gets, Token_frees;89,2336 #define PTRS_PTERM 91,2378 static unsigned Pterm_gets,92,2424 static unsigned Pterm_gets, Pterm_frees;92,2424 Token get_token(101,2534 void free_token(115,2705 Pterm get_pterm(128,2865 void free_pterm(142,3036 void fprint_parse_mem(161,3408 void p_parse_mem(193,4220 void p_tokens(210,4405 void translate_neg_equalities(238,4950 Term translate_neg_eq(250,5132 Term untranslate_neg_eq(276,5697 void free_pterm_list(302,6270 void free_token_list(321,6527 BOOL end_char(340,6788 BOOL comment_char(352,6920 BOOL quote_char(364,7067 BOOL punctuation_char(376,7214 BOOL ordinary_char(394,7496 BOOL special_char(410,7749 BOOL white_char(448,8430 BOOL all_whitespace(465,8733 int finish_comment(494,9236 int read_buf(545,10478 String_buf max_special_symbol(605,11583 Token tokenize(653,12639 int comma_terms(737,14469 void transfer_comma_term(752,14722 BOOL quantifier(771,15075 BOOL ordinary_constant_string(787,15320 BOOL ordinary_constant(801,15524 BOOL quant_prefix(816,15755 Term terms_to_term(836,16173 void next_token(985,20811 Term toks_to_set(1005,21119 Term make_a_list(1022,21443 Term toks_to_list(1043,21856 Pterm toks_to_terms(1107,23377 Term toks_to_term(1226,26058 void fprint_parse_error(1259,26820 Term sread_term(1296,27820 Term read_term(1347,29180 Term parse_term_from_string(1395,30120 void arrange_term(1410,30364 void sb_remove_some_space(1528,33570 void sb_write_term(1564,34452 void fwrite_term(1594,35155 void fwrite_term_nl(1617,35633 char *process_quoted_symbol(1633,35843 void remember_multiple_char_special_syms(1661,36447 void forget_multiple_char_special_syms(1681,36944 void look_for_illegal_symbols(1701,37433 void declare_parse_type(1721,37933 void declare_quantifier_precedence(1744,38457 void declare_standard_parse_types(1759,38684 BOOL redeclare_symbol_and_copy_parsetype(1815,40550 void skip_to_nl(1852,41549 Plist split_string(1872,41888 void set_cons_char(1902,42418 char get_cons_char(1917,42581 void set_quote_char(1932,42746 char get_quote_char(1947,42913 void parenthesize(1962,43079 void check_for_illegal_symbols(1977,43267 ../ladr/pindex.c,636 struct pair_index pair_index23,813 #define INT_LARGE 35,1259 #define IN_RANGE(IN_RANGE36,1332 #define PTRS_PAIR_INDEX 42,1430 static unsigned Pair_index_gets,43,1486 static unsigned Pair_index_gets, Pair_index_frees;43,1486 Pair_index get_pair_index(52,1616 void free_pair_index(68,1870 void fprint_pindex_mem(87,2269 void p_pindex_mem(113,2906 Pair_index init_pair_index(137,3368 void zap_pair_index(180,4129 int pairs_exhausted(210,4697 void init_pair(224,4894 void insert_pair_index(265,5757 void delete_pair_index(304,6619 void retrieve_pair(401,8657 void p_pair_index(514,11412 int pair_already_used(558,12222 ../ladr/random.c,224 Term random_term(45,1344 Term random_nonvariable_term(112,2549 Term random_complex_term(136,3110 Ilist random_path(161,3687 void random_permutation(194,4356 Topform random_clause(238,5072 Term random_op_term(265,5604 ../ladr/resolve.c,1076 static BOOL Ordered 24,834 static BOOL Check_instances 25,875 static int Ur_nucleus_limit 27,917 static BOOL Initial_nuclei 28,995 static BOOL Production_mode 29,1075 static int Res_instance_prunes 31,1117 void resolution_options(45,1271 int res_instance_prunes(70,1772 BOOL unit_check(82,1923 BOOL pos_hyper_sat_test(95,2118 BOOL neg_hyper_sat_test(111,2430 void hyper_sat_atom(127,2738 void hyper_satellite(191,4489 void hyper_nucleus(214,5115 void hyper_resolution(258,6158 BOOL target_check(276,6562 void ur_sat_atom(297,7005 void ur_satellite(364,8858 void ur_nucleus(385,9332 void ur_resolution(430,10391 void xx_res(446,10724 void binary_resolvent(479,11566 BOOL binary_parent_test(529,12788 Topform instantiate_clause(576,14334 BOOL check_instance(594,14738 BOOL check_instances(628,15574 void bin_res_lit(647,15930 void binary_resolution(681,16847 void binary_factors(716,17626 void merge_literals(759,18566 Topform copy_inference(795,19439 Topform resolve2(827,20231 Topform resolve3(883,21518 Topform xx_resolve2(903,21972 ../ladr/std_options.c,252 static int Prolog_style_variables 25,831 static int Ignore_option_dependencies 26,898 static int Clocks 27,967 void init_standard_options(39,1136 void process_standard_options(58,1559 int clocks_id(86,2038 int prolog_style_variables_id(101,2202 ../ladr/strbuf.c,953 struct string_buf string_buf25,817 #define CHUNK_SIZE 30,876 struct chunk chunk32,900 typedef struct chunk *Chunk;Chunk37,963 #define PTRS_CHUNK 43,1022 static unsigned Chunk_gets,44,1068 static unsigned Chunk_gets, Chunk_frees;44,1068 #define PTRS_STRING_BUF 46,1110 static unsigned String_buf_gets,47,1166 static unsigned String_buf_gets, String_buf_frees;47,1166 Chunk get_chunk(56,1286 void free_chunk(70,1457 String_buf get_string_buf(86,1654 void free_string_buf(100,1860 void fprint_strbuf_mem(119,2259 void p_strbuf_mem(151,3110 String_buf init_string_buf(173,3495 void fprint_sb(191,3762 void p_sb(218,4235 void sb_append(238,4549 void sb_append_char(273,5138 void sb_replace_char(312,6005 char sb_char(337,6493 void sb_cat_copy(363,6960 void sb_cat(386,7480 void zap_string_buf(404,7764 char *sb_to_malloc_string(438,8673 char *sb_to_malloc_char_array(469,9262 int sb_size(494,9618 void sb_append_int(510,9847 ../ladr/string.c,468 static char *Float_format 23,813 BOOL str_ident(36,1027 char *new_str_copy(53,1325 BOOL string_member(71,1585 int which_string_member(92,1983 BOOL initial_substring(112,2308 BOOL substring(131,2563 void reverse_chars(153,2935 int natural_string(171,3220 int char_occurrences(192,3479 char *escape_char(215,3849 BOOL str_to_int(243,4396 char *int_to_str(266,4802 BOOL str_to_double(286,5142 char *double_to_str(316,5653 BOOL string_of_repeated(349,6145 ../ladr/subsume.c,574 static int Nonunit_subsumption_tests 23,814 int nonunit_subsumption_tests(35,966 BOOL subsume_literals(53,1367 BOOL subsume_bt_literals(87,2046 BOOL subsumes(133,2991 BOOL subsumes_bt(158,3532 Topform forward_subsume(185,4008 Plist back_subsume(238,5526 Topform back_subsume_one(294,7039 void atom_conflict(343,8206 void unit_conflict_by_index(388,9345 Topform try_unit_conflict(413,9942 void unit_delete(445,10778 Plist back_unit_del_by_index(519,12836 void simplify_literals(566,13936 BOOL eq_removable_literal(604,14823 void simplify_literals2(646,15920 ../ladr/symbols.c,5368 struct symbol symbol23,813 #define SYM_TAB_SIZE 42,1707 static Plist By_id[44,1736 static Plist By_sym[45,1804 static unsigned Symbol_count;47,1874 static char *True_sym 51,1944 static char *False_sym 52,1977 static char *And_sym 53,2010 static char *Or_sym 54,2042 static char *Not_sym 55,2074 static char *Iff_sym 56,2106 static char *Imp_sym 57,2140 static char *Impby_sym 58,2173 static char *All_sym 59,2206 static char *Exists_sym 60,2240 static char *Quant_sym 61,2277 static char *Attrib_sym 65,2359 static char *Eq_sym 66,2434 static char *Neq_sym 67,2504 char *true_sym(79,2670 char *false_sym(94,2820 char *and_sym(109,2967 char *or_sym(124,3107 char *not_sym(139,3245 char *iff_sym(154,3386 char *imp_sym(169,3527 char *impby_sym(184,3670 char *all_sym(199,3817 char *exists_sym(214,3961 char *quant_sym(229,4118 char *attrib_sym(244,4273 char *eq_sym(259,4422 char *neq_sym(274,4560 void set_operation_symbol(289,4714 char *get_operation_symbol(335,6043 BOOL symbol_in_use(382,7339 Symbol get_symbol(427,8477 int new_symnum(457,9065 unsigned hash_sym(470,9212 unsigned hash_id(488,9464 Symbol lookup_by_id(500,9607 Symbol lookup_by_sym(518,9879 int str_to_sn(544,10557 void fprint_syms(580,11386 void p_syms(609,12018 void fprint_sym(626,12269 void sprint_sym(643,12568 void p_sym(660,12851 BOOL str_exists(678,13168 int greatest_symnum(705,13684 char *sn_to_str(725,14205 BOOL is_symbol(747,14552 int sn_to_arity(767,14966 int sn_to_occurrences(787,15289 void set_unfold_symbol(807,15626 BOOL is_unfold_symbol(823,15842 void declare_aux_symbols(839,16059 char *parse_type_to_str(862,16573 void clear_parse_type_for_all_symbols(887,17104 void clear_parse_type(910,17488 void check_diff_type_same_prec(932,17865 void set_parse_type(979,19088 BOOL binary_parse_type(1023,20238 BOOL unary_parse_type(1048,20824 int special_parse_type(1073,21340 static int Assoc_comm_symbols 1089,21815 static int Comm_symbols 1090,21873 void set_assoc_comm(1108,22278 void set_commutative(1135,22822 BOOL assoc_comm_symbols(1161,23274 BOOL comm_symbols(1178,23537 BOOL is_assoc_comm(1199,24000 BOOL is_commutative(1221,24518 static int Eq_symnum 1231,24896 static int Or_symnum 1232,24922 static int Not_symnum 1233,24948 BOOL is_eq_symbol(1248,25234 int not_symnum(1267,25529 int or_symnum(1285,25782 void declare_base_symbols(1302,26006 static Variable_style Var_style 1315,26405 void set_variable_style(1328,26616 Variable_style variable_style(1344,26855 BOOL variable_name(1362,27200 void symbol_for_variable(1387,27814 Ilist variable_symbols(1424,28651 Ilist remove_variable_symbols(1448,29133 void set_symbol_type(1471,29682 Symbol_type get_symbol_type(1489,29974 BOOL function_symbol(1507,30255 BOOL relation_symbol(1522,30464 BOOL function_or_relation_symbol(1537,30686 void declare_functions_and_relations(1553,30981 int function_or_relation_sn(1576,31540 Ilist all_function_symbols(1601,31983 Ilist all_relation_symbols(1626,32397 void set_lrpo_status(1655,33045 void all_symbols_lrpo_status(1673,33373 Lrpo_status sn_to_lrpo_status(1698,33908 static BOOL Zero_wt_kb 1708,34288 void set_kb_weight(1720,34455 BOOL zero_wt_kb(1750,35093 int sn_to_kb_wt(1766,35329 void print_kbo_weights(1785,35579 static char *Skolem_constant_prefix 1801,36121 static char *Skolem_function_prefix 1802,36164 static int Next_skolem_constant 1803,36207 static int Next_skolem_function 1804,36279 static BOOL Skolem_check 1805,36351 void set_skolem(1818,36591 void skolem_check(1835,36818 BOOL skolem_ok(1847,36957 int next_skolem_symbol(1876,37565 Ilist skolem_symbols(1910,38221 BOOL is_skolem(1935,38599 void skolem_reset(1952,38858 void decommission_skolem_symbols(1970,39178 void set_skolem_symbols(1995,39590 static Ilist Preliminary_prec_func 2010,40092 static Ilist Preliminary_prec_pred 2011,40135 void set_lex_val(2025,40387 int sn_to_lex_val(2047,40891 Ordertype sym_precedence(2066,41309 Ilist syms_with_lex_val(2099,41911 BOOL exists_preliminary_precedence(2124,42311 Ordertype preliminary_lex_compare(2150,42998 Ordertype lex_compare_base(2189,43968 Ordertype lex_compare_arity_0123(2278,46207 Ordertype lex_compare_arity_0213(2299,46616 void lex_order(2337,47653 Ilist insert_by_lex_val(2370,48473 Ilist sort_by_lex_val(2396,48902 Ilist remove_syms_without_lex_val(2412,49147 Ilist current_fsym_precedence(2438,49598 Ilist current_rsym_precedence(2456,49899 Ilist not_in_preliminary_precedence(2474,50206 void print_fsym_precedence(2500,50789 void print_rsym_precedence(2523,51210 int min_lex_val(2546,51623 int max_lex_val(2566,51921 void assign_greatest_precedence(2589,52261 BOOL has_greatest_precedence(2604,52489 void lex_insert_after_initial_constants(2619,52729 Ilist skolem_insert(2650,53369 void add_skolems_to_preliminary_precedence(2676,53990 static unsigned Mark_for_new_symbols 2695,54752 int fresh_symbol(2711,55152 int gen_new_symbol(2738,55564 void mark_for_new_symbols(2769,56107 I2list new_symbols_since_mark(2784,56336 void add_new_symbols(2806,56707 void new_constant_properties(2833,57314 Ilist collect_multiples(2855,57751 Ilist arity_check(2888,58425 int symbol_with_string(2905,58718 void process_skolem_list(2925,59051 void process_lex_list(2950,59593 Ilist symnums_of_arity(2992,60712 ../ladr/term.c,2866 static Term Shared_variables[59,2360 #define PTRS_TERM 65,2430 static unsigned Term_gets,66,2474 static unsigned Term_gets, Term_frees;66,2474 static unsigned Arg_mem;68,2514 Term get_term(77,2655 void free_term(114,3487 void fprint_term_mem(135,3937 void p_term_mem(165,4627 Term get_variable_term(187,4957 Term get_rigid_term_like(219,5707 Term get_rigid_term(240,6162 Term get_rigid_term_dangerously(274,7100 void zap_term(295,7514 BOOL term_ident(319,8002 Term copy_term(347,8545 BOOL ground_term(373,9027 int biggest_variable(398,9454 int term_depth(423,9882 int symbol_count(450,10328 BOOL occurs_in(475,10893 void fprint_term(499,11283 void sprint_term(535,11939 char *term_to_string(573,12641 void p_term(596,13110 BOOL all_args_vars(615,13409 Term build_binary_term(642,13867 Term build_binary_term_safe(665,14354 Term build_unary_term(683,14730 Term build_unary_term_safe(704,15159 Term subst_term(721,15501 Term subst_var_term(748,16050 int greatest_variable(775,16576 int greatest_symnum_in_term(802,17086 void upward_term_links(829,17592 BOOL check_upward_term_links(851,18011 int occurrences(877,18501 Term trm_set_vars_recurse(899,18882 void term_set_variables(945,19996 Term nat_to_term(978,20634 Term int_to_term(998,20964 Term bool_to_term(1020,21308 Term double_to_term(1038,21642 int natural_constant_term(1057,21999 int arg_position(1078,22377 BOOL is_term(1099,22694 BOOL is_constant(1115,22935 char *term_symbol(1132,23223 BOOL term_to_int(1153,23647 BOOL term_to_double(1186,24258 BOOL term_to_number(1207,24666 BOOL true_term(1230,24990 BOOL false_term(1245,25161 BOOL term_to_bool(1263,25461 I2list symbols_in_term(1289,25893 Ilist fsym_set_in_term(1310,26218 Term renum_vars_recurse(1335,26816 Term set_vars_recurse(1373,27707 I2list multiset_of_vars(1409,28397 I2list multiset_vars(1431,28748 Plist set_of_vars(1447,28955 Plist set_of_variables(1474,29395 int number_of_vars_in_term(1490,29631 Ilist set_of_ivars(1509,29907 Ilist set_of_ivariables(1536,30404 BOOL variables_subset(1551,30594 BOOL variables_multisubset(1571,30945 Term term_at_pos(1603,31527 Ilist pos_of_subterm(1622,31811 Ilist position_of_subterm(1653,32563 int symbol_occurrences(1674,32923 BOOL args_distinct_vars(1699,33383 unsigned hash_term(1750,34178 BOOL skolem_term(1773,34502 BOOL contains_skolem_term(1788,34682 BOOL contains_skolem_function(1813,35067 Term term0(1839,35480 Term term1(1855,35692 Term term2(1873,35949 BOOL symbol_in_term(1891,36190 BOOL same_structure(1917,36623 Plist copy_plist_of_terms(1942,37049 void zap_plist_of_terms(1966,37448 BOOL eq_term(1989,37848 Plist plist_of_subterms(2004,38032 BOOL tlist_member(2025,38416 int position_of_term_in_tlist(2045,38717 BOOL tlist_subset(2065,39018 BOOL tlist_set(2083,39271 Plist free_vars_term(2104,39673 ../ladr/termflag.c,410 #define TERM_BITS 25,842 #define SET_BIT(SET_BIT27,893 #define CLEAR_BIT(CLEAR_BIT28,949 static int bits_in_use[31,1058 int claim_term_flag(47,1414 void release_term_flag(73,1862 void term_flag_set(99,2602 void term_flag_clear(119,3045 BOOL term_flag(139,3489 int term_flags(162,3944 Term copy_term_with_flags(180,4242 Term copy_term_with_flag(209,4822 void term_flag_clear_recursively(236,5289 ../ladr/termorder.c,697 Order_method Ordering_method 24,838 void assign_order_method(36,1014 Ordertype term_compare_basic(55,1421 Ordertype term_compare_ncv(107,2712 Ordertype term_compare_vcp(155,3913 Ordertype term_compare_vr(203,5088 Ordertype flatterm_compare_vr(246,6030 BOOL lrpo_multiset(291,6920 BOOL lrpo_lex(306,7244 BOOL lrpo(354,8491 void init_kbo_weights(413,9891 int kbo_weight(454,10743 BOOL kbo(478,11082 BOOL term_greater(536,12612 Ordertype term_order(556,13071 int flat_kbo_weight(578,13455 BOOL flat_kbo(601,13814 BOOL flat_lrpo_multiset(659,15326 BOOL flat_lrpo_lex(677,15699 BOOL flat_lrpo(731,16764 BOOL flat_greater(796,18114 BOOL greater_multiset_current_ordering(828,18956 ../ladr/test.c,57 #define N 22,795 void compute_args(24,808 main(35,987 ../ladr/tlist.c,140 void zap_tlist(35,1035 Plist tlist_remove(56,1346 Plist tlist_union(87,1890 Ilist constants_in_term(114,2345 Plist tlist_copy(142,2788 ../ladr/top_input.c,1344 typedef struct readlist * Readlist;Readlist29,933 struct readlist readlist31,970 static Readlist Input_lists 39,1179 static Plist Lex_function_list 41,1216 static Plist Lex_predicate_list 42,1255 static Plist Skolem_list 43,1295 static char *Program_name 45,1372 #define PTRS_READLIST 51,1434 static unsigned Readlist_gets,52,1486 static unsigned Readlist_gets, Readlist_frees;52,1486 Readlist get_readlist(61,1608 void free_readlist(76,1806 void fprint_top_input_mem(96,2208 void p_top_input_mem(122,2844 void init_standard_ladr(142,3117 void fatal_input_error(161,3449 void set_program_name(186,3927 BOOL condition_is_true(198,4083 void process_op2(210,4246 void process_op(249,5317 void process_redeclare(298,6408 void execute_unknown_action(333,7283 void flag_handler(361,7923 void parm_handler(390,8658 void process_symbol_list(440,9806 Readlist readlist_member(468,10675 Readlist readlist_member_wild(485,10995 void accept_list(513,11772 void input_symbols(538,12219 void symbol_check_and_declare(582,13457 void read_from_file(697,16616 void read_all_input(880,22079 void check_formula_attributes(913,22828 Plist process_input_formulas(939,23499 Plist process_demod_formulas(992,25007 Plist process_goal_formulas(1032,26043 Term read_commands(1081,27281 Plist embed_formulas_in_topforms(1175,29840 ../ladr/topform.c,1249 #define PTRS_TOPFORM 27,843 static unsigned Topform_gets,28,893 static unsigned Topform_gets, Topform_frees;28,893 Topform get_topform(40,1038 void free_topform(54,1223 void fprint_topform_mem(73,1608 void p_topform_mem(99,2226 void zap_topform(124,2712 void fprint_clause(143,3010 void p_clause(184,3756 Topform term_to_clause(206,4271 Topform term_to_topform(233,4712 Term topform_to_term(269,5528 Term topform_to_term_without_attributes(304,6331 void clause_set_variables(338,7176 void renumber_variables(405,8912 void term_renumber_variables(453,10002 Plist renum_vars_map(482,10453 void upward_clause_links(526,11387 BOOL check_upward_clause_links(545,11754 Topform copy_clause(568,12208 Topform copy_clause_with_flags(589,12614 Topform copy_clause_with_flag(610,13056 void inherit_attributes(634,13587 void gather_symbols_in_topform(653,14047 void gather_symbols_in_topforms(674,14485 Ilist fsym_set_in_topforms(691,14791 Ilist rsym_set_in_topforms(713,15154 BOOL min_depth(736,15582 BOOL initial_clause(760,16026 BOOL negative_clause_possibly_compressed(777,16322 Term topform_properties(797,16764 void append_label_attribute(848,18000 Ordertype cl_id_compare(863,18250 Ordertype cl_wt_id_compare(883,18545 ../ladr/tptp_trans.c,562 void declare_tptp_input_types(152,4779 void declare_tptp_output_types(198,5945 Term tptp2_to_ladr_term(250,7493 Term tptp3_to_ladr_term(301,8629 Formula tptp_input_to_ladr_formula(418,11841 void rename_vars_to_upper(459,12889 Term ladr_term_to_tptp_term(482,13388 Plist ladr_list_to_tptp_list(564,15539 Ilist syms_in_form(613,16793 BOOL good_tptp_sym(667,18225 BOOL good_ladr_sym(697,18731 I2list map_for_bad_tptp_syms(712,18909 I2list map_for_bad_ladr_syms(752,19771 Term replace_bad_syms_term(793,20657 Term replace_bad_tptp_syms_form(824,21289 ../ladr/unify.c,1146 struct trail trail28,1016 #define BIND_TR(BIND_TR36,1258 #define MAX_MULTIPLIERS 41,1456 static BOOL Multipliers[45,1510 int next_available_multiplier(54,1669 #define PTRS_CONTEXT 70,2011 static unsigned Context_gets,71,2061 static unsigned Context_gets, Context_frees;71,2061 #define PTRS_TRAIL 73,2107 static unsigned Trail_gets,74,2153 static unsigned Trail_gets, Trail_frees;74,2153 Context get_context(86,2294 void free_context(104,2553 Trail get_trail(120,2853 void free_trail(134,3044 void fprint_unify_mem(153,3416 void p_unify_mem(185,4242 BOOL unify(241,5800 BOOL variant(333,7872 BOOL occur_check(370,8651 BOOL match(419,10170 Term apply(477,11462 Term apply_substitute(516,12530 Term apply_substitute2(546,13300 Term apply_demod(585,14289 void undo_subst(613,14835 void undo_subst_2(646,15760 void fprint_context(669,16166 void p_context(712,17023 void fprint_trail(728,17281 void p_trail(751,17676 BOOL match_weight(767,17874 Ilist vars_in_trail(824,19130 Plist context_to_pairs(842,19386 BOOL empty_substitution(873,19923 BOOL variable_substitution(893,20202 BOOL subst_changes_term(919,20673 ../ladr/weight.c,987 static Plist Rules;26,874 static double Constant_weight;28,895 static double Sk_constant_weight;29,926 static double Not_weight;30,960 static double Or_weight;31,986 static double Prop_atom_weight;32,1011 static double Variable_weight;33,1043 static double Nest_penalty;34,1074 static double Depth_penalty;35,1102 static double Var_penalty;36,1131 static double Complexity;37,1158 static BOOL Not_rules;38,1184 static BOOL Or_rules;39,1239 static int Eq_sn;43,1319 static int Weight_sn;44,1357 static int Sum_sn;46,1402 static int Prod_sn;47,1450 static int Neg_sn;48,1498 static int Div_sn;49,1546 static int Max_sn;50,1594 static int Min_sn;51,1642 static int Depth_sn;52,1690 static int Vars_sn;53,1725 static int Call_sn;54,1759 static int Avar_sn;55,1793 BOOL weight_beta_check(64,1912 BOOL weight_rule_check(100,2720 void init_weight(125,3224 int apply_depth(193,4832 double weight_calc(217,5280 double weight(301,7546 double clause_weight(358,8787 ../ladr/weight2.c,186 #define IMAX(IMAX39,1413 int char_array_ident(52,1612 int char_array_find(69,1954 double complexity_1(88,2316 double test1(141,3647 double call_weight(166,4182 int main(179,4426 ../ladr/xproofs.c,350 void check_parents_and_uplinks_in_proof(36,975 Topform xx_res2(65,1751 void xx_simp2(108,2678 Topform factor(134,3290 void merge1(171,4145 Topform proof_id_to_clause(201,4773 int greatest_id_in_proof(222,5088 Plist expand_proof(251,5910 void renumber_proof(539,14887 Plist copy_and_renumber_proof(568,15492 Plist proof_to_xproof(585,15778 LADR-2009-11A/mace4.src/ground.h0000644000175000017500000000426711105110732015244 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef MACE4_GROUND_H #define MACE4_GROUND_H /* INTRODUCTION */ /* Public definitions */ typedef struct mclause * Mclause; struct mclause { Term *lits; Mclause next; BOOL subsumed; int numlits; /* The following union exists in case long int is smaller than pointer; This is because "active" is sometimes handled as a pointer. */ union { long int active; void *for_padding_only; } u; }; #define MAX_MACE_VARS 50 #define TERM_FLAG(t,flag) (TP_BIT(t->private_flags, 1 << flag)) #define NEGATED(t) (TERM_FLAG(t,Negation_flag)) #define LITERAL(t) (TERM_FLAG(t,Relation_flag)) #define LIT(c,i) ((c)->lits[i]) #define OR_TERM(t) (SYMNUM((Term) t) == Or_sn) /* ok if variable */ #define NOT_TERM(t) (SYMNUM((Term) t) == Not_sn) /* ok if variable */ #define EQ_TERM(t) (SYMNUM((Term) t) == Eq_sn) /* ok if variable */ #define FALSE_TERM(t) ((t) == Domain[0]) /* ok if not variable */ #define TRUE_TERM(t) ((t) == Domain[1]) /* ok if not variable */ /* End of public definitions */ /* Public function prototypes from syms.c */ void fprint_mclause_mem(FILE *fp, int heading); void p_mclause_mem(void); void zap_mterm(Term t); void zap_mclause(Mclause c); int lit_position(Mclause parent, Term child); Mclause containing_mclause(Term t); Term containing_mliteral(Term t); void generate_ground_clauses(Topform c, Mstate state); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/mace4.c0000644000175000017500000001412211120260270014721 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "../ladr/banner.h" #include /************* * * init_attrs() * *************/ void init_attrs(void) { // This will allow these attributes to occur on clauses. // Mace4 will ignore these attributes. int id; id = register_attribute("label", STRING_ATTRIBUTE); id = register_attribute("bsub_hint_wt", INT_ATTRIBUTE); id = register_attribute("answer", TERM_ATTRIBUTE); id = register_attribute("action", TERM_ATTRIBUTE); id = register_attribute("action2", TERM_ATTRIBUTE); } /* init_attrs */ /************* * * mace4_sig_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mace4_sig_handler(int condition) { printf("\nmace4_sig_handler: condition %d", condition); switch (condition) { case SIGSEGV: p_stats(); mace4_exit(MACE_SIGSEGV_EXIT); break; case SIGINT: p_stats(); mace4_exit(MACE_SIGINT_EXIT); break; case SIGUSR1: p_stats(); fflush(stdout); break; default: fatal_error("mace4_sig_handler, unknown signal"); } } /* mace4_sig_handler */ /************* * * process_distinct_terms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist process_distinct_terms(Plist distinct) { Plist p; Plist forms = NULL; for (p = distinct; p; p = p->next) { Term list = p->v; if (!proper_listterm(list)) fatal_error("process_distinct_terms: lists must be proper, e.g., [a,b,c].\n"); while (!nil_term(list)) { Term a = ARG(list,0); Term rest = ARG(list,1); while (!nil_term(rest)) { Term b = ARG(rest,0); Term neq = build_unary_term_safe(not_sym(), build_binary_term_safe(eq_sym(), copy_term(a), copy_term(b))); Formula f = term_to_formula(neq); zap_term(neq); forms = plist_append(forms, f); rest = ARG(rest, 1); } list = ARG(list, 1); } } return forms; } /* process_distinct_terms */ /************* * * read_mace4_input() * *************/ static Plist read_mace4_input(int argc, char **argv, BOOL allow_unknown_things, Mace_options opt) { Plist wild_formulas, goals; Plist distinct_lists, distinct_forms; Plist wild_terms, hints; /* we won't use these */ // Tell the top_input package what lists to accept and where to put them. // Accept hints, but they will not be used. accept_list("hints", FORMULAS, TRUE, &hints); // Accept goals; these are negated individually (each must be falsified) accept_list("goals", FORMULAS, FALSE, &goals); // Accept lists of distinct items accept_list("distinct", TERMS, FALSE, &distinct_lists); // Accept any other clauses and formulas. Each must be true. accept_list("", FORMULAS, FALSE, &wild_formulas); // Accept any terms. These will not be used. accept_list("", TERMS, FALSE, &wild_terms); // Read commands such as set, clear, op, lex. // Read lists, filling in variables given to the accept_list calls. print_separator(stdout, "INPUT", TRUE); read_all_input(argc, argv, stdout, TRUE, allow_unknown_things ? WARN_UNKNOWN : KILL_UNKNOWN); if (wild_terms) printf("%% term list(s) ignored\n"); if (hints) printf("%% hints list(s) ignored\n"); process_command_line_args(argc, argv, opt); print_separator(stdout, "end of input", TRUE); if (!option_dependencies_state()) { /* This might be needed in the future. */ printf("\n%% Enabling option dependencies (ignore applies only on input).\n"); enable_option_dependencies(); } distinct_forms = process_distinct_terms(distinct_lists); wild_formulas = plist_cat(wild_formulas, distinct_forms); wild_formulas = embed_formulas_in_topforms(wild_formulas, TRUE); goals = embed_formulas_in_topforms(goals, FALSE); // Clausify print_separator(stdout, "PROCESS NON-CLAUSAL FORMULAS", TRUE); printf("\n%% Formulas that are not ordinary clauses:\n"); wild_formulas = process_input_formulas(wild_formulas, TRUE); goals = process_goal_formulas(goals, TRUE); /* negates goals */ print_separator(stdout, "end of process non-clausal formulas", TRUE); wild_formulas = plist_cat(wild_formulas, goals); return wild_formulas; } /* read_mace4_input */ /************* * * main() * *************/ int main(int argc, char **argv) { struct mace_options opt; Plist clauses; Mace_results results; /* Following says whether to ignore unregognized set/clear/assigns. */ BOOL prover_compatability_mode = member_args(argc, argv, "-c"); init_standard_ladr(); init_mace_options(&opt); /* We must do this before calling usage_message. */ init_attrs(); if (member_args(argc, argv, "help") || member_args(argc, argv, "-help")) { usage_message(stderr, &opt); exit(1); } print_banner(argc, argv, PROGRAM_NAME, PROGRAM_VERSION, PROGRAM_DATE, FALSE); set_program_name(PROGRAM_NAME); /* for conditional input */ signal(SIGINT, mace4_sig_handler); signal(SIGUSR1, mace4_sig_handler); signal(SIGSEGV, mace4_sig_handler); clauses = read_mace4_input(argc, argv, prover_compatability_mode, &opt); print_separator(stdout, "CLAUSES FOR SEARCH", TRUE); fwrite_clause_list(stdout, clauses, "mace4_clauses", CL_FORM_BARE); print_separator(stdout, "end of clauses for search", TRUE); results = mace4(clauses, &opt); mace4_exit(results->return_code); /* print messages and exit */ exit(0); /* won't happen */ } /* main */ LADR-2009-11A/mace4.src/negpropindex.c0000644000175000017500000002154711107445542016457 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" extern Symbol_data Symbols; extern Symbol_data *Sn_to_mace_sn; extern int Domain_size; extern int Relation_flag; extern int Negation_flag; extern int Eq_sn; void ****Index; /* The index is a simple discrimination tree in which each node is simply an array of pointers to the children. 0: Index void **** 1: sign negative positive void *** 2: symbol sym1 sym2 sym3 sym1 sym2 sym3 void ** 3: value v1 v2 v1 v2 v1 v2 v1 v2 v1 v2 v1 v2 void * 4: domain element of arg 0 plus the special value "eterm" 5: domain element of arg 1 plus the special value "eterm" etc. After level 3, the processing is recursive, and the * on the void get replenished. That's what makes the typing kludgy, but the compiler accepts it. The term space is not very big, so we construct a full tree at the start. */ /************* * * init_recurse() * *************/ static void *init_recurse(int n) { if (n == 0) return NULL; else { void **p; int i; p = calloc(Domain_size+1, sizeof(void *)); for (i = 0; i < Domain_size+1; i++) p[i] = init_recurse(n-1); /* assign a void** to a void* */ return p; } } /* init_recurse */ /************* * * init_negprop_index() * *************/ void init_negprop_index(void) { int sign, sym, val; int num_syms = 0; Symbol_data p; for(p = Symbols; p != NULL; p = p->next) num_syms++; Index = calloc(2, sizeof(void *)); for (sign = 0; sign < 2; sign++) { Index[sign] = calloc(num_syms, sizeof(void *)); for (sym = 0, p = Symbols; sym < num_syms; sym++, p = p->next) { /* Do nothing if this is the equality symbol. */ /* Do nothing if this is a relation symbol and we are negative. */ if (p->attribute != EQUALITY_SYMBOL && !(p->type == RELATION && sign == 0)) { int range_size = (p->type == FUNCTION ? Domain_size : 2); Index[sign][sym] = calloc(range_size, sizeof(void *)); for (val = 0; val < range_size; val++) { Index[sign][sym][val] = init_recurse(p->arity); } } } } } /* init_negprop_index */ /************* * * free_recurse() * *************/ static void free_recurse(int n, void **p) { if (n == 0) return; else { int i; for (i = 0; i < Domain_size+1; i++) free_recurse(n-1, p[i]); free(p); } } /* free_recurse */ /************* * * free_negprop_index() * *************/ void free_negprop_index(void) { int sign, sym, val; int num_syms = 0; Symbol_data p; for(p = Symbols; p != NULL; p = p->next) num_syms++; for (sign = 0; sign < 2; sign++) { for (sym = 0, p = Symbols; sym < num_syms; sym++, p = p->next) { /* Do nothing if this is the equality symbol. */ /* Do nothing if this is a relation symbol and we are negative. */ if (p->attribute != EQUALITY_SYMBOL && !(p->type == RELATION && sign == 0)) { int range_size = (p->type == FUNCTION ? Domain_size : 2); for (val = 0; val < range_size; val++) { free_recurse(p->arity, Index[sign][sym][val]); } free(Index[sign][sym]); } } free(Index[sign]); } free(Index); Index = NULL; } /* free_negprop_index */ /************* * * p_recurse() * *************/ static void p_recurse(void **p, int x, int n, int depth) { int j; for (j = 0; j < depth; j++) printf(" "); printf("[%d] %p", x, p); if (n == 0) { if (p != NULL) { Term t; for (t = (Term) p; t != NULL; t = t->u.vp) { printf(" : "); fwrite_term(stdout, (Term) t); } } printf("\n"); } else { int i; printf("\n"); for (i = 0; i < Domain_size+1; i++) { p_recurse(p[i], i, n-1, depth+1); } } } /* p_recurse */ /************* * * p_negprop_index() * *************/ void p_negprop_index(void) { int sign, sym, val; int num_syms = 0; Symbol_data p; for(p = Symbols; p != NULL; p = p->next) num_syms++; for (sign = 0; sign < 2; sign++) { for (sym = 0, p = Symbols; sym < num_syms; sym++, p = p->next) { /* Do nothing if this is the equality symbol. */ /* Do nothing if this is a relation symbol and we are negative. */ if (p->attribute != EQUALITY_SYMBOL && !(p->type == RELATION && sign == 0)) { int range_size = (p->type == FUNCTION ? Domain_size : 2); for (val = 0; val < range_size; val++) { printf("%s %s val=%d\n", sign == 0 ? "~" : "+", sn_to_str(p->sn), val); p_recurse(Index[sign][sym][val], -1, p->arity, 1); } } } } } /* p_negprop_index */ /************* * * insert_recurse() * *************/ static void insert_recurse(void **p, Term atom, Term t, int n, Mstate state) { Term arg = ARG(t,n); int i; /* If the argument is not a domain element, then use the subtree "Domain_size", which is 1 more than the maximum domain element. Note that many terms correspond to each leaf. */ i = (VARIABLE(arg) ? VARNUM(arg) : Domain_size); if (ARITY(t) == n+1) { /* We are at a leaf. Insert the atom into the list. If this is an eterm, then the list will never have more than one member. */ if (atom->u.vp != NULL) fatal_error("insert_recurse: atom link in use"); state->stack = update_and_push((void **) &(atom->u.vp),p[i],state->stack); state->stack = update_and_push((void **) &(p[i]), atom, state->stack); } else insert_recurse(p[i], atom, t, n+1, state); } /* insert_recurse */ /************* * * insert_negprop_eq() * * Insert an equality atom into the index. The parameters * alpha and val are used so that we don't have to figure * out (again) the orientation. * *************/ void insert_negprop_eq(Term atom, Term alpha, int val, Mstate state) { int sign = (NEGATED(atom) ? 0 : 1); int sym = Sn_to_mace_sn[SYMNUM(alpha)]->mace_sn; #if 0 printf("insert_negprop_eq: "); p_matom(atom); #endif if (ARITY(alpha) == 0) /* This could be handled if we need it. The assignments are atom->u.p = Index[sign][sym][val]; Index[sign][sym][val] = atom; */ fatal_error("insert_negprop_eq, arity 0"); else insert_recurse(Index[sign][sym][val], atom, alpha, 0, state); } /* insert_negprop_eq */ /************* * * insert_negprop_noneq() * * Insert a nonequality atom into the index. * *************/ void insert_negprop_noneq(Term atom, Mstate state) { int val = (NEGATED(atom) ? 0 : 1); int sym = Sn_to_mace_sn[SYMNUM(atom)]->mace_sn; #if 0 printf("insert_negprop_noneq: "); p_matom(atom); #endif if (ARITY(atom) == 0) /* This could be handled if we need it. The assignments are atom->u.p = Index[1][sym][val]; Index[1][sym][val] = atom; */ fatal_error("insert_negprop_noneq, arity 0"); else insert_recurse(Index[1][sym][val], atom, atom, 0, state); } /* insert_negprop_noneq */ /************* * * nterm() * * Check if a term is "nearly evaluable". That is, exactly * one argument is not a domain element, and that argument * is an eterm. For example, f(2,g(3)) is an nterm. * * If so, set "position" to the index of the eterm argument * and "id" to the ID of the eterm argument. * *************/ BOOL nterm(Term t, int *ppos, int *pid) { if (t == NULL || VARIABLE(t) || arith_rel_term(t) || arith_op_term(t)) return FALSE; else { int i; int pos = -1; for (i = 0; i < ARITY(t); i++) { if (!VARIABLE(ARG(t,i))) { if (pos != -1) return FALSE; else if (eterm(ARG(t,i), pid)) pos = i; else return FALSE; } } if (pos == -1) return FALSE; else { *ppos = pos; return TRUE; } } } /* nterm */ /************* * * negprop_find_near() * *************/ static Term negprop_find_near_recurse(void **p, Term query, int pos, int n) { int i = (pos == 0 ? Domain_size : VARNUM(ARG(query, n))); if (ARITY(query) == n+1) return (Term) p[i]; else return negprop_find_near_recurse(p[i], query, pos-1, n+1); } Term negprop_find_near(int sign, int sym, int val, Term query, int pos) { return negprop_find_near_recurse(Index[sign][sym][val], query, pos, 0); } /* negprop_find_near */ LADR-2009-11A/mace4.src/estack.h0000644000175000017500000000426510607745010015227 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_ESTACK_H #define TP_ESTACK_H #include "../ladr/header.h" #include "../ladr/memory.h" /* INTRODUCTION Estacks can be used to manage generic pointer assignments that must be undone at a later time. This is typically used in backtracking procedures that work by moving pointers around. Say you need to assign the value of one pointer *a to another pointer *b, and some time later you'll need to undo that assignment, restoring a to its old value. Instead of using a special-purpose data structure to store a's old value, you can write
    estack = update_and_push((void **) &a, b, estack);
    ...
    restore_from_stack(estack);
The update_and_push call assigns b to a and records the assignment in the Estack. The restore_from_stack call undoes a whole stack of assignments.

This mechanism uses void pointers for both a and b, so it works for any kind of pointer. If b is not a pointer (for example an integral type), make sure it is the same size as a pointer. */ /* Public definitions */ typedef struct estack * Estack; /* End of public definitions */ /* Public function prototypes from estack.c */ /* from estack.c */ void fprint_estack_mem(FILE *fp, int heading); void p_estack_mem(void); void free_estack_memory(void); int estack_bytes(void); Estack update_and_push(void **p, void *new, Estack stack); void restore_from_stack(Estack stack); void zap_estack(Estack s); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/print.c0000644000175000017500000002507710654416431015114 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "../ladr/banner.h" extern Symbol_data Symbols; extern int Number_of_cells; extern struct cell *Cells; extern Term *Domain; extern int Domain_size; extern int Negation_flag; extern int Eq_sn; /* Statistics for entire run */ extern Clock Mace4_clock; extern unsigned Total_models; extern struct mace_stats Mstats; /************* * * f[01234]_val() * *************/ static int id2val(int id) { return (Cells[id].value == NULL ? -1 : VARNUM(Cells[id].value)); } /* id2val */ static int f0_val(int base) { int id = X0(base); return id2val(id); } /* f0_val */ static int f1_val(int base, int i) { int id = X1(base,i); return id2val(id); } /* f1_val */ static int f2_val(int base, int i, int j) { int id = X2(base,i,j); return id2val(id); } /* f2_val */ /************* * * p_model() * *************/ void p_model(BOOL print_head) { Symbol_data p; int n = Domain_size; if (print_head) { print_separator(stdout, "MODEL", TRUE); printf("\n%% Model %d at %.2f seconds.\n", Total_models, user_seconds()); } for (p = Symbols; p != NULL; p = p->next) { char *name = sn_to_str(p->sn); if (p->attribute != EQUALITY_SYMBOL) { /* This prints both relations and functions. */ if (p->arity == 0) { int v = f0_val(p->base); if (v < 0) printf("\n %s : -\n", name); else printf("\n %s : %d\n", name, v); } else if (p->arity == 1) { char *s1 = n <= 10 ? "%2d" : "%3d"; char *s2 = n <= 10 ? "--" : "---"; char *s3 = n <= 10 ? " -" : " -"; int i; for (i = 0; i < n; i++) { printf("\n %s :\n", name); printf(" "); for (i = 0; i < n; i++) printf(s1, i); printf("\n ---"); for (i = 0; i < n; i++) printf(s2); printf("\n "); for (i = 0; i < n; i++) { int v = f1_val(p->base, i); if (v < 0) printf(s3); else printf(s1, v); } printf("\n"); } } else if (p->arity == 2) { char *s1 = n <= 10 ? "%2d" : "%3d"; char *s2 = n <= 10 ? "--" : "---"; char *s3 = n <= 10 ? " -" : " -"; int i, j; printf("\n %s :\n", name); printf(" |"); for (i = 0; i < n; i++) printf(s1, i); printf("\n --+"); for (i = 0; i < n; i++) printf(s2); printf("\n"); for (i = 0; i < n; i++) { printf("%5d |", i); for (j = 0; j < n; j++) { int v = f2_val(p->base, i, j); if (v < 0) printf(s3); else printf(s1, v); } printf("\n"); } } else { int n = int_power(Domain_size, p->arity); int i; Variable_style save_style = variable_style(); set_variable_style(INTEGER_STYLE); for (i = 0; i < n; i++) { int id = p->base + i; fwrite_term(stdout, Cells[id].eterm); if (Cells[id].value == NULL) printf(" = -.\n"); else printf(" = %d.\n", VARNUM(Cells[id].value)); } set_variable_style(save_style); } } } if (print_head) print_separator(stdout, "end of model", TRUE); } /* p_model */ /************* * * print_model_standard() * *************/ void print_model_standard(FILE *fp, BOOL print_head) { int syms_printed; Symbol_data s; if (print_head) print_separator(fp, "MODEL", TRUE); fprintf(fp, "\ninterpretation( %d, [number=%d, seconds=%d], [\n", Domain_size, Total_models, (int) user_seconds()); syms_printed = 0; for (s = Symbols; s != NULL; s = s->next) { if (s->attribute != EQUALITY_SYMBOL) { int i, n; if (syms_printed > 0) fprintf(fp, ",\n"); fprintf(fp, "\n %s(%s%s", s->type == FUNCTION ? "function" : "relation", sn_to_str(s->sn), s->arity == 0 ? "" : "(_"); for (i = 1; i < s->arity; i++) fprintf(fp, ",_"); fprintf(fp,"%s, [%s", s->arity == 0 ? "" : ")", s->arity >= 2 ? "\n\t\t\t " : ""); n = int_power(Domain_size, s->arity); for (i = 0; i < n; i++) { int id = s->base + i; if (Cells[id].value == NULL) fprintf(fp, "-"); else fprintf(fp, "%2d", VARNUM(Cells[id].value)); if (i < n-1) fprintf(fp, ",%s", (i+1) % Domain_size == 0 ? "\n\t\t\t " : ""); else fprintf(fp, " ])"); } syms_printed++; } } fprintf(fp, "\n]).\n"); if (print_head) print_separator(fp, "end of model", TRUE); } /* print_model_standard */ /************* * * interp_term() * * Construct a term representing the current interpretation, e.g. * * interpretation( 3, [ * function(B, [2]), * function(g(_), [1,0,1])]). * *************/ Term interp_term(void) { Symbol_data s; Term symlist = get_nil_term(); for (s = Symbols; s != NULL; s = s->next) { if (s->attribute != EQUALITY_SYMBOL) { int i, n; Term entry, symterm, tableterm; symterm = get_rigid_term_dangerously(s->sn, s->arity); for (i = 0; i < s->arity; i++) ARG(symterm,i) = get_variable_term(i); n = int_power(Domain_size, s->arity); tableterm = get_nil_term(); for (i = n-1; i >= 0; i--) { int id = s->base + i; Term it; if (Cells[id].value == NULL) fatal_error("interp_term, incomplete interpretation"); it = nat_to_term(VARNUM(Cells[id].value)); tableterm = listterm_cons(it, tableterm); } entry = build_binary_term(str_to_sn(s->type == FUNCTION ? "function" : "relation", 2), symterm, tableterm); symlist = listterm_cons(entry, symlist); } } return build_binary_term(str_to_sn("interpretation", 2), nat_to_term(Domain_size), symlist); } /* interp_term */ /************* * * p_matom() * *************/ void p_matom(Term atom) { if (atom == NULL) printf("(NULL)"); else if (!NEGATED(atom)) fwrite_term(stdout, atom); else if (EQ_TERM(atom)){ fwrite_term(stdout, ARG(atom,0)); printf(" != "); fwrite_term(stdout, ARG(atom,1)); } else { printf("~("); fwrite_term(stdout, atom); printf(")"); } printf(".\n"); } /* p_matom */ /************* * * p_mclause() * *************/ void p_mclause(Mclause c) { int i; printf("numlits=%d, active=%ld, subsumed=%d: ", c->numlits, c->u.active, c->subsumed); for (i = 0; i < c->numlits; i++) { Term atom = LIT(c,i); if (!NEGATED(atom)) fwrite_term(stdout, atom); else { printf("~("); fwrite_term(stdout, atom); printf(")"); } if (i < c->numlits-1) printf(" | "); else printf(".\n"); } } /* p_mclause */ /************* * * p_eterms() * *************/ static int eterms_count(Term t) { return (t == NULL ? 0 : 1 + eterms_count(t->u.vp)); } void p_eterms(void) { int i, j; printf("\n------- Cells --------\n"); for (i = 0; i < Number_of_cells; i++) { int n = eterms_count(Cells[i].occurrences); if (n > 0) { fwrite_term(stdout, Cells[i].occurrences); printf(": %d occ, id=%d, val=", n, i); if (Cells[i].value == NULL) printf("NULL"); else fwrite_term(stdout, Cells[i].value); printf(", pvals="); for (j = 0; j < id_to_domain_size(i); j++) { if (Cells[i].possible[j] == NULL) printf(" -"); else printf("%2d", j); } printf("\n"); } } } /* p_eterms */ /************* * * p_stats() * *************/ void p_stats(void) { print_separator(stdout, "STATISTICS", TRUE); printf("\nFor domain size %d.\n\n",Domain_size); printf("Current CPU time: %.2f seconds ", clock_seconds(Mace4_clock)); printf("(total CPU time: %.2f seconds).\n",user_seconds()); printf("Ground clauses: seen=%u, kept=%u.\n", Mstats.ground_clauses_seen, Mstats.ground_clauses_kept); printf("Selections=%u, assignments=%u, propagations=%u, current_models=%u.\n", Mstats.selections, Mstats.assignments, Mstats.propagations, Mstats.current_models); printf("Rewrite_terms=%u, rewrite_bools=%u, indexes=%u.\n", Mstats.rewrite_terms, Mstats.rewrite_bools, Mstats.indexes); printf("Rules_from_neg_clauses=%u, cross_offs=%d.\n", Mstats.rules_from_neg, Mstats.cross_offs); #if 0 printf("Negative propagation:\n"); printf(" attempts agone egone\n"); printf("Neg_elim %10u %10u %10u\n", Mstats.neg_elim_attempts, Mstats.neg_elim_agone, Mstats.neg_elim_egone); printf("Neg_assign %10u %10u %10u\n", Mstats.neg_assign_attempts, Mstats.neg_assign_agone, Mstats.neg_assign_egone); printf("Neg_near_elim %10u %10u %10u\n", Mstats.neg_near_elim_attempts, Mstats.neg_near_elim_agone, Mstats.neg_near_elim_egone); printf("Neg_near_assign %10u %10u %10u\n", Mstats.neg_near_assign_attempts, Mstats.neg_near_assign_agone, Mstats.neg_near_assign_egone); #endif print_separator(stdout, "end of statistics", TRUE); } /* p_stats */ /************* * * p_mem() * *************/ void p_mem(void) { printf("\n------------- memory usage (for entire run) -------------------\n"); printf("\nTotal malloced: %d megabytes\n", megs_malloced()); fprint_strbuf_mem(stdout, 1); fprint_parse_mem(stdout, 0); fprint_glist_mem(stdout, 0); fprint_term_mem(stdout, 0); fprint_topform_mem(stdout, 0); fprint_clist_mem(stdout, 0); fprint_mclause_mem(stdout, 0); fprint_mstate_mem(stdout, 0); fprint_estack_mem(stdout, 0); memory_report(stdout); } /* p_mem */ /************* * * reset_current_stats() * *************/ void reset_current_stats(void) { Mstats.current_models = 0; Mstats.selections = 0; Mstats.assignments = 0; Mstats.propagations = 0; Mstats.cross_offs = 0; Mstats.rewrite_terms = 0; Mstats.rewrite_bools = 0; Mstats.indexes = 0; Mstats.ground_clauses_seen = 0; Mstats.ground_clauses_kept = 0; Mstats.rules_from_neg = 0; Mstats.neg_elim_attempts = 0; Mstats.neg_elim_agone = 0; Mstats.neg_elim_egone = 0; Mstats.neg_assign_attempts = 0; Mstats.neg_assign_agone = 0; Mstats.neg_assign_egone = 0; Mstats.neg_near_assign_attempts = 0; Mstats.neg_near_assign_agone = 0; Mstats.neg_near_assign_egone = 0; Mstats.neg_near_elim_attempts = 0; Mstats.neg_near_elim_agone = 0; Mstats.neg_near_elim_egone = 0; } /* reset_current_stats */ LADR-2009-11A/mace4.src/help0000644000175000017500000000237611106737674014474 0ustar mccunemccune I have to evaluate ground expressions involving division by 0. Expressions have (+ * - div mod < <= > >= =) and the leaves are integers. div and mod produce integers. 1. We can't just fail when see division by zero, because, e.g., 3/0 = 3/0 has to evaluate to TRUE. 2. We can't say that division by 0 produces a special value "undefined", which is propagated up to the top of the expression, because, e.g., 3/0 = 3/0 (undefined=undefined) has to evaluate to TRUE, and 3/0 = 4/0 (undefined=undefined) has to evaluate to FALSE. 3. <+,-,*> is the ring of integers, so simplification with x*0=0 and x-x = 0 can get rid of subexpressions involving division by 0. Current idea: starting with an expression with < <= > >= or = at the root, simplify to a unique canonical form. If that gets rid of all division by 0 (including mod 0), we should have TRUE or FALSE, and we're done. Otherwise, if the root is =, it is TRUE iff the 2 arguments are identical. If it is some other relation, it is FALSE. However, I don't know if this theory has unique canonical forms. such that two terms are equal iff their canincal forms are identical. What is this theory, anyway? <+,-,*> is the ring of integers, but when we add / and mod, we don't have a field (no multiplicative inverses). LADR-2009-11A/mace4.src/t1.in0000644000175000017500000000010511156472006014447 0ustar mccunemccuneop(490,infix,"!!"). formulas(assumptions). P(!!(a,b)). end_of_list. LADR-2009-11A/mace4.src/negprop.c0000644000175000017500000002234210607745010015416 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "propagate.h" /* External variables defined in mace4.c. */ extern Mace_options Opt; extern struct cell *Cells; extern Symbol_data *Sn_to_mace_sn; extern int Domain_size; extern Term *Domain; extern int Relation_flag; /* term flag */ extern struct mace_stats Mstats; /************* * * nterm_id() * * Given an nterm, e.g., f(3,g(2)), find the ID of the eterm * obtained by replacing the subterm with 0, that is, f(3,0). * *************/ static int nterm_id(Term t) { int id = Sn_to_mace_sn[SYMNUM(t)]->base; int mult = 1; int i; for (i = ARITY(t)-1; i >= 0; i--) { if (VARIABLE(ARG(t,i))) id += VARNUM(ARG(t,i)) * mult; mult *= Domain_size; } return id; } /* nterm_id */ /************* * * negprop_elim() * * Given an elimination, e.g., f(1,2)!=3, derive new eliminations * by finding appropriate near assignments in the negprop index. * *************/ static void negprop_elim(int id, Term beta, Mstate state) { struct cell *c = Cells + id; int arity = c->symbol->arity; int sym = c->symbol->mace_sn; Term alpha = c->eterm; int i; for (i = 0; i < arity; i++) { Term results = negprop_find_near(1, sym, VARNUM(beta), alpha, i); while (results) { /* We don't know the orientation. */ Term found_alpha = (VARIABLE(ARG(results,0)) ? ARG(results,1) : ARG(results,0)); #if 0 fwrite_term(stdout, alpha); printf(" != %d ELIM ", VARNUM(beta)); p_matom(results); #endif if (VARIABLE(found_alpha)) Mstats.neg_elim_agone++; else { Term e = ARG(found_alpha, i); int subterm_id; if (!eterm(e, &subterm_id)) Mstats.neg_elim_egone++; else { Mstats.neg_elim_attempts++; new_elimination(subterm_id, ARG(alpha,i), state); if (!state->ok) return; /* contradiction */ } } results = results->u.vp; } /* results */ } /* position */ } /* negprop_elim */ /************* * * negprop_assign() * * Given an assignment, derive new eliminations by finding near * assignments and near eliminations in the negprop index. * *************/ static void negprop_assign(int id, Mstate state) { struct cell *c = Cells + id; int arity = c->symbol->arity; int sym = c->symbol->mace_sn; Term alpha = c->eterm; Term beta = c->value; int i; if (c->symbol->type == FUNCTION) { for (i = 0; i < arity; i++) { Term results = negprop_find_near(0, sym, VARNUM(beta), alpha, i); while (results) { /* We don't know the orientation. */ Term found_alpha = (VARIABLE(ARG(results,0)) ? ARG(results,1) : ARG(results,0)); #if 0 fwrite_term(stdout, alpha); printf(" = %d ASSIGN1 ", VARNUM(beta)); p_matom(results); #endif if (VARIABLE(found_alpha)) Mstats.neg_assign_agone++; else { Term e = ARG(found_alpha, i); int subterm_id; if (!eterm(e, &subterm_id)) Mstats.neg_assign_egone++; else { Mstats.neg_assign_attempts++; new_elimination(subterm_id, ARG(alpha,i), state); if (!state->ok) return; /* contradiction */ } } results = results->u.vp; } /* results */ } /* position */ } /* FUNCTION */ /* Now make inferences like f(3,4)=5, f(3,g(2))=6 -> g(2)!=4. This applies to nonequations as well as equations, because P(0) is handled as P(0)=1, and ~P(0) is handled as P(0)=0. */ for (i = 0; i < arity; i++) { int j; int n = (c->symbol->type == FUNCTION ? Domain_size : 2); for (j = 0; j < n; j++) { if (j != VARNUM(beta)) { Term results = negprop_find_near(1, sym, j, alpha, i); /* results can look like: f(1,2)=3, 3=f(1,2), P(2), ~P(3) */ while (results) { Term found_alpha; if (c->symbol->type == RELATION) found_alpha = results; else found_alpha = (VARIABLE(ARG(results,0)) ? ARG(results,1) : ARG(results,0)); #if 0 fwrite_term(stdout, alpha); printf(" = %d ASSIGN2 ", VARNUM(beta)); p_matom(results); #endif if (VARIABLE(found_alpha)) Mstats.neg_assign_agone++; else { Term e = ARG(found_alpha, i); int subterm_id; if (!eterm(e, &subterm_id)) Mstats.neg_assign_egone++; else { Mstats.neg_assign_attempts++; new_elimination(subterm_id, ARG(alpha,i), state); if (!state->ok) return; /* contradiction */ } } results = results->u.vp; } /* results */ } /* j ok */ } /* domain */ } /* position */ } /* negprop_assign */ /************* * * negprop_near_elim() * * Given a near elimination, derive new eliminations by finding * appropriate assignments in the cell table. * *************/ static void negprop_near_elim(int subterm_id, Term alpha, Term beta, int pos, Mstate state) { if (VARIABLE(alpha)) Mstats.neg_near_elim_agone++; else if (VARIABLE(ARG(alpha,pos))) Mstats.neg_near_elim_egone++; else { int i; int id = nterm_id(alpha); int increment = int_power(Domain_size, (ARITY(alpha) - 1) - pos); for (i = 0; i < Domain_size; i++) { if (Cells[id].value == beta) { Mstats.neg_near_elim_attempts++; new_elimination(subterm_id, Domain[i], state); if (!state->ok) return; } id += increment; } } } /* negprop_near_elim */ /************* * * negprop_near_assign() * * Given a near assignment, derive new eliminations by finding * eliminations and assignments in the cell table. * *************/ static void negprop_near_assign(int subterm_id, Term alpha, Term beta, int pos, Mstate state) { if (VARIABLE(alpha)) Mstats.neg_near_assign_agone++; else if (VARIABLE(ARG(alpha,pos))) Mstats.neg_near_assign_egone++; else { int i; int base_id = nterm_id(alpha); int increment = int_power(Domain_size, (ARITY(alpha) - 1) - pos); int id = base_id; if (!LITERAL(alpha)) { for (i = 0; i < Domain_size; i++) { if (Cells[id].possible[VARNUM(beta)] == NULL) { Mstats.neg_near_assign_attempts++; new_elimination(subterm_id, Domain[i], state); if (!state->ok) return; } id += increment; } /* domain */ } /* equation */ /* Now make inferences like f(3,g(2))=5, f(3,4)=6 -> g(2)!=4. This applies to nonequations as well as equations, because P(0) is handled as P(0)=1, and ~P(0) is handled as P(0)=0. */ { int j; int n = (LITERAL(alpha) ? 2 : Domain_size); for (j = 0; j < n; j++) { if (j != VARNUM(beta)) { id = base_id; for (i = 0; i < Domain_size; i++) { if (Cells[id].value == Domain[j]) { Mstats.neg_near_assign_attempts++; new_elimination(subterm_id, Domain[i], state); if (!state->ok) return; } id += increment; } /* domain */ } /* equation */ } /* beta */ } /* block */ } } /* negprop_near_assign */ /************* * * propagate_negative() * * There are 4 inference rules to derive new eliminations: * * NEG_ELIM - new clause is an elimination: * NEG_ASSIGN - new clause is a assignment: * NEG_ELIM_NEAR - new clause is an near elimination: * NEG_ASSIGN_NEAR - new clause is a near assignment: * * type id alpha beta pos comment * * (for the first 2, id gives the alpha, e.g., 32 is g(0)) * * ASSIGNMENT 32 NULL NULL -1 g(0)={in table} * ELIMINATION 32 NULL 2 -1 g(0)!=2 * * (for the next 4, id gives the eterm subterm, e.g., 32 is g(0)) * * NEAR_ASSIGNMENT 32 g(g(0)) 2 0 g(g(0))=2 * NEAR_ASSIGNMENT 32 P(g(0)) 1 0 P(g(0)) * NEAR_ASSIGNMENT 32 P(g(0)) 0 0 ~P(g(0)) * NEAR_ELIMINATION 32 g(g(0)) 2 0 g(g(0))!=2 * * Notes: * * Eterms and alphas may have been simplified by the time they arrive here. * * For ASSIGNMENT, the assignment has already been made * For ELIMINATION, the cross-off has already been done. * * If a contradiction is found, set state->ok to FALSE. * *************/ void propagate_negative(int type, int id, Term alpha, Term beta, int pos, Mstate state) { switch (type) { case ELIMINATION: if (flag(Opt->neg_elim)) negprop_elim(id, beta, state); break; case ASSIGNMENT: if (flag(Opt->neg_assign)) negprop_assign(id, state); break; case NEAR_ELIMINATION: if (flag(Opt->neg_elim_near)) negprop_near_elim(id, alpha, beta, pos, state); break; case NEAR_ASSIGNMENT: if (flag(Opt->neg_assign_near)) negprop_near_assign(id, alpha, beta, pos, state); break; } } /* propagate_negative */ LADR-2009-11A/mace4.src/h1.out0000644000175000017500000001225211156471214014642 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2009-02A, February 2009. Process 24442 was started by mccune on cleo, Fri Mar 13 08:49:39 2009 The command was "mace4 -f h1.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file h1.in op(500,infix,"+"). op(490,infix,";"). op(490,infix,"*"). op(480,postfix,"^"). op(490,infix,"||"). op(490,infix,"/\"). op(490,infix,"!!"). if(Prover9). % Conditional input omitted. end_if. if(Mace4). % Conditional input included. assign(max_seconds,60). end_if. formulas(assumptions). x + y = y + x. x + 0 = x. x + (y + z) = (x + y) + z. x ; 1 = x & 1 ; x = x. x ; (y ; z) = (x ; y) ; z. x * 1 = x & 1 * x = x. x * (y * z) = (x * y) * z. (x + y) ; z = x ; z + y ; z. (x + y) * z = x * z + y * z. z ; (x + y) = z ; x + z ; y. z * (x + y) = z * x + z * y. 0 ; x = 0. x ; 0 = 0. 0 * x = 0. x * 0 = 0. x + x = x. x <= y <-> x + y = y. (x * x1) ; (y * y1) <= (x1 ; y) * (x ; y1). x /\ y <= x. x /\ y <= y. z <= x & z <= y -> z <= x /\ y. x || y = (x ; y) /\ (y ; x). x !! y = (x /\ 1) ; y + x ; (y /\ 1). end_of_list. formulas(goals). x !! y = y !! x. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 x ; 1 = x & 1 ; x = x # label(non_clause). [assumption]. 2 x * 1 = x & 1 * x = x # label(non_clause). [assumption]. 3 x <= y <-> x + y = y # label(non_clause). [assumption]. 4 z <= x & z <= y -> z <= x /\ y # label(non_clause). [assumption]. 5 x !! y = y !! x # label(non_clause) # label(goal). [goal]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). x + y = y + x. x + 0 = x. x + (y + z) = (x + y) + z. x ; 1 = x. 1 ; x = x. x ; (y ; z) = (x ; y) ; z. x * 1 = x. 1 * x = x. x * (y * z) = (x * y) * z. (x + y) ; z = x ; z + y ; z. (x + y) * z = x * z + y * z. x ; (y + z) = x ; y + x ; z. x * (y + z) = x * y + x * z. 0 ; x = 0. x ; 0 = 0. 0 * x = 0. x * 0 = 0. x + x = x. -(x <= y) | x + y = y. x <= y | x + y != y. (x * y) ; (z * u) <= (y ; z) * (x ; u). x /\ y <= x. x /\ y <= y. -(x <= y) | -(x <= z) | x <= y /\ z. x || y = (x ; y) /\ (y ; x). x !! y = (x /\ 1) ; y + x ; (y /\ 1). c2 !! c1 != c1 !! c2. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 1. ============================== DOMAIN SIZE 2 ========================= ============================== STATISTICS ============================ For domain size 2. Current CPU time: 0.00 seconds (total CPU time: 0.01 seconds). Ground clauses: seen=129, kept=58. Selections=3, assignments=6, propagations=28, current_models=0. Rewrite_terms=121, rewrite_bools=61, indexes=0. Rules_from_neg_clauses=6, cross_offs=6. ============================== end of statistics ===================== ============================== DOMAIN SIZE 3 ========================= ============================== STATISTICS ============================ For domain size 3. Current CPU time: 0.00 seconds (total CPU time: 0.12 seconds). Ground clauses: seen=391, kept=251. Selections=2425, assignments=7275, propagations=14992, current_models=0. Rewrite_terms=458623, rewrite_bools=164648, indexes=14310. Rules_from_neg_clauses=4543, cross_offs=12388. ============================== end of statistics ===================== ============================== DOMAIN SIZE 4 ========================= ============================== MODEL ================================= interpretation( 4, [number=1, seconds=4], [ function(c1, [ 2 ]), function(c2, [ 3 ]), function(!!(_,_), [ 0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 0, 0, 0, 3, 2, 3 ]), function(*(_,_), [ 0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 0, 2, 0, 3, 2, 3 ]), function(+(_,_), [ 0, 1, 2, 3, 1, 1, 1, 1, 2, 1, 2, 3, 3, 1, 3, 3 ]), function(/\(_,_), [ 0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 2, 2, 0, 3, 2, 3 ]), function(;(_,_), [ 0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 0, 0, 0, 3, 2, 3 ]), function(||(_,_), [ 0, 0, 0, 0, 0, 1, 2, 3, 0, 2, 0, 0, 0, 3, 0, 3 ]), relation(<=(_,_), [ 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 4. Current CPU time: 0.00 seconds (total CPU time: 4.78 seconds). Ground clauses: seen=921, kept=696. Selections=36759, assignments=147005, propagations=665193, current_models=1. Rewrite_terms=18503894, rewrite_bools=6591134, indexes=1533814. Rules_from_neg_clauses=132667, cross_offs=660041. ============================== end of statistics ===================== User_CPU=4.78, System_CPU=0.01, Wall_clock=9. Exiting with 1 model. Process 24442 exit (max_models) Fri Mar 13 08:49:48 2009 The process finished Fri Mar 13 08:49:48 2009 LADR-2009-11A/mace4.src/propagate.h0000644000175000017500000000263010607745010015731 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_PROPAGATE_H #define TP_PROPAGATE_H /* types of items in the Todo list */ #define ASSIGNMENT 0 /* f(1,2)=3 P(1,2) ~P(1,2) */ #define NEAR_ASSIGNMENT 1 /* f(1,g(2))=3 P(1,g(2)) ~P(1,g(2)) */ #define ELIMINATION 2 /* f(1,2) != 3 */ #define NEAR_ELIMINATION 3 /* f(1,g(2)) != 3 */ /* Public function prototypes from propagate.c */ BOOL eterm(Term t, int *id); Term decode_eterm_id(int id); void process_initial_clause(Mclause c, Mstate state); Estack assign_and_propagate(int id, Term value); Estack reset_estack(void); void new_elimination(int id, Term beta, Mstate state); #endif /* conditional compilation of whole file */ LADR-2009-11A/mace4.src/puzzles/0000755000175000017500000000000011110444601015301 5ustar mccunemccuneLADR-2009-11A/mace4.src/puzzles/f1.in~0000644000175000017500000000120511107462354016346 0ustar mccunemccuneop(400, infix, +). op(390, infix, *). redeclare(conjunction, and). % change the conjunction symbol to and. set(arithmetic). formulas(assumptions). ((SIEVE_1*cons_2 >= SIEVE_1*filter_2 and SIEVE_1*cons_3 >= SIEVE_1*filter_3) and filter_2*nil_1 + filter_3 >= nil_1 and cons_2*filter_2 >= if_4 and cons_3*filter_2 + filter_3 >= if_1*isdiv_3 + if_5 and if_4 >= filter_2 and if_1*true_1 + if_5 >= filter_3 and if_4 >= cons_2*filter_2 and false_1*if_1 + if_5 >= cons_2*filter_3 + cons_3 and isdiv_3 >= true_1 and isdiv_3 >= false_1 and (SIEVE_1*cons_3 > SIEVE_1*filter_3 and SIEVE_1*cons_2 >= 0 and SIEVE_1*cons_3 + SIEVE_2 >= 0)). end_of_list. LADR-2009-11A/mace4.src/puzzles/zebra2.out0000644000175000017500000001203711110442740017224 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15833 was started by mccune on cleo, Mon Nov 17 21:34:40 2008 The command was "../mace4 -f zebra2.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file zebra2.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. assign(domain_size,5). % assign(domain_size, 5) -> assign(start_size, 5). % assign(domain_size, 5) -> assign(end_size, 5). formulas(assumptions). England = Red. Lucky = Juice. Spain = Dog. Ukraine = Tea. Norway = 0. Japan = Parlaiment. Kool = Yellow. neighbors(Kool,Horse). neighbors(Chesterfield,Fox). Coffee = Green. neighbors(Norway,Blue). successor(Green,Ivory). Winston = Snail. Milk = 2. successor(x,y) <-> x + 1 = y. neighbors(x,y) <-> successor(x,y) | successor(y,x). end_of_list. list(distinct). [England,Spain,Ukraine,Japan,Norway]. [Dog,Snail,Horse,Zebra,Fox]. [Water,Milk,Juice,Tea,Coffee]. [Red,Blue,Yellow,Ivory,Green]. [Lucky,Winston,Kool,Chesterfield,Parlaiment]. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 successor(x,y) <-> x + 1 = y # label(non_clause). [assumption]. 2 neighbors(x,y) <-> successor(x,y) | successor(y,x) # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). England = Red. Lucky = Juice. Spain = Dog. Ukraine = Tea. Norway = 0. Japan = Parlaiment. Kool = Yellow. neighbors(Kool,Horse). neighbors(Chesterfield,Fox). Coffee = Green. neighbors(Norway,Blue). successor(Green,Ivory). Winston = Snail. Milk = 2. -successor(x,y) | x + 1 = y. successor(x,y) | x + 1 != y. -neighbors(x,y) | successor(x,y) | successor(y,x). neighbors(x,y) | -successor(x,y). neighbors(x,y) | -successor(y,x). England != Spain. England != Ukraine. England != Japan. England != Norway. Spain != Ukraine. Spain != Japan. Spain != Norway. Ukraine != Japan. Ukraine != Norway. Japan != Norway. Dog != Snail. Dog != Horse. Dog != Zebra. Dog != Fox. Snail != Horse. Snail != Zebra. Snail != Fox. Horse != Zebra. Horse != Fox. Zebra != Fox. Water != Milk. Water != Juice. Water != Tea. Water != Coffee. Milk != Juice. Milk != Tea. Milk != Coffee. Juice != Tea. Juice != Coffee. Tea != Coffee. Red != Blue. Red != Yellow. Red != Ivory. Red != Green. Blue != Yellow. Blue != Ivory. Blue != Green. Yellow != Ivory. Yellow != Green. Ivory != Green. Lucky != Winston. Lucky != Kool. Lucky != Chesterfield. Lucky != Parlaiment. Winston != Kool. Winston != Chesterfield. Winston != Parlaiment. Kool != Chesterfield. Kool != Parlaiment. Chesterfield != Parlaiment. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 2. ============================== DOMAIN SIZE 5 ========================= ============================== MODEL ================================= interpretation( 5, [number=1, seconds=0], [ function(Blue, [ 1 ]), function(Chesterfield, [ 1 ]), function(Coffee, [ 3 ]), function(Dog, [ 4 ]), function(England, [ 2 ]), function(Fox, [ 0 ]), function(Green, [ 3 ]), function(Horse, [ 1 ]), function(Ivory, [ 4 ]), function(Japan, [ 3 ]), function(Juice, [ 4 ]), function(Kool, [ 0 ]), function(Lucky, [ 4 ]), function(Milk, [ 2 ]), function(Norway, [ 0 ]), function(Parlaiment, [ 3 ]), function(Red, [ 2 ]), function(Snail, [ 2 ]), function(Spain, [ 4 ]), function(Tea, [ 1 ]), function(Ukraine, [ 1 ]), function(Winston, [ 2 ]), function(Yellow, [ 0 ]), relation(neighbors(_,_), [ 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]), relation(successor(_,_), [ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]), function(Water, [ 0 ]), function(Zebra, [ 3 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 5. Current CPU time: 0.00 seconds (total CPU time: 0.01 seconds). Ground clauses: seen=189, kept=113. Selections=8, assignments=33, propagations=89, current_models=1. Rewrite_terms=254, rewrite_bools=199, indexes=1. Rules_from_neg_clauses=17, cross_offs=92. ============================== end of statistics ===================== User_CPU=0.01, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15833 exit (max_models) Mon Nov 17 21:34:40 2008 The process finished Mon Nov 17 21:34:40 2008 LADR-2009-11A/mace4.src/puzzles/temp0000644000175000017500000000012311110444601016165 0ustar mccunemccunef1.in kenken6.in queens1.in queens2.in send-money.in sudoku.in zebra1.in zebra2.in LADR-2009-11A/mace4.src/puzzles/f1.in0000644000175000017500000000113611110442634016144 0ustar mccunemccuneset(arithmetic). redeclare(conjunction, and). % change the conjunction symbol to and. formulas(assumptions). ((SIEVE_1*cons_2 >= SIEVE_1*filter_2 and SIEVE_1*cons_3 >= SIEVE_1*filter_3) and filter_2*nil_1 + filter_3 >= nil_1 and cons_2*filter_2 >= if_4 and cons_3*filter_2 + filter_3 >= if_1*isdiv_3 + if_5 and if_4 >= filter_2 and if_1*true_1 + if_5 >= filter_3 and if_4 >= cons_2*filter_2 and false_1*if_1 + if_5 >= cons_2*filter_3 + cons_3 and isdiv_3 >= true_1 and isdiv_3 >= false_1 and (SIEVE_1*cons_3 > SIEVE_1*filter_3 and SIEVE_1*cons_2 >= 0 and SIEVE_1*cons_3 + SIEVE_2 >= 0)). end_of_list. LADR-2009-11A/mace4.src/puzzles/zebra1.out0000644000175000017500000002250711110442740017226 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15832 was started by mccune on cleo, Mon Nov 17 21:34:40 2008 The command was "../mace4 -f zebra1.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file zebra1.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. assign(domain_size,5). % assign(domain_size, 5) -> assign(start_size, 5). % assign(domain_size, 5) -> assign(end_size, 5). formulas(assumptions). England(x) <-> Red(x). Spain(x) <-> Dog(x). Norway(0). Kool(x) <-> Yellow(x). Chesterfield(x) & Fox(y) -> adjacent(x,y). Norway(x) & Blue(y) -> adjacent(x,y). Winston(x) <-> Snail(x). Lucky(x) <-> Juice(x). Ukraine(x) <-> Tea(x). Japan(x) <-> Parlaiment(x). Kool(x) & Horse(y) -> adjacent(x,y). Coffee(x) <-> Green(x). Green(x) & Ivory(y) -> successor(y,x). Milk(2). successor(x,y) <-> x + 1 = y. adjacent(x,y) <-> successor(x,y) | successor(y,x). England(x) | Spain(x) | Ukraine(x) | Japan(x) | Norway(x). Dog(x) | Snail(x) | Horse(x) | Zebra(x) | Fox(x). Water(x) | Milk(x) | Juice(x) | Tea(x) | Coffee(x). Red(x) | Blue(x) | Yellow(x) | Ivory(x) | Green(x). Lucky(x) | Winston(x) | Kool(x) | Chesterfield(x) | Parlaiment(x). England(x) & England(y) -> x = y. Spain(x) & Spain(y) -> x = y. Ukraine(x) & Ukraine(y) -> x = y. Japan(x) & Japan(y) -> x = y. Norway(x) & Norway(y) -> x = y. Dog(x) & Dog(y) -> x = y. Snail(x) & Snail(y) -> x = y. Horse(x) & Horse(y) -> x = y. Zebra(x) & Zebra(y) -> x = y. Fox(x) & Fox(y) -> x = y. Water(x) & Water(y) -> x = y. Milk(x) & Milk(y) -> x = y. Juice(x) & Juice(y) -> x = y. Tea(x) & Tea(y) -> x = y. Coffee(x) & Coffee(y) -> x = y. Red(x) & Red(y) -> x = y. Blue(x) & Blue(y) -> x = y. Yellow(x) & Yellow(y) -> x = y. Ivory(x) & Ivory(y) -> x = y. Green(x) & Green(y) -> x = y. Lucky(x) & Lucky(y) -> x = y. Winston(x) & Winston(y) -> x = y. Kool(x) & Kool(y) -> x = y. Chesterfield(x) & Chesterfield(y) -> x = y. Parlaiment(x) & Parlaiment(y) -> x = y. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 England(x) <-> Red(x) # label(non_clause). [assumption]. 2 Spain(x) <-> Dog(x) # label(non_clause). [assumption]. 3 Kool(x) <-> Yellow(x) # label(non_clause). [assumption]. 4 Chesterfield(x) & Fox(y) -> adjacent(x,y) # label(non_clause). [assumption]. 5 Norway(x) & Blue(y) -> adjacent(x,y) # label(non_clause). [assumption]. 6 Winston(x) <-> Snail(x) # label(non_clause). [assumption]. 7 Lucky(x) <-> Juice(x) # label(non_clause). [assumption]. 8 Ukraine(x) <-> Tea(x) # label(non_clause). [assumption]. 9 Japan(x) <-> Parlaiment(x) # label(non_clause). [assumption]. 10 Kool(x) & Horse(y) -> adjacent(x,y) # label(non_clause). [assumption]. 11 Coffee(x) <-> Green(x) # label(non_clause). [assumption]. 12 Green(x) & Ivory(y) -> successor(y,x) # label(non_clause). [assumption]. 13 successor(x,y) <-> x + 1 = y # label(non_clause). [assumption]. 14 adjacent(x,y) <-> successor(x,y) | successor(y,x) # label(non_clause). [assumption]. 15 England(x) & England(y) -> x = y # label(non_clause). [assumption]. 16 Spain(x) & Spain(y) -> x = y # label(non_clause). [assumption]. 17 Ukraine(x) & Ukraine(y) -> x = y # label(non_clause). [assumption]. 18 Japan(x) & Japan(y) -> x = y # label(non_clause). [assumption]. 19 Norway(x) & Norway(y) -> x = y # label(non_clause). [assumption]. 20 Dog(x) & Dog(y) -> x = y # label(non_clause). [assumption]. 21 Snail(x) & Snail(y) -> x = y # label(non_clause). [assumption]. 22 Horse(x) & Horse(y) -> x = y # label(non_clause). [assumption]. 23 Zebra(x) & Zebra(y) -> x = y # label(non_clause). [assumption]. 24 Fox(x) & Fox(y) -> x = y # label(non_clause). [assumption]. 25 Water(x) & Water(y) -> x = y # label(non_clause). [assumption]. 26 Milk(x) & Milk(y) -> x = y # label(non_clause). [assumption]. 27 Juice(x) & Juice(y) -> x = y # label(non_clause). [assumption]. 28 Tea(x) & Tea(y) -> x = y # label(non_clause). [assumption]. 29 Coffee(x) & Coffee(y) -> x = y # label(non_clause). [assumption]. 30 Red(x) & Red(y) -> x = y # label(non_clause). [assumption]. 31 Blue(x) & Blue(y) -> x = y # label(non_clause). [assumption]. 32 Yellow(x) & Yellow(y) -> x = y # label(non_clause). [assumption]. 33 Ivory(x) & Ivory(y) -> x = y # label(non_clause). [assumption]. 34 Green(x) & Green(y) -> x = y # label(non_clause). [assumption]. 35 Lucky(x) & Lucky(y) -> x = y # label(non_clause). [assumption]. 36 Winston(x) & Winston(y) -> x = y # label(non_clause). [assumption]. 37 Kool(x) & Kool(y) -> x = y # label(non_clause). [assumption]. 38 Chesterfield(x) & Chesterfield(y) -> x = y # label(non_clause). [assumption]. 39 Parlaiment(x) & Parlaiment(y) -> x = y # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). -England(x) | Red(x). England(x) | -Red(x). -Spain(x) | Dog(x). Spain(x) | -Dog(x). Norway(0). -Kool(x) | Yellow(x). Kool(x) | -Yellow(x). -Chesterfield(x) | -Fox(y) | adjacent(x,y). -Norway(x) | -Blue(y) | adjacent(x,y). -Winston(x) | Snail(x). Winston(x) | -Snail(x). -Lucky(x) | Juice(x). Lucky(x) | -Juice(x). -Ukraine(x) | Tea(x). Ukraine(x) | -Tea(x). -Japan(x) | Parlaiment(x). Japan(x) | -Parlaiment(x). -Kool(x) | -Horse(y) | adjacent(x,y). -Coffee(x) | Green(x). Coffee(x) | -Green(x). -Green(x) | -Ivory(y) | successor(y,x). Milk(2). -successor(x,y) | x + 1 = y. successor(x,y) | x + 1 != y. -adjacent(x,y) | successor(x,y) | successor(y,x). adjacent(x,y) | -successor(x,y). adjacent(x,y) | -successor(y,x). England(x) | Spain(x) | Ukraine(x) | Japan(x) | Norway(x). Dog(x) | Snail(x) | Horse(x) | Zebra(x) | Fox(x). Water(x) | Milk(x) | Juice(x) | Tea(x) | Coffee(x). Red(x) | Blue(x) | Yellow(x) | Ivory(x) | Green(x). Lucky(x) | Winston(x) | Kool(x) | Chesterfield(x) | Parlaiment(x). -England(x) | -England(y) | y = x. -Spain(x) | -Spain(y) | y = x. -Ukraine(x) | -Ukraine(y) | y = x. -Japan(x) | -Japan(y) | y = x. -Norway(x) | -Norway(y) | y = x. -Dog(x) | -Dog(y) | y = x. -Snail(x) | -Snail(y) | y = x. -Horse(x) | -Horse(y) | y = x. -Zebra(x) | -Zebra(y) | y = x. -Fox(x) | -Fox(y) | y = x. -Water(x) | -Water(y) | y = x. -Milk(x) | -Milk(y) | y = x. -Juice(x) | -Juice(y) | y = x. -Tea(x) | -Tea(y) | y = x. -Coffee(x) | -Coffee(y) | y = x. -Red(x) | -Red(y) | y = x. -Blue(x) | -Blue(y) | y = x. -Yellow(x) | -Yellow(y) | y = x. -Ivory(x) | -Ivory(y) | y = x. -Green(x) | -Green(y) | y = x. -Lucky(x) | -Lucky(y) | y = x. -Winston(x) | -Winston(y) | y = x. -Kool(x) | -Kool(y) | y = x. -Chesterfield(x) | -Chesterfield(y) | y = x. -Parlaiment(x) | -Parlaiment(y) | y = x. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 2. ============================== DOMAIN SIZE 5 ========================= ============================== MODEL ================================= interpretation( 5, [number=1, seconds=0], [ relation(Blue(_), [ 0, 1, 0, 0, 0 ]), relation(Chesterfield(_), [ 0, 1, 0, 0, 0 ]), relation(Coffee(_), [ 0, 0, 0, 0, 1 ]), relation(Dog(_), [ 0, 0, 0, 1, 0 ]), relation(England(_), [ 0, 0, 1, 0, 0 ]), relation(Fox(_), [ 1, 0, 0, 0, 0 ]), relation(Green(_), [ 0, 0, 0, 0, 1 ]), relation(Horse(_), [ 0, 1, 0, 0, 0 ]), relation(Ivory(_), [ 0, 0, 0, 1, 0 ]), relation(Japan(_), [ 0, 0, 0, 0, 1 ]), relation(Juice(_), [ 0, 0, 0, 1, 0 ]), relation(Kool(_), [ 1, 0, 0, 0, 0 ]), relation(Lucky(_), [ 0, 0, 0, 1, 0 ]), relation(Milk(_), [ 0, 0, 1, 0, 0 ]), relation(Norway(_), [ 1, 0, 0, 0, 0 ]), relation(Parlaiment(_), [ 0, 0, 0, 0, 1 ]), relation(Red(_), [ 0, 0, 1, 0, 0 ]), relation(Snail(_), [ 0, 0, 1, 0, 0 ]), relation(Spain(_), [ 0, 0, 0, 1, 0 ]), relation(Tea(_), [ 0, 1, 0, 0, 0 ]), relation(Ukraine(_), [ 0, 1, 0, 0, 0 ]), relation(Water(_), [ 1, 0, 0, 0, 0 ]), relation(Winston(_), [ 0, 0, 1, 0, 0 ]), relation(Yellow(_), [ 1, 0, 0, 0, 0 ]), relation(Zebra(_), [ 0, 0, 0, 0, 1 ]), relation(adjacent(_,_), [ 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]), relation(successor(_,_), [ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 5. Current CPU time: 0.00 seconds (total CPU time: 0.34 seconds). Ground clauses: seen=957, kept=704. Selections=12995, assignments=25978, propagations=233365, current_models=1. Rewrite_terms=0, rewrite_bools=1430401, indexes=0. Rules_from_neg_clauses=0, cross_offs=0. ============================== end of statistics ===================== User_CPU=0.34, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15832 exit (max_models) Mon Nov 17 21:34:40 2008 The process finished Mon Nov 17 21:34:40 2008 LADR-2009-11A/mace4.src/puzzles/queens1.out0000644000175000017500000000637611110442735017435 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15828 was started by mccune on cleo, Mon Nov 17 21:34:37 2008 The command was "../mace4 -f queens1.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file queens1.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. formulas(assumptions). x != z -> Q(x) != Q(z). x != z -> z -- x != Q(z) -- Q(x). x != z -> z -- x != Q(x) -- Q(z). end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 x != z -> Q(x) != Q(z) # label(non_clause). [assumption]. 2 x != z -> z -- x != Q(z) -- Q(x) # label(non_clause). [assumption]. 3 x != z -> z -- x != Q(x) -- Q(z) # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). x = y | Q(x) != Q(y). x = y | Q(x) -- Q(y) != x -- y. x = y | Q(y) -- Q(x) != x -- y. end_of_list. ============================== end of clauses for search ============= % There are no natural numbers in the input. ============================== DOMAIN SIZE 2 ========================= ============================== STATISTICS ============================ For domain size 2. Current CPU time: 0.00 seconds (total CPU time: 0.00 seconds). Ground clauses: seen=12, kept=6. Selections=1, assignments=2, propagations=2, current_models=0. Rewrite_terms=16, rewrite_bools=4, indexes=0. Rules_from_neg_clauses=2, cross_offs=2. ============================== end of statistics ===================== ============================== DOMAIN SIZE 3 ========================= ============================== STATISTICS ============================ For domain size 3. Current CPU time: 0.00 seconds (total CPU time: 0.00 seconds). Ground clauses: seen=27, kept=18. Selections=4, assignments=12, propagations=2, current_models=0. Rewrite_terms=119, rewrite_bools=41, indexes=0. Rules_from_neg_clauses=2, cross_offs=8. ============================== end of statistics ===================== ============================== DOMAIN SIZE 4 ========================= ============================== MODEL ================================= interpretation( 4, [number=1, seconds=0], [ function(Q(_), [ 1, 3, 0, 2 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 4. Current CPU time: 0.00 seconds (total CPU time: 0.00 seconds). Ground clauses: seen=48, kept=36. Selections=6, assignments=19, propagations=2, current_models=1. Rewrite_terms=284, rewrite_bools=126, indexes=0. Rules_from_neg_clauses=2, cross_offs=14. ============================== end of statistics ===================== User_CPU=0.00, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15828 exit (max_models) Mon Nov 17 21:34:37 2008 The process finished Mon Nov 17 21:34:37 2008 LADR-2009-11A/mace4.src/puzzles/kenken6.in0000644000175000017500000000207111110442232017170 0ustar mccunemccuneset(arithmetic). % KenKen is a puzzle similar in some ways to Sudoku. % Solutions are Latin squares (each row and each column % is a permuatation of the domain). The grid is partitioned % into blocks of various sizes and shapes, and an arithmetic % relation is specified for each block; for example, the % sum of the members is 8, or the difference (for a block of % size 2 is 3. % % See the Wikipedia Web page on KenKen. % % Ordinarily, KenKen uses the {1,...,n}, but we use {0,...,n-1}. assign(domain_size, 6). % domain is {0,1,2,3,4,5} formulas(assumptions). % Latin Square f(x,y1) = f(x,y2) -> y1=y2. f(x1,y) = f(x2,y) -> x1=x2. % Clues for the blocks. f(0,1) * f(0,2) = 0. f(0,0) + f(1,0) = 5. f(0,3) * f(1,3) = 20. f(0,4) * f(0,5) * f(1,5) * f(2,5) = 6. f(1,4) + f(2,4) = 2. abs(f(1,1) -- f(1,2)) = 3. f(2,0) * f(2,1) * f(3,0) * f(3,1) = 240. f(2,2) * f(2,3) = 6. f(3,2) * f(4,2) = 0. f(3,3) + f(4,3) + f(4,4) = 7. f(3,4) * f(3,5) = 0. f(4,0) * f(4,1) = 6. abs(f(4,5) -- f(5,5)) = 1. f(5,0) + f(5,1) + f(5,2) = 8. f(5,3) + f(5,4) = 3. end_of_list. LADR-2009-11A/mace4.src/puzzles/zebra2.in0000644000175000017500000000167611107457547017053 0ustar mccunemccuneset(arithmetic). assign(domain_size, 5). % Assume a domain of size 5: {0,1,2,3,4} formulas(assumptions). England = Red. Lucky = Juice. Spain = Dog. Ukraine = Tea. Norway = 0. Japan = Parlaiment. Kool = Yellow. neighbors(Kool,Horse). neighbors(Chesterfield,Fox). Coffee = Green. neighbors(Norway,Blue). successor(Green,Ivory). Winston = Snail. Milk = 2. % Definitions of successor and neighbors. successor(x,y) <-> x+1 = y. neighbors(x,y) <-> successor(x,y) | successor(y,x). end_of_list. list(distinct). % Objects in each list are distinct. [England,Spain,Ukraine,Japan,Norway]. [Dog,Snail,Horse,Zebra,Fox]. [Water,Milk,Juice,Tea,Coffee]. [Red,Blue,Yellow,Ivory,Green]. [Lucky,Winston,Kool,Chesterfield,Parlaiment]. end_of_list. LADR-2009-11A/mace4.src/puzzles/kenken6.out0000644000175000017500000000632411110442735017406 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15827 was started by mccune on cleo, Mon Nov 17 21:34:37 2008 The command was "../mace4 -f kenken6.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file kenken6.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. assign(domain_size,6). % assign(domain_size, 6) -> assign(start_size, 6). % assign(domain_size, 6) -> assign(end_size, 6). formulas(assumptions). f(x,y1) = f(x,y2) -> y1 = y2. f(x1,y) = f(x2,y) -> x1 = x2. f(0,1) * f(0,2) = 0. f(0,0) + f(1,0) = 5. f(0,3) * f(1,3) = 20. f(0,4) * f(0,5) * f(1,5) * f(2,5) = 6. f(1,4) + f(2,4) = 2. abs(f(1,1) -- f(1,2)) = 3. f(2,0) * f(2,1) * f(3,0) * f(3,1) = 240. f(2,2) * f(2,3) = 6. f(3,2) * f(4,2) = 0. f(3,3) + f(4,3) + f(4,4) = 7. f(3,4) * f(3,5) = 0. f(4,0) * f(4,1) = 6. abs(f(4,5) -- f(5,5)) = 1. f(5,0) + f(5,1) + f(5,2) = 8. f(5,3) + f(5,4) = 3. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 f(x,y1) = f(x,y2) -> y1 = y2 # label(non_clause). [assumption]. 2 f(x1,y) = f(x2,y) -> x1 = x2 # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). f(x,y) != f(x,z) | y = z. f(x,y) != f(z,y) | x = z. f(0,1) * f(0,2) = 0. f(0,0) + f(1,0) = 5. f(0,3) * f(1,3) = 20. f(0,4) * f(0,5) * f(1,5) * f(2,5) = 6. f(1,4) + f(2,4) = 2. abs(f(1,1) -- f(1,2)) = 3. f(2,0) * f(2,1) * f(3,0) * f(3,1) = 240. f(2,2) * f(2,3) = 6. f(3,2) * f(4,2) = 0. f(3,3) + f(4,3) + f(4,4) = 7. f(3,4) * f(3,5) = 0. f(4,0) * f(4,1) = 6. abs(f(4,5) -- f(5,5)) = 1. f(5,0) + f(5,1) + f(5,2) = 8. f(5,3) + f(5,4) = 3. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 240. ============================== DOMAIN SIZE 6 ========================= ============================== MODEL ================================= interpretation( 6, [number=1, seconds=0], [ function(f(_,_), [ 5, 0, 3, 4, 1, 2, 0, 1, 4, 5, 2, 3, 4, 5, 2, 3, 0, 1, 3, 4, 1, 2, 5, 0, 2, 3, 0, 1, 4, 5, 1, 2, 5, 0, 3, 4 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 6. Current CPU time: 0.00 seconds (total CPU time: 0.17 seconds). Ground clauses: seen=447, kept=375. Selections=9666, assignments=57959, propagations=1697, current_models=1. Rewrite_terms=437866, rewrite_bools=159862, indexes=0. Rules_from_neg_clauses=1697, cross_offs=86308. ============================== end of statistics ===================== User_CPU=0.17, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15827 exit (max_models) Mon Nov 17 21:34:37 2008 The process finished Mon Nov 17 21:34:37 2008 LADR-2009-11A/mace4.src/puzzles/queens2.in0000644000175000017500000000112111110442440017205 0ustar mccunemccuneset(arithmetic). formulas(assumptions). % n-Queens Puzzle % % Relation Q(x,y) means there is a queen at row x, column y. all x exists y Q(x,y). % Each row has at *least* one queen. Q(x,y1) & Q(x,y2) -> y1 = y2. % Each row has at most one queen. Q(x1,y) & Q(x2,y) -> x1 = x2. % Each column has at most one queen. Q(x1,y1) & Q(x2,y2) & (x2 -- x1 = y2 -- y1) -> x1 = x2 & y1 = y2. % Each \ diagonal has at most one queen. Q(x1,y1) & Q(x2,y2) & (x1 -- x2 = y2 -- y1) -> x1 = x2 & y1 = y2. % Each / diagonal has at most one queen. end_of_list. LADR-2009-11A/mace4.src/puzzles/send-money.out0000644000175000017500000000556011110442740020120 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15830 was started by mccune on cleo, Mon Nov 17 21:34:37 2008 The command was "../mace4 -f send-money.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file send-money.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. assign(domain_size,10). % assign(domain_size, 10) -> assign(start_size, 10). % assign(domain_size, 10) -> assign(end_size, 10). list(distinct). [S,E,N,D,M,O,R,Y]. end_of_list. formulas(assumptions). D + E = Y + C1 * 10. N + R + C1 = E + C2 * 10. E + O + C2 = N + C3 * 10. S + M + C3 = O + M * 10. S != 0. M != 0. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). D + E = Y + C1 * 10. N + R + C1 = E + C2 * 10. E + O + C2 = N + C3 * 10. S + M + C3 = O + M * 10. S != 0. M != 0. S != E. S != N. S != D. S != M. S != O. S != R. S != Y. E != N. E != D. E != M. E != O. E != R. E != Y. N != D. N != M. N != O. N != R. N != Y. D != M. D != O. D != R. D != Y. M != O. M != R. M != Y. O != R. O != Y. R != Y. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 10. ============================== DOMAIN SIZE 10 ======================== ============================== MODEL ================================= interpretation( 10, [number=1, seconds=2], [ function(C1, [ 1 ]), function(C2, [ 1 ]), function(C3, [ 0 ]), function(D, [ 7 ]), function(E, [ 5 ]), function(M, [ 1 ]), function(N, [ 6 ]), function(O, [ 0 ]), function(R, [ 8 ]), function(S, [ 9 ]), function(Y, [ 2 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 10. Current CPU time: 0.00 seconds (total CPU time: 2.70 seconds). Ground clauses: seen=34, kept=34. Selections=242526, assignments=2425201, propagations=0, current_models=1. Rewrite_terms=7196584, rewrite_bools=5030322, indexes=0. Rules_from_neg_clauses=0, cross_offs=89005. ============================== end of statistics ===================== User_CPU=2.70, System_CPU=0.02, Wall_clock=3. Exiting with 1 model. Process 15830 exit (max_models) Mon Nov 17 21:34:40 2008 The process finished Mon Nov 17 21:34:40 2008 LADR-2009-11A/mace4.src/puzzles/queens2.out0000644000175000017500000000751311110442735017430 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15829 was started by mccune on cleo, Mon Nov 17 21:34:37 2008 The command was "../mace4 -f queens2.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file queens2.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. formulas(assumptions). (all x exists y Q(x,y)). Q(x,y1) & Q(x,y2) -> y1 = y2. Q(x1,y) & Q(x2,y) -> x1 = x2. Q(x1,y1) & Q(x2,y2) & x2 -- x1 = y2 -- y1 -> x1 = x2 & y1 = y2. Q(x1,y1) & Q(x2,y2) & x1 -- x2 = y2 -- y1 -> x1 = x2 & y1 = y2. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 (all x exists y Q(x,y)) # label(non_clause). [assumption]. 2 Q(x,y1) & Q(x,y2) -> y1 = y2 # label(non_clause). [assumption]. 3 Q(x1,y) & Q(x2,y) -> x1 = x2 # label(non_clause). [assumption]. 4 Q(x1,y1) & Q(x2,y2) & x2 -- x1 = y2 -- y1 -> x1 = x2 & y1 = y2 # label(non_clause). [assumption]. 5 Q(x1,y1) & Q(x2,y2) & x1 -- x2 = y2 -- y1 -> x1 = x2 & y1 = y2 # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). Q(x,f1(x)). -Q(x,y) | -Q(x,z) | z = y. -Q(x,y) | -Q(z,y) | z = x. -Q(x,y) | -Q(z,u) | z -- x != u -- y | z = x. -Q(x,y) | -Q(z,u) | z -- x != u -- y | u = y. -Q(x,y) | -Q(z,u) | x -- z != u -- y | z = x. -Q(x,y) | -Q(z,u) | x -- z != u -- y | u = y. end_of_list. ============================== end of clauses for search ============= % There are no natural numbers in the input. ============================== DOMAIN SIZE 2 ========================= ============================== STATISTICS ============================ For domain size 2. Current CPU time: 0.00 seconds (total CPU time: 0.01 seconds). Ground clauses: seen=82, kept=18. Selections=1, assignments=2, propagations=10, current_models=0. Rewrite_terms=4, rewrite_bools=44, indexes=2. Rules_from_neg_clauses=2, cross_offs=2. ============================== end of statistics ===================== ============================== DOMAIN SIZE 3 ========================= ============================== STATISTICS ============================ For domain size 3. Current CPU time: 0.00 seconds (total CPU time: 0.01 seconds). Ground clauses: seen=381, kept=79. Selections=1, assignments=3, propagations=30, current_models=0. Rewrite_terms=8, rewrite_bools=276, indexes=5. Rules_from_neg_clauses=5, cross_offs=11. ============================== end of statistics ===================== ============================== DOMAIN SIZE 4 ========================= ============================== MODEL ================================= interpretation( 4, [number=1, seconds=0], [ function(f1(_), [ 1, 3, 0, 2 ]), relation(Q(_,_), [ 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 4. Current CPU time: 0.00 seconds (total CPU time: 0.02 seconds). Ground clauses: seen=1156, kept=212. Selections=2, assignments=6, propagations=45, current_models=1. Rewrite_terms=13, rewrite_bools=533, indexes=9. Rules_from_neg_clauses=7, cross_offs=19. ============================== end of statistics ===================== User_CPU=0.02, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15829 exit (max_models) Mon Nov 17 21:34:37 2008 The process finished Mon Nov 17 21:34:37 2008 LADR-2009-11A/mace4.src/puzzles/queens1.in0000644000175000017500000000110011110442400017175 0ustar mccunemccuneset(arithmetic). formulas(assumptions). % n-Queens Puzzle % % In this representation, Q(i)=n means that Row i Column n has a queen. % The constraint that no queens can be in the same row is always satisfied % in this representation, because Q is a function; that is, % Q(x) != Q(z) -> x != z is always satisfied. % Note that "--" is the binary "minus" operation. x != z -> Q(x) != Q(z). % No 2 queens in the same column. x != z -> z -- x != Q(z) -- Q(x). % No 2 queens in \ diagonal. x != z -> z -- x != Q(x) -- Q(z). % No 2 queens in / diagonal. end_of_list. LADR-2009-11A/mace4.src/puzzles/send-money.in0000644000175000017500000000061611110307501017707 0ustar mccunemccuneset(arithmetic). assign(domain_size, 10). % domain is {0,1,2,3,4,5,6,7,8,9}. % S E N D % + M O R E % --------- % M O N E Y list(distinct). [S,E,N,D,M,O,R,Y]. end_of_list. formulas(assumptions). D + E = Y + C1 * 10. N + R + C1 = E + C2 * 10. E + O + C2 = N + C3 * 10. S + M + C3 = O + M * 10. % Leading zeros are not allowed. S != 0. M != 0. end_of_list. LADR-2009-11A/mace4.src/puzzles/f1.out0000644000175000017500000000763211110442735016356 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15826 was started by mccune on cleo, Mon Nov 17 21:34:37 2008 The command was "../mace4 -f f1.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file f1.in set(arithmetic). % set(arithmetic) -> clear(lnh). % set(arithmetic) -> assign(selection_order, 0). % Declaring Mace4 arithmetic parse types. redeclare(conjunction,and). % op(780, infix_right, and). % copying parse/print properties from & to and formulas(assumptions). SIEVE_1 * cons_2 >= SIEVE_1 * filter_2 and SIEVE_1 * cons_3 >= SIEVE_1 * filter_3 and filter_2 * nil_1 + filter_3 >= nil_1 and cons_2 * filter_2 >= if_4 and cons_3 * filter_2 + filter_3 >= if_1 * isdiv_3 + if_5 and if_4 >= filter_2 and if_1 * true_1 + if_5 >= filter_3 and if_4 >= cons_2 * filter_2 and false_1 * if_1 + if_5 >= cons_2 * filter_3 + cons_3 and isdiv_3 >= true_1 and isdiv_3 >= false_1 and SIEVE_1 * cons_3 > SIEVE_1 * filter_3 and SIEVE_1 * cons_2 >= 0 and SIEVE_1 * cons_3 + SIEVE_2 >= 0. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 SIEVE_1 * cons_2 >= SIEVE_1 * filter_2 and SIEVE_1 * cons_3 >= SIEVE_1 * filter_3 and filter_2 * nil_1 + filter_3 >= nil_1 and cons_2 * filter_2 >= if_4 and cons_3 * filter_2 + filter_3 >= if_1 * isdiv_3 + if_5 and if_4 >= filter_2 and if_1 * true_1 + if_5 >= filter_3 and if_4 >= cons_2 * filter_2 and false_1 * if_1 + if_5 >= cons_2 * filter_3 + cons_3 and isdiv_3 >= true_1 and isdiv_3 >= false_1 and SIEVE_1 * cons_3 > SIEVE_1 * filter_3 and SIEVE_1 * cons_2 >= 0 and SIEVE_1 * cons_3 + SIEVE_2 >= 0 # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). SIEVE_1 * cons_2 >= SIEVE_1 * filter_2. SIEVE_1 * cons_3 >= SIEVE_1 * filter_3. filter_2 * nil_1 + filter_3 >= nil_1. cons_2 * filter_2 >= if_4. cons_3 * filter_2 + filter_3 >= if_1 * isdiv_3 + if_5. if_4 >= filter_2. if_1 * true_1 + if_5 >= filter_3. if_4 >= cons_2 * filter_2. false_1 * if_1 + if_5 >= cons_2 * filter_3 + cons_3. isdiv_3 >= true_1. isdiv_3 >= false_1. SIEVE_1 * cons_3 > SIEVE_1 * filter_3. SIEVE_1 * cons_2 >= 0. SIEVE_1 * cons_3 + SIEVE_2 >= 0. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 0. ============================== DOMAIN SIZE 2 ========================= ============================== MODEL ================================= interpretation( 2, [number=1, seconds=0], [ function(SIEVE_1, [ 1 ]), function(SIEVE_2, [ 0 ]), function(cons_2, [ 1 ]), function(cons_3, [ 1 ]), function(false_1, [ 0 ]), function(filter_2, [ 1 ]), function(filter_3, [ 0 ]), function(if_1, [ 0 ]), function(if_4, [ 1 ]), function(if_5, [ 1 ]), function(isdiv_3, [ 0 ]), function(nil_1, [ 0 ]), function(true_1, [ 0 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 2. Current CPU time: 0.00 seconds (total CPU time: 0.01 seconds). Ground clauses: seen=14, kept=14. Selections=117, assignments=227, propagations=0, current_models=1. Rewrite_terms=668, rewrite_bools=235, indexes=0. Rules_from_neg_clauses=0, cross_offs=0. ============================== end of statistics ===================== User_CPU=0.01, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15826 exit (max_models) Mon Nov 17 21:34:37 2008 The process finished Mon Nov 17 21:34:37 2008 LADR-2009-11A/mace4.src/puzzles/sudoku.out0000644000175000017500000001257311110442740017356 0ustar mccunemccune============================== Mace4 ================================= Mace4 (32) version 2008-10A+, October 2008. Process 15831 was started by mccune on cleo, Mon Nov 17 21:34:40 2008 The command was "../mace4 -f sudoku.in". ============================== end of head =========================== ============================== INPUT ================================= % Reading from file sudoku.in assign(domain_size,9). % assign(domain_size, 9) -> assign(start_size, 9). % assign(domain_size, 9) -> assign(end_size, 9). formulas(assumptions). S(x,y1) = S(x,y2) -> y1 = y2. S(x1,y) = S(x2,y) -> x1 = x2. (all x all z exists y S(x,y) = z). (all y all z exists x S(x,y) = z). same_interval(x,x). same_interval(x,y) -> same_interval(y,x). same_interval(x,y) & same_interval(y,z) -> same_interval(x,z). same_interval(0,1). same_interval(1,2). same_interval(3,4). same_interval(4,5). same_interval(6,7). same_interval(7,8). -same_interval(0,3). -same_interval(3,6). -same_interval(0,6). S(x1,y1) = S(x2,y2) & same_interval(x1,x2) & same_interval(y1,y2) -> x1 = x2 & y1 = y2. S(0,0) = 8. S(0,5) = 3. S(0,7) = 5. S(1,0) = 3. S(1,1) = 1. S(1,3) = 4. S(1,6) = 8. S(2,2) = 5. S(3,1) = 0. S(3,3) = 2. S(4,1) = 5. S(4,5) = 0. S(4,6) = 3. S(4,7) = 6. S(5,0) = 4. S(5,5) = 5. S(5,7) = 8. S(6,6) = 2. S(7,2) = 2. S(7,5) = 1. S(7,7) = 3. S(7,8) = 7. S(8,1) = 3. S(8,5) = 2. S(8,8) = 1. end_of_list. ============================== end of input ========================== ============================== PROCESS NON-CLAUSAL FORMULAS ========== % Formulas that are not ordinary clauses: 1 S(x,y1) = S(x,y2) -> y1 = y2 # label(non_clause). [assumption]. 2 S(x1,y) = S(x2,y) -> x1 = x2 # label(non_clause). [assumption]. 3 (all x all z exists y S(x,y) = z) # label(non_clause). [assumption]. 4 (all y all z exists x S(x,y) = z) # label(non_clause). [assumption]. 5 same_interval(x,y) -> same_interval(y,x) # label(non_clause). [assumption]. 6 same_interval(x,y) & same_interval(y,z) -> same_interval(x,z) # label(non_clause). [assumption]. 7 S(x1,y1) = S(x2,y2) & same_interval(x1,x2) & same_interval(y1,y2) -> x1 = x2 & y1 = y2 # label(non_clause). [assumption]. ============================== end of process non-clausal formulas === ============================== CLAUSES FOR SEARCH ==================== formulas(mace4_clauses). S(x,y) != S(x,z) | y = z. S(x,y) != S(z,y) | x = z. S(x,f1(x,y)) = y. S(f2(x,y),x) = y. same_interval(x,x). -same_interval(x,y) | same_interval(y,x). -same_interval(x,y) | -same_interval(y,z) | same_interval(x,z). same_interval(0,1). same_interval(1,2). same_interval(3,4). same_interval(4,5). same_interval(6,7). same_interval(7,8). -same_interval(0,3). -same_interval(3,6). -same_interval(0,6). S(x,y) != S(z,u) | -same_interval(z,x) | -same_interval(u,y) | x = z. S(x,y) != S(z,u) | -same_interval(z,x) | -same_interval(u,y) | y = u. S(0,0) = 8. S(0,5) = 3. S(0,7) = 5. S(1,0) = 3. S(1,1) = 1. S(1,3) = 4. S(1,6) = 8. S(2,2) = 5. S(3,1) = 0. S(3,3) = 2. S(4,1) = 5. S(4,5) = 0. S(4,6) = 3. S(4,7) = 6. S(5,0) = 4. S(5,5) = 5. S(5,7) = 8. S(6,6) = 2. S(7,2) = 2. S(7,5) = 1. S(7,7) = 3. S(7,8) = 7. S(8,1) = 3. S(8,5) = 2. S(8,8) = 1. end_of_list. ============================== end of clauses for search ============= % The largest natural number in the input is 8. ============================== DOMAIN SIZE 9 ========================= ============================== MODEL ================================= interpretation( 9, [number=1, seconds=0], [ function(S(_,_), [ 8, 6, 4, 1, 2, 3, 7, 5, 0, 3, 1, 0, 4, 5, 7, 8, 2, 6, 7, 2, 5, 6, 0, 8, 4, 1, 3, 6, 0, 3, 2, 8, 4, 1, 7, 5, 2, 5, 8, 7, 1, 0, 3, 6, 4, 4, 7, 1, 3, 6, 5, 0, 8, 2, 1, 4, 7, 5, 3, 6, 2, 0, 8, 5, 8, 2, 0, 4, 1, 6, 3, 7, 0, 3, 6, 8, 7, 2, 5, 4, 1 ]), function(f1(_,_), [ 8, 3, 4, 5, 2, 7, 1, 6, 0, 2, 1, 7, 0, 3, 4, 8, 5, 6, 4, 7, 1, 8, 6, 2, 3, 0, 5, 1, 6, 3, 2, 5, 8, 0, 7, 4, 5, 4, 0, 6, 8, 1, 7, 3, 2, 6, 2, 8, 3, 0, 5, 4, 1, 7, 7, 0, 6, 4, 1, 3, 5, 2, 8, 3, 5, 2, 7, 4, 0, 6, 8, 1, 0, 8, 5, 1, 7, 6, 2, 4, 3 ]), function(f2(_,_), [ 8, 6, 4, 1, 5, 7, 3, 2, 0, 3, 1, 2, 8, 6, 4, 0, 5, 7, 1, 5, 7, 3, 0, 2, 8, 6, 4, 7, 0, 3, 5, 1, 6, 2, 4, 8, 2, 4, 0, 6, 7, 1, 5, 8, 3, 4, 7, 8, 0, 3, 5, 6, 1, 2, 5, 3, 6, 4, 2, 8, 7, 0, 1, 6, 2, 1, 7, 8, 0, 4, 3, 5, 0, 8, 5, 2, 4, 3, 1, 7, 6 ]), relation(same_interval(_,_), [ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]) ]). ============================== end of model ========================== ============================== STATISTICS ============================ For domain size 9. Current CPU time: 0.00 seconds (total CPU time: 0.05 seconds). Ground clauses: seen=15595, kept=3193. Selections=7, assignments=45, propagations=422, current_models=1. Rewrite_terms=7132, rewrite_bools=4936, indexes=71. Rules_from_neg_clauses=245, cross_offs=2038. ============================== end of statistics ===================== User_CPU=0.05, System_CPU=0.00, Wall_clock=0. Exiting with 1 model. Process 15831 exit (max_models) Mon Nov 17 21:34:40 2008 The process finished Mon Nov 17 21:34:40 2008 LADR-2009-11A/mace4.src/puzzles/sudoku.in0000644000175000017500000000266711110442467017166 0ustar mccunemccuneassign(domain_size, 9). formulas(assumptions). S(x, y1) = S(x, y2) -> y1 = y2. % At most one of each in each row. S(x1, y) = S(x2, y) -> x1 = x2. % At most one of each in each column. % "At least" rules. These are not necessary, but they reduce the search. all x all z exists y S(x,y) = z. % At least one of each in each row. all y all z exists x S(x,y) = z. % At least one of each in each column. % For 9x9 puzzles, the intervals are {0,1,2}, {3,4,5}, {6,7,8}; % same_interval(x,y) is an equivalence relation. same_interval(x,x). same_interval(x,y) -> same_interval(y,x). same_interval(x,y) & same_interval(y,z) -> same_interval(x,z). same_interval(0,1). same_interval(1,2). same_interval(3,4). same_interval(4,5). same_interval(6,7). same_interval(7,8). -same_interval(0,3). -same_interval(3,6). -same_interval(0,6). % The preceding formulas completely specify the same_interval relation. % Rule 3a: At most one of each in each region. ( S(x1, y1) = S(x2, y2) & same_interval(x1,x2) & same_interval(y1,y2) -> x1 = x2 & y1 = y2 ). % The initial state of the puzzle. This should be a hard one. S(0,0) = 8. S(0,5) = 3. S(0,7) = 5. S(1,0) = 3. S(1,1) = 1. S(1,3) = 4. S(1,6) = 8. S(2,2) = 5. S(3,1) = 0. S(3,3) = 2. S(4,1) = 5. S(4,5) = 0. S(4,6) = 3. S(4,7) = 6. S(5,0) = 4. S(5,5) = 5. S(5,7) = 8. S(6,6) = 2. S(7,2) = 2. S(7,5) = 1. S(7,7) = 3. S(7,8) = 7. S(8,1) = 3. S(8,5) = 2. S(8,8) = 1. end_of_list. LADR-2009-11A/mace4.src/puzzles/zebra1.in0000644000175000017500000000362211110442536017025 0ustar mccunemccuneset(arithmetic). assign(domain_size, 5). formulas(assumptions). % The clues. England(x) <-> Red(x). Spain(x) <-> Dog(x). Norway(0). Kool(x) <-> Yellow(x). Chesterfield(x) & Fox(y) -> adjacent(x,y). Norway(x) & Blue(y) -> adjacent(x,y). Winston(x) <-> Snail(x). Lucky(x) <-> Juice(x). Ukraine(x) <-> Tea(x). Japan(x) <-> Parlaiment(x). Kool(x) & Horse(y) -> adjacent(x,y). Coffee(x) <-> Green(x). Green(x) & Ivory(y) -> successor(y,x). Milk(2). % Definitions of successor and adjacent. successor(x,y) <-> x+1 = y. adjacent(x,y) <-> successor(x,y) | successor(y,x). % Each house has at least one nationality, pet, drink, color, smoke. England(x) | Spain(x) | Ukraine(x) | Japan(x) | Norway(x). Dog(x) | Snail(x) | Horse(x) | Zebra(x) | Fox(x). Water(x) | Milk(x) | Juice(x) | Tea(x) | Coffee(x). Red(x) | Blue(x) | Yellow(x) | Ivory(x) | Green(x). Lucky(x) | Winston(x) | Kool(x) | Chesterfield(x) | Parlaiment(x). % Each property applies to at most one house. England(x) & England(y) -> x = y. Spain(x) & Spain(y) -> x = y. Ukraine(x) & Ukraine(y) -> x = y. Japan(x) & Japan(y) -> x = y. Norway(x) & Norway(y) -> x = y. Dog(x) & Dog(y) -> x = y. Snail(x) & Snail(y) -> x = y. Horse(x) & Horse(y) -> x = y. Zebra(x) & Zebra(y) -> x = y. Fox(x) & Fox(y) -> x = y. Water(x) & Water(y) -> x = y. Milk(x) & Milk(y) -> x = y. Juice(x) & Juice(y) -> x = y. Tea(x) & Tea(y) -> x = y. Coffee(x) & Coffee(y) -> x = y. Red(x) & Red(y) -> x = y. Blue(x) & Blue(y) -> x = y. Yellow(x) & Yellow(y) -> x = y. Ivory(x) & Ivory(y) -> x = y. Green(x) & Green(y) -> x = y. Lucky(x) & Lucky(y) -> x = y. Winston(x) & Winston(y) -> x = y. Kool(x) & Kool(y) -> x = y. Chesterfield(x) & Chesterfield(y) -> x = y. Parlaiment(x) & Parlaiment(y) -> x = y. end_of_list. LADR-2009-11A/mace4.src/mstate.c0000644000175000017500000001053210607745010015237 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" /* * memory management */ #define PTRS_MSTATE CEILING(sizeof(struct mstate),BYTES_POINTER) static unsigned Mstate_gets, Mstate_frees; #define PTRS_JNODE CEILING(sizeof(struct jnode),BYTES_POINTER) static unsigned Jnode_gets, Jnode_frees; /************* * * Mstate get_mstate() * *************/ Mstate get_mstate(void) { Mstate p = get_cmem(PTRS_MSTATE); p->ok = TRUE; Mstate_gets++; return(p); } /* get_mstate */ /************* * * free_mstate() * *************/ void free_mstate(Mstate p) { free_mem(p, PTRS_MSTATE); Mstate_frees++; } /* free_mstate */ /************* * * Jnode get_jnode() * *************/ Jnode get_jnode(void) { Jnode p = get_mem(PTRS_JNODE); Jnode_gets++; return(p); } /* get_jnode */ /************* * * free_jnode() * *************/ void free_jnode(Jnode p) { free_mem(p, PTRS_JNODE); Jnode_frees++; } /* free_jnode */ /************* * * fprint_mstate_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the mstate package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_mstate_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct mstate); fprintf(fp, "mstate (%4d) %11u%11u%11u%9.1f K\n", n, Mstate_gets, Mstate_frees, Mstate_gets - Mstate_frees, ((Mstate_gets - Mstate_frees) * n) / 1024.); n = sizeof(struct jnode); fprintf(fp, "jnode (%4d) %11u%11u%11u%9.1f K\n", n, Jnode_gets, Jnode_frees, Jnode_gets - Jnode_frees, ((Jnode_gets - Jnode_frees) * n) / 1024.); } /* fprint_mstate_mem */ /************* * * p_mstate_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the mstate package. */ /* PUBLIC */ void p_mstate_mem() { fprint_mstate_mem(stdout, TRUE); } /* p_mstate_mem */ /* * end of memory management */ /************* * * job_append() * *************/ void job_append(Mstate s, int type, int id, Term alpha, Term beta, int pos) { Jnode j = get_jnode(); j->type = type; j->id = id; j->alpha = alpha; j->beta = beta; j->pos = pos; if (s->first_job == NULL) { j->prev = NULL; j->next = NULL; s->first_job = j; s->last_job = j; } else { j->prev = s->last_job; j->next = NULL; s->last_job->next = j; s->last_job = j; } } /* job_append */ /************* * * job_prepend() * *************/ void job_prepend(Mstate s, int type, int id, Term alpha, Term beta, int pos) { Jnode j = get_jnode(); j->type = type; j->id = id; j->alpha = alpha; j->beta = beta; j->pos = pos; if (s->first_job == NULL) { j->prev = NULL; j->next = NULL; s->first_job = j; s->last_job = j; } else { j->next = s->first_job; j->prev = NULL; s->first_job->prev = j; s->first_job = j; } } /* job_prepend */ /************* * * job_pop() * *************/ void job_pop(Mstate s) { if (s->first_job == NULL) fatal_error("job_pop: empty list"); else { Jnode p = s->first_job; s->first_job = p->next; if (s->first_job == NULL) s->last_job = NULL; else s->first_job->prev = NULL; free_jnode(p); } } /* job_pop */ /************* * * zap_jobs() * *************/ void zap_jobs(Mstate ms) { Jnode j = ms->first_job; while (j) { Jnode p = j; j = j->next; free_jnode(p); } } /* zap_jobs */ LADR-2009-11A/mace4.src/msearch.c~0000644000175000017500000006314711133704177015600 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include "../ladr/banner.h" // #define DEBUG /*****************************************************************************/ /* Variables -- most are used (extern) by other source files */ /* Options and Statistics */ Mace_options Opt; struct mace_stats Mstats; /* List of symbols and associated data */ Symbol_data Symbols; /* This maps OPS symbol IDs to MACE symbol IDs, which start with 0. */ static int Sn_map_size; Symbol_data *Sn_to_mace_sn; /* Cell table is indexed by eterm IDs. */ int Number_of_cells; struct cell *Cells; /* the table of cells (dynamically allocated) */ struct cell **Ordered_cells; /* (pointers to) permutation of Cells */ int First_skolem_cell; /* Misc Variables*/ int Domain_size; Term *Domain; /* array of terms representing (shared) domain elements */ BOOL Skolems_last; Plist Ground_clauses; /* Mclauses (see ground.h) */ int Relation_flag; /* term flag */ int Negation_flag; /* term flag */ int Eq_sn; int Or_sn; int Not_sn; static int Max_domain_element_in_input; /* For Least Number Heuristic */ static Plist Models; /* in case we collect models as terms */ Clock Mace4_clock; /* stats for entire run */ unsigned Total_models; static double Start_seconds; static double Start_domain_seconds; static int Start_megs; /* end of variables */ /*****************************************************************************/ /* search return codes */ enum { SEARCH_GO_MODELS, /* continue: model(s) found on current path */ SEARCH_GO_NO_MODELS, /* continue: no models found on current path */ SEARCH_MAX_MODELS, /* stop */ SEARCH_MAX_MEGS, /* stop */ SEARCH_MAX_TOTAL_SECONDS, /* stop */ SEARCH_MAX_DOMAIN_SECONDS, /* stop */ SEARCH_DOMAIN_OUT_OF_RANGE /* stop */ }; /* Ground terms. MACE4 operates on ground clauses, which are represented by the structure mclause. Ground terms (and atoms) are represented with ordinary LADR terms. There are a few tricks: (1) We use upward pointers from terms to superterms and from atoms to clauses. (2) We need to mark atoms with a termflag, so that we know when to stop when following the upward pointers. Also, a termflag is used to indicate that an atom is negated. (3) Domain elements are represented by variables (sorry, but it is very convenient to do so). Also, there is only one actual copy of each domain element (structure sharing of domain elements). Global array *Domain contains them. IDs. If all of the arguments of a term (including atoms) are domain elements, that term is called an eterm. For example, f(3,4), a, P(0), and Q. Each eterm has a unique ID which is used as an index into the cell table, for example, when a new eterm is obtained by evaluating a subterm to a domain element, we have to quickly check if this new eterm can be evaluated. We do this by calculating its ID and looking up in Cells[ID].value. And when we have a new assignment, say f(3,4)=2, we find the list of occurrences of f(3,4) by looking in Cells[ID].occurrences. */ /************* * * init_mace_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_mace_options(Mace_options opt) { opt->domain_size = init_parm("domain_size", 0, 0, INT_MAX); opt->start_size = init_parm("start_size", 2, 2, INT_MAX); opt->end_size = init_parm("end_size", -1, -1, INT_MAX); opt->iterate_up_to = init_parm("iterate_up_to", -1, -1, INT_MAX); opt->max_models = init_parm("max_models", 1, -1, INT_MAX); opt->max_seconds = init_parm("max_seconds", -1, -1, INT_MAX); opt->max_seconds_per = init_parm("max_seconds_per", -1, -1, INT_MAX); opt->selection_order = init_parm("selection_order", 2, 0, 2); opt->selection_measure = init_parm("selection_measure",4, 0, 4); opt->increment = init_parm("increment", 1, 1, INT_MAX); opt->max_megs = init_parm("max_megs", 200, -1, INT_MAX); opt->report_stderr = init_parm("report_stderr", -1, -1, INT_MAX); opt->print_models = init_flag("print_models", TRUE); opt->print_models_tabular = init_flag("print_models_tabular", FALSE); opt->lnh = init_flag("lnh", TRUE); opt->trace = init_flag("trace", FALSE); opt->negprop = init_flag("negprop", TRUE); opt->neg_assign = init_flag("neg_assign", TRUE); opt->neg_assign_near = init_flag("neg_assign_near", TRUE); opt->neg_elim = init_flag("neg_elim", TRUE); opt->neg_elim_near = init_flag("neg_elim_near", TRUE); opt->verbose = init_flag("verbose", FALSE); opt->integer_ring = init_flag("integer_ring", FALSE); opt->order_domain = init_flag("order_domain", FALSE); opt->arithmetic = init_flag("arithmetic", FALSE); opt->iterate_primes = init_flag("iterate_primes", FALSE); opt->iterate_nonprimes = init_flag("iterate_nonprimes", FALSE); opt->skolems_last = init_flag("skolems_last", FALSE); opt->return_models = init_flag("return_models", FALSE); opt->iterate = init_stringparm("iterate", 5, "all", "evens", "odds", "primes", "nonprimes"); /* dependencies */ flag_flag_dependency(opt->print_models_tabular,TRUE,opt->print_models,FALSE); flag_flag_dependency(opt->print_models,TRUE,opt->print_models_tabular,FALSE); flag_flag_dependency(opt->iterate_primes, TRUE,opt->iterate_nonprimes,FALSE); flag_flag_dependency(opt->iterate_nonprimes, TRUE,opt->iterate_primes,FALSE); parm_parm_dependency(opt->domain_size, opt->start_size, 1, TRUE); parm_parm_dependency(opt->domain_size, opt->end_size, 1, TRUE); parm_parm_dependency(opt->iterate_up_to, opt->end_size, 1, TRUE); flag_stringparm_dependency(opt->iterate_primes,TRUE,opt->iterate,"primes"); flag_stringparm_dependency(opt->iterate_nonprimes,TRUE,opt->iterate,"nonprimes"); flag_flag_dependency(opt->integer_ring, TRUE, opt->lnh, FALSE); flag_flag_dependency(opt->order_domain, TRUE, opt->lnh, FALSE); flag_flag_dependency(opt->arithmetic, TRUE, opt->lnh, FALSE); flag_parm_dependency(opt->arithmetic,TRUE,opt->selection_order,0); } /* init_mace_options */ /************* * * exit_string() * *************/ static char *exit_string(int code) { char *message; switch (code) { case MAX_MODELS_EXIT: message = "max_models"; break; case ALL_MODELS_EXIT: message = "all_models"; break; case EXHAUSTED_EXIT: message = "exhausted"; break; case MAX_MEGS_YES_EXIT: message = "max_megs_yes"; break; case MAX_MEGS_NO_EXIT: message = "max_megs_no" ; break; case MAX_SEC_YES_EXIT: message = "max_sec_yes"; break; case MAX_SEC_NO_EXIT: message = "max_sec_no"; break; case MACE_SIGINT_EXIT: message = "mace_sigint"; break; case MACE_SIGSEGV_EXIT: message = "mace_sigsegv"; break; default: message = "???"; } return message; } /* exit_string */ /************* * * mace4_exit() * *************/ void mace4_exit(int exit_code) { if (Opt && flag(Opt->verbose)) p_mem(); if (Opt && parm(Opt->report_stderr) > 0) fprintf(stderr, "Domain_size=%d. Models=%d. User_CPU=%.2f.\n", Domain_size, Total_models, user_seconds()); printf("\nUser_CPU=%.2f, System_CPU=%.2f, Wall_clock=%d.\n", user_seconds(), system_seconds(), wallclock()); if (Total_models == 0) printf("\nExiting with failure.\n"); else printf("\nExiting with %d model%s.\n", Total_models, Total_models == 1 ? "" : "s"); fprintf(stderr, "\n------ process %d exit (%s) ------\n", my_process_id(), exit_string(exit_code)); printf("\nProcess %d exit (%s) %s", my_process_id(), exit_string(exit_code), get_date()); printf("The process finished %s", get_date()); exit(exit_code); } /* mace4_exit */ /************* * * initialize_for_search() * * This is the initialization that has to be done only once * for a given set of clauses. It is independent of the * domain size. * *************/ static void initialize_for_search(Plist clauses) { int max, i; Symbol_data s; Mace4_clock = clock_init("Mace4"); /* In ground clauses, VARIABLEs represent domain elements, so from here on, print variables as integers. */ // set_variable_style(INTEGER_STYLE); /* These flags are for ground clause (mclause) literals. */ Relation_flag = claim_term_flag(); Negation_flag = claim_term_flag(); /* Cache some symbol numbers. */ Eq_sn = str_to_sn(eq_sym(), 2); Or_sn = str_to_sn(or_sym(), 2); Not_sn = str_to_sn(not_sym(), 1); /* Set up Symbols list. */ init_built_in_symbols(); /* =/2 (and maybe others) */ /* Maybe initialize for arithmetic. */ if (flag(Opt->arithmetic)) init_arithmetic(); Skolems_last = flag(Opt->skolems_last); /* Collect data for each symbol. */ Max_domain_element_in_input = -1; i = collect_mace4_syms(clauses, flag(Opt->arithmetic)); Max_domain_element_in_input = MAX(Max_domain_element_in_input, i); if (Max_domain_element_in_input == -1) printf("\n%% There are no natural numbers in the input.\n"); else printf("\n%% The largest natural number in the input is %d.\n", Max_domain_element_in_input); /* Set up map from ordinary symnums to mace symnums. */ max = 0; i = 0; for (s = Symbols; s != NULL; s = s->next) { s->mace_sn = i++; /* printf("mace symbol: %s/%d\n", sn_to_str(s->sn), sn_to_arity(s->sn)); */ max = (s->sn > max ? s->sn : max); } Sn_map_size = max+1; Sn_to_mace_sn = malloc(Sn_map_size * sizeof(void *)); for (i = 0; i < Sn_map_size; i++) Sn_to_mace_sn[i] = NULL; for (s = Symbols; s != NULL; s = s->next) { Sn_to_mace_sn[s->sn] = s; } } /* initialize_for_search */ /************* * * init_for_domain_size() * * Given the list of (general) clauses, set up the various data * structures that will be needed for a given domain size. * *************/ static void init_for_domain_size(void) { int i, j, nextbase, id; Symbol_data s; /* Give each symbol its "base" value, which is used to index cells. */ nextbase = 0; for (s = Symbols; s != NULL; s = s->next) { s->base = nextbase; nextbase += int_power(Domain_size, s->arity); } /* Set up the array of domain terms. All ground terms refer to these. */ Domain = malloc(Domain_size * sizeof(void *)); for (i = 0; i < Domain_size; i++) Domain[i] = get_variable_term(i); /* Set up the table of cells. */ Number_of_cells = nextbase; Cells = malloc(Number_of_cells * sizeof(struct cell)); Ordered_cells = malloc(Number_of_cells * sizeof(void *)); for (id = 0; id < Number_of_cells; id++) { struct cell *c = Cells + id; int n; c->id = id; c->occurrences = NULL; c->value = NULL; c->symbol = find_symbol_node(id); c->eterm = decode_eterm_id(id); c->max_index = max_index(id, c->symbol); n = id_to_domain_size(id); c->possible = malloc(n * sizeof(void *)); for (j = 0; j < n; j++) c->possible[j] = Domain[j]; /* really just a flag */ } order_cells(flag(Opt->verbose)); if (flag(Opt->negprop)) init_negprop_index(); } /* init_for_domain_size */ /************* * * built_in_assignments() * *************/ static void built_in_assignments(void) { Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { if (s->attribute == EQUALITY_SYMBOL) { int i, j; for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[i==j ? 1 : 0]); } } } /* built_in_assignments */ /************* * * special_assignments() * *************/ static void special_assignments(void) { if (flag(Opt->integer_ring)) { /* Fix [+,-,*] as the ring of integers mod domain_size. */ /* If any of those operations doesn't exist, then ignore it.*/ Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { int i, j; if (is_symbol(s->sn, "+", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[(i + j) % Domain_size]; } else if (is_symbol(s->sn, "*", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[(i * j) % Domain_size]; } else if (is_symbol(s->sn, "-", 1)) { for (i = 0; i < Domain_size; i++) Cells[X1(s->base,i)].value = Domain[(Domain_size - i) % Domain_size]; } else if (is_symbol(s->sn, "--", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = Domain[((i + Domain_size) - j) % Domain_size]; } } } if (flag(Opt->order_domain)) { Symbol_data s; for (s = Symbols; s != NULL; s = s->next) { int i, j; if (is_symbol(s->sn, "<", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[isn, "<=", 2)) { for (i = 0; i < Domain_size; i++) for (j = 0; j < Domain_size; j++) Cells[X2(s->base,i,j)].value = (Domain[i<=j ? 1 : 0]); } } } } /* special_assignments */ /************* * * check_that_ground_clauses_are_true() * *************/ static BOOL check_that_ground_clauses_are_true(void) { Plist g; BOOL ok = TRUE; for (g = Ground_clauses; g != NULL; g = g->next) { Mclause c = g->v; if (!c->subsumed) { fprintf(stderr, "ERROR, model reported, but clause not true!\n"); fprintf(stdout, "ERROR, model reported, but clause not true! "); p_mclause(c); ok = FALSE; } } return ok; } /* check_that_ground_clauses_are_true */ /************* * * possible_model() * *************/ static int possible_model(void) { if (flag(Opt->arithmetic)) { if (!check_with_arithmetic(Ground_clauses)) return SEARCH_GO_NO_MODELS; } else if (!check_that_ground_clauses_are_true()) fatal_error("possible_model, bad model found"); { static int next_message = 1; Total_models++; Mstats.current_models++; if (flag(Opt->return_models)) { Term modelterm = interp_term(); Interp model = compile_interp(modelterm, FALSE); zap_term(modelterm); Models = plist_append(Models, model); } if (flag(Opt->print_models)) print_model_standard(stdout, TRUE); else if (flag(Opt->print_models_tabular)) p_model(FALSE); else if (next_message == Total_models) { printf("\nModel %d has been found.\n", Total_models); next_message *= 10; } fflush(stdout); if (parm(Opt->max_models) != -1 && Total_models >= parm(Opt->max_models)) return SEARCH_MAX_MODELS; else return SEARCH_GO_MODELS; } } /* possible_model */ /************* * * mace_megs() * *************/ static int mace_megs(void) { return (megs_malloced() - Start_megs) + (estack_bytes() / (1024*1024)); } /* mace_megs */ /************* * * check_time_memory() * *************/ static int check_time_memory(void) { static int Next_report; double seconds = user_seconds(); int max_seconds = parm(Opt->max_seconds); int max_seconds_per = parm(Opt->max_seconds_per); int max_megs = parm(Opt->max_megs); int report = parm(Opt->report_stderr); if (max_seconds != -1 && seconds - Start_seconds > max_seconds) return SEARCH_MAX_TOTAL_SECONDS; else if (max_seconds_per != -1 && seconds - Start_domain_seconds > parm(Opt->max_seconds_per)) return SEARCH_MAX_DOMAIN_SECONDS; else if (max_megs != -1 && mace_megs() > parm(Opt->max_megs)) return SEARCH_MAX_MEGS; else { if (report > 0) { if (Next_report == 0) Next_report = parm(Opt->report_stderr); if (seconds >= Next_report) { fprintf(stderr, "Domain_size=%d. Models=%d. User_CPU=%.2f.\n", Domain_size, Total_models, seconds); fflush(stderr); while (seconds >= Next_report) Next_report += report; } } return SEARCH_GO_NO_MODELS; } } /* check_time_memory */ /************* * * mace4_skolem_check() * *************/ static BOOL mace4_skolem_check(int id) { /* Should we keep going w.r.t. the Skolem restriction? */ if (!flag(Opt->skolems_last)) return TRUE; else if (Cells[id].symbol->attribute == SKOLEM_SYMBOL) { printf("pruning\n"); return FALSE; } else return TRUE; } /* mace4_skolem_check */ /************* * * p_possible_values() * *************/ #if 0 static void p_possible_values(void) { int i; for (i = 0; i < Number_of_cells; i++) { if (Cells[i].symbol->attribute == ORDINARY_SYMBOL) { int j; printf("Cell %d: ", i); for (j = 0; j < id_to_domain_size(i); j++) { if (Cells[i].possible[j] != NULL) printf(" %d", j); } printf("\n"); } } } /* p_possible_values */ #endif /************* * * search() * * Max_constrained is the maximum constrained domain element * (or -1 is none is constrained). Greater domain elements * can all be considered symmetric. An element can become * constrained in two ways: (1) it is an index of some selected * cell, or (2) it is the value assigned to some selected cell. * (Propagation does not constrain elements. This might need * careful justification.) * * To apply the least number heuristic, we consider values * 0 ... MIN(max_constrained+1, Domain_size-1). * * To make this effective, we should keep max_constrained as low as * possible by selecting cells with maximum index <= max_constrained. * * return: * SEARCH_GO_MODELS * SEARCH_GO_NO_MODELS * SEARCH_MAX_MODELS * SEARCH_MAX_MEGS * SEARCH_MAX_TOTAL_SECONDS * SEARCH_MAX_DOMAIN_SECONDS * *************/ static int search(int max_constrained, int depth) { int id; BOOL go; int rc = check_time_memory(); if (rc != SEARCH_GO_NO_MODELS) return rc; else { id = select_cell(max_constrained); if (id == -1) { rc = possible_model(); return rc; } else { int i, last; /* we'll do 0 .. last */ int x = Cells[id].max_index; max_constrained = MAX(max_constrained, x); Mstats.selections++; if (flag(Opt->trace)) { printf("select: "); p_model(FALSE); /* p_possible_values(); */ } if (Cells[id].symbol->type == RELATION) last = 1; else if (flag(Opt->lnh)) last = MIN(max_constrained+1, Domain_size-1); else last = Domain_size-1; for (i = 0, go = TRUE; i <= last && go; i++) { Estack stk; Mstats.assignments++; if (flag(Opt->trace)) { printf("assign: "); fwrite_term(stdout, Cells[id].eterm); printf("=%d (%d) depth=%d\n", i, last, depth); } stk = assign_and_propagate(id, Domain[i]); if (stk != NULL) { /* no contradiction found during propagation, so we recurse */ rc = search(MAX(max_constrained, i), depth+1); /* undo assign_and_propagate changes */ restore_from_stack(stk); if (rc == SEARCH_GO_MODELS) go = mace4_skolem_check(id); else go = (rc == SEARCH_GO_NO_MODELS); } } return rc; } } } /* search */ /************* * * mace4n() -- look for a model of a specific size * *************/ static int mace4n(Plist clauses, int order) { Plist p, g; int i, rc; Mstate initial_state = get_mstate(); Variable_style save_style = variable_style(); set_variable_style(INTEGER_STYLE); if (Max_domain_element_in_input >= order) { if (flag(Opt->arithmetic)) { if (!ok_for_arithmetic(clauses, order)) return SEARCH_DOMAIN_OUT_OF_RANGE; } else return SEARCH_DOMAIN_OUT_OF_RANGE; } Domain_size = order; init_for_domain_size(); built_in_assignments(); /* Fill out equality table (and maybe others). */ special_assignments(); /* assignments determined by options */ /* Instantiate clauses over the domain. This also (1) makes any domain element constants into real domain elements, (2) applies OR, NOT, and EQ simplification, and (3) does unit propagation (which pushes events onto initial_state->stack). Do the units first, then the 2-clauses, then the rest. */ for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) < 2) generate_ground_clauses(p->v, initial_state); for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) == 2) generate_ground_clauses(p->v, initial_state); for (p = clauses; initial_state->ok && p != NULL; p = p->next) if (number_of_literals(p->v) > 2) generate_ground_clauses(p->v, initial_state); /* The preceding calls push propagation events onto initial_state->stack. We won't have to undo those initial events during the search, but we can undo them after the search. */ if (flag(Opt->verbose)) { printf("\nInitial partial model:\n"); p_model(FALSE); fflush(stdout); } /* Here we go! */ if (initial_state->ok) rc = search(Max_domain_element_in_input, 0); else rc = SEARCH_GO_NO_MODELS; /* contradiction in initial state */ /* Free all of the memory associated with the current domain size. */ restore_from_stack(initial_state->stack); free_mstate(initial_state); if (flag(Opt->negprop)) free_negprop_index(); free(Ordered_cells); Ordered_cells = NULL; for (i = 0; i < Number_of_cells; i++) { zap_mterm(Cells[i].eterm); free(Cells[i].possible); } free(Cells); Cells = NULL; for (i = 0; i < Domain_size; i++) zap_term(Domain[i]); free(Domain); Domain = NULL; for (g = Ground_clauses; g != NULL; g = g->next) zap_mclause(g->v); zap_plist(Ground_clauses); Ground_clauses = NULL; set_variable_style(save_style); return rc; } /* mace4n */ /************* * * iterate_ok() * *************/ static BOOL iterate_ok(int n, char *class) { if (str_ident(class, "all")) return TRUE; else if (str_ident(class, "evens")) return n % 2 == 0; else if (str_ident(class, "odds")) return n % 2 == 1; else if (str_ident(class, "primes")) return prime(n); else if (str_ident(class, "nonprimes")) return !prime(n); else { fatal_error("iterate_ok, unknown class"); return FALSE; /* to please compiler */ } } /* iterate_ok */ /************* * * next_domain_size() * *************/ static int next_domain_size(n) { int top = (parm(Opt->end_size) == -1 ? INT_MAX : parm(Opt->end_size)); if (n == 0) n = parm(Opt->start_size); /* first call */ else n += parm(Opt->increment); while (!iterate_ok(n, stringparm1(Opt->iterate))) n += parm(Opt->increment); return (n > top ? -1 : n); } /* next_domain_size */ /************* * * mace4() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Mace_results mace4(Plist clauses, Mace_options opt) { int n, rc; Mace_results results = malloc(sizeof(struct mace_results)); disable_max_megs(); /* mace4 does its own max_megs check */ Start_seconds = user_seconds(); Start_megs = megs_malloced(); Opt = opt; /* put options into a global variable */ initialize_for_search(clauses); n = next_domain_size(0); /* returns -1 if we're done */ rc = SEARCH_GO_NO_MODELS; while (n >= 2 && (rc == SEARCH_GO_NO_MODELS || rc == SEARCH_GO_MODELS)) { char str[20]; sprintf(str, "DOMAIN SIZE %d", n); print_separator(stdout, str, TRUE); fflush(stdout); fprintf(stderr,"\n=== Mace4 starting on domain size %d. ===\n",n); Start_domain_seconds = user_seconds(); clock_start(Mace4_clock); rc = mace4n(clauses, n); if (rc == SEARCH_MAX_DOMAIN_SECONDS) { printf("\n====== Domain size %d terminated by max_seconds_per. ======\n",n); rc = SEARCH_GO_NO_MODELS; } else if (rc == SEARCH_DOMAIN_OUT_OF_RANGE) { printf("\n====== Domain size %d skipped because domain elememt too big. ======\n",n); rc = SEARCH_GO_NO_MODELS; } clock_stop(Mace4_clock); p_stats(); reset_current_stats(); clock_reset(Mace4_clock); n = next_domain_size(n); /* returns -1 if we're done */ } /* free memory used for all domain sizes */ free_estack_memory(); free(Sn_to_mace_sn); Sn_to_mace_sn = NULL; results->success = Total_models != 0; results->models = Models; /* NULL if no models or not collecting models */ results->user_seconds = user_seconds() - Start_seconds; if (rc == SEARCH_MAX_MODELS) results->return_code = MAX_MODELS_EXIT; else if (rc == SEARCH_GO_MODELS || rc == SEARCH_GO_NO_MODELS) results->return_code = Total_models==0 ? EXHAUSTED_EXIT : ALL_MODELS_EXIT; else if (rc == SEARCH_MAX_TOTAL_SECONDS) results->return_code = Total_models==0 ? MAX_SEC_NO_EXIT : MAX_SEC_YES_EXIT; else if (rc == SEARCH_MAX_MEGS) results->return_code = Total_models==0 ? MAX_MEGS_NO_EXIT : MAX_MEGS_YES_EXIT; else fatal_error("mace4: unknown return code"); enable_max_megs(); return results; } /* mace4 */ LADR-2009-11A/mace4.src/Changelog.old0000644000175000017500000000336410333733542016175 0ustar mccunemccuneMace4 Changelog. Most recent changes are at the top. May 26, 2004. Change iterate_up_to parameter to allow a value of -1, which means to iterate forever. May 26, 2004. In ../ladr/formula.c, update the CNF transformation, making it more efficient. Prompted by the May 18, 2004 bug. May 18, 2004. Release mace4-2004-C. May 18, 2004. Soundness bug from Geoff Sutcliffe. CNF transformation. This affects non-clausal input only (formulas(...) in the input). Since this is a serious bug, a new release will be made today. January 7, 2004. Bug from Guy Erez. Segfault if a domain element is used as a propositional variable, as in the clause "0.". Fixed by checking for that case (and causing a fatal_error) in collect_mace_syms. November 20, 2003. Fixed minor memory leak that shows up when using iterate_up_to. November 19, 2003. Added flag iterate_primes. When using assign(iterate_up_to, n), set(iterate_primes) says to skip the non-prime domain sizes. The corresponding command-line argument is -q1. November 19, 2003. Added parm increment (default 1). When using assign(iterate_up_to, n), assign(increment, i) does the obvious. The corresponding command-line argument is, for example, -i2. November 11, 2003. Added flag integer_ring. This fixes the operations [+,-,*] as the ring of integers mod domain_size. The corresponding command-line argument is -R1. October 17, 2003. mace4-2003-B released. This is the first formal release of Mace4. ---(probably some unrecorded changes)--- October 28, 2004. (Many changes to LADR) Changed negation symbol from ~ to -. (Sorry.) Changed simp_term in ground.c so that - can be used as a function symbol as well as a logic symbol. --- Further changes are listed in the LADR Changelog file (../Changelog). LADR-2009-11A/mace4.src/save/0000755000175000017500000000000010316336077014541 5ustar mccunemccuneLADR-2009-11A/mace4.src/save/raw-cooked~0000644000175000017500000000252010316336065016711 0ustar mccunemccune/************* * * print_model_cooked() * *************/ void print_model_cooked(FILE *fp, BOOL print_head) { Symbol_data p; Variable_style save_style = variable_style(); /* restore at end */ set_variable_style(INTEGER_STYLE); if (print_head) fprintf(fp, "\n-------- Model %d at %.2f seconds --------\n", Total_models, user_seconds()); fprintf(fp, "\n%% Size of model is %d.\n", Domain_size); for (p = Symbols; p != NULL; p = p->next) { if (p->attribute != EQUALITY_SYMBOL) { BOOL relation = (p->type == RELATION); int n = int_power(Domain_size, p->arity); int i; fprintf(fp, "\n"); for (i = 0; i < n; i++) { int id = p->base + i; if (relation) { BOOL positive = (VARNUM(Cells[id].value) == 0); if (positive) fwrite_term_nl(fp, Cells[id].eterm); else { Term negation = build_unary_term(str_to_sn(NOT_SYM, 1), Cells[id].eterm); fwrite_term_nl(fp, negation); free_term(negation); /* top node only */ } } else { fwrite_term(fp, Cells[id].eterm); if (Cells[id].value == NULL) fprintf(fp, " = -.\n"); else fprintf(fp, " = %d.\n", VARNUM(Cells[id].value)); } } } } if (print_head) fprintf(fp, "\n-------- end of model --------\n"); set_variable_style(save_style); } /* print_model_cooked */ LADR-2009-11A/mace4.src/save/raw-cooked0000644000175000017500000000430510316336077016521 0ustar mccunemccune/************* * * print_model_cooked() * *************/ void print_model_cooked(FILE *fp, BOOL print_head) { Symbol_data p; Variable_style save_style = variable_style(); /* restore at end */ set_variable_style(INTEGER_STYLE); if (print_head) fprintf(fp, "\n-------- Model %d at %.2f seconds --------\n", Total_models, user_seconds()); fprintf(fp, "\n%% Size of model is %d.\n", Domain_size); for (p = Symbols; p != NULL; p = p->next) { if (p->attribute != EQUALITY_SYMBOL) { BOOL relation = (p->type == RELATION); int n = int_power(Domain_size, p->arity); int i; fprintf(fp, "\n"); for (i = 0; i < n; i++) { int id = p->base + i; if (relation) { BOOL positive = (VARNUM(Cells[id].value) == 0); if (positive) fwrite_term_nl(fp, Cells[id].eterm); else { Term negation = build_unary_term(str_to_sn(NOT_SYM, 1), Cells[id].eterm); fwrite_term_nl(fp, negation); free_term(negation); /* top node only */ } } else { fwrite_term(fp, Cells[id].eterm); if (Cells[id].value == NULL) fprintf(fp, " = -.\n"); else fprintf(fp, " = %d.\n", VARNUM(Cells[id].value)); } } } } if (print_head) fprintf(fp, "\n-------- end of model --------\n"); set_variable_style(save_style); } /* print_model_cooked */ /************* * * print_model_raw() * *************/ void print_model_raw(FILE *fp, BOOL print_head) { Symbol_data p; if (print_head) fprintf(fp, "\n-------- Model %d at %.2f seconds --------\n", Total_models, user_seconds()); for (p = Symbols; p != NULL; p = p->next) { char *name = sn_to_str(p->sn); if (p->attribute != EQUALITY_SYMBOL) { int n = int_power(Domain_size, p->arity); int i; fprintf(fp, "\n%s %s / %d\n\n", p->type == FUNCTION ? "Function" : "Relation", name, p->arity); for (i = 0; i < n; i++) { int id = p->base + i; fprintf(fp, " %2d", VARNUM(Cells[id].value)); if (i % Domain_size == Domain_size-1) fprintf(fp, "\n"); } if (p->arity == 0) fprintf(fp, "\n"); } } if (print_head) fprintf(fp, "\n-------- end of model --------\n"); } /* print_model_raw */ LADR-2009-11A/mace4.src/syms.c0000644000175000017500000001137411105135665014745 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" extern Symbol_data Symbols; extern int Domain_size; extern struct cell *Cells; /************* * * Symbol_data get_symbol_data() * *************/ Symbol_data get_symbol_data(void) { Symbol_data p = tp_alloc(sizeof(struct symbol_data)); p->sn = 0; p->mace_sn = 0; p->arity = 0; p->type = 0; p->base = 0; p->attribute = ORDINARY_SYMBOL; p->next = NULL; return(p); } /* get_symbol_data */ /************* * * Symbol_data find_symbol_data() * *************/ Symbol_data find_symbol_data(int sn) { Symbol_data p = Symbols; while (p != NULL && p->sn != sn) p = p->next; return p; } /* find_symbol_data */ /************* * * init_built_in_symbols() * *************/ void init_built_in_symbols(void) { Symbol_data s; s = get_symbol_data(); s->sn = str_to_sn(eq_sym(), 2); s->arity = 2; s->type = RELATION; s->attribute = EQUALITY_SYMBOL; s->next = Symbols; Symbols = s; } /* init_built_in_symbols */ /************* * * insert_mace4_sym() * *************/ static Symbol_data insert_mace4_sym(Symbol_data syms, int sn, int type) { if (syms == NULL || sn_to_lex_val(sn) < sn_to_lex_val(syms->sn)) { Symbol_data new = get_symbol_data(); new->sn = sn; new->arity = sn_to_arity(sn); new->type = type; if (is_skolem(sn)) new->attribute = SKOLEM_SYMBOL; new->next = syms; return new; } else { syms->next = insert_mace4_sym(syms->next, sn, type); return syms; } } /* insert_mace4_sym */ /************* * * collect_mace4_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int collect_mace4_syms(Plist clauses, BOOL arithmetic) { Ilist fsyms, rsyms, p; int max_domain = -1; fsyms = fsym_set_in_topforms(clauses); rsyms = rsym_set_in_topforms(clauses); lex_order(fsyms, rsyms, NULL, NULL, lex_compare_arity_0123); for (p = fsyms; p; p = p->next) { int sn = p->i; int dom = natural_string(sn_to_str(sn)); if (dom >= 0) max_domain = MAX(dom, max_domain); else if (arithmetic && arith_op_sn(sn)) ; /* don't insert */ else Symbols = insert_mace4_sym(Symbols, sn, FUNCTION); } for (p = rsyms; p; p = p->next) { int sn = p->i; int dom = natural_string(sn_to_str(sn)); if (dom >= 0) { printf("\nThe bad symbol is: %s\n", sn_to_str(sn)); fatal_error("collect_mace4_syms, relation symbol is domain element"); } else if (is_eq_symbol(sn) || (arithmetic && arith_rel_sn(sn))) ; /* don't insert */ else Symbols = insert_mace4_sym(Symbols, sn, RELATION); } zap_ilist(fsyms); zap_ilist(rsyms); return max_domain; } /* collect_mace4_syms */ /************* * * p_symbol_data() * *************/ void p_symbol_data(Symbol_data s) { if (s != NULL) printf("%s/%d, sn=%d, mace_sn=%d, base=%d, type=%d, attribute=%d.\n", sn_to_str(s->sn), s->arity, s->sn, s->mace_sn, s->base, s->type, s->attribute); } /* p_symbol_data */ /************* * * find_symbol_node() * *************/ Symbol_data find_symbol_node(int id) { /* Assume bases are increasing and that the id is in range. Return node with the largest base <= the id. */ Symbol_data prev = NULL; Symbol_data curr = Symbols; while (curr != NULL && curr->base <= id) { prev = curr; curr = curr->next; } return prev; } /* find_symbol_node */ /************* * * id_to_domain_size() * *************/ int id_to_domain_size(int id) { /* Assume the id is in range. */ Symbol_data s = Cells[id].symbol; return (s->type == RELATION ? 2 : Domain_size); } /* id_to_domain_size */ /************* * * max_index() * * If the cell given by ID represents f(i,j,k,...), return the * maximum of (i,j,k,...). If it is a constant, return -1. * *************/ int max_index(int id, Symbol_data s) { int max = -1; int n = Domain_size; int x = id - s->base; int i; for (i = s->arity - 1; i >= 0; i--) { int p = int_power(n, i); int e = x / p; max = MAX(e,max); x = x % p; } return max; } /* max_index */ LADR-2009-11A/mace4.src/util0000777000175000017500000000000011176424560016535 2../ladr/utilustar mccunemccuneLADR-2009-11A/mace4.src/select.c0000644000175000017500000001612211151267347015231 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" extern Mace_options Opt; extern Symbol_data Symbols; extern int Number_of_cells; extern struct cell *Cells; extern struct cell **Ordered_cells; /* Permutation of Cells. */ extern int First_skolem_cell; /* =Number_of_cells if !Skolems_last */ extern int Domain_size; extern Term *Domain; extern struct mace_stats Mstats; /* Here are the meanings of the parameters that control selection. */ #define SELECT_LINEAR 0 /* selection orders */ #define SELECT_CONCENTRIC 1 #define SELECT_CONCENTRIC_BAND 2 #define NO_MEASURE 0 /* selection measures */ #define MOST_OCCURRENCES 1 #define MOST_PROPAGATIONS 2 #define MOST_CONTRADICTIONS 3 #define MOST_CROSSED 4 /************* * * num_contradictions() - for a given ID, try all assignments and see * how many give contradiction by propagation. * * Leave the Propaagtions statistic as it was. * * We're not interested in a number less than max_so_far, and * if we determine that we'll never get that many, we return -1. * *************/ static int num_contradictions(int id, int max_so_far) { int n = 0; int save_prop_count = Mstats.propagations; int ds = id_to_domain_size(id); int i, to_try; for (i = 0; i < ds; i++) { Estack stk = assign_and_propagate(id, Domain[i]); if (stk == NULL) n++; else restore_from_stack(stk); to_try = (ds - i) - 1; if (n + to_try <= max_so_far) { Mstats.propagations = save_prop_count; return -1; /* can't beat max_so_far */ } } Mstats.propagations = save_prop_count; return n; } /* num_contradictions */ /************* * * num_propagations() - for a given ID, try all assignments * and return the total number of propagations. * * Leave the Propaagtions statistic as it was. * *************/ static int num_propagations(int id) { int n = 0; int i; int save_prop_count = Mstats.propagations; int ds = id_to_domain_size(id); Mstats.propagations = 0; for (i = 0; i < ds; i++) { Estack stk = assign_and_propagate(id, Domain[i]); restore_from_stack(stk); n += Mstats.propagations; Mstats.propagations = 0; } Mstats.propagations = save_prop_count; return n; } /* num_propagations */ /************* * * num_crossed() - number of values crossed off for a given ID. * *************/ static int num_crossed(int id) { Term *p = Cells[id].possible; int n = 0; int i; int ds = id_to_domain_size(id); for (i = 0; i < ds; i++) if (p[i] == NULL) n++; return n; } /* num_crossed */ /************* * * num_occurrences() - number of (active) occurrences of an eterm * *************/ static int num_occurrences(int id) { Term t; int n = 0; for (t = Cells[id].occurrences; t != NULL; t = t->u.vp) n++; return n; } /* num_occurrences */ /************* * * selection_measure() * *************/ static void selection_measure(int id, int *max, int *max_id) { int n = 0; switch (parm(Opt->selection_measure)) { case MOST_OCCURRENCES: n = num_occurrences(id); break; case MOST_PROPAGATIONS: n = num_propagations(id); break; case MOST_CONTRADICTIONS: n = num_contradictions(id, *max); break; case MOST_CROSSED: n = num_crossed(id); break; default: fatal_error("selection_measure: bad selection measure"); } if (n > *max) { *max = n; *max_id = id; } } /* selection_measure */ /************* * * select_linear() * *************/ int select_linear(int min_id, int max_id) { if (parm(Opt->selection_measure) == NO_MEASURE) { /* Return the first open cell. */ int i = min_id; while (i <= max_id && Cells[i].value != NULL) i++; return (i > max_id ? -1 : i); } else { int id_of_max = -1; int max = -1; int i; for (i = min_id; i <= max_id; i++) { if (Cells[i].value == NULL) { selection_measure(i, &max, &id_of_max); } } return id_of_max; } } /* select_linear */ /************* * * select_concentric() * * This assumes that Ordered_cells is ordered FIRST by max_index. * * If the first open cell has max_index n, return the best open * cell with max index n. * *************/ int select_concentric(int min_id, int max_id) { /* Find the first open cell. */ int i = min_id; while (i <= max_id && Ordered_cells[i]->value != NULL) i++; if (i > max_id) return -1; else { /* Find the best cell with the same max_index as the first open cell. */ int n = Ordered_cells[i]->max_index; int max_val = -1; int id_of_max = -1; while (i <= max_id && Ordered_cells[i]->max_index <= n) { if (Ordered_cells[i]->value == NULL) selection_measure(Ordered_cells[i]->id, &max_val, &id_of_max); i++; } return id_of_max; } } /* select_concentric */ /************* * * select_concentric_band() * *************/ int select_concentric_band(min_id, max_id, max_constrained) { int max = -1; int id_of_max = -1; int i = min_id; while (i <= max_id && Ordered_cells[i]->max_index <= max_constrained) { if (Ordered_cells[i]->value == NULL) selection_measure(Ordered_cells[i]->id, &max, &id_of_max); i++; } if (id_of_max >= 0) return id_of_max; else /* There is nothing in the band, so revert to select_concentric. This is a bit redundant, because it will scan (again) the full cells. */ return select_concentric(min_id, max_id); } /* select_concentric_band */ /************* * * select_cell() * *************/ int select_cell(int max_constrained) { int id = -1; switch (parm(Opt->selection_order)) { case SELECT_LINEAR: id = select_linear(0, First_skolem_cell-1); break; case SELECT_CONCENTRIC: id = select_concentric(0, First_skolem_cell-1); break; case SELECT_CONCENTRIC_BAND: id = select_concentric_band(0, First_skolem_cell-1, max_constrained); break; default: fatal_error("bad selection order"); } if (id >= 0) return id; switch (parm(Opt->selection_order)) { case SELECT_LINEAR: id = select_linear(First_skolem_cell, Number_of_cells-1); break; case SELECT_CONCENTRIC: id = select_concentric(First_skolem_cell, Number_of_cells-1); break; case SELECT_CONCENTRIC_BAND: id = select_concentric_band(First_skolem_cell, Number_of_cells-1, max_constrained); break; default: fatal_error("bad selection order"); } return id; } /* select_cell */ LADR-2009-11A/mace4.src/commandline.c0000644000175000017500000001624610707204741016242 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" #include /************* * * member_args() * *************/ BOOL member_args(int argc, char **argv, char *str) { int i; for (i = 1; i < argc; i++) if (str_ident(argv[i], str)) return TRUE; return FALSE; } /* member_args */ /************* * * command_line_flag() * *************/ static void command_line_flag(int id, char *optarg) { if (!optarg || str_ident(optarg, "1")) { set_flag(id, TRUE); printf("\n%% From the command line: set(%s).\n", flag_id_to_str(id)); } else if (str_ident(optarg, "0")) { clear_flag(id, TRUE); printf("\n%% From the command line: clear(%s).\n", flag_id_to_str(id)); } else fatal_error("Command-line flag must have 0 or 1 as the value"); } /* command_line_flag */ /************* * * command_line_parm() * *************/ static void command_line_parm(int id, char *optarg) { int n = atoi(optarg); assign_parm(id, n, TRUE); printf("\n%% From the command line: assign(%s, %d).\n", parm_id_to_str(id),n); } /* command_line_parm */ /************* * * usage_message() * *************/ void usage_message(FILE *fp, Mace_options opt) { fprintf(fp, "%s %s (%s) -- Search for finite models.\n" "\n" "Input commands, clauses, and formulas are taken from standard input.\n" "\n" "Command-line options override any settings in the input file.\n" "To set or clear a flag, you must give 1 or 0 as the value.\n" "\n" "Basic Options\n" "\n" " -n n : (lower case) parm domain_size (%d).\n" " -N n : (upper case) parm end_size (%d).\n" " -i n : (lower case) parm increment (%d).\n" " -P n : (upper case) flag print_models (%s).\n" " -p n : (lower case) flag print_models_tabular (%s).\n" " -m n : parm max_models (%d).\n" " -t n : parm max_seconds (%d).\n" " -s n : parm max_seconds_per (%d).\n" " -b n : parm max_megs (%d).\n" " -V n : (upper case) flag prolog_style_variables (%s).\n" " -v n : (lower case) flag verbose (%s).\n" "\n" "Advanced Options\n" "\n" " -L n : flag lnh (%s).\n" " -O n : parm selection_order (%d).\n" " -M n : parm Selection_measure (%d).\n" " -G n : flag negprop (%s).\n" " -H n : flag neg_assign (%s).\n" " -I n : flag neg_assign_near (%s).\n" " -J n : flag neg_elim (%s).\n" " -K n : flag neg_elim_near (%s).\n" " -T n : flag trace (%s).\n" " -R n : flag integer_ring (%s).\n" " -q n : flag iterate_primes (%s).\n" " -S n : flag skolems_last (%s).\n" "\n" "Special Flags (not corresponding to set/clear/assign commands)\n" "\n" " -c : Ignore unrecognized set/clear/assign commands in the input\n" " file. This is useful for running MACE4 on an input file\n" " designed for another program such as a theorem prover.\n" "\n" , PROGRAM_NAME, PROGRAM_VERSION, PROGRAM_DATE, parm(opt->domain_size), parm(opt->iterate_up_to), parm(opt->increment), flag(opt->print_models) ? "set" : "clear", flag(opt->print_models_tabular) ? "set" : "clear", parm(opt->max_models), parm(opt->max_seconds), parm(opt->max_seconds_per), parm(opt->max_megs), flag(prolog_style_variables_id()) ? "set" : "clear", flag(opt->verbose) ? "set" : "clear", flag(opt->lnh) ? "set" : "clear", parm(opt->selection_order), parm(opt->selection_measure), flag(opt->negprop) ? "set" : "clear", flag(opt->neg_assign) ? "set" : "clear", flag(opt->neg_assign_near) ? "set" : "clear", flag(opt->neg_elim) ? "set" : "clear", flag(opt->neg_elim_near) ? "set" : "clear", flag(opt->trace) ? "set" : "clear", flag(opt->integer_ring) ? "set" : "clear", flag(opt->iterate_primes) ? "set" : "clear", flag(opt->skolems_last) ? "set" : "clear" ); } /* usage_message */ /************* * * process_command_line_args() * *************/ void process_command_line_args(int argc, char **argv, Mace_options opt) { extern char *optarg; int c; /* No colons: no argument. One colon: argument required. Two colons: argument optional. (GNU extension! Don't use it!) */ while ((c = getopt(argc, argv, "n:N:m:t:s:b:O:M:p:P:v:L:G:H:I:J:K:T:R:i:q:Q:S:cf:g")) != EOF) { switch (c) { case 'n': command_line_parm(opt->domain_size, optarg); break; case 'N': command_line_parm(opt->end_size, optarg); break; case 'm': command_line_parm(opt->max_models, optarg); break; case 't': command_line_parm(opt->max_seconds, optarg); break; case 's': command_line_parm(opt->max_seconds_per, optarg); break; case 'b': command_line_parm(opt->max_megs, optarg); break; case 'O': command_line_parm(opt->selection_order, optarg); break; case 'M': command_line_parm(opt->selection_measure, optarg); break; case 'P': command_line_flag(opt->print_models, optarg); break; case 'p': command_line_flag(opt->print_models_tabular, optarg); break; #if 0 /* Prolog-style variables cannot be set from the command line. */ case 'V': command_line_flag(prolog_style_variables_id(), optarg); break; #endif case 'v': command_line_flag(opt->verbose, optarg); break; case 'L': command_line_flag(opt->lnh, optarg); break; case 'G': command_line_flag(opt->negprop, optarg); break; case 'H': command_line_flag(opt->neg_assign, optarg); break; case 'I': command_line_flag(opt->neg_assign_near, optarg); break; case 'J': command_line_flag(opt->neg_elim, optarg); break; case 'K': command_line_flag(opt->neg_elim_near, optarg); break; case 'T': command_line_flag(opt->trace, optarg); break; case 'R': command_line_flag(opt->integer_ring, optarg); break; case 'i': command_line_parm(opt->increment, optarg); break; case 'q': command_line_flag(opt->iterate_primes, optarg); break; case 'Q': command_line_flag(opt->iterate_nonprimes, optarg); break; case 'S': command_line_flag(opt->skolems_last, optarg); break; case 'c': /* prover compatability mode */ case 'f': /* input files */ case 'g': /* tptp syntax */ /* do nothing---these are handled elsewhere */ break; case '?': default: usage_message(stderr, opt); fatal_error("unrecognized command-line option or missing value (flags take 0 or 1)"); } } } /* process_command_line_args */ LADR-2009-11A/mace4.src/msearch.h0000644000175000017500000001454611133701323015374 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #define PROGRAM_NAME "Mace4" #include "../VERSION_DATE.h" /*********************************************** LADR includes */ #include "../ladr/header.h" #include "../ladr/top_input.h" /* includes most of what we need */ #include "../ladr/clausify.h" #include "../ladr/clock.h" #include "../ladr/nonport.h" #include "../ladr/interp.h" /*********************************************** local includes */ #include "estack.h" #include "arithmetic.h" #include "mstate.h" #include "syms.h" #include "ground.h" #include "propagate.h" /*********************************************** macro definitions */ #define MAX(a,b) ((a) > (b) ? a : b) #define MIN(a,b) ((a) < (b) ? a : b) typedef struct mace_options * Mace_options; struct mace_options { /* This structure holds the option IDs, not the option values! */ /* flags */ int print_models, print_models_tabular, lnh, trace, negprop, neg_assign, neg_assign_near, neg_elim, neg_elim_near, verbose, integer_ring, order_domain, arithmetic, iterate_primes, iterate_nonprimes, skolems_last, return_models; /* special case */ /* parms */ int domain_size, start_size, end_size, iterate_up_to, increment, max_models, selection_order, selection_measure, max_seconds, max_seconds_per, max_megs, report_stderr; /* stringparms */ int iterate; }; struct mace_stats { /* stats for the current domain size */ unsigned current_models, selections, assignments, propagations, cross_offs, rewrite_terms, rewrite_bools, indexes, ground_clauses_seen, ground_clauses_kept, rules_from_neg, neg_elim_attempts, neg_elim_agone, neg_elim_egone, neg_assign_attempts, neg_assign_agone, neg_assign_egone, neg_near_assign_attempts, neg_near_assign_agone, neg_near_assign_egone, neg_near_elim_attempts, neg_near_elim_agone, neg_near_elim_egone; }; /* Mace results */ typedef struct mace_results * Mace_results; struct mace_results { BOOL success; Plist models; double user_seconds; int return_code; }; /* Exit codes */ enum { MAX_MODELS_EXIT = 0, /* FATAL_EXIT = 1, declared elsewhere, and not needed here*/ EXHAUSTED_EXIT = 2, ALL_MODELS_EXIT = 3, MAX_SEC_YES_EXIT = 4, MAX_SEC_NO_EXIT = 5, MAX_MEGS_YES_EXIT = 6, MAX_MEGS_NO_EXIT = 7, MACE_SIGINT_EXIT = 101, MACE_SIGSEGV_EXIT = 102 }; /*********************************************** structure declarations */ /* A cell is member of a function or relation table. For example, if we have a group operation and the domain is size 6, then the term f(2,3) represents one cell of the group multiplication table. We will dynamically allocate a (1-dimensional) array of cells (to hold all tables) at the beginning of the run after we know how many we'll need. The array will be indexed by IDs that are constructed from the terms representing the cells. (Each symbol has a "base" value, and the cell ID is an offset from the base.) We have, in effect, multidimensional arrays within our main array of cells, we calculate the IDs from the symbol base and the term arguments. Anyway, given a term like f(2,3), in which all of the arguments are domain members, we can quickly get to the corresponding cell. */ struct cell { int id; Term eterm; /* the term representation, e.g., f(2,3) */ Term value; /* current value of cell (domain element or NULL) */ Term occurrences; /* current occurrences of the term */ Term *possible; /* current set of possible values */ int max_index; /* maximum index for this cell */ Symbol_data symbol; /* data on the function or relation symbol */ }; /* These macros take you to the correct cell in the Cells table. That is, given the base for the symbol and the indexes, get the ID. */ #define X0(b) (b) #define X1(b,i) (b) + (i) #define X2(b,i,j) (b) + (i)*Domain_size + (j) #define X3(b,i,j,k) (b) + (i)*Domain_size*Domain_size + (j)*Domain_size + (k) #define X4(b,i,j,k,l) (b) + (i)*Domain_size*Domain_size*Domain_size + (j)*Domain_size*Domain_size + (k)*Domain_size + (l) /*********************************************** function prototypes */ /* from msearch.c */ void init_mace_options(Mace_options opt); Mace_results mace4(Plist clauses, Mace_options opt); void mace4_exit(int exit_code); /* from util.c */ void random_permutation(int *a, int n); int int_power(int n, int exp); BOOL prime(int n); /* from print.c */ void p_model(BOOL print_head); void print_model_standard(FILE *fp, BOOL print_head); void p_matom(Term atom); void p_mclause(Mclause c); void p_eterms(void); void p_stats(void); void p_mem(void); void reset_current_stats(void); Term interp_term(void); /* from select.c */ int select_cell(int max_constrained); /* from negpropindex.c */ void init_negprop_index(void); void free_negprop_index(void); void p_negprop_index(void); void insert_negprop_index(Term atom); void negprop_n_index(Term atom); void insert_negprop_eq(Term atom, Term alpha, int val, Mstate state); void insert_negprop_noneq(Term atom, Mstate state); BOOL nterm(Term t, int *ppos, int *pid); Term negprop_find_near(int sign, int sn, int val, Term query, int pos); /* from negprop.c */ void propagate_negative(int type, int id, Term alpha, Term beta, int pos, Mstate state); /* from ordercells.c */ void order_cells(BOOL verbose); /* from commandline.c */ BOOL member_args(int argc, char **argv, char *str); void usage_message(FILE *fp, Mace_options opt); void process_command_line_args(int argc, char **argv, Mace_options opt); LADR-2009-11A/mace4.src/ground.c0000644000175000017500000002763711156241600015252 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "msearch.h" extern int Domain_size; extern Term *Domain; extern Plist Ground_clauses; extern struct mace_stats Mstats; extern struct cell *Cells; extern int Eq_sn; extern int Or_sn; extern int Not_sn; extern int Relation_flag; extern int Negation_flag; /* * memory management */ #define PTRS_MCLAUSE CEILING(sizeof(struct mclause),BYTES_POINTER) static unsigned Mclause_gets, Mclause_frees; static unsigned Mclause_use, Mclause_high; /************* * * Mclause get_mclause(arity) * *************/ static Mclause get_mclause(int numlits) { /* This is a little tricky. The pointers to the literals are in an array (p->lits) that is just after (contiguous with) the mclause. */ Mclause p = get_mem(PTRS_MCLAUSE + numlits); p->numlits = numlits; if (numlits == 0) p->lits = NULL; /* not sure if this can happen */ else { void **v = (void **) p; p->lits = (Term *) (v + PTRS_MCLAUSE); /* just after the struct */ } /* initialization */ p->subsumed = FALSE; p->u.active = -1; p->next = NULL; Mclause_gets++; Mclause_use += (PTRS_MCLAUSE + numlits) * BYTES_POINTER; Mclause_high = IMAX(Mclause_use, Mclause_high); return(p); } /* get_mclause */ /************* * * free_mclause() * *************/ static void free_mclause(Mclause p) { Mclause_frees++; Mclause_use -= (PTRS_MCLAUSE + p->numlits) * BYTES_POINTER; free_mem(p, PTRS_MCLAUSE + p->numlits); } /* free_mclause */ /* end of get and free routines for each type */ /************* * * fprint_mclause_mem() * *************/ void fprint_mclause_mem(FILE *fp, int heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct mclause); fprintf(fp, "mclause (%4d) %11u%11u%11u%9.1f K (%.1f K high)\n", n, Mclause_gets, Mclause_frees, Mclause_gets - Mclause_frees, Mclause_use / 1024.0, Mclause_high / 1024.0); /* end of printing for each type */ } /* fprint_mclause_mem */ /************* * * p_mclause_mem() * *************/ void p_mclause_mem() { fprint_mclause_mem(stdout, 1); } /* p_mclause_mem */ /************* * * zap_mterm() * * Do not free variable terms (that is, domain elements). * *************/ void zap_mterm(Term t) { if (!VARIABLE(t)) { int i; for (i = 0; i < ARITY(t); i++) zap_mterm(ARG(t,i)); free_term(t); } } /* zap_mterm */ /************* * * zap_mclause() * *************/ void zap_mclause(Mclause c) { int i; for (i = 0; i < c->numlits; i++) zap_mterm(LIT(c,i)); free_mclause(c); } /* zap_mclause */ /************* * * lit_position() * *************/ int lit_position(Mclause parent, Term child) { int i; for (i = 0; i < parent->numlits; i++) { if (LIT(parent,i) == child) return i; } return -1; } /* lit_position */ /************* * * set_parent_pointers() * * Make each term, except for variables, point to its parent. * *************/ static void set_parent_pointers(Term t) { if (!VARIABLE(t)) { int i; for (i = 0; i < ARITY(t); i++) { if (VARIABLE(ARG(t,i))) ARG(t,i)->container = NULL; else ARG(t,i)->container = t; set_parent_pointers(ARG(t,i)); } } } /* set_parent_pointers */ /************* * * check_parent_pointers() * * Check that each term, except for variables, points to its parent. * If not, print a message to stdout. * *************/ void check_parent_pointers(Term t) { if (!VARIABLE(t)) { int i; for (i = 0; i < ARITY(t); i++) { if (VARIABLE(ARG(t,i))) { if (ARG(t,i)->container != NULL) { printf("check_parent_pointers, bad link: "); p_term(t); } } else { if (ARG(t,i)->container != t) { printf("check_parent_pointers, bad link: "); p_term(t); } } set_parent_pointers(ARG(t,i)); } } } /* check_parent_pointers */ /************* * * containing_mclause() * *************/ Mclause containing_mclause(Term t) { while (!LITERAL(t)) t = t->container; return t->container; } /* containing_mclause */ /************* * * containing_mliteral() * *************/ Term containing_mliteral(Term t) { while (!LITERAL(t)) t = t->container; return t; } /* containing_mliteral */ /************* * * eterm_index_term() - recursive * * Insert each eterm into the occurrence list of that cell. * *************/ static void eterm_index_term(Term t) { int id; if (VARIABLE(t)) return; else if (eterm(t, &id)) { t->u.vp = Cells[id].occurrences; Cells[id].occurrences = t; } else { int i; for (i = 0; i < ARITY(t); i++) { eterm_index_term(ARG(t,i)); } } } /* eterm_index_term */ /************* * * simp_tv() * * Simplify a term (or atom) with respect to OR, NOT, and * any assignments that have already been made. * *************/ static BOOL member(Term x, Term t) { /* This does not assume OR_TERMs are right associated. */ if (term_ident(x,t)) return TRUE; else if (!OR_TERM(t)) return FALSE; else if (member(x,ARG(t,0))) return TRUE; else return member(x,ARG(t,1)); } static Term merge(Term t) { /* This assumes OR_TERMs are right associated. */ if (!OR_TERM(t)) return t; else { ARG(t,1) = merge(ARG(t,1)); if (!member(ARG(t,0), ARG(t,1))) return t; else { Term t1 = ARG(t,1); zap_mterm(ARG(t,0)); free_term(t); return t1; } } } static Term simp_term(Term t) { if (VARIABLE(t)) return t; else { int i, id; for (i = 0; i < ARITY(t); i++) ARG(t,i) = simp_term(ARG(t,i)); if (eterm(t, &id) && Cells[id].value != NULL) { zap_mterm(t); return Cells[id].value; } else return t; } } static Term simp_tv(Term t) { if (true_term(t)) { zap_mterm(t); return Domain[1]; } else if (false_term(t)) { zap_mterm(t); return Domain[0]; } else if (OR_TERM(t)) { t = merge(t); if (!OR_TERM(t)) return simp_tv(t); else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = simp_tv(ARG(t,i)); if (TRUE_TERM(ARG(t,0)) || TRUE_TERM(ARG(t,1))) { zap_mterm(t); return Domain[1]; } else if (FALSE_TERM(ARG(t,0))) { Term t2 = ARG(t,1); zap_mterm(ARG(t,0)); free_term(t); return t2; } else if (FALSE_TERM(ARG(t,1))) { Term t2 = ARG(t,0); zap_mterm(ARG(t,1)); free_term(t); return t2; } else return t; } } /* end of OR_TERM */ else if (NOT_TERM(t)) { ARG(t,0) = simp_tv(ARG(t,0)); if (TRUE_TERM(ARG(t,0))) { zap_mterm(t); return Domain[0]; } else if (FALSE_TERM(ARG(t,0))) { zap_mterm(t); return Domain[1]; } else return t; } /* end of NOT_TERM */ else { /* It is an atomic formula. */ int i, id; for (i = 0; i < ARITY(t); i++) ARG(t,i) = simp_term(ARG(t,i)); if (arith_rel_term(t)) { BOOL evaluated; int b = arith_eval(t, &evaluated); if (evaluated) { zap_term(t); return (b ? Domain[1] : Domain[0]); } else return t; } else if (eterm(t, &id) && Cells[id].value != NULL) { zap_mterm(t); return Cells[id].value; } else if (EQ_TERM(t)) { /* f(4,3)=2; check if 2 has been crossed off of f(4,3) list. */ int value; if (VARIABLE(ARG(t,1)) && eterm(ARG(t,0), &id)) value = VARNUM(ARG(t,1)); else if (VARIABLE(ARG(t,0)) && eterm(ARG(t,1), &id)) value = VARNUM(ARG(t,0)); else return t; if (Cells[id].possible[value] == NULL) { zap_mterm(t); return Domain[0]; } else return t; } else return t; } } /* simp_tv */ /************* * * term_to_mclause() * *************/ Plist term_to_lits(Term t) { if (!OR_TERM(t)) { Plist g = get_plist(); g->v = t; return g; } else { Plist g0 = term_to_lits(ARG(t,0)); Plist g1 = term_to_lits(ARG(t,1)); free_term(t); /* the OR node */ return plist_cat(g0,g1); } } static Mclause term_to_mclause(Term t) { Plist g = term_to_lits(t); int n = plist_count(g); Plist g2; int i = 0; Mclause c = get_mclause(n); c->u.active = n; for (g2 = g; g2 != NULL; g2 = g2->next) { Term lit = g2->v; Term atom; if (NOT_TERM(lit)) { atom = ARG(lit,0); free_term(lit); /* the NOT node */ term_flag_set(atom, Negation_flag); } else atom = lit; term_flag_set(atom, Relation_flag); LIT(c,i) = atom; i++; } zap_plist(g); return c; } /* term_to_mclause */ /************* * * subst_domain_elements_term() * *************/ static Term subst_domain_elements_term(Term t, int *vals) { if (VARIABLE(t)) { Term t2 = Domain[vals[VARNUM(t)]]; zap_term(t); return t2; } else { int i; i = natural_constant_term(t); if (i >= 0) { zap_term(t); if (i < Domain_size) return Domain[i]; /* domain element */ else return get_variable_term(i); /* natural number of arithmetic only */ } else { for (i = 0; i < ARITY(t); i++) ARG(t,i) = subst_domain_elements_term(ARG(t,i), vals); return t; } } } /* subst_domain_elements_term */ /************* * * instances_recurse() * *************/ static void instances_recurse(Topform c, int *vals, int *domains, int nextvar, int nvars, Mstate state) { if (nextvar == nvars) { Term t = topform_to_term_without_attributes(c); subst_domain_elements_term(t, vals); #if 0 printf("\nbefore: "); fwrite_term_nl(stdout, t); fflush(stdout); #endif t = simp_tv(t); #if 0 printf("after: "); fwrite_term_nl(stdout, t); fflush(stdout); #endif Mstats.ground_clauses_seen++; if (FALSE_TERM(t)) { fprintf(stdout, "\nNOTE: unsatisfiability detected on input.\n"); fprintf(stderr, "\nNOTE: unsatisfiability detected on input.\n"); state->ok = FALSE; return; } else if (!TRUE_TERM(t)) { int i; Mclause m = term_to_mclause(t); for (i = 0; i < m->numlits; i++) { eterm_index_term(LIT(m,i)); set_parent_pointers(LIT(m,i)); LIT(m,i)->container = m; } process_initial_clause(m, state); if (!state->ok) { fprintf(stdout, "\nNOTE: unsatisfiability detected on input.\n"); fprintf(stderr, "\nNOTE: unsatisfiability detected on input.\n"); return; } Ground_clauses = plist_prepend(Ground_clauses, m); Mstats.ground_clauses_kept++; } } else if (domains[nextvar] == -1) { /* in case the current variable does not appear in the clause */ instances_recurse(c, vals, domains, nextvar+1, nvars, state); if (!state->ok) return; } else { int i; for (i = 0; i < domains[nextvar]; i++) { vals[nextvar] = i; instances_recurse(c, vals, domains, nextvar+1, nvars, state); if (!state->ok) return; } } } /* instances_recurse */ /************* * * generate_ground_clauses() * * SIDE EFFECT: global Stack is updated. * *************/ void generate_ground_clauses(Topform c, Mstate state) { int i, biggest_var, vals[MAX_MACE_VARS], domains[MAX_MACE_VARS]; biggest_var = greatest_variable_in_clause(c->literals); for (i = 0; i <= biggest_var; i++) domains[i] = Domain_size; instances_recurse(c, vals, domains, 0, biggest_var+1, state); } /* generate_ground_clauses */ LADR-2009-11A/mace4.src/index.html0000644000175000017500000000305507667467535015626 0ustar mccunemccune MACE4 Model Searcher

MACE4 Model Searcher


MACE4 searches for finite models of first-order statements.

MACE4 is an entirely different program from MACE-2.0 which is distributed with Otter-3, and the input languages are different. MACE-2.0 is usually better for problems with many multiliteral clauses, and MACE4 is usually better for equational problems.

An early version of MACE4 was entered (under the name ICGNS) in the first-order satisfiability division of the 2002 CASC theorem proving competition. Here is the abstract that accompanied the entry, and here are the results of the competition.

Examples

Documentation


William McCune
Mathematics and Computer Science Division
Argonne National Laboratory LADR-2009-11A/sed.gnu-blurb0000644000175000017500000000140710777037535014430 0ustar mccunemccune1i\ /* Copyright (C) 2006-2008 William McCune\ \ This file is part of the LADR Deduction Library.\ \ The LADR Deduction Library is free software; you can redistribute it\ and/or modify it under the terms of the GNU General Public License,\ version 2.\ \ The LADR Deduction Library is distributed in the hope that it will be\ useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\ GNU General Public License for more details.\ \ You should have received a copy of the GNU General Public License\ along with the LADR Deduction Library; if not, write to the Free Software\ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\ */\ LADR-2009-11A/utilities-old/0000755000175000017500000000000010562675660014622 5ustar mccunemccuneLADR-2009-11A/utilities-old/proofs_to_hints0000755000175000017500000000654410305647210017761 0ustar mccunemccune#!/usr/bin/perl use Getopt::Std; sub member { local ($object, @list) = @_; local ($element); foreach $element (@list) { return 1 if ($element eq $object); } return 0; } # member $arguments = join(" ", @ARGV); %options=(); getopts("xrajn:", \%options); # this removes args it recognizes if (@ARGV != 1) { print "proofs_to_hints [-xaj] output_file\n"; print " -x : use expanded proofs\n"; print " -r : use renumbered proofs\n"; print " -a : copy attributes\n"; print " -j : include justifications as comments\n"; print " -n 3: use only the third proof (for example)\n"; exit; } $output_attr = (defined $options{a} ? 1 : 0); $output_just = (defined $options{j} ? 1 : 0); $expanded = (defined $options{x} ? 1 : 0); $renumbered = (defined $options{r} ? 1 : 0); $proof_to_get = (defined $options{n} ? "$options{n}" : "\\d*"); $filename = $ARGV[0]; open(FH, $filename) || die "Cannot open file $filename.\n"; $proofs = 0; $get_this_one = 0; $collect = 0; while ($line = ) { if ($line =~ /- Proof $proof_to_get -/) { $info = $line; $info =~ s/.* Proof $proof_to_get -*//; $get_this_one = 1; } elsif ($get_this_one && (( $expanded && $renumbered && $line =~ / (RX|XR)PROOF /) || ( $expanded && !$renumbered && $line =~ / XPROOF /) || (!$expanded && $renumbered && $line =~ / RPROOF /) || (!$expanded && !$renumbered && $line =~ / PROOF /))) { $proofs++; $get_this_one = 0; $collect = 1; } elsif ($line =~ /end of .*proof/) { $collect = 0; } elsif ($collect) { if ($line =~ /Length of /) { chop($line); push(@lengths, "% $line $info"); } elsif ($line =~ /Maximum clause weight/) { ; # skip it } elsif ($line =~ /Level of proof/) { ; # skip it } elsif ($line ne "\n") { # Now it is a clause in the proof. chop $line; # break clause into (id literals attributes justification) $id = $line; $id =~ s/ .*//; $clause = $line; $clause =~ s/^[0-9A-Z]* *//; $clause =~ s/\..*//; $literal = $clause; # this is really all literals in the clause $literal =~ s/ #.*//; # don't include the clause if we've already seen it if (! &member($literal, @literals)) { $attribute = $clause; $attribute =~ s/.*#/#/; $attribute =~ s/\.//; $attribute =~ s/^[^#].*//; # in case there are none $just = $line; $just =~ s/^.*\. *//; # print "\nid: $id\n"; # print "clause: $clause\n"; # print "literal: $literal\n"; # print "attribute: $attribute\n"; # print "just: $just\n"; push(@ids, $id); push(@literals, $literal); push(@attributes, $attribute); push(@justs, $just); } } } } $num = @ids; if ($proof_to_get == 0) { $pmess = $proofs . ($proofs == 1 ? " proof" : " proofs"); } else { $pmess = "proof $proof_to_get"; } ############################################################# print "clauses(hints).\n"; print "% Arguments: $arguments\n"; print "% $num hints were constructed from the clauses in $pmess.\n"; print @lengths; for ($i = 0; $i < @ids; $i++) { $literal = $literals[$i]; $attribute = $output_attr ? " $attributes[$i]" : ""; $label = " # label($ids[$i])"; $just = $output_just ? " % $justs[$i]" : ""; print "$literal$attribute$label.$just\n"; } print "end_of_list.\n"; LADR-2009-11A/utilities-old/oproofs_to_goals0000755000175000017500000000512110461706644020120 0ustar mccunemccune#!/usr/bin/perl use Getopt::Std; $deny = "$ENV{HOME}/LADR/bin/deny"; $tmpfile = "/tmp/deny$$"; die "$deny binary not found or not executable" if (! -x $deny); sub member { local ($object, @list) = @_; local ($element); foreach $element (@list) { return 1 if ($element eq $object); } return 0; } # member $arguments = join(" ", @ARGV); # %options=(); # # getopts("xrajn:", \%options); # removes args it regocnizes # # if (@ARGV != 1) { # print "proofs_to_goals [-xaj] output_file\n"; # print " -x : use expanded proofs\n"; # print " -r : use renumbered proofs\n"; # print " -a : copy attributes\n"; # print " -j : include justifications as comments\n"; # print " -n 3: use only the third proof (for example)\n"; # exit; # } # # $output_attr = (defined $options{a} ? 1 : 0); # $output_just = (defined $options{j} ? 1 : 0); # $expanded = (defined $options{x} ? 1 : 0); # $renumbered = (defined $options{r} ? 1 : 0); # $proof_to_get = (defined $options{n} ? "$options{n}" : "\\d*"); $filename = $ARGV[0]; open(FH, $filename) || die "Cannot open file $filename.\n"; $collect = 0; while ($line = ) { if ($line =~ /^op\([0-9]*,/ || $line =~ /set\(prolog_style_variables\)\./) { push(@commands, $line); } elsif ($line =~ /PROOF/) { $collect = 1; } elsif ($line =~ /end of proof/) { $collect = 0; } elsif ($collect) { if ($line ne "\n" && !($line =~ /(\$F|\||~|!=| \$[Aa][Nn][Ss])/)) { # Now it is a posiive unit clause in the proof. chop $line; $id = $line; $id =~ s/ .*//; $id =~ s/,/_/; # in double IDs, replace , with _. if (! &member($id, @ids)) { $clause = $line; $clause =~ s/^.*\] //; $clause =~ s/\|\$[Aa][Nn][Ss].*//; #print "\nid: $id\n"; #print "clause: $clause\n"; push(@ids, $id); push(@clauses, $clause); } } } } open(FH1, "> $tmpfile"); print FH1 @commands; print FH1 "clauses(junk).\n"; print FH1 @clauses; close(FH1); $output = `$deny -c < $tmpfile`; system("/bin/rm $tmpfile"); $output =~ s/\.//g; $output =~ s/\$c/c_/g; @denials = split('\n', $output); die("wrong number of denials") if ($#clauses != $#denials); $num = @denials; ############################################################# print "clauses(goals).\n"; print "% Arguments: $arguments\n"; print "% $num denials were constructed from the units in the proofs.\n"; print @lengths; for ($i = 0; $i < @denials; $i++) { $denial = $denials[$i]; $answer = " # answer($ids[$i])"; print "$denial$answer.\n"; } print "end_of_list.\n"; LADR-2009-11A/utilities-old/iterate0000755000175000017500000000364310135760410016173 0ustar mccunemccune#!/usr/bin/perl $prover = "$ENV{HOME}/LADR/bin/prover7"; $tmpfile = "/tmp/prover7_$$"; sub position { # return index of first line that matches a reg expression (or -1) my ($re, @lines) = @_; my $i = 0; foreach $line (@lines) { return $i if ($line =~ /$re/); $i++ } return -1; } # position # prover exit codes $max_proofs = 0; $fatal_error = 1; $sos_empty = 2; $max_megs = 3; $max_seconds = 4; $max_given = 5; $max_kept = 6; $sigint = 101; $sigsegv = 102; die "$prover binary not found or not executable" if (! -x $prover); if (@ARGV != 2) { print "iterate initial_max_wt increment\n"; exit; } $initial_max_wt = $ARGV[0]; $increment = $ARGV[1]; @input = ; # read all of stdin # find position at which to insert max_wt line (just before first list) $pos1 = &position('clauses\(|formulas\(|terms\(', @input); # find position of max_seconds line (if it exists) $pos2 = &position('assign\(max_seconds', @input); if ($pos2 != -1) { $max_sec = $input[$pos2]; $max_sec =~ s/^.*max_seconds.*, *//; $max_sec =~ s/\).*//; } # insert new max_wt line (even if one already exists) splice(@input, $pos1, 0, "assign(max_weight, $initial_max_wt).\n"); $max_wt = $initial_max_wt; $go = 1; while ($go) { open(FH, ">$tmpfile") || die "cannot open $tmpfile"; print FH @input; close(FH); $rc = system("$prover < $tmpfile"); $rc = $rc / 256; # get the actual exit code if ($rc == $sos_empty) { # increase max_wt $max_wt += $increment; $input[$pos1] =~ s/,.*/, $max_wt)./; if ($pos2 != -1) { # decrease max_sec by time used so far ($user, $system, $cuser, $csystem) = times; my $remaining_sec = $max_sec - int($cuser); $input[$pos2] =~ s/,.*/, $remaining_sec)./; } print "Restarting with max_weight=$max_wt\n"; print STDERR "Restarting with max_weight=$max_wt\n"; } else { $go = 0; } } `/bin/rm $tmpfile`; LADR-2009-11A/utilities-old/oproofs_to_hints0000755000175000017500000000377610461706644020156 0ustar mccunemccune#!/usr/bin/perl use Getopt::Std; sub member { local ($object, @list) = @_; local ($element); foreach $element (@list) { return 1 if ($element eq $object); } return 0; } # member $arguments = join(" ", @ARGV); %options=(); # getopts("xrajn:", \%options); # this removes args it recognizes # # if (@ARGV != 1) { # print "proofs_to_hints otter_output_file\n"; # print " -x : use expanded proofs\n"; # print " -r : use renumbered proofs\n"; # print " -a : copy attributes\n"; # print " -j : include justifications as comments\n"; # print " -n 3: use only the third proof (for example)\n"; # exit; # } # # $output_attr = (defined $options{a} ? 1 : 0); # $output_just = (defined $options{j} ? 1 : 0); # $expanded = (defined $options{x} ? 1 : 0); # $renumbered = (defined $options{r} ? 1 : 0); # $proof_to_get = (defined $options{n} ? "$options{n}" : "\\d*"); $filename = $ARGV[0]; open(FH, $filename) || die "Cannot open file $filename.\n"; $collect = 0; while ($line = ) { if ($line =~ /PROOF/) { $collect = 1; } elsif ($line =~ /end of proof/) { $collect = 0; } elsif ($collect) { if ($line ne "\n") { # Now it is a clause in the proof. chop $line; $id = $line; $id =~ s/ .*//; $id =~ s/,/_/; # in double IDs, replace , with _. if (! &member($id, @ids)) { $clause = $line; $clause =~ s/^.*\] //; $clause =~ s/\.$//; $clause =~ s/\|\$[Aa][Nn][Ss].*//; $clause =~ s/^\$[Aa][Nn][Ss].*/\$F/; #print "\nid: $id\n"; #print "clause: $clause\n"; push(@ids, $id); push(@clauses, $clause); } } } } $num = @ids; ############################################################# print "clauses(hints).\n"; print "% Arguments: $arguments\n"; print "% $num hints were constructed.\n"; print @lengths; for ($i = 0; $i < @ids; $i++) { $clause = $clauses[$i]; $label = " # label($ids[$i])"; print "$clause$label.\n"; } print "end_of_list.\n"; LADR-2009-11A/utilities-old/looper.pl0000755000175000017500000000376710562424361016465 0ustar mccunemccune#!/usr/bin/perl -w $| = 1; # flush output $scriptname = "looper"; if ($#ARGV != 2 || !($ARGV[0] eq "prover9" || $ARGV[0] eq "mace4") || !($ARGV[1] eq "assumptions" || $ARGV[1] eq "goals") ) { print STDERR "$scriptname (prover9|mace4) (assumptions|goals) head < candidates\n"; die; } $program = "$ARGV[0]"; $list = "$ARGV[1]"; open(FIN, $ARGV[2]) || die "head file not found"; $host=`hostname`; chop($host); $date=`date`; chop($date); print "Started $scriptname $date on $host.\n"; @head = ; # read the whole head file print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; print @head; print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; $i = 0; # problem counter $input = "in$$"; while ($problem = ) { $i++; chop $problem; print "-----------------------------------------------------\n"; print "$problem % Problem $i\n\n"; open(FH, ">$input") || die "Cannot open file $input"; print FH @head; print FH "formulas($list).\n"; print FH "$problem\n"; print FH "end_of_list.\n"; close(FH); $command = "$program < $input 2> /dev/null | " . "awk " . "'/(Fatal|Given|Selections|CPU|Process.*exit)/ {print} " . "/= PROOF =/,/= end of proof =/ {print} " . "/= MODEL =/,/= end of model =/ {print}'"; @out = `$command`; if (grep(/Fatal/, @out)) { print STDERR "\nFatal error in $program, see output.\n\n"; system("/bin/rm $input"); die; } ($timeline) = grep(/User_CPU/, @out); ($_,$sec) = split(/[=,]/, $timeline); $id = $problem; if ($problem =~ /label/) { $id =~ s/.*label/label/; } print @out; if (grep(/max_proofs/, @out)) { print "\n$id Proved $sec seconds PROBLEM $i\n"; } elsif (grep(/max_models/, @out)) { print "\n$id Disproved $sec seconds PROBLEM $i\n"; } else { print "\n$id Failed $sec seconds PROBLEM $i\n"; } } system("/bin/rm $input"); $date=`date`; chop($date); print "\nFinished $scriptname $date on $host.\n"; LADR-2009-11A/utilities-old/attack20000755000175000017500000001002410562425552016067 0ustar mccunemccune#!/usr/bin/perl -w # This script takes a Mace4 input file (the head) and a stream of # candidates. It builds a list of models (M) of the candidates w.r.t. # the clauses in the head. # # For each candidate C, if the C is true in any member of M, # it is discarded; otherwise look for a model of C and the # clauses in the head; if a model is found, add it to M and # discard C; otherwise pass C through to the standard output. # # Call it, for example, like this: # # attack head interps < candidates > candidates.out # # The file interps is created from scratch and must not exist at the start. # # The candidates must be one per line. A candidate need not be a single # clause, e.g., it can be a pair of clauses. The important thing # is that it makes sense when surrounded by "formulas(cand)." and # "end_of_list." An exception: lines that start with "%" are treated # as comment lines and are passed directly through to stdout. $host = `hostname`; chop($host); $date = `date`; chop($date); $mace4 = "mace4"; $interpfilter = "interpfilter"; $get_interps = "get_interps"; $model_exit_A = 0; # one of the mace4 exit codes for "model found" $model_exit_B = 3; # one of the mace4 exit codes for "model found" $model_exit_C = 4; # one of the mace4 exit codes for "model found" $error_exit = 1; # mace4 exit code for "error" $min = "min"; $mout = "mout"; $fin = "fin"; $fout = "fout"; if ($#ARGV != 1) { print "need two args: head (must exist), interps (must not exist).\n"; die; } $mhead = $ARGV[0]; $interps = $ARGV[1]; open(FH, $mhead) || die "Cannot open file $mhead.\n"; @mace_head = ; # This reads the whole head file. close(FH); if (-e $interps) { die "file $interps already exists"; } open(FH, ">$interps") || die "Cannot open (create) file $interps.\n"; print FH "% Started on $host at $date.\n"; print FH "% Here is the head file $mhead.\n\n"; print FH "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; print FH `cat $mhead | sed 's/^/% /'`; print FH "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"; close(FH); $checked = 0; $passed = 0; $new_interps = 0; while ($cand = ) { # for each line on the standard input if ($cand =~ /^%/) { print $cand; # Pass comment lines through to output. } else { # Assume it's a candidate. $checked++; if ($checked % 100 == 0) { print STDERR "checked $checked\n"; } open(FH, ">$fin") || die "Cannot open file $fin"; print FH "$cand\n"; close(FH); system("$interpfilter $fin all_true < $interps > $fout"); # If interpfilter had error, that stderr message goes to this stderr. if (system("grep 'passed 0' $fout > /dev/null 2> /dev/null") == 0) { # Candidate is still alive, so try to kill it. # print "still alive $cand"; open(FH, ">$min") || die "Cannot open file $min"; print FH @mace_head; print FH "formulas(candidate). \n $cand \n end_of_list.\n"; close(FH); $rc = system("$mace4 -P1 < $min > $mout 2> /dev/null"); $rc = $rc / 256; # This gets the actual exit code. if ($rc == $error_exit) { print "Mace4 error (in $mhead?), candidate $cand\n"; } elsif ($rc == $model_exit_A || $rc == $model_exit_B || $rc == $model_exit_C) { # print "just killed $cand"; # Candidate has been killed; add the interp to our arsenal. $new_interps++; # Wrong if there is more than one interp. open(FH, ">>$interps"); chop $cand; print FH "% $cand % cand $checked killed by\n\n"; close(FH); system("$get_interps < $mout >> $interps"); } else { # print "kept $cand"; $passed++; chop $cand; print "$cand % cand $checked\n"; } } else { # print "killed by old $cand"; } } } print "% attack $mhead $interps (on $host): checked $checked," . " passed $passed, new_interps $new_interps.\n"; $date = `date`; chop($date); open(FH, ">>$interps") || die "Cannot open file $interps.\n"; print FH "% Checked $checked, passed $passed, new_interps $new_interps.\n"; print FH "% Finished $date.\n"; close(FH); system("/bin/rm -f $min $mout $fin $fout"); LADR-2009-11A/utilities-old/proofs_to_goals0000755000175000017500000000752310305650150017734 0ustar mccunemccune#!/usr/bin/perl use Getopt::Std; $deny = "$ENV{HOME}/LADR/bin/deny"; $tmpfile = "/tmp/deny$$"; die "$deny binary not found or not executable" if (! -x $deny); sub member { local ($object, @list) = @_; local ($element); foreach $element (@list) { return 1 if ($element eq $object); } return 0; } # member $arguments = join(" ", @ARGV); %options=(); getopts("xrajn:", \%options); # removes args it regocnizes if (@ARGV != 1) { print "proofs_to_goals [-xaj] output_file\n"; print " -x : use expanded proofs\n"; print " -r : use renumbered proofs\n"; print " -a : copy attributes\n"; print " -j : include justifications as comments\n"; print " -n 3: use only the third proof (for example)\n"; exit; } $output_attr = (defined $options{a} ? 1 : 0); $output_just = (defined $options{j} ? 1 : 0); $expanded = (defined $options{x} ? 1 : 0); $renumbered = (defined $options{r} ? 1 : 0); $proof_to_get = (defined $options{n} ? "$options{n}" : "\\d*"); $filename = $ARGV[0]; open(FH, $filename) || die "Cannot open file $filename.\n"; $proofs = 0; $get_this_one = 0; $collect = 0; while ($line = ) { if ($line =~ /^op\([0-9]*,/ || $line =~ /set\(prolog_style_variables\)\./) { push(@commands, $line); } elsif ($line =~ /- Proof $proof_to_get -/) { $info = $line; $info =~ s/.* Proof $proof_to_get -*//; $get_this_one = 1; } elsif ($get_this_one && (( $expanded && $renumbered && $line =~ / (RX|XR)PROOF /) || ( $expanded && !$renumbered && $line =~ / XPROOF /) || (!$expanded && $renumbered && $line =~ / RPROOF /) || (!$expanded && !$renumbered && $line =~ / PROOF /))) { $proofs++; $get_this_one = 0; $collect = 1; } elsif ($line =~ /end of .*proof/) { $collect = 0; } elsif ($collect) { if ($line =~ /Length of /) { chop($line); push(@lengths, "% $line $info"); } elsif ($line =~ /Maximum clause/) { ; # skip it } elsif ($line =~ /Level of proof/) { ; # skip it } elsif ($line ne "\n" && !($line =~ /(\$F|\||~|!=)/)) { # Now it is a positive unit clause in the proof. chop $line; $id = $line; $id =~ s/ .*//; $clause = $line; $clause =~ s/^[0-9A-Z]* *//; $clause =~ s/\..*//; $literal = $clause; $literal =~ s/ #.*//; # don't include the clause if we've already seen it if (! &member("$literal.\n", @literals)) { $attribute = $clause; $attribute =~ s/.*#/#/; $attribute =~ s/\.//; $attribute =~ s/^[^#].*//; # in case there are none $just = $line; $just =~ s/^.*\. *//; # print "\nid: $id\n"; # print "clause: $clause\n"; # print "literal: $literal\n"; # print "attribute: $attribute\n"; # print "just: $just\n"; push(@ids, $id); push(@literals, "$literal.\n"); push(@attributes, $attribute); push(@justs, $just); } } } } open(FH1, "> $tmpfile"); print FH1 @commands; print FH1 "clauses(junk).\n"; print FH1 @literals; close(FH1); $output = `$deny -c < $tmpfile`; system("/bin/rm $tmpfile"); $output =~ s/\.//g; $output =~ s/\$c/c_/g; @denials = split('\n', $output); die("wrong number of denials") if ($#literals != $#denials); $num = @denials; if ($proof_to_get == 0) { $pmess = $proofs . ($proofs == 1 ? " proof" : " proofs"); } else { $pmess = "proof $proof_to_get"; } ############################################################# print "clauses(goals).\n"; print "% Arguments: $arguments\n"; print "% $num denials were constructed from the units in $pmess.\n"; print @lengths; for ($i = 0; $i < @denials; $i++) { $denial = $denials[$i]; $attribute = $output_attr ? " $attributes[$i]" : ""; $answer = " # answer($ids[$i])"; $just = $output_just ? " % $justs[$i]" : ""; print "$denial$attribute$answer.$just\n"; } print "end_of_list.\n"; LADR-2009-11A/ladr/0000755000175000017500000000000011274373242012745 5ustar mccunemccuneLADR-2009-11A/ladr/term.c0000644000175000017500000011621311106210563014052 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "term.h" /* Sharing Variables. In the original design, no term sharing occurred. This allows compact data structures and simpler algorithms for processiong terms. Then we tried sharing variables only (using the same data structures). In most cases of practical work, nearly all of the leaves in the clause spaces are variables (as opposed to constants). Assuming most function applications are binary, this means that variables take up about half of the term storage. We can save all of this by sharing variables. All terms have a containment field, which points to the containing clause. (If we wished to have terms point to immediate superterms, we could do that instead.) We need containment, because indexing returns terms, and we have to get from those terms to the containing clauses. BUT, we don't index variables, so we can do without containment pointers in variables. Making the change to shared variables was easy. We introduced an array of term pointers, static Term Shared_variables[MAX_VNUM], and changed get_variable_term to return one of those instead of a fresh one. Also, we eliminated the routine set_variable, which changes the variable number of a variable term. If you want to do that now (with shared or with nonshared variables), just free the old one and get a new one. Things to be careful about: (1) Don't change variable numbers of variable terms. Just use get_variable_term and free_term. (2) Don't use the container field of variables. January 29, 2003. */ /* Private definitions and types */ static Term Shared_variables[MAX_VNUM]; /* * memory management */ #define PTRS_TERM PTRS(sizeof(struct term)) static unsigned Term_gets, Term_frees; static unsigned Arg_mem; /* memory (pointers) for arrays of args */ /************* * * Term get_term(arity) * *************/ static Term get_term(int arity) { /* This is a little tricky. The pointers to the subterms are in an array (p->args) that is just after (contiguous with) the term. private_symbol is not initialized. args array is not initialized. */ Term p = get_mem(PTRS_TERM + arity); /* non-initialized memory */ p->arity = arity; if (arity == 0) p->args = NULL; else { void **v = (void **) p; p->args = (Term *) (v + PTRS_TERM); /* just after the (struct term) */ } p->private_flags = 0; p->container = NULL; p->u.vp = NULL; Term_gets++; Arg_mem += arity; return(p); } /* get_term */ /************* * * free_term() * *************/ /* DOCUMENTATION This routine frees a term node only. To recursively free all of the subterms as well, call zap_term(t) instead. */ /* PUBLIC */ void free_term(Term p) { if (VARIABLE(p)) return; /* variables are never freed, because they are shared */ Arg_mem -= p->arity; free_mem(p, PTRS_TERM + p->arity); Term_frees++; } /* free_term */ /************* * * fprint_term_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for Terms. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_term_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct term); fprintf(fp, "term (%4d) %11u%11u%11u%9.1f K\n", n, Term_gets, Term_frees, Term_gets - Term_frees, ((Term_gets - Term_frees) * n) / 1024.); fprintf(fp, " term arg arrays: %9.1f K\n", Arg_mem * BYTES_POINTER / 1024.); /* end of printing for each type */ } /* fprint_term_mem */ /************* * * p_term_mem() * *************/ /* DOCUMENTATION This routine prints memory usage statistics for Terms to stdout. */ /* PUBLIC */ void p_term_mem(void) { fprint_term_mem(stdout, 1); } /* p__mem */ /* * end of memory management */ /************* * * get_variable_term() * *************/ /* DOCUMENTATION This routine returns a term of type VARIABLE. The index of the variable is set to var_num, which should be an integer >= 0. */ /* PUBLIC */ Term get_variable_term(int var_num) { if (var_num < 0 || var_num >= MAX_VAR) fatal_error("get_variable_term: var_num out of range"); if (var_num >= MAX_VNUM || Shared_variables[var_num] == NULL) { Term t = malloc(sizeof(struct term)); t->private_symbol = var_num; t->arity = 0; t->private_flags = 0; t->container = NULL; t->u.id = 0; if (var_num >= MAX_VNUM) return t; /* will not be shared */ else Shared_variables[var_num] = t; } return Shared_variables[var_num]; } /* get_variable_term */ /************* * * get_rigid_term_like() * *************/ /* DOCUMENTATION This routine allocates and returns a term node with the same symbol and arity as the given Term t. */ /* PUBLIC */ Term get_rigid_term_like(Term t) { Term t1 = get_term(ARITY(t)); t1->private_symbol = t->private_symbol; return t1; } /* get_rigid_term_like */ /************* * * get_rigid_term() * *************/ /* DOCUMENTATION This routine allocates and returns a term node with the given symbol and arity. If you already have a similar term node, say t, (containing the symbol and arity you need) call get_rigid_term_like(t) instead. */ /* PUBLIC */ Term get_rigid_term(char *sym, int arity) { Term t1; int sn; if (arity > MAX_ARITY) { printf("\nArity %d requested for symbol \"%s\"\n", arity, sym); fprintf(stderr, "\nArity %d requested for symbol \"%s\".\n", arity, sym); fatal_error("get_rigid_term, arity too big"); } t1 = get_term(arity); sn = str_to_sn(sym, arity); if (sn >= MAX_SYM) fatal_error("get_rigid_term, too many symbols"); t1->private_symbol = -sn; return t1; } /* get_rigid_term */ /************* * * get_rigid_term_dangerously() * *************/ /* DOCUMENTATION This routine can be used to allocate a term node if all you have is the symbol ID and arity. If the arity is not correct for the symbol ID, terrible things will happen!

If you have a similar term, use get_rigid_term_like() instead. If you can afford the time to access the symbol table, use sn_to_str() and get_rigid_term() instead. */ /* PUBLIC */ Term get_rigid_term_dangerously(int symnum, int arity) { Term t1 = get_term(arity); t1->private_symbol = -symnum; return t1; } /* get_rigid_term_dangerously */ /************* * * zap_term(term) * * Free a term and all of its subterms. * *************/ /* DOCUMENTATION This routine frees a term t and all of its subterms. You should not refer to t after calling zap_term(t). */ /* PUBLIC */ void zap_term(Term t) { int i; for (i = 0; i < ARITY(t); i++) zap_term(ARG(t,i)); free_term(t); } /* zap_term */ /************* * * int term_ident(term1, term2) -- Compare two terms. * * If identical return 1); else return 0. The bits * field is not checked. * *************/ /* DOCUMENTATION This function checks if two terms are identical. Only the structure and symbols are checked---any extra fields such as bits or u are NOT checked. */ /* PUBLIC */ BOOL term_ident(Term t1, Term t2) { if (t1->private_symbol != t2->private_symbol) return 0; else { int i; for (i = 0; i < ARITY(t1); i++) if (!term_ident(ARG(t1,i), ARG(t2,i))) return 0; return 1; } } /* term_ident */ /************* * * Term copy_term(term) -- Return a copy of the term. * * The bits field is not copied. * *************/ /* DOCUMENTATION This routine copies a term. Only the symbols and structure are copied---any extra fields such as bits or u are NOT copied. */ /* PUBLIC */ Term copy_term(Term t) { if (t == NULL) return NULL; else if (VARIABLE(t)) return get_variable_term(VARNUM(t)); else { int i; Term t2 = get_rigid_term_like(t); for (i = 0; i < ARITY(t); i++) ARG(t2,i) = copy_term(ARG(t,i)); return t2; } } /* copy_term */ /************* * * int ground_term(t) -- is a term ground? * *************/ /* DOCUMENTATION This function checks if a term is ground, that is, has no variables. */ /* PUBLIC */ BOOL ground_term(Term t) { if (VARIABLE(t)) return FALSE; else { int i; for (i = 0; i < ARITY(t); i++) if (!ground_term(ARG(t,i))) return FALSE; return TRUE; } } /* ground_term */ /************* * * biggest_variable() * *************/ /* DOCUMENTATION This routine returns the greatest variable index of any variable int the given term t. If t is ground, -1 is returned. */ /* PUBLIC */ int biggest_variable(Term t) { if (VARIABLE(t)) return VARNUM(t); else { int i, max, v; for (max = -1, i = 0; i < ARITY(t); i++) { v = biggest_variable(ARG(t,i)); max = (v > max ? v : max); } return max; } } /* biggest_variable */ /************* * * term_depth() * *************/ /* DOCUMENTATION Return the depth of a term. Variables and constants have depth 0. */ /* PUBLIC */ int term_depth(Term t) { if (VARIABLE(t) || CONSTANT(t)) return 0; else { int i; int max = 0; for (i = 0; i < ARITY(t); i++) { int d = term_depth(ARG(t,i)); max = IMAX(max,d); } return max+1; } } /* term_depth */ /************* * * symbol_count * *************/ /* DOCUMENTATION This routine returns the total number of symbols (i.e., the number of nodes) in the given term t. */ /* PUBLIC */ int symbol_count(Term t) { int i; int count = 0; for (i = 0; i < ARITY(t); i++) count += symbol_count(ARG(t,i)); return count+1; } /* symbol_count */ /************* * * int occurs_in(t1, t2) -- Does t1 occur in t2 (including t1==t2)? * * term_ident is used to check identity. * *************/ /* DOCUMENTATION This function checks if Term t2 is identical to a subterm of Term t1, including the case term_ident(t1,t2). All identity checks are done with term_ident(), so extra fields such as bits or u are not checked. */ /* PUBLIC */ BOOL occurs_in(Term t1, Term t2) { if (term_ident(t1, t2)) return TRUE; else { int i; for (i = 0; i < ARITY(t2); i++) if (occurs_in(t1, ARG(t2,i))) return TRUE; return FALSE; } } /* occurs_in */ /************* * * fprint_term(fp, t) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a term. A newline is NOT printed. */ /* PUBLIC */ void fprint_term(FILE *fp, Term t) { if (t == NULL) fprintf(fp, "fprint_term: NULL term\n"); else { if (VARIABLE(t)) fprintf(fp, "v%d", VARNUM(t)); else { fprint_sym(fp, SYMNUM(t)); if (COMPLEX(t)) { int i; fprintf(fp, "("); for (i = 0; i < ARITY(t); i++) { fprint_term(fp, ARG(t,i)); if (i < ARITY(t)-1) fprintf(fp, ","); } fprintf(fp, ")"); } } } fflush(fp); } /* fprint_term */ /************* * * sprint_term(sb, t) * *************/ /* DOCUMENTATION This (recursive) routine appends the string representation of a term to a String_buf. A newline is not included. */ /* PUBLIC */ void sprint_term(String_buf sb, Term t) { if (t == NULL) printf("sprint_term: NULL term\n"); else { if (VARIABLE(t)) { char s[MAX_NAME]; sprintf(s, "v%d", VARNUM(t)); sb_append(sb, s); } else { sprint_sym(sb, SYMNUM(t)); if (COMPLEX(t)) { int i; sb_append(sb, "("); for (i = 0; i < ARITY(t); i++) { sprint_term(sb, ARG(t,i)); if (i < ARITY(t)-1) sb_append(sb, ","); } sb_append(sb, ")"); } } } } /* sprint_term */ /************* * * term_to_string() * *************/ /* DOCUMENTATION Convert a term to a string in standard prefix form. The string is malloced, so call free on it when done with it. */ /* PUBLIC */ char *term_to_string(Term t) { char *s; String_buf sb = get_string_buf(); sprint_term(sb, t); s = sb_to_malloc_string(sb); zap_string_buf(sb); return s; } /* term_to_string */ /************* * * p_term(t) * *************/ /* DOCUMENTATION This routine prints a term, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_term() instead. If you want the term put into a string, use sprint_term() instead. */ /* PUBLIC */ void p_term(Term t) { fprint_term(stdout, t); printf("\n"); fflush(stdout); } /* p_term */ /************* * * all_args_vars(t) * *************/ /* DOCUMENTATION This Boolean routine checks if all argumets of Term t are VARIABLEs. (It is true also if t is a VARIABLE.) */ /* PUBLIC */ BOOL all_args_vars(Term t) { if (VARIABLE(t)) return TRUE; else { int i; for (i = 0; i < ARITY(t); i++) if (!VARIABLE(ARG(t,i))) return FALSE; return TRUE; } } /* all_args_vars */ /************* * * build_binary_term() * *************/ /* DOCUMENTATION Build and return a binary term with SYMNUM sn, first term a1, and second term a2.

WARNING: if sn is not a binary symbol, bad things will happen! */ /* PUBLIC */ Term build_binary_term(int sn, Term a1, Term a2) { Term t = get_rigid_term_dangerously(sn, 2); ARG(t,0) = a1; ARG(t,1) = a2; return(t); } /* build_binary_term */ /************* * * build_binary_term_safe() * *************/ /* DOCUMENTATION Build and return a binary term with root str, first term a1, and second term a2.

If you know the symnum, and you're certain it has arity 2, you can use the faster routine build_binary_term() instead; */ /* PUBLIC */ Term build_binary_term_safe(char *str, Term a1, Term a2) { return build_binary_term(str_to_sn(str, 2), a1, a2); } /* build_binary_term_safe */ /************* * * build_unary_term() * *************/ /* DOCUMENTATION Build and return a unary term with SYMNUM sn and argument term a.

WARNING: if sn is not a unary symbol, bad things will happen! */ /* PUBLIC */ Term build_unary_term(int sn, Term a) { Term t = get_rigid_term_dangerously(sn, 1); ARG(t,0) = a; return(t); } /* build_unary_term */ /************* * * build_unary_term_safe() * *************/ /* DOCUMENTATION Build and return a unary term with root str, argument a.

If you know the symnum, and you're certain it has arity 1, you can use the faster routine build_unary_term() instead; */ /* PUBLIC */ Term build_unary_term_safe(char *str, Term a) { return build_unary_term(str_to_sn(str, 1), a); } /* build_unary_term_safe */ /************* * * subst_term() * *************/ /* DOCUMENTATION In term t, replace all occurrences of Term target with copies of Term replacement. Free all of the replaced terms; */ /* PUBLIC */ Term subst_term(Term t, Term target, Term replacement) { if (term_ident(t, target)) { zap_term(t); return copy_term(replacement); } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = subst_term(ARG(t,i), target, replacement); return t; } } /* subst_term */ /************* * * subst_var_term() * *************/ /* DOCUMENTATION In Term t, replace all CONSTANT terms containing SYMNUM symnum with a variable containing VARNUM varnum. Free the replaced constants and return the result. */ /* PUBLIC */ Term subst_var_term(Term t, int symnum, int varnum) { if (CONSTANT(t) && SYMNUM(t) == symnum) { Term v = get_variable_term(varnum); zap_term(t); return v; } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = subst_var_term(ARG(t,i), symnum, varnum); return t; } } /* subst_var_term */ /************* * * greatest_variable() * *************/ /* DOCUMENTATION This routine returns the greatest variable index in a term. If the term is ground, -1 is returned. */ /* PUBLIC */ int greatest_variable(Term t) { if (VARIABLE(t)) return VARNUM(t); else { int i, max, v; for (max = -1, i = 0; i < ARITY(t); i++) { v = greatest_variable(ARG(t,i)); max = (v > max ? v : max); } return max; } } /* greatest_variable */ /************* * * greatest_symnum_in_term() * *************/ /* DOCUMENTATION This function returns the greatest SYMNUM (of a CONSTANT or COMPLEX term) in the given Term t. If the term is a VARIABLE, return -1. */ /* PUBLIC */ int greatest_symnum_in_term(Term t) { if (VARIABLE(t)) return -1; else { int max = SYMNUM(t); int i; for (i = 0; i < ARITY(t); i++) { int sm = greatest_symnum_in_term(ARG(t,i)); max = (sm > max ? sm : max); } return max; } } /* greatest_symnum_in_term */ /************* * * upward_term_links() * *************/ /* DOCUMENTATION In the given Term t, make the "container" field of t and each subterm, except variables, point to (void *) p. */ /* PUBLIC */ void upward_term_links(Term t, void *p) { int i; if (!VARIABLE(t)) { t->container = p; for (i = 0; i < ARITY(t); i++) upward_term_links(ARG(t,i), p); } } /* upward_term_links */ /************* * * check_upward_term_links() * *************/ /* DOCUMENTATION In the given Term t, check that the "container" field of t and each subterm, except variables, point to (void *) p. */ /* PUBLIC */ BOOL check_upward_term_links(Term t, void *p) { int i; if (!VARIABLE(t)) { if (t->container != p) return FALSE; for (i = 0; i < ARITY(t); i++) { if (!check_upward_term_links(ARG(t,i), p)) return FALSE; } } return TRUE; } /* check_upward_term_links */ /************* * * occurrences() * *************/ /* DOCUMENTATION This function returns the number of occurrences of Term target in Term t. The checks are made with term_ident(). */ /* PUBLIC */ int occurrences(Term t, Term target) { if (term_ident(t, target)) return 1; else { int n = 0; int i; for (i = 0; i < ARITY(t); i++) n += occurrences(ARG(t,i), target); return n; } } /* occurrences */ /************* * * trm_set_vars_recurse() * * There might be another (static) copy of this routine in clause.c. * *************/ static Term trm_set_vars_recurse(Term t, char **varnames, int max_vars) { if (CONSTANT(t)) { char *name = sn_to_str(SYMNUM(t)); if (variable_name(name)) { int i = 0; while (i < max_vars && varnames[i] != NULL && varnames[i] != name) i++; if (i == max_vars) fatal_error("trm_set_vars_recurse: max_vars"); else { if (varnames[i] == NULL) varnames[i] = name; free_term(t); t = get_variable_term(i); } } } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = trm_set_vars_recurse(ARG(t,i), varnames, max_vars); } return t; } /* trm_set_vars_recurse */ /************* * * term_set_variables() * *************/ /* DOCUMENTATION This routine traverses a term and changes the constants that should be variables, into variables. On input, the term should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

If you are dealing with clauses, use clause_set_variables() instead. */ /* PUBLIC */ void term_set_variables(Term t, int max_vars) { char *a[MAX_VARS], **vmap; int i; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; for (i = 0; i < ARITY(t); i++) ARG(t,i) = trm_set_vars_recurse(ARG(t,i), vmap, max_vars); if (max_vars > MAX_VARS) free(vmap); } /* term_set_variables */ /************* * * nat_to_term() * *************/ /* DOCUMENTATION This routine takes a nonnegative integer and returns a constant Term with the string representation of the integer as the constant symbol. */ /* PUBLIC */ Term nat_to_term(int n) { char s[25]; if (n < 0) fatal_error("nat_to_term: negative term"); return get_rigid_term(int_to_str(n, s, 25), 0); } /* nat_to_term */ /************* * * int_to_term() * *************/ /* DOCUMENTATION This routine takes an integer and returns the Term representation. */ /* PUBLIC */ Term int_to_term(int i) { char s[25]; Term t; t = get_rigid_term(int_to_str(abs(i), s, 25), 0); if (i < 0) t = build_unary_term_safe("-", t); return t; } /* int_to_term */ /************* * * bool_to_term() * *************/ /* DOCUMENTATION This routine takes an Bool and returns the Term representation. */ /* PUBLIC */ Term bool_to_term(BOOL val) { return get_rigid_term( val ? true_sym() : false_sym() , 0); } /* bool_to_term */ /************* * * double_to_term() * *************/ /* DOCUMENTATION This routine takes a double and returns a constant Term with the string representation of the double as the constant symbol. */ /* PUBLIC */ Term double_to_term(double d) { char s[25]; return get_rigid_term(double_to_str(d, s, 25), 0); } /* double_to_term */ /************* * * natural_constant_term(t) * *************/ /* DOCUMENTATION This routine takes a term, and if the term represents an nonnegative integer, that integer is returned; otherwise, -1 is returned. */ /* PUBLIC */ int natural_constant_term(Term t) { if (!CONSTANT(t)) return -1; else return natural_string(sn_to_str(SYMNUM(t))); } /* natural_constant_term */ /************* * * arg_position() * *************/ /* DOCUMENTATION If the given terms are in a parent-child relatioship, return the argument position (index) of the child. Otherwise, return -1. */ /* PUBLIC */ int arg_position(Term parent, Term child) { int i; for (i = 0; i < ARITY(parent); i++) { if (ARG(parent,i) == child) return i; } return -1; } /* arg_position */ /************* * * is_term() * *************/ /* DOCUMENTATION Does term t have the the given symbol and arity? */ /* PUBLIC */ BOOL is_term(Term t, char *str, int arity) { return t != NULL && is_symbol(SYMNUM(t), str, arity); } /* is_term */ /************* * * is_constant() * *************/ /* DOCUMENTATION Is term t a specific constant? */ /* PUBLIC */ BOOL is_constant(Term t, char *str) { return is_term(t, str, 0); } /* is_constant */ /************* * * term_symbol() * *************/ /* DOCUMENTATION Return the print string associated with the given nonvariable term. If the term is a variable, return NULL. */ /* PUBLIC */ char *term_symbol(Term t) { return VARIABLE(t) ? NULL : sn_to_str(SYMNUM(t)); } /* term_symbol */ /************* * * term_to_int() * *************/ /* DOCUMENTATION Given a term, see if it represents an integer. If so, set *result to the integer and return TRUE. If not, return FALSE.

The term representation of a negative integer is the function symbol "-" applied to a nonnegative integer. */ /* PUBLIC */ BOOL term_to_int(Term t, int *result) { if (CONSTANT(t)) { return str_to_int(sn_to_str(SYMNUM(t)), result); } else if (is_term(t, "-", 1)) { if (!CONSTANT(ARG(t,0))) return FALSE; else { if (str_to_int(sn_to_str(SYMNUM(ARG(t,0))), result)) { *result = -(*result); return TRUE; } else return FALSE; } } else return FALSE; } /* term_to_int */ /************* * * term_to_double() * *************/ /* DOCUMENTATION Given a term, see if it represents a double. If so, set *result to the double and return TRUE. If not, return FALSE. */ /* PUBLIC */ BOOL term_to_double(Term t, double *result) { if (CONSTANT(t)) return str_to_double(sn_to_str(SYMNUM(t)), result); else return FALSE; } /* term_to_double */ /************* * * term_to_number() * *************/ /* DOCUMENTATION Given a term, see if it represents an integer or a double. If so, set *result (a double) to the number and return TRUE. If not, return FALSE. */ /* PUBLIC */ BOOL term_to_number(Term t, double *result) { int i; if (term_to_int(t, &i)) { *result = (double) i; return TRUE; } else if (term_to_double(t, result)) return TRUE; else return FALSE; } /* term_to_number */ /************* * * true_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL true_term(Term t) { return is_term(t, true_sym(), 0); } /* true_term */ /************* * * false_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL false_term(Term t) { return is_term(t, false_sym(), 0); } /* false_term */ /************* * * term_to_bool() * *************/ /* DOCUMENTATION Given a term, see if it represents an Boolean value. If so, set *result to the value and return TRUE. If not, return FALSE. */ /* PUBLIC */ BOOL term_to_bool(Term t, BOOL *result) { if (true_term(t)) { *result = TRUE; return TRUE; } else if (false_term(t)) { *result = FALSE; return TRUE; } else return FALSE; } /* term_to_bool */ /************* * * symbols_in_term() * *************/ /* DOCUMENTATION This routine collects the multiset of nonvariable symbols in a term. An Ilist of symbol IDs (symnums) is returned */ /* PUBLIC */ I2list symbols_in_term(Term t, I2list g) { if (!VARIABLE(t)) { int i; g = multiset_add(g, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) g = symbols_in_term(ARG(t,i), g); } return g; } /* symbols_in_term */ /************* * * fsym_set_in_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist fsym_set_in_term(Term t) { I2list a = symbols_in_term(t, NULL); Ilist b = multiset_to_set(a); zap_i2list(a); return b; } /* fsym_set_in_term */ /************* * * renum_vars_recurse() * *************/ /* DOCUMENTATION This routine renumbers the variables of a term. It is assumed that vmap has been filled with -1 on the initial call and that the size of vmap is at least max_vars.

This returns a Term instead of being void, in case the given term is itself a variable. (Recall that variables may be shared, so we can't just change a variable's index. */ /* PUBLIC */ Term renum_vars_recurse(Term t, int vmap[], int max_vars) { if (VARIABLE(t)) { int i = 0; while (i < max_vars && vmap[i] != -1 && vmap[i] != VARNUM(t)) i++; if (i == max_vars) fatal_error("renum_vars_recurse: too many variables"); if (vmap[i] == -1) vmap[i] = VARNUM(t); free_term(t); return get_variable_term(i); } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = renum_vars_recurse(ARG(t,i), vmap, max_vars); return t; } } /* renum_vars_recurse */ /************* * * set_vars_recurse() * *************/ /* DOCUMENTATION This routine sets the variables of a term. It is assumed that vnames has been filled with NULL on the initial call and that the size of vnames is at least max_vars.

This returns a Term instead of being void, in case the given term is itself becomes a variable. */ /* PUBLIC */ Term set_vars_recurse(Term t, char *vnames[], int max_vars) { if (CONSTANT(t)) { char *name = sn_to_str(SYMNUM(t)); if (variable_name(name)) { int i = 0; while (i < max_vars && vnames[i] != NULL && vnames[i] != name) i++; if (i == max_vars) fatal_error("set_vars_recurse: max_vars"); else { if (vnames[i] == NULL) vnames[i] = name; free_term(t); t = get_variable_term(i); } } } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = set_vars_recurse(ARG(t,i), vnames, max_vars); } return t; } /* set_vars_recurse */ /************* * * multiset_of_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list multiset_of_vars(Term t, I2list vars) { if (VARIABLE(t)) return multiset_add(vars, VARNUM(t)); else { int i; for (i = 0; i < ARITY(t); i++) vars = multiset_of_vars(ARG(t,i), vars); return vars; } } /* multiset_of_vars */ /************* * * multiset_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list multiset_vars(Term t) { return multiset_of_vars(t, NULL); } /* multiset_vars */ /************* * * set_of_vars() * *************/ /* DOCUMENTATION See set_of_variables(t). */ /* PUBLIC */ Plist set_of_vars(Term t, Plist vars) { if (VARIABLE(t)) { if (plist_member(vars, t)) return vars; else return plist_prepend(vars, t); } else { int i; for (i = 0; i < ARITY(t); i++) vars = set_of_vars(ARG(t,i), vars); return vars; } } /* set_of_vars */ /************* * * set_of_variables() * *************/ /* DOCUMENTATION Given a Term, return the set of variables. */ /* PUBLIC */ Plist set_of_variables(Term t) { return set_of_vars(t, NULL); } /* set_of_variables */ /************* * * number_of_vars_in_term() * *************/ /* DOCUMENTATION Given a Term, return the set of variables. */ /* PUBLIC */ int number_of_vars_in_term(Term t) { Plist p = set_of_vars(t, NULL); int n = plist_count(p); zap_plist(p); return n; } /* number_of_vars_in_term */ /************* * * set_of_ivars() * *************/ /* DOCUMENTATION See set_of_ivariables(t). */ /* PUBLIC */ Ilist set_of_ivars(Term t, Ilist ivars) { if (VARIABLE(t)) { if (ilist_member(ivars, VARNUM(t))) return ivars; else return ilist_prepend(ivars, VARNUM(t)); } else { int i; for (i = 0; i < ARITY(t); i++) ivars = set_of_ivars(ARG(t,i), ivars); return ivars; } } /* set_of_ivars */ /************* * * set_of_ivariables() * *************/ /* DOCUMENTATION Given a Term, return the set of integers corresponding to its variables. */ /* PUBLIC */ Ilist set_of_ivariables(Term t) { return set_of_ivars(t, NULL); } /* set_of_ivariables */ /************* * * variables_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL variables_subset(Term t1, Term t2) { Plist t1_vars = set_of_variables(t1); Plist t2_vars = set_of_variables(t2); BOOL ok = plist_subset(t1_vars, t2_vars); zap_plist(t1_vars); zap_plist(t2_vars); return ok; } /* variables_subset */ /************* * * variables_multisubset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL variables_multisubset(Term a, Term b) { #if 1 I2list a_vars = multiset_vars(a); I2list b_vars = multiset_vars(b); BOOL ok = i2list_multisubset(a_vars, b_vars); zap_i2list(a_vars); zap_i2list(b_vars); return ok; #else /* old version */ Plist a_vars = set_of_variables(a); Plist p; BOOL ok = TRUE; for (p = a_vars; p && ok; p = p->next) ok = occurrences(b, p->v) >= occurrences(a, p->v); zap_plist(a_vars); return ok; #endif } /* variables_multisubset */ /************* * * term_at_pos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term term_at_pos(Term t, Ilist pos) { if (pos == NULL) return t; else { if (pos->i > ARITY(t)) return NULL; else return term_at_pos(ARG(t,pos->i - 1), pos->next); } } /* term_at_pos */ /************* * * pos_of_subterm() * *************/ static Ilist pos_of_subterm(Term t, Term subterm) { if (VARIABLE(t)) return NULL; else if (t == subterm) /* We need to let the caller know that we found it, and we also need to return the position vector (NULL). The easiest way I can see to do that is to return a non-NULL position consisting of a "terminator" which will have to be removed later. */ return ilist_prepend(NULL, INT_MAX); /* terminator */ else { int i; Ilist p = NULL; for (i = 0; i < ARITY(t) && p == NULL; i++) p = pos_of_subterm(ARG(t, i), subterm); return p ? ilist_prepend(p, i) : NULL; } } /* pos_of_subterm */ /************* * * position_of_subterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist position_of_subterm(Term t, Term subterm) { Ilist pos = pos_of_subterm(t, subterm); if (pos == NULL) return NULL; else { return ilist_remove_last(pos); } } /* position_of_subterm */ /************* * * symbol_occurrences() * *************/ /* DOCUMENTATION Return the number of occurrences of a symbol in a term. */ /* PUBLIC */ int symbol_occurrences(Term t, int symnum) { if (VARIABLE(t)) return 0; else { int n = (SYMNUM(t) == symnum ? 1 : 0); int i; for (i = 0; i < ARITY(t); i++) n += symbol_occurrences(ARG(t,i), symnum); return n; } } /* symbol_occurrences */ /************* * * args_distinct_vars() * *************/ /* DOCUMENTATION Is the Term a nonvariable with distinct variables as arguments? (Constants satisfy this.) */ /* PUBLIC */ BOOL args_distinct_vars(Term t) { #if 1 if (VARIABLE(t)) return FALSE; else { int i; for (i = 0; i < ARITY(t); i++) { if (!VARIABLE(ARG(t,i))) return FALSE; else { int j; for (j = 0; j < i; j++) if (VARNUM(ARG(t,i)) == VARNUM(ARG(t,j))) return FALSE; } } return TRUE; } #else if (VARIABLE(t)) return FALSE; else { int *p = calloc(ARITY(t), sizeof(int)); int i; BOOL ok = TRUE; for (i = 0; i < ARITY(t) && ok; i++) { Term s = ARG(t,i); if (!VARIABLE(s)) ok = FALSE; else if (p[VARNUM(s)]) ok = FALSE; else p[VARNUM(s)] = TRUE; } free(p); return ok; } #endif } /* args_distinct_vars */ /************* * * hash_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned hash_term(Term t) { if (VARIABLE(t)) return VARNUM(t); else { int i; unsigned x = SYMNUM(t); for (i = 0; i < ARITY(t); i++) x = (x << 3) ^ hash_term(ARG(t,i)); return x; } } /* hash_term */ /************* * * skolem_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL skolem_term(Term t) { return is_skolem(SYMNUM(t)); } /* skolem_term */ /************* * * contains_skolem_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL contains_skolem_term(Term t) { if (VARIABLE(t)) return FALSE; else if (skolem_term(t)) return TRUE; else { int i; for (i = 0; i < ARITY(t); i++) if (contains_skolem_term(ARG(t,i))) return TRUE; return FALSE; } } /* contains_skolem_term */ /************* * * contains_skolem_function() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL contains_skolem_function(Term t) { if (VARIABLE(t)) return FALSE; else if (COMPLEX(t) && skolem_term(t)) return TRUE; else { int i; for (i = 0; i < ARITY(t); i++) if (contains_skolem_function(ARG(t,i))) return TRUE; return FALSE; } } /* contains_skolem_function */ /************* * * term0() * *************/ /* DOCUMENTATION Build constant Term. */ /* PUBLIC */ Term term0(char *sym) { return get_rigid_term(sym, 0); } /* term0 */ /************* * * term1() * *************/ /* DOCUMENTATION Build a unary term. The argument Term is not copied. */ /* PUBLIC */ Term term1(char *sym, Term arg) { Term t = get_rigid_term(sym, 1); ARG(t,0) = arg; return t; } /* term1 */ /************* * * term2() * *************/ /* DOCUMENTATION Build a binary term. The argument Terms are not copied. */ /* PUBLIC */ Term term2(char *sym, Term arg1, Term arg2) { Term t = get_rigid_term(sym, 2); ARG(t,0) = arg1; ARG(t,1) = arg2; return t; } /* term2 */ /************* * * symbol_in_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL symbol_in_term(int symnum, Term t) { if (VARIABLE(t)) return FALSE; else if (SYMNUM(t) == symnum) return TRUE; else { int i; for (i = 0; i < ARITY(t); i++) if (symbol_in_term(symnum, ARG(t,i))) return TRUE; return FALSE; } } /* symbol_in_term */ /************* * * same_structure() * *************/ /* DOCUMENTATION If variables are ignored, are the terms identical? */ /* PUBLIC */ BOOL same_structure(Term a, Term b) { if (VARIABLE(a) || VARIABLE(b)) return VARIABLE(a) && VARIABLE(b); else if (SYMNUM(a) != SYMNUM(b)) return FALSE; else { int i; for (i = 0; i < ARITY(a); i++) if (!same_structure(ARG(a,i), ARG(b,i))) return FALSE; return TRUE; } } /* same_structure */ /************* * * copy_plist_of_terms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist copy_plist_of_terms(Plist terms) { if (terms == NULL) return NULL; else { Plist tail = copy_plist_of_terms(terms->next); Plist head = get_plist(); head->v = copy_term(terms->v); head->next = tail; return head; } } /* copy_plist_of_terms */ /************* * * zap_plist_of_terms() * *************/ /* DOCUMENTATION Free a Plist of terms. */ /* PUBLIC */ void zap_plist_of_terms(Plist lst) { Plist p = lst; while (p != NULL) { Plist p2 = p; p = p->next; zap_term(p2->v); free_plist(p2); } } /* zap_plist_of_terms */ /************* * * eq_term() * *************/ /* DOCUMENTATION This function checks if an atom is an equality atom (positive or negative) for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL eq_term(Term a) { return is_eq_symbol(SYMNUM(a)); } /* eq_term */ /************* * * plist_of_subterms() -- shallow * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist plist_of_subterms(Term t) { Plist subterms = NULL; int i; for (i = 0; i < ARITY(t); i++) subterms = plist_append(subterms, ARG(t,i)); return subterms; } /* plist_of_subterms */ /************* * * tlist_member() * *************/ /* DOCUMENTATION This function checks if a term is a member of a Plist. The function term_ident(t1,t2) is used. */ /* PUBLIC */ BOOL tlist_member(Term t, Plist lst) { if (lst == NULL) return FALSE; else if (term_ident(lst->v, t)) return TRUE; else return tlist_member(t, lst->next); } /* tlist_member */ /************* * * position_of_term_in_tlist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int position_of_term_in_tlist(Term t, Plist lst) { Plist p; int i; for (p = lst, i = 1; p; p = p->next, i++) if (term_ident(p->v, t)) return i; return -1; } /* position_of_term_in_tlist */ /************* * * tlist_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL tlist_subset(Plist a, Plist b) { if (a == NULL) return TRUE; else return tlist_member(a->v, b) && tlist_subset(a->next, b); } /* tlist_subset */ /************* * * tlist_set() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL tlist_set(Plist a) { if (a == NULL) return TRUE; else return !tlist_member(a->v, a->next) && tlist_set(a->next); } /* tlist_set */ /************* * * free_vars_term() * *************/ /* DOCUMENTATION Return the set of constants that look like variables. The terms are newly constructed; if they are not used, the list should be deallocated with zap_tlist(). */ /* PUBLIC */ Plist free_vars_term(Term t, Plist vars) { if (VARIABLE(t)) fatal_error("free_vars_term, VARIABLE term"); if (ARITY(t) == 0) { if (variable_name(sn_to_str(SYMNUM(t))) && !tlist_member(t, vars)) vars = plist_append(vars, copy_term(t)); } else { int i; for (i = 0; i < ARITY(t); i++) vars = free_vars_term(ARG(t,i), vars); } return vars; } /* free_vars_term */ LADR-2009-11A/ladr/discrim.c0000644000175000017500000001170310637466321014550 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "discrim.h" /* Private definitions and types */ /* * memory management */ #define PTRS_DISCRIM PTRS(sizeof(struct discrim)) static unsigned Discrim_gets, Discrim_frees; #define PTRS_DISCRIM_POS PTRS(sizeof(struct discrim_pos)) static unsigned Discrim_pos_gets, Discrim_pos_frees; /************* * * Discrim get_discrim() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Discrim get_discrim(void) { Discrim p = get_cmem(PTRS_DISCRIM); Discrim_gets++; return(p); } /* get_discrim */ /************* * * free_discrim() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_discrim(Discrim p) { free_mem(p, PTRS_DISCRIM); Discrim_frees++; } /* free_discrim */ /************* * * Discrim_pos get_discrim_pos() * *************/ /* DOCUMENTATION The structure is not initialized. */ /* PUBLIC */ Discrim_pos get_discrim_pos(void) { Discrim_pos p = get_mem(PTRS_DISCRIM_POS); /* not initialized */ Discrim_pos_gets++; return(p); } /* get_discrim_pos */ /************* * * free_discrim_pos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_discrim_pos(Discrim_pos p) { free_mem(p, PTRS_DISCRIM_POS); Discrim_pos_frees++; } /* free_discrim_pos */ /************* * * fprint_discrim_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrim package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_discrim_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct discrim); fprintf(fp, "discrim (%4d) %11u%11u%11u%9.1f K\n", n, Discrim_gets, Discrim_frees, Discrim_gets - Discrim_frees, ((Discrim_gets - Discrim_frees) * n) / 1024.); n = sizeof(struct discrim_pos); fprintf(fp, "discrim_pos (%4d) %11u%11u%11u%9.1f K\n", n, Discrim_pos_gets, Discrim_pos_frees, Discrim_pos_gets - Discrim_pos_frees, ((Discrim_pos_gets - Discrim_pos_frees) * n) / 1024.); } /* fprint_discrim_mem */ /************* * * p_discrim_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the discrim package. */ /* PUBLIC */ void p_discrim_mem(void) { fprint_discrim_mem(stdout, TRUE); } /* p_discrim_mem */ /* * end of memory management */ /************* * * discrim_init() * *************/ /* DOCUMENTATION This routine allocates and returns an empty discrimination index. It can be used for either wild or tame indexing. */ /* PUBLIC */ Discrim discrim_init(void) { return get_discrim(); } /* discrim_init */ /************* * * discrim_dealloc(d) * *************/ /* DOCUMENTATION This routine frees an empty discrimination index (wild or tame). */ /* PUBLIC */ void discrim_dealloc(Discrim d) { if (d->u.kids) { fatal_error("discrim_dealloc, nonempty index."); } else free_discrim(d); } /* discrim_dealloc */ /************* * * zap_discrim_tree() * *************/ static void zap_discrim_tree(Discrim d, int n) { if (n == 0) { zap_plist(d->u.data); } else { int arity; Discrim k, prev; k = d->u.kids; while (k != NULL) { if (k->type == AC_ARG_TYPE || k->type == AC_NV_ARG_TYPE) arity = 0; else if (DVAR(k)) arity = 0; else arity = sn_to_arity(k->symbol); prev = k; k = k->next; zap_discrim_tree(prev, n+arity-1); } } free_discrim(d); } /* zap_discrim_tree */ /************* * * destroy_discrim_tree() * *************/ /* DOCUMENTATION This routine frees all the memory associated with a discrimination index. It can be used with either wild or tame trees. */ /* PUBLIC */ void destroy_discrim_tree(Discrim d) { zap_discrim_tree(d, 1); } /* destroy_discrim_tree */ /************* * * discrim_empty() * *************/ /* DOCUMENTATION This Boolean function checks if a discrimination index is empty. It can be used with either wild or tame trees. */ /* PUBLIC */ BOOL discrim_empty(Discrim d) { return (d == NULL ? TRUE : (d->u.kids == NULL ? TRUE : FALSE)); } /* discrim_empty */ LADR-2009-11A/ladr/listterm.h0000644000175000017500000000312711151265363014762 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_LISTTERM_H #define TP_LISTTERM_H #include "term.h" /* INTRODUCTION This package has routines for managing binary-tree lists built from Terms, which allows you to do some LISPy and Prology things. However, you must be careful to keep track of any terms that are shared and to recycle your own garbage. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from listterm.c */ Term get_nil_term(); Term listterm_cons(Term t1, Term t2); BOOL cons_term(Term t); BOOL nil_term(Term t); BOOL proper_listterm(Term t); Term listterm_append(Term list, Term element); int listterm_length(Term t); Term listterm_i(Term lst, int i); BOOL listterm_member(Term t, Term lst); Plist listterm_to_tlist(Term t); void listterm_zap(Term t); Term listterm_reverse(Term t); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/ac_redun.h0000644000175000017500000000242311151265364014676 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_AC_REDUN_H #define TP_AC_REDUN_H #include "parautil.h" #include "accanon.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from ac_redun.c */ BOOL same_top(Term t1, Term t2); int commutativity(Term atom); int associativity(Term atom); int c_associativity(Term atom); int associativity3(Term atom); int associativity4(Term atom); BOOL cac_tautology(Literals lits); BOOL cac_redundancy(Topform c, BOOL print); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/symbols.c0000644000175000017500000016707011274137207014613 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "symbols.h" /* Private definitions and types*/ struct symbol { int symnum; /* unique identifier */ char *name; /* the print symbol */ int arity; /* 0 for constants */ Symbol_type type; /* function, relation, unspecified */ Parsetype parse_type; /* infix, prefix, etc. */ int parse_prec; /* precedence for parsing/printing */ Unif_theory unif_theory; /* e.g., associative-commutative */ int occurrences; /* how often it occurs somewhere */ int lex_val; /* precedence for term orderings */ int kb_weight; /* for Knuth-Bendix ordering */ Lrpo_status lrpo_status; /* for LRPO, LPO, RPO */ BOOL skolem; BOOL unfold; BOOL auxiliary; /* not part of theory, e.g., in hints only */ /* IF YOU ADD MORE FIELDS, MAKE SURE TO INITIALIZE THEM ! */ }; #define SYM_TAB_SIZE 50000 static Plist By_id[SYM_TAB_SIZE]; /* for access by symnum (ID) */ static Plist By_sym[SYM_TAB_SIZE]; /* for access by string/arity */ static unsigned Symbol_count; /* Logic symbols when in Term form */ static char *True_sym = "$T"; static char *False_sym = "$F"; static char *And_sym = "&"; static char *Or_sym = "|"; static char *Not_sym = "-"; static char *Iff_sym = "<->"; static char *Imp_sym = "->"; static char *Impby_sym = "<-"; static char *All_sym = "all"; static char *Exists_sym = "exists"; static char *Quant_sym = "$quantified"; /* Other symbols when in Term form */ static char *Attrib_sym = "#"; /* operator for attaching attributes */ static char *Eq_sym = "="; /* for equality inference rules */ static char *Neq_sym = "!="; /* abbreviation for negation of Eq_sym */ /************* * * true_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *true_sym(void) { return True_sym; } /* true_sym */ /************* * * false_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *false_sym() { return False_sym; } /* false_sym */ /************* * * and_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *and_sym() { return And_sym; } /* and_sym */ /************* * * or_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *or_sym() { return Or_sym; } /* or_sym */ /************* * * not_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *not_sym() { return Not_sym; } /* not_sym */ /************* * * iff_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *iff_sym() { return Iff_sym; } /* iff_sym */ /************* * * imp_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *imp_sym() { return Imp_sym; } /* imp_sym */ /************* * * impby_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *impby_sym() { return Impby_sym; } /* impby_sym */ /************* * * all_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *all_sym() { return All_sym; } /* all_sym */ /************* * * exists_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *exists_sym() { return Exists_sym; } /* exists_sym */ /************* * * quantified_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *quant_sym() { return Quant_sym; } /* quantified_sym */ /************* * * attrib_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *attrib_sym() { return Attrib_sym; } /* attrib_sym */ /************* * * eq_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *eq_sym() { return Eq_sym; } /* eq_sym */ /************* * * neq_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *neq_sym() { return Neq_sym; } /* neq_sym */ /************* * * set_operation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_operation_symbol(char *operation, char *symbol) { if (str_ident(operation, "true")) True_sym = symbol; else if (str_ident(operation, "false")) False_sym = symbol; else if (str_ident(operation, "conjunction")) And_sym = symbol; else if (str_ident(operation, "disjunction")) Or_sym = symbol; else if (str_ident(operation, "negation")) Not_sym = symbol; else if (str_ident(operation, "implication")) Imp_sym = symbol; else if (str_ident(operation, "backward_implication")) Impby_sym = symbol; else if (str_ident(operation, "equivalence")) Iff_sym = symbol; else if (str_ident(operation, "universal_quantification")) All_sym = symbol; else if (str_ident(operation, "existential_quantification")) Exists_sym = symbol; else if (str_ident(operation, "quantification")) Quant_sym = symbol; else if (str_ident(operation, "attribute")) Attrib_sym = symbol; else if (str_ident(operation, "equality")) Eq_sym = symbol; else if (str_ident(operation, "negated_equality")) Neq_sym = symbol; else { printf("The unknown operation is %s\n", operation); fatal_error("set_operation_symbol, unknown operation"); } } /* set_operation_symbol */ /************* * * get_operation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *get_operation_symbol(char *operation) { if (str_ident(operation, "true")) return True_sym; else if (str_ident(operation, "false")) return False_sym; else if (str_ident(operation, "conjunction")) return And_sym; else if (str_ident(operation, "disjunction")) return Or_sym; else if (str_ident(operation, "negation")) return Not_sym; else if (str_ident(operation, "implication")) return Imp_sym; else if (str_ident(operation, "backward_implication")) return Impby_sym; else if (str_ident(operation, "equivalence")) return Iff_sym; else if (str_ident(operation, "universal_quantification")) return All_sym; else if (str_ident(operation, "existential_quantification")) return Exists_sym; else if (str_ident(operation, "quantification")) return Quant_sym; else if (str_ident(operation, "attribute")) return Attrib_sym; else if (str_ident(operation, "equality")) return Eq_sym; else if (str_ident(operation, "negated_equality")) return Neq_sym; else { printf("The unknown operation is %s\n", operation); fatal_error("get_operation_symbol, unknown operation"); return ""; } } /* get_operation_symbol */ /************* * * symbol_in_use() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL symbol_in_use(char *str) { if (str_ident(str, True_sym)) return TRUE; else if (str_ident(str, False_sym)) return TRUE; else if (str_ident(str, And_sym)) return TRUE; else if (str_ident(str, Or_sym)) return TRUE; else if (str_ident(str, Not_sym)) return TRUE; else if (str_ident(str, Imp_sym)) return TRUE; else if (str_ident(str, Impby_sym)) return TRUE; else if (str_ident(str, Iff_sym)) return TRUE; else if (str_ident(str, All_sym)) return TRUE; else if (str_ident(str, Exists_sym)) return TRUE; else if (str_ident(str, Quant_sym)) return TRUE; else if (str_ident(str, Attrib_sym)) return TRUE; else if (str_ident(str, Eq_sym)) return TRUE; else if (str_ident(str, Neq_sym)) return TRUE; else return FALSE; } /* symbol_in_use */ /****************************************************************************/ /* This section is about the symbol table. */ /****************************************************************************/ /************* * * Symbol get_symbol() * *************/ static Symbol get_symbol(void) { Symbol p = malloc(sizeof(struct symbol)); p->name = ""; p->symnum = 0; p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; p->arity = -1; p->unif_theory = EMPTY_THEORY; p->occurrences = -1; p->lex_val = INT_MAX; p->lrpo_status = LRPO_LR_STATUS; p->kb_weight = 1; p->type = UNSPECIFIED_SYMBOL; p->skolem = FALSE; p->unfold = FALSE; p->auxiliary = FALSE; return(p); } /* get_symbol */ /************* * * int new_symnum() * * Return the next available symbol number. It is always POSITIVE. * *************/ static int new_symnum(void) { Symbol_count++; return(Symbol_count); } /* new_symnum */ /************* * * hash_sym() * *************/ static unsigned hash_sym(char *s, int arity) { unsigned x = arity; while (*s != '\0') { unsigned c = *s; x = (x << 4) | c; s++; } return abs(x) % SYM_TAB_SIZE; } /* hash_sym */ /************* * * hash_id() * *************/ static unsigned hash_id(int id) { return abs(id) % SYM_TAB_SIZE; } /* hash_id */ /************* * * lookup_by_id() * *************/ static Symbol lookup_by_id(int symnum) { Plist p; for (p = By_id[hash_id(symnum)]; p; p = p->next) { Symbol s = p->v; if (s->symnum == symnum) return s; } return NULL; } /* lookup_by_id */ /************* * * lookup_by_sym() * *************/ static Symbol lookup_by_sym(char *name, int arity) { Plist p; for (p = By_sym[hash_sym(name,arity)]; p; p = p->next) { Symbol s = p->v; if (s->arity == arity && str_ident(s->name, name)) return s; } return NULL; } /* lookup_by_sym */ /************* * * int str_to_sn() * *************/ /* DOCUMENTATION This routine takes a string and an arity, and returns an integer identifier for the pair. If the pair is not already in the symbol table, a new entry is inserted into the table. A pair, say ("f",2), is sometimes written as f/2, which is a different symbol from f/3. There is no limit on the length of the string (which is copied). */ /* PUBLIC */ int str_to_sn(char *str, int arity) { Symbol s = lookup_by_sym(str, arity); if (s == NULL) { s = get_symbol(); s->name = new_str_copy(str); s->arity = arity; s->symnum = new_symnum(); /* printf("New Symbol: %s/%d, sn=%d\n", str, arity, s->symnum); */ /* insert into both hash tables */ { int hashval_id = hash_id(s->symnum); int hashval_sym = hash_sym(str, arity); By_sym[hashval_sym] = plist_prepend(By_sym[hashval_sym], s); By_id[hashval_id] = plist_prepend(By_id[hashval_id], s); } } return(s->symnum); } /* str_to_sn */ /************* * * fprint_syms(file_ptr) -- Display the symbol list. * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the symbol table, including many of the attributes of each symbol. */ /* PUBLIC */ void fprint_syms(FILE *fp) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; fprintf(fp, "%d %s/%d %s, lex_val=%d, kb_weight=%d\n", s->symnum, s->name, s->arity, s->type == FUNCTION_SYMBOL ? "function" : s->type == PREDICATE_SYMBOL ? "relation" : "", s->lex_val, s->kb_weight); } } } /* fprint_syms */ /************* * * p_syms() * *************/ /* DOCUMENTATION This routine prints (to stdout) the symbol table, including all of the attributes of each symbol. */ /* PUBLIC */ void p_syms(void) { fprint_syms(stdout); } /* p_syms */ /************* * * fprint_sym() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void fprint_sym(FILE *fp, int symnum) { fprintf(fp, "%s", sn_to_str(symnum)); } /* fprint_sym */ /************* * * sprint_sym() * *************/ /* DOCUMENTATION This routine appends, to String_buf sb, the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void sprint_sym(String_buf sb, int symnum) { sb_append(sb, sn_to_str(symnum)); } /* fprint_sym */ /************* * * p_sym() * *************/ /* DOCUMENTATION This routine prints (stdout) the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void p_sym(int symnum) { fprint_sym(stdout, symnum); } /* p_sym */ /************* * * str_exists() * *************/ /* DOCUMENTATION This function checks if the given string occurs in the symbol table (with any arity). This should be used judiciously, because the whole table is scanned. */ /* PUBLIC */ BOOL str_exists(char *str) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (str_ident(str, s->name)) return TRUE; } } return FALSE; } /* str_exists */ /************* * * greatest_symnum() * *************/ /* DOCUMENTATION This function returns the greatest symnum (symbol ID) currently in use. This can be used if you need to dynamnically allocate an array of objects to be indexed by symnum. */ /* PUBLIC */ int greatest_symnum(void) { return Symbol_count; } /* greatest_symnum */ /****************************************************************************/ /* This section is about miscellaneous properties of symbols. */ /****************************************************************************/ /************* * * char *sn_to_str(symnum) -- given a symbol number, return the name * *************/ /* DOCUMENTATION This routine returns the string assocated with a symbol ID. */ /* PUBLIC */ char *sn_to_str(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(""); else return(p->name); } /* sn_to_str */ /************* * * int is_symbol(symbol, str, arity) * *************/ /* DOCUMENTATION This Boolean routine checks if a given symbol ID matches a given (string,arity) pair. */ /* PUBLIC */ BOOL is_symbol(int symnum, char *str, int arity) { Symbol n = lookup_by_id(symnum); if (n == NULL) return FALSE; else return (n->arity == arity && str_ident(n->name, str)); } /* is_symbol */ /************* * * int sn_to_arity(symnum) -- given a symbol number, return the arity * *************/ /* DOCUMENTATION This routine returns the arity associated with a symbol ID. */ /* PUBLIC */ int sn_to_arity(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->arity); } /* sn_to_arity */ /************* * * int sn_to_occurrences(symnum) * *************/ /* DOCUMENTATION This routine returns the occurrences associated with a symbol ID. */ /* PUBLIC */ int sn_to_occurrences(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->occurrences); } /* sn_to_occurrences */ /************* * * set_unfold_symbol() * *************/ /* DOCUMENTATION This routine declares that a symbol is a Skolem function (or constant). */ /* PUBLIC */ void set_unfold_symbol(int symnum) { Symbol p = lookup_by_id(symnum); p->unfold = TRUE; } /* set_unfold_symbol */ /************* * * is_unfold_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL is_unfold_symbol(int symnum) { Symbol p = lookup_by_id(symnum); return p->unfold; } /* is_unfold_symbol */ /************* * * declare_aux_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_aux_symbols(Ilist syms) { Ilist p; for (p = syms; p; p = p->next) { Symbol s = lookup_by_id(p->i); s->auxiliary = TRUE; } } /* declare_aux_symbols */ /****************************************************************************/ /* This section is about parse properties of symbols. */ /****************************************************************************/ /************* * * parse_type_to_str() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *parse_type_to_str(Parsetype type) { switch (type) { case INFIX_LEFT: return "infix_left"; case INFIX_RIGHT: return "infix_right"; case INFIX: return "infix"; case PREFIX: return "prefix"; case PREFIX_PAREN: return "prefix_paren"; case POSTFIX: return "postfix"; case POSTFIX_PAREN: return "postfix_paren"; case NOTHING_SPECIAL: return "ordinary"; } return "???"; } /* parse_type_to_str */ /************* * * clear_parse_type_for_all_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clear_parse_type_for_all_symbols(void) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; s->parse_type = NOTHING_SPECIAL; s->parse_prec = 0; } } } /* clear_parse_type_for_all_symbols */ /************* * * clear_parse_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clear_parse_type(char *str) { Symbol p; p = lookup_by_sym(str, 1); if (p != NULL) { p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; } p = lookup_by_sym(str, 2); if (p != NULL) { p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; } } /* clear_parse_type */ /************* * * check_diff_type_same_prec() * *************/ static void check_diff_type_same_prec(char *str, int prec, Parsetype type) { if (type != NOTHING_SPECIAL) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; Parsetype type2 = s->parse_type; int prec2 = s->parse_prec; char *name = s->name; if (type2 != type && prec == prec2 && !str_ident(name, str)) { printf("\nConflicting declarations (the first may be built in):\n"); printf(" op(%d, %s, \"%s\").\n", prec2,parse_type_to_str(type2),name); printf(" op(%d, %s, \"%s\").\n", prec,parse_type_to_str(type),str); fatal_error("cannot declare different parse types with same " "precedence (see output file)"); } } } } } /* check_diff_type_same_prec */ /************* * * set_parse_type() * *************/ /* DOCUMENTATION This routine sets the parse/print properties of a binary or unary symbol. The types for binary infix symbols are INFIX_LEFT, INFIX_RIGHT, INFIX. The types for prefix unary symbols are PREFIX, PREFIX_PAREN. The types for postfix unary symbols are POSTFIX, POSTFIX_PAREN.

If the precedence is out of range [MIN_PRECEDENCE ... MAX_PRECEDENCE], a fatal error occurs. */ /* PUBLIC */ void set_parse_type(char *str, int precedence, Parsetype type) { if (precedence < MIN_PRECEDENCE || precedence > MAX_PRECEDENCE) fatal_error("set_parse_type: precedence out of range"); else { Symbol p = NULL; clear_parse_type(str); /* in case it has parse type of diff. arity */ check_diff_type_same_prec(str, precedence, type); switch (type) { case INFIX_LEFT: case INFIX_RIGHT: case INFIX: p = lookup_by_id(str_to_sn(str, 2)); p->parse_type = type; p->parse_prec = precedence; break; case PREFIX: case PREFIX_PAREN: case POSTFIX: case POSTFIX_PAREN: p = lookup_by_id(str_to_sn(str, 1)); p->parse_type = type; p->parse_prec = precedence; break; case NOTHING_SPECIAL: /* already cleared above */ break; } } } /* set_parse_type */ /************* * * binary_parse_type() * *************/ /* DOCUMENTATION This routine gets the parse/print properties for a binary symbol. If *str is a binary symbol, TRUE is returned and the properties are filled in. If *str is a not a binary symbol, FALSE is returned. */ /* PUBLIC */ BOOL binary_parse_type(char *str, int *precedence, Parsetype *type) { Symbol p = lookup_by_sym(str, 2); if (p == NULL || p->parse_type == NOTHING_SPECIAL) return FALSE; else { *precedence = p->parse_prec; *type = p->parse_type; return TRUE; } } /* binary_parse_type */ /************* * * unary_parse_type() * *************/ /* DOCUMENTATION This routine gets the parse/print properties for a unary symbol. If *str is a unary symbol, TRUE is returned and the properties are filled in. If *str is a not a unary symbol, FALSE is returned. */ /* PUBLIC */ BOOL unary_parse_type(char *str, int *precedence, Parsetype *type) { Symbol p = lookup_by_sym(str, 1); if (p == NULL || p->parse_type == NOTHING_SPECIAL) return FALSE; else { *precedence = p->parse_prec; *type = p->parse_type; return TRUE; } } /* unary_parse_type */ /************* * * special_parse_type() * *************/ /* DOCUMENTATION Is the string a unary or binary "special_parse_type" (e.g., PREFIX or INFIX)? If so, return the arity; otherwise return -1. */ /* PUBLIC */ int special_parse_type(char *str) { int prec; Parsetype type; if (binary_parse_type(str, &prec, &type)) return 2; else if (unary_parse_type(str, &prec, &type)) return 1; else return -1; } /* special_parse_type */ /****************************************************************************/ /* This section is about associativity-commutativity properties. */ /****************************************************************************/ static int Assoc_comm_symbols = 0; /* number declared */ static int Comm_symbols = 0; /* number decoared */ /************* * * set_assoc_comm() * *************/ /* DOCUMENTATION This routine declares a string to be a (binary) symbol with the logical property "associative-commutative". This property is used for AC unification/matching/identity. (If you wish to print AC expressions without parentheses, see set_parse_type().) */ /* PUBLIC */ void set_assoc_comm(char *str, BOOL set) { int sn = str_to_sn(str, 2); Symbol p = lookup_by_id(sn); if (set) { p->unif_theory = ASSOC_COMMUTE; Assoc_comm_symbols++; } else { p->unif_theory = EMPTY_THEORY; Assoc_comm_symbols--; } } /* set_assoc_comm */ /************* * * set_commutative() * *************/ /* DOCUMENTATION This routine declares a string to be a (binary) symbol with the logical property "commutative". This property is used for commutative unification/matching/identity. */ /* PUBLIC */ void set_commutative(char *str, BOOL set) { int sn = str_to_sn(str, 2); Symbol p = lookup_by_id(sn); if (set) { p->unif_theory = COMMUTE; Comm_symbols++; } else { p->unif_theory = EMPTY_THEORY; Comm_symbols--; } } /* set_commutative */ /************* * * assoc_comm_symbols() * *************/ /* DOCUMENTATION This function tells you if any symbol has been declared to be associative-commutative; */ /* PUBLIC */ BOOL assoc_comm_symbols(void) { return Assoc_comm_symbols != 0; } /* assoc_comm_symbols */ /************* * * comm_symbols() * *************/ /* DOCUMENTATION This function tells you if any symbol has been declared to be commutative. */ /* PUBLIC */ BOOL comm_symbols(void) { return Comm_symbols != 0; } /* comm_symbols */ /************* * * is_assoc_comm * * NOTE: may wish to avoid hash if no AC symbols exist. * *************/ /* DOCUMENTATION This function checks if a symbol ID has the associative-commutative property. Note that set_assoc_comm() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms. */ /* PUBLIC */ BOOL is_assoc_comm(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->unif_theory == ASSOC_COMMUTE); } /* is_assoc_comm */ /************* * * is_commutative * * NOTE: may wish to avoid hash if no C symbols exist. * *************/ /* DOCUMENTATION This function checks if a symbol ID has the commutative property. Note that set_commutative() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms. */ /* PUBLIC */ BOOL is_commutative(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->unif_theory == COMMUTE); } /* is_commutative */ /****************************************************************************/ /* This section is about some built-in logic symbols. */ /****************************************************************************/ static int Eq_symnum = 0; static int Or_symnum = 0; static int Not_symnum = 0; /************* * * int is_eq_symbol(symbol) * *************/ /* DOCUMENTATION This Boolean routine checks if a given symbol ID is for eq_sym()/2. One could use is_symbol(symnum, eq_sym(), 2) instead, but this should be a bit faster. */ /* PUBLIC */ BOOL is_eq_symbol(int symnum) { if (Eq_symnum == 0) { Eq_symnum = str_to_sn(eq_sym(), 2); } return (symnum == Eq_symnum ? TRUE : FALSE); } /* is_eq_symbol */ /************* * * not_symnum() * *************/ /* DOCUMENTATION Return the symnum for not_sym()/1. */ /* PUBLIC */ int not_symnum(void) { if (Not_symnum == 0) Not_symnum = str_to_sn(not_sym(), 1); return Not_symnum; } /* not_symnum */ /************* * * or_symnum() * *************/ /* DOCUMENTATION Return the symnum for or_sym()/2. */ /* PUBLIC */ int or_symnum(void) { if (Or_symnum == 0) Or_symnum = str_to_sn(or_sym(), 2); return Or_symnum; } /* or_symnum */ /************* * * declare_base_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_base_symbols(void) { int sn; sn = str_to_sn(false_sym(), 0); sn = str_to_sn(true_sym(), 0); sn = str_to_sn("false", 0); sn = str_to_sn("true", 0); } /* declare_base_symbols */ /****************************************************************************/ /* This section is about variables. */ /****************************************************************************/ static Variable_style Var_style = STANDARD_STYLE; /************* * * set_variable_style() * *************/ /* DOCUMENTATION This routine determines how variables are parsed and printed. */ /* PUBLIC */ void set_variable_style(Variable_style style) { Var_style = style; } /* set_variable_style */ /************* * * variable_style() * *************/ /* DOCUMENTATION This routine gives the current variable style. */ /* PUBLIC */ Variable_style variable_style(void) { return Var_style; } /* set_variable_style */ /************* * * variable_name() * *************/ /* DOCUMENTATION Is the given name a variable? Formulas can have free variables (not explicitly quantified), so we have a rule to distinguish variables from constants. This is it. */ /* PUBLIC */ BOOL variable_name(char *s) { if (variable_style() == PROLOG_STYLE) return (*s >= 'A' && *s <= 'Z'); else if (variable_style() == INTEGER_STYLE) return (*s >= '0' && *s <= '9'); else return (*s >= 'u' && *s <= 'z'); } /* variable_name */ /************* * * symbol_for_variable() * *************/ /* DOCUMENTATION Given a pointer to a string and a variable index, fill in the string with the variable symbol. The variable symbol is determined by the current variable style (standard, prolog, integer, etc.), which can be changed with set_variable_style(). */ /* PUBLIC */ void symbol_for_variable(char *str, int varnum) { if (variable_style() == INTEGER_STYLE) /* 0,1,2,3,4,5,6,7,... */ sprintf(str, "%d", varnum); else if (variable_style() == PROLOG_STYLE) { /* A,B,C,D,E,F,V6,V7,V8,... */ if (varnum < 6) sprintf(str, "%c", 'A' + varnum); else sprintf(str, "V%d", varnum); } else { /* x,y,z,u,w,v5,v6,v7,v8,... */ if (varnum < 3) sprintf(str, "%c", 'x' + varnum); else if (varnum == 3) sprintf(str, "%c", 'u'); else if (varnum == 4) sprintf(str, "%c", 'w'); else sprintf(str, "v%d", varnum); } } /* symbol_for_variable */ /************* * * variable_symbols() * *************/ /* DOCUMENTATION Given a Plist of symbols (symnums), return a (new) list of the symnums that correspond to variables. */ /* PUBLIC */ Ilist variable_symbols(Ilist syms) { if (syms == NULL) return NULL; else { Ilist work = variable_symbols(syms->next); if (sn_to_arity(syms->i) == 0 && variable_name(sn_to_str(syms->i))) work = ilist_prepend(work, syms->i); return work; } } /* variable_symbols */ /************* * * remove_variable_symbols() * *************/ /* DOCUMENTATION Given a Plist of symbols (symnums), remove the ones that correspond to variables. */ /* PUBLIC */ Ilist remove_variable_symbols(Ilist syms) { Ilist vars = variable_symbols(syms); Ilist result = ilist_subtract(syms,vars); zap_ilist(syms); zap_ilist(vars); return result; } /* remove_variable_symbols */ /****************************************************************************/ /* This section is about FUNCTION/RELATION distinction. */ /****************************************************************************/ /************* * * set_symbol_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_symbol_type(int symnum, Symbol_type type) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("set_symbol_type: bad symnum"); p->type = type; } /* set_symbol_type */ /************* * * get_symbol_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Symbol_type get_symbol_type(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("get_symbol_type: bad symnum"); return p->type; } /* get_symbol_type */ /************* * * function_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL function_symbol(int symnum) { return get_symbol_type(symnum) == FUNCTION_SYMBOL; } /* function_symbol */ /************* * * relation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL relation_symbol(int symnum) { return get_symbol_type(symnum) == PREDICATE_SYMBOL; } /* relation_symbol */ /************* * * function_or_relation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL function_or_relation_symbol(int symnum) { Symbol_type t = get_symbol_type(symnum); return t == PREDICATE_SYMBOL || t == FUNCTION_SYMBOL; } /* function_or_relation_symbol */ /************* * * declare_functions_and_relations() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_functions_and_relations(Ilist fsyms, Ilist rsyms) { Ilist p; for (p = fsyms; p; p = p->next) set_symbol_type(p->i, FUNCTION_SYMBOL); for (p = rsyms; p; p = p->next) set_symbol_type(p->i, PREDICATE_SYMBOL); } /* declare_functions_and_relations */ /************* * * function_or_relation_sn() * *************/ /* DOCUMENTATION If there is a function or relation symbol in the table with the given string, return the symnum; otherwise return -1. (If there is more than one, the first one found is returned.) */ /* PUBLIC */ int function_or_relation_sn(char *str) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if ((s->type == FUNCTION_SYMBOL || s->type == PREDICATE_SYMBOL) && str_ident(str, s->name)) return s->symnum; } } return -1; } /* function_or_relation_sn */ /************* * * all_function_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist all_function_symbols(void) { Ilist syms = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->type == FUNCTION_SYMBOL) syms = ilist_append(syms, s->symnum); } } return syms; } /* all_function_symbols */ /************* * * all_relation_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist all_relation_symbols(void) { Ilist syms = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->type == PREDICATE_SYMBOL) syms = ilist_append(syms, s->symnum); } } return syms; } /* all_relation_symbols */ /****************************************************************************/ /* This section is all about LRPO status. */ /****************************************************************************/ /************* * * set_lrpo_status() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_lrpo_status(int symnum, Lrpo_status status) { Symbol p = lookup_by_id(symnum); p->lrpo_status = status; } /* set_lrpo_status */ /************* * * all_symbols_lrpo_status() * *************/ /* DOCUMENTATION Assign all symbols the given lrpo status: LRPO_LR_STATUS or LRPO_MULTISET_STATUS. */ /* PUBLIC */ void all_symbols_lrpo_status(Lrpo_status status) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; s->lrpo_status = status; } } } /* all_symbols_lrpo_status */ /************* * * sn_to_lrpo_status * *************/ /* DOCUMENTATION This routine returns the LRPO status associated with a symbol ID. The default value is LRPO_LR_STATUS. See order.h for the possible values. If the symbol ID is not valid, 0 is returned. */ /* PUBLIC */ Lrpo_status sn_to_lrpo_status(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->lrpo_status); } /* sn_to_lrpo_status */ /****************************************************************************/ /* This section is all about KB weights. */ /****************************************************************************/ static BOOL Zero_wt_kb = FALSE; /* is there symbol with kb_weight=0? */ /************* * * set_kb_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_kb_weight(int symnum, int weight) { Symbol p = lookup_by_id(symnum); if (p == NULL) { fatal_error("set_kb_weight, symbol not found"); } if (weight == 0) { if (Zero_wt_kb) fatal_error("set_kb_weight, more than one symbol of weight 0"); else if (p->arity != 1 || p->type != FUNCTION_SYMBOL) fatal_error("set_kb_weight, weight 0 symbols must be unary" " function symbols"); else Zero_wt_kb = TRUE; } p->kb_weight = weight; } /* set_kb_weight */ /************* * * zero_wt_kb() * *************/ /* DOCUMENTATION Is there already a symbol with KB weight 0? */ /* PUBLIC */ BOOL zero_wt_kb(void) { return Zero_wt_kb; } /* zero_wt_kb */ /************* * * int sn_to_kb_wt() * *************/ /* DOCUMENTATION This routine returns the Knuth-Bendix weight associated with a symbol ID. */ /* PUBLIC */ int sn_to_kb_wt(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->kb_weight); } /* sn_to_kb_wt */ /************* * * print_kbo_weights() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_kbo_weights(FILE *fp) { Ilist fsyms = current_fsym_precedence(); Ilist p; fprintf(fp, "Function symbol KB weights: "); for (p = fsyms; p; p = p->next) fprintf(fp, " %s=%d.", sn_to_str(p->i), sn_to_kb_wt(p->i)); fprintf(fp, "\n"); zap_ilist(fsyms); } /* print_kbo_weights */ /****************************************************************************/ /* This section is all about Skolem symbols. */ /****************************************************************************/ static char *Skolem_constant_prefix = "c"; static char *Skolem_function_prefix = "f"; static int Next_skolem_constant = 1; /* counter for c1, c2, ... */ static int Next_skolem_function = 1; /* counter for f1, f2, ... */ static BOOL Skolem_check = TRUE; /* make sure Skolem symbols are unique */ /************* * * set_skolem() * *************/ /* DOCUMENTATION This routine declares that a symbol is a Skolem function (or constant). */ /* PUBLIC */ void set_skolem(int symnum) { Symbol p = lookup_by_id(symnum); p->skolem = TRUE; p->type = FUNCTION_SYMBOL; } /* set_skolem */ /************* * * skolem_check() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void skolem_check(BOOL flag) { Skolem_check = flag; } /* skolem_check */ /************* * * skolem_ok() * *************/ static BOOL skolem_ok(char *name, int arity) { if (!Skolem_check) return TRUE; else { Symbol s = lookup_by_sym(name, arity); if (s == NULL) return TRUE; else return s->auxiliary; } } /* skolem_ok */ /************* * * next_skolem_symbol() * *************/ /* DOCUMENTATION This routine returns a fresh symbol ID, which is intended to be used as a Skolem symbol. The symbols are c1, c2, c3, ... for arity 0 (constants) and f1, f2, f3, ... for arity != 0. If some of those symbols already exist in the symbol table (with any arity), they will be skipped. */ /* PUBLIC */ int next_skolem_symbol(int arity) { char name[20]; do { if (arity == 0) { sprintf(name, "%s%d", Skolem_constant_prefix, Next_skolem_constant); Next_skolem_constant++; } else { sprintf(name, "%s%d", Skolem_function_prefix, Next_skolem_function); Next_skolem_function++; } } while (!skolem_ok(name,arity)); { int symnum = str_to_sn(name, arity); set_skolem(symnum); return symnum; } } /* next_skolem_symbol */ /************* * * skolem_symbols() * *************/ /* DOCUMENTATION Return the list of SYMNUMs (increasing) that have been declared to be Skolem symbols. */ /* PUBLIC */ Ilist skolem_symbols(void) { Ilist g = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->skolem) g = ilist_prepend(g, s->symnum); } } return reverse_ilist(g); } /* skolem_symbols */ /************* * * is_skolem() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL is_skolem(int symnum) { Symbol p = lookup_by_id(symnum); return p->skolem; } /* is_skolem */ /************* * * skolem_reset() * *************/ /* DOCUMENTATION Reset the Skolem symbol counters (constant and function) to 1. */ /* PUBLIC */ void skolem_reset(void) { Next_skolem_constant = 1; Next_skolem_function = 1; } /* skolem_reset */ /************* * * decommission_skolem_symbols() * *************/ /* DOCUMENTATION For each symbol in the symbol table, if it is marked "skolem", unmark it and set the type to "unspecified". */ /* PUBLIC */ void decommission_skolem_symbols(void) { Ilist fsyms = all_function_symbols(); Ilist p; for (p = fsyms; p; p = p->next) { Symbol n = lookup_by_id(p->i); if (n->skolem) { n->skolem = FALSE; n->type = UNSPECIFIED_SYMBOL; } } zap_ilist(fsyms); } /* decommission_skolem_symbols */ /************* * * set_skolem_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_skolem_symbols(Ilist symnums) { Ilist p; for (p = symnums; p; p = p->next) { Symbol sym = lookup_by_id(p->i); if (sym == NULL) fatal_error("set_skolem_symbols, symbol not found"); sym->skolem = TRUE; } } /* set_skolem_symbols */ /****************************************************************************/ /* This section is all about lex_val and symbol precedence. */ /****************************************************************************/ static Ilist Preliminary_prec_func = NULL; static Ilist Preliminary_prec_pred = NULL; /************* * * set_lex_val() * *************/ /* DOCUMENTATION This routine is used to assign a lexical value to a symbol. The value can be retrieved later with sn_to_lex_val(); */ /* PUBLIC */ void set_lex_val(int symnum, int lex_val) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("set_lex_val, invalid symnum"); p->lex_val = lex_val; /* printf("set_lex_val %s/%d, %d\n", p->name, p->arity, lex_val); */ } /* set_lex_val */ /************* * * sn_to_lex_val * *************/ /* DOCUMENTATION This routine returns the lexical value associated with a symbol ID. The default value is INT_MAX. If the symbol ID is not valid, INT_MIN is returned. */ /* PUBLIC */ int sn_to_lex_val(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? INT_MIN : p->lex_val); } /* sn_to_lex_val */ /************* * * int sym_precedence(symnum_1, symnum_2) * *************/ /* DOCUMENTATION This routine compares two symbol IDs by looking at their lex_val in the symbol table. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}. */ /* PUBLIC */ Ordertype sym_precedence(int symnum_1, int symnum_2) { int p1, p2; if (symnum_1 == symnum_2) return SAME_AS; else { p1 = sn_to_lex_val(symnum_1); p2 = sn_to_lex_val(symnum_2); if (p1 == INT_MAX || p2 == INT_MAX) return NOT_COMPARABLE; else if (p1 > p2) return GREATER_THAN; else if (p1 < p2) return LESS_THAN; else return SAME_AS; } } /* sym_precedence */ /************* * * syms_with_lex_val() * *************/ /* DOCUMENTATION Return an Ilist containing symnums of symbols to which lex_vals have been assigned. */ /* PUBLIC */ Ilist syms_with_lex_val(void) { Ilist g = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->lex_val != INT_MAX) g = ilist_append(g, s->symnum); } } return g; } /* syms_with_lex_val */ /************* * * exists_preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL exists_preliminary_precedence(Symbol_type type) { if (type == FUNCTION_SYMBOL) return Preliminary_prec_func != NULL; else if (type == PREDICATE_SYMBOL) return Preliminary_prec_pred != NULL; else return FALSE; } /* exists_preliminary_precedence */ /************* * * preliminary_lex_compare() * *************/ /* DOCUMENTATION Compare the given strings with respect to the list of strings given to the set_preliminary_precedence call. Strings without preliminary_precedence are smaller than those with. Two different strings without preliminary_precedence are NOT_COMPARABLE.

Return LESS_THAN, GREATER_THAN, SAME_AS, NOT_COMPARABLE. */ /* PUBLIC */ Ordertype preliminary_lex_compare(Symbol a, Symbol b) { int ai = -1; int bi = -1; if (a->type != b->type) return NOT_COMPARABLE; else if (a->type == UNSPECIFIED_SYMBOL) return NOT_COMPARABLE; else if (a->type == FUNCTION_SYMBOL) { ai = position_in_ilist(a->symnum, Preliminary_prec_func); bi = position_in_ilist(b->symnum, Preliminary_prec_func); } else if (a->type == PREDICATE_SYMBOL) { ai = position_in_ilist(a->symnum, Preliminary_prec_pred); bi = position_in_ilist(b->symnum, Preliminary_prec_pred); } /* printf("%s=%d, %s=%d\n", a, ai, b, bi); */ if (ai == -1) ai = INT_MIN; if (bi == -1) bi = INT_MIN; if (ai < bi) return LESS_THAN; else if (ai > bi) return GREATER_THAN; else if (ai == INT_MIN) return NOT_COMPARABLE; /* neither in preliminary_precedence */ else return SAME_AS; } /* preliminary_lex_compare */ /************* * * lex_compare_base() * *************/ static Ordertype lex_compare_base(Symbol s1, Symbol s2) { if (s1 == s2) return SAME_AS; else if (s1 == NULL) return LESS_THAN; else if (s2 == NULL) return GREATER_THAN; /* FUNCTION < RELATION < others (don't know if there can be others) */ else if (s1->type == FUNCTION_SYMBOL && s2->type != FUNCTION_SYMBOL) return LESS_THAN; else if (s1->type != FUNCTION_SYMBOL && s2->type == FUNCTION_SYMBOL) return GREATER_THAN; else if (s1->type == PREDICATE_SYMBOL && s2->type != PREDICATE_SYMBOL) return LESS_THAN; else if (s1->type != PREDICATE_SYMBOL && s2->type == PREDICATE_SYMBOL) return GREATER_THAN; /* Now they have the same type (FUNCTION, RELATION, other). */ /* Check for preliminary order (lex command). */ else if (preliminary_lex_compare(s1, s2) == LESS_THAN) return LESS_THAN; else if (preliminary_lex_compare(s1, s2) == GREATER_THAN) return GREATER_THAN; /* = < other relations */ else if (s1->type == PREDICATE_SYMBOL && is_eq_symbol(s2->symnum)) return GREATER_THAN; else if (s1->type == PREDICATE_SYMBOL && is_eq_symbol(s1->symnum)) return LESS_THAN; /* if arities same: (1) Skolems > non-Skolems (2) if both Skolems, use sumnum (3) more-occurrences < fewer-occurrences (4) Use UNIX's strcomp, which is lexical ascii ordering. */ else if (s1->arity == s2->arity) { if (s1->skolem || s2->skolem) { if (!s2->skolem) return GREATER_THAN; else if (!s1->skolem) return LESS_THAN; else if (s1->symnum > s2->symnum) return GREATER_THAN; else if (s1->symnum < s2->symnum) return LESS_THAN; else return SAME_AS; } else if (s1->occurrences < s2->occurrences) return GREATER_THAN; else if (s1->occurrences > s2->occurrences) return LESS_THAN; else { int i = strcmp(s1->name, s2->name); if (i < 0) return LESS_THAN; else if (i > 0) return GREATER_THAN; else return SAME_AS; } } /* the type is the same, but arities are different */ else return NOT_COMPARABLE; /* code for "not yet decided" */ } /* lex_compare_base */ /************* * * lex_compare_arity_0123() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype lex_compare_arity_0123(Symbol s1, Symbol s2) { Ordertype base = lex_compare_base(s1, s2); if (base != NOT_COMPARABLE) return base; else /* symbols same type, but with different arities */ return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; } /* lex_compare_arity_0123 */ /************* * * lex_compare_arity_0213() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype lex_compare_arity_0213(Symbol s1, Symbol s2) { Ordertype base = lex_compare_base(s1, s2); if (base != NOT_COMPARABLE) return base; else { /* Symbols same type, but with different arities. Relations: order by arity. Functions: constants < arity-2 < arity-1 < arity-3 < arity-4 ... . */ if (s1->type == PREDICATE_SYMBOL) return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; else if (s1->arity == 1) return s2->arity >= 3 ? LESS_THAN : GREATER_THAN; else if (s2->arity == 1) return s1->arity < 3 ? LESS_THAN : GREATER_THAN; else return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; } } /* lex_compare_arity_0213 */ /************* * * lex_order() * *************/ /* DOCUMENTATION Assign a total order on lex_vals of (fsyms U rsyms). If a list of strings was previously given to set_preliminary_precedence, that order is maintained for symbols that have those strings. For the other rules, see *comp_proc (lex_compare*). */ /* PUBLIC */ void lex_order(Ilist fsyms, Ilist rsyms, I2list fsyms_multiset, I2list rsyms_multiset, Ordertype (*comp_proc) (Symbol, Symbol)) { int n = ilist_count(fsyms) + ilist_count(rsyms); Symbol *a = malloc(n * sizeof(void *)); Ilist p; int i = 0; for (p = fsyms; p; p = p->next, i++) { a[i] = lookup_by_id(p->i); a[i]->occurrences = multiset_occurrences(fsyms_multiset, p->i); } for (p = rsyms; p; p = p->next, i++) { a[i] = lookup_by_id(p->i); a[i]->occurrences = multiset_occurrences(rsyms_multiset, p->i); } add_skolems_to_preliminary_precedence(); merge_sort((void **) a, n, (Ordertype (*)(void*, void*)) comp_proc); for (i = 0; i < n; i++) a[i]->lex_val = i; free(a); } /* lex_order */ /************* * * insert_by_lex_val() * *************/ static Ilist insert_by_lex_val(Ilist head, Ilist tail) { if (tail == NULL) { head->next = NULL; return head; } else if (sn_to_lex_val(head->i) < sn_to_lex_val(tail->i)) { head->next = tail; return head; } else { tail->next = insert_by_lex_val(head, tail->next); return tail; } } /* insert_by_lex_val */ /************* * * sort_by_lex_val() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist sort_by_lex_val(Ilist p) { if (p == NULL) return NULL; else { return insert_by_lex_val(p, sort_by_lex_val(p->next)); } } /* sort_by_lex_val */ /************* * * remove_syms_without_lex_val() * *************/ static Ilist remove_syms_without_lex_val(Ilist syms) { if (syms == NULL) return NULL; else { syms->next = remove_syms_without_lex_val(syms->next); if (sn_to_lex_val(syms->i) == INT_MAX) { Ilist rest = syms->next; free_ilist(syms); return rest; } else return syms; } } /* remove_syms_without_lex_val */ /************* * * current_fsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist current_fsym_precedence() { Ilist syms = all_function_symbols(); syms = remove_syms_without_lex_val(syms); syms = sort_by_lex_val(syms); return syms; } /* current_fsym_precedence */ /************* * * current_rsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist current_rsym_precedence() { Ilist syms = all_relation_symbols(); syms = remove_syms_without_lex_val(syms); syms = sort_by_lex_val(syms); return syms; } /* current_rsym_precedence */ /************* * * not_in_preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist not_in_preliminary_precedence(Ilist syms, Symbol_type type) { Ilist missing = NULL; Ilist p; for (p = syms; p; p = p->next) { if (type == FUNCTION_SYMBOL && position_in_ilist(p->i, Preliminary_prec_func) == -1) missing = ilist_append(missing, p->i); else if (type == PREDICATE_SYMBOL && position_in_ilist(p->i, Preliminary_prec_pred) == -1) missing = ilist_append(missing, p->i); } return missing; } /* not_in_preliminary_precedence */ /************* * * print_fsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_fsym_precedence(FILE *fp) { Ilist fsyms = current_fsym_precedence(); Ilist p; printf("Function symbol precedence: function_order(["); for (p = fsyms; p; p = p->next) printf(" %s%s", sn_to_str(p->i), p->next ? "," : ""); printf(" ]).\n"); zap_ilist(fsyms); } /* print_fsym_precedence */ /************* * * print_rsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_rsym_precedence(FILE *fp) { Ilist rsyms = current_rsym_precedence(); Ilist p; printf("Predicate symbol precedence: predicate_order(["); for (p = rsyms; p; p = p->next) printf(" %s%s", sn_to_str(p->i), p->next ? "," : ""); printf(" ]).\n"); zap_ilist(rsyms); } /* print_rsym_precedence */ /************* * * min_lex_val() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int min_lex_val(void) { Ilist a = syms_with_lex_val(); Ilist p; int min = INT_MAX; for (p = a; p; p = p->next) { int x = sn_to_lex_val(p->i); min = IMIN(min, x); } zap_ilist(a); return min; } /* min_lex_val */ /************* * * max_lex_val() * *************/ static int max_lex_val(void) { Ilist a = syms_with_lex_val(); Ilist p; int max = INT_MIN; for (p = a; p; p = p->next) { int x = sn_to_lex_val(p->i); max = IMAX(max, x); } zap_ilist(a); return max; } /* min_lex_val */ /************* * * assign_greatest_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void assign_greatest_precedence(int symnum) { set_lex_val(symnum, max_lex_val() + 1); } /* assign_greatest_precedence */ /************* * * has_greatest_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL has_greatest_precedence(int symnum) { return sn_to_lex_val(symnum) == max_lex_val(); } /* has_greatest_precedence */ /************* * * lex_insert_after_initial_constants() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void lex_insert_after_initial_constants(Ilist syms) { if (syms) { Ilist all = current_fsym_precedence(); Ilist a, s; int val = 1; for (a = all; a && sn_to_arity(a->i) == 0; a = a->next) { if (!ilist_member(syms, a->i)) set_lex_val(a->i, val++); } syms = sort_by_lex_val(syms); /* so that relative order is unchanged */ for (s = syms; s; s = s->next) set_lex_val(s->i, val++); for (; a; a = a->next) { if (!ilist_member(syms, a->i)) set_lex_val(a->i, val++); } } } /* lex_insert_after_initial_constants */ /************* * * skolem_insert() * *************/ static Ilist skolem_insert(Ilist prec, int i) { if (prec == NULL) return ilist_append(NULL, i); else if (sn_to_arity(prec->i) > sn_to_arity(i)) return ilist_prepend(prec, i); else { prec->next = skolem_insert(prec->next, i); return prec; } } /* skolem_insert */ /************* * * add_skolems_to_preliminary_precedence() * *************/ /* DOCUMENTATION If there is a preliminary precedence, add the skolem symbols to it in the following way. For each Skolem symbol of arity-n, add it to Preliminary_precedence just before the first symbol of higher arity (else at the end). */ /* PUBLIC */ void add_skolems_to_preliminary_precedence(void) { if (Preliminary_prec_func != NULL) { Ilist skolems = skolem_symbols(); Ilist p; /* printf("Before adding skolems: "); p_ilist(Preliminary_precedence); */ for (p = skolems; p; p = p->next) { if (!ilist_member(Preliminary_prec_func, p->i)) Preliminary_prec_func = skolem_insert(Preliminary_prec_func, p->i); } /* printf("After adding skolems: "); p_ilist(Preliminary_precedence); */ zap_ilist(skolems); } } /* add_skolems_to_preliminary_precedence */ /****************************************************************************/ /* This section is all about symbols generated on the fly. */ /****************************************************************************/ static unsigned Mark_for_new_symbols = 0; /* */ /************* * * fresh_symbol() * *************/ /* DOCUMENTATION This routine returns a symbol ID for a new symbol with the given arity. The symbol is made up of the given prefix followed by the smallest natural number that results in a new symbol (regardless of arity). The prefix must be less than MAX_NAME characters. */ /* PUBLIC */ int fresh_symbol(char *prefix, int arity) { char name[MAX_NAME+20]; int i = 0; if (strlen(prefix) > MAX_NAME) { fatal_error("fresh_symbol, prefix is too big."); } do { sprintf(name, "%s%d", prefix, i); i++; } while (str_exists(name)); return str_to_sn(name, arity); } /* fresh_symbol */ /************* * * gen_new_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int gen_new_symbol(char *prefix, int arity, Ilist syms) { char name[MAX_NAME+20]; int symnum; int i = 0; if (strlen(prefix) > MAX_NAME) fatal_error("gen_new_symbol, prefix is too big."); sprintf(name, "%s%d", prefix, i); symnum = str_to_sn(name, arity); while (ilist_member(syms, symnum)) { i++; sprintf(name, "%s%d", prefix, i); symnum = str_to_sn(name, arity); } return symnum; } /* gen_new_symbol */ /************* * * mark_for_new_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_for_new_symbols(void) { Mark_for_new_symbols = Symbol_count + 1; /* next symnum */ } /* mark_for_new_symbols */ /************* * * new_symbols_since_mark() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list new_symbols_since_mark(void) { I2list p = NULL; int sn; for (sn = Mark_for_new_symbols; sn <= Symbol_count; sn++) { if (function_or_relation_symbol(sn)) { p = i2list_append(p, sn, sn_to_arity(sn)); } } return p; } /* new_symbols_since_mark */ /************* * * add_new_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void add_new_symbols(I2list syms) { I2list p; for (p = syms; p; p = p->next) { int sn; int symnum = p->i; int arity = p->j; if (symnum != Symbol_count+1) fatal_error("add_new_symbols, bad symnum"); sn = fresh_symbol("child_symbol_", arity); if (sn != symnum) fatal_error("add_new_symbols, symnums do not match"); } } /* add_new_symbols */ /************* * * new_constant_properties() * *************/ /* DOCUMENTATION In the symbol table entry for the given symbol number, set type=function, kb_weight=1, lex_val=(after initial constants) */ /* PUBLIC */ void new_constant_properties(int sn) { Symbol s = lookup_by_id(sn); if (s == NULL || s->arity != 0) fatal_error("new_constant_properties, bad symbol number"); s->type = FUNCTION_SYMBOL; s->kb_weight = 1; { Ilist syms = ilist_append(NULL, sn); lex_insert_after_initial_constants(syms); zap_ilist(syms); } } /* new_constant_properties */ /************* * * collect_multiples() * *************/ static Ilist collect_multiples(Ilist syms) { /* Example: Given (f/0, f/1, g/0, h/2), return (f/0, f/1). */ Ilist p1; Ilist p2; Ilist bad_syms = NULL; for (p1 = syms; p1; p1 = p1->next) { char *s1 = sn_to_str(p1->i); for (p2 = p1->next; p2; p2 = p2->next) { char *s2 = sn_to_str(p2->i); if (str_ident(s1, s2)) { if (!ilist_member(bad_syms, p1->i)) bad_syms = ilist_prepend(bad_syms, p1->i); if (!ilist_member(bad_syms, p2->i)) bad_syms = ilist_prepend(bad_syms, p2->i); } } } return bad_syms; } /* collect_multiples */ /************* * * arity_check() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist arity_check(Ilist fsyms, Ilist rsyms) { Ilist syms = ilist_cat(ilist_copy(fsyms), ilist_copy(rsyms)); Ilist bad_syms = collect_multiples(syms); return bad_syms; } /* arity_check */ /************* * * symbol_with_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int symbol_with_string(Ilist syms, char *str) { if (syms == NULL) return -1; else if (str_ident(str, sn_to_str(syms->i))) return syms->i; else return symbol_with_string(syms->next, str); } /* symbol_with_string */ /************* * * process_skolem_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_skolem_list(Plist skolem_strings, Ilist fsyms) { Ilist skolems = NULL; Plist p; for (p = skolem_strings; p; p = p->next) { int sn = symbol_with_string(fsyms, p->v); if (sn == -1) fprintf(stderr, "WARNING, declared Skolem symbol not found in formulas: %s\n", (char *) p->v); else skolems = ilist_append(skolems, sn); } set_skolem_symbols(skolems); zap_ilist(skolems); } /* process_skolem_list */ /************* * * process_lex_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_lex_list(Plist lex_strings, Ilist syms, Symbol_type type) { Ilist lexs = NULL; Plist p; Plist not_in_formulas = NULL; for (p = lex_strings; p; p = p->next) { int sn = symbol_with_string(syms, p->v); if (sn == -1) not_in_formulas = plist_append(not_in_formulas, p->v); else lexs = ilist_append(lexs, sn); } if (not_in_formulas) { char *s = (type == FUNCTION_SYMBOL ? "function" : "predicate"); fprintf(stderr, "WARNING, %s symbols in %s_order (lex) command not found in formulas: ", s, s); fprintf(stdout, "WARNING, %s symbols in %s_order (lex) command not found in formulas: ", s, s); for (p = not_in_formulas; p; p = p->next) { fprintf(stderr, "%s%s", (char *) p->v, p->next ? ", " : ".\n"); fprintf(stdout, "%s%s", (char *) p->v, p->next ? ", " : ".\n"); } } if (type == FUNCTION_SYMBOL) Preliminary_prec_func = lexs; else Preliminary_prec_pred = lexs; zap_plist(not_in_formulas); } /* process_lex_list */ /************* * * symnums_of_arity() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist symnums_of_arity(Ilist p, int i) { if (p == NULL) return NULL; else if (sn_to_arity(p->i) != i) { Ilist r = p->next; free_ilist(p); return symnums_of_arity(r, i); } else { p->next = symnums_of_arity(p->next, i); return p; } } /* symnums_of_arity */ LADR-2009-11A/ladr/string.c0000644000175000017500000001425311135654452014425 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "string.h" /* Private definitions and types */ static char *Float_format = "%.3f"; /************* * * int str_ident(s, t) -- Identity of strings * *************/ /* DOCUMENTATION This function routine checks identity of two strings. */ /* PUBLIC */ BOOL str_ident(char *s, char *t) { return strcmp(s, t) == 0; } /* str_ident */ /************* * * new_str_copy() * *************/ /* DOCUMENTATION Return a malloced copy of the given string. To avoid memory leaks, call free() on the copy if you finish referring to it. */ /* PUBLIC */ char *new_str_copy(char *str) { char *p = malloc(strlen(str)+1); strcpy(p, str); return p; } /* new_str_copy */ /************* * * string_member() * *************/ /* DOCUMENTATION Is "string" a member of an array of "strings"? */ /* PUBLIC */ BOOL string_member(char *string, char **strings, int n) { int i; for (i = 0; i < n; i++) if (string && strings[i] && str_ident(string, strings[i])) return TRUE; return FALSE; } /* string_member */ /************* * * which_string_member() * *************/ /* DOCUMENTATION If "string" is a member of an array of "strings", return the index; else return -1. */ /* PUBLIC */ int which_string_member(char *string, char **strings, int n) { int i; for (i = 1; i < n; i++) if (str_ident(strings[i], string)) return i; return -1; } /* which_string_member */ /************* * * initial_substring() * *************/ /* DOCUMENTATION Is x an initial substring of y? */ /* PUBLIC */ BOOL initial_substring(char *x, char *y) { while (*x && *y && *x == *y) { x++; y++; } return *x == '\0'; } /* initial_substring */ /************* * * substring() * *************/ /* DOCUMENTATION Is x a substring of y? */ /* PUBLIC */ BOOL substring(char *x, char *y) { BOOL found = initial_substring(x,y); while (*y && !found) { y++; found = initial_substring(x,y); } return found; } /* substring */ /************* * * reverse_chars() * *************/ /* DOCUMENTATION This routine reverses an array of characters. You must give the starting and ending positions. */ /* PUBLIC */ void reverse_chars(char *s, int start, int end) { if (start < end) { char c = s[start]; s[start] = s[end]; s[end] = c; reverse_chars(s, start+1, end-1); } } /* reverse_chars */ /************* * * natural_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int natural_string(char *str) { int i; if (!str_to_int(str, &i)) return -1; else if (i < 0) return -1; else return i; } /* natural_string */ /************* * * char_occurrences() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int char_occurrences(char *s, char c) { int n = 0; int i; for (i = 0; i < strlen(s); i++) { if (s[i] == c) n++; } return n; } /* char_occurrences */ /************* * * escape_char() * *************/ /* DOCUMENTATION Retun a newly malloced string in which all occurrences of char c is is escaped (preceded with a backslash). */ /* PUBLIC */ char *escape_char(char *s, char c) { int n = char_occurrences(s, c); char *new = malloc(strlen(s) + n + 1); int j = 0; int i; for (i = 0; i < strlen(s); i++) { if (s[i] == c) new[j++] = '\\'; new[j++] = s[i]; } new[j] = '\0'; return new; } /* escape_char */ /************* * * str_to_int() * *************/ /* DOCUMENTATION This routine tries to convert a string into an integer (using strtol()). If successful, TRUE is returned and *ip is set to the integer. If failure, FALSE is returned. */ /* PUBLIC */ BOOL str_to_int(char *str, int *ip) { char *end; *ip = strtol(str, &end, 10); if (*end != '\0') return FALSE; else return TRUE; } /* str_to_int */ /************* * * int_to_str() * *************/ /* DOCUMENTATION This routine converts an integer to a string (in decimal form). The character array s must be large enough to hold the string. The string is returned. */ /* PUBLIC */ char *int_to_str(int n, char *s, int size) { int used = snprintf(s, size, "%d", n); if (used >= size) fatal_error("float_to_str, string too small"); return s; } /* int_to_str */ /************* * * str_to_double(string, double_ptr) -- convert a string to a double * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL str_to_double(char *s, double *dp) { char *end; double f; if (*s != '\"') return(FALSE); else if (*(s+1) == '\"') return(FALSE); else { f = strtod(s+1, &end); *dp = f; return (*end == '\"'); } } /* str_to_double */ /************* * * double_to_str(double, size, str, n) -- translate a double to a string * * Like snprintf, except that format is built in and string is * surrouded by double quotes. * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *double_to_str(double d, char *s, int size) { int used = snprintf(s, size, Float_format, d); if (used >= size) { fatal_error("double_to_str, string too small"); return NULL; } else { int i; int n = strlen(s); for (i=n; i>0; i--) s[i] = s[i-1]; s[0] = '\"'; s[n+1] = '\"'; s[n+2] = '\0'; return s; } } /* double_to_str */ /************* * * string_of_repeated() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL string_of_repeated(char c, char *s) { int i; for (i = 0; i < strlen(s); i++) if (s[i] != c) return FALSE; return TRUE; } /* string_of_repeated */ LADR-2009-11A/ladr/clist.c0000644000175000017500000004404510637466321014241 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clist.h" /* Private definitions and types */ /* * memory management */ #define PTRS_CLIST_POS PTRS(sizeof(struct clist_pos)) static unsigned Clist_pos_gets, Clist_pos_frees; #define PTRS_CLIST PTRS(sizeof(struct clist)) static unsigned Clist_gets, Clist_frees; /************* * * Clist_pos get_clist_pos() * *************/ static Clist_pos get_clist_pos(void) { Clist_pos p = get_cmem(PTRS_CLIST_POS); Clist_pos_gets++; return(p); } /* get_clist_pos */ /************* * * free_clist_pos() * *************/ static void free_clist_pos(Clist_pos p) { free_mem(p, PTRS_CLIST_POS); Clist_pos_frees++; } /* free_clist_pos */ /************* * * Clist get_clist() * *************/ static Clist get_clist(void) { Clist p = get_cmem(PTRS_CLIST); Clist_gets++; return(p); } /* get_clist */ /************* * * free_clist() * *************/ static void free_clist(Clist p) { free_mem(p, PTRS_CLIST); Clist_frees++; } /* free_clist */ /************* * * fprint_clist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_clist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct clist_pos); fprintf(fp, "clist_pos (%4d) %11u%11u%11u%9.1f K\n", n, Clist_pos_gets, Clist_pos_frees, Clist_pos_gets - Clist_pos_frees, ((Clist_pos_gets - Clist_pos_frees) * n) / 1024.); n = sizeof(struct clist); fprintf(fp, "clist (%4d) %11u%11u%11u%9.1f K\n", n, Clist_gets, Clist_frees, Clist_gets - Clist_frees, ((Clist_gets - Clist_frees) * n) / 1024.); } /* fprint_clist_mem */ /************* * * p_clist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clist package. */ /* PUBLIC */ void p_clist_mem() { fprint_clist_mem(stdout, TRUE); } /* p_clist_mem */ /* * end of memory management */ /************* * * clist_init() * *************/ /* DOCUMENTATION This routine allocates and returns an empty Clist, which is a doubly-linked list of pointers to clauses. You give it a string (any length, which is copied), representing the name of the list. If don't wish to name the list, send NULL. (You can name the list later with name_clist().) */ /* PUBLIC */ Clist clist_init(char *name) { Clist p = get_clist(); if (name == NULL) p->name = NULL; else p->name = new_str_copy(name); return p; } /* clist_init */ /************* * * name_clist() * *************/ /* DOCUMENTATION This routine names or renames a Clist. The string you supply can be any length and is copied. */ /* PUBLIC */ void name_clist(Clist p, char *name) { if (p->name != NULL) free(p->name); if (name == NULL) p->name = NULL; else p->name = new_str_copy(name); } /* name_clist */ /************* * * clist_free() * *************/ /* DOCUMENTATION This routine frees an empty Clist. If the Clist is not empty, nothing happens. */ /* PUBLIC */ void clist_free(Clist p) { if (p->first == NULL) { if (p->name != NULL) { free(p->name); p->name = NULL; } free_clist(p); } } /* clist_free */ /************* * * clist_append() * *************/ /* DOCUMENTATION This routine appends a Topform to a Clist. */ /* PUBLIC */ void clist_append(Topform c, Clist l) { Clist_pos p; p = get_clist_pos(); p->list = l; p->c = c; p->nocc = c->containers; c->containers = p; p->next = NULL; p->prev = l->last; l->last = p; if (p->prev) p->prev->next = p; else l->first = p; l->length++; } /* clist_append */ /************* * * clist_prepend() * *************/ /* DOCUMENTATION This routine inserts a Topform as the first member of a Clist. */ /* PUBLIC */ void clist_prepend(Topform c, Clist l) { Clist_pos p; p = get_clist_pos(); p->list = l; p->c = c; p->nocc = c->containers; c->containers = p; p->prev = NULL; p->next = l->first; l->first = p; if (p->next) p->next->prev = p; else l->last = p; l->length++; } /* clist_prepend */ /************* * * clist_insert_before() * *************/ /* DOCUMENTATION This routine inserts a Topform before a given position in a Clist. */ /* PUBLIC */ void clist_insert_before(Topform c, Clist_pos pos) { Clist_pos p; p = get_clist_pos(); p->list = pos->list; p->c = c; p->nocc = c->containers; c->containers = p; p->next = pos; p->prev = pos->prev; pos->prev = p; if (p->prev) p->prev->next = p; else pos->list->first = p; pos->list->length++; } /* clist_insert_before */ /************* * * clist_insert_after() * *************/ /* DOCUMENTATION This routine inserts a Topform after a given position in a Clist. */ /* PUBLIC */ void clist_insert_after(Topform c, Clist_pos pos) { Clist_pos p; p = get_clist_pos(); p->list = pos->list; p->c = c; p->nocc = c->containers; c->containers = p; p->prev = pos; p->next = pos->next; pos->next = p; if (p->next) p->next->prev = p; else pos->list->last = p; pos->list->length++; } /* clist_insert_after */ /************* * * clist_remove() * *************/ /* DOCUMENTATION This routine removes a clause from a Clist. If the Topform occurs more than once in the Clist, the most recently inserted occurrence is removed. A fatal error occurs if the Topform is not in the Clist. */ /* PUBLIC */ void clist_remove(Topform c, Clist l) { Clist_pos p, prev; /* Find position from containment list of clause. */ for (p = c->containers, prev = NULL; p && p->list != l; prev = p, p = p->nocc); if (!p) fatal_error("clist_remove: clause not in list"); /* First update normal links. */ if (p->prev) p->prev->next = p->next; else p->list->first = p->next; if (p->next) p->next->prev = p->prev; else p->list->last = p->prev; /* Now update containment links. */ if (prev) prev->nocc = p->nocc; else c->containers = p->nocc; free_clist_pos(p); l->length--; } /* clist_remove */ /************* * * clist_remove_all_clauses() * *************/ /* DOCUMENTATION This routine removes all clauses from a clist. The clauses are NOT deleted, even if they occur nowhere else. */ /* PUBLIC */ void clist_remove_all_clauses(Clist l) { while (l->first) clist_remove(l->first->c, l); } /* clist_remove_all_clauses */ /************* * * clist_remove_all() * *************/ /* DOCUMENTATION This routine removes a clause from all lists in which it occurs. The number of lists from which it was removed is returned. */ /* PUBLIC */ int clist_remove_all(Topform c) { int i = 0; while (c->containers) { clist_remove(c, c->containers->list); i++; } return i; } /* clist_remove_all */ /************* * * clist_member() * *************/ /* DOCUMENTATION This Boolean routine checks if a Topform is a member of a Clist. */ /* PUBLIC */ int clist_member(Topform c, Clist l) { Clist_pos p; for (p = c->containers; p; p = p->nocc) { if (p->list == l) return TRUE; } return FALSE; } /* clist_member */ /************* * * fprint_clist() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) each clause in a Clist. If the Clist has a non-empty name, say "usable", the string "list(usable).\n" is printed first. The string "end_of_list.\n" is always printed at the end. */ /* PUBLIC */ void fprint_clist(FILE *fp, Clist l) { Clist_pos p; if (l->name != NULL) fprintf(fp, "list(%s).\n", l->name); for(p = l->first; p; p = p->next) fprint_clause(fp, p->c); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fprint_clist */ /************* * * p_clist() * *************/ /* DOCUMENTATION This routine prints (to stdout) each clause in a Clist. See fprint_clist(). */ /* PUBLIC */ void p_clist(Clist l) { fprint_clist(stdout, l); } /* p_clist */ /************* * * clist_zap() * *************/ /* DOCUMENTATION For each Topform (occurrence) in a Clist, remove it, and if it occurs in no other Clist, call zap_topform() to delete the clause. Then, free the Clist. */ /* PUBLIC */ void clist_zap(Clist l) { Clist_pos p; Topform c; p = l->first; while (p) { c = p->c; p = p->next; clist_remove(c, l); if (c->containers == NULL) zap_topform(c); } clist_free(l); } /* clist_zap */ /************* * * clist_check() * *************/ /* DOCUMENTATION This routine checks the integrity of a Clist. If any errors are found, a message is sent to stdout. This is used for debugging. */ /* PUBLIC */ void clist_check(Clist l) { Clist_pos p; int n = 0; for (p = l->first; p; p = p->next) { n++; if (p->list != l) printf("clist_check error0\n"); if (p->next) { if (p->next->prev != p) printf("clist_check error1\n"); } else if (p != l->last) printf("clist_check error2\n"); if (p->prev) { if (p->prev->next != p) printf("clist_check error3\n"); } else if (p != l->first) printf("clist_check error4\n"); } if (l->length != n) printf("clist_check error5\n"); } /* clist_check */ /************* * * clist_append_all() * *************/ /* DOCUMENTATION Append each member of l2 to l1, then zap l2. Do not refer to l2 after the call. */ /* PUBLIC */ void clist_append_all(Clist l1, Clist l2) { Clist_pos p; for (p = l2->first; p != NULL; p = p->next) clist_append(p->c, l1); clist_zap(l2); /* This doesn't zap clauses, because they now occur in l1. */ } /* clist_append_all */ /************* * * clist_empty() * *************/ /* DOCUMENTATION This function checks if a (non-NULL) Clist is empty. */ /* PUBLIC */ BOOL clist_empty(Clist lst) { return lst->first == NULL; } /* clist_empty */ /************* * * clist_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clist_length(Clist l) { return l->length; } /* clist_length */ /************* * * max_wt_in_clist() * *************/ /* DOCUMENTATION Scan a Clist, and return the maximum clause weight seen. */ /* PUBLIC */ int max_wt_in_clist(Clist l) { int max = INT_MIN; Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (p->c->weight > max) max = p->c->weight; return max; } /* max_wt_in_clist */ /************* * * horn_clist() * *************/ /* DOCUMENTATION Is every clause in the list a Horn clause? */ /* PUBLIC */ BOOL horn_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (!horn_clause(p->c->literals)) return FALSE; return TRUE; } /* horn_clist */ /************* * * unit_clist() * *************/ /* DOCUMENTATION Is every clause in the list a unit clause? */ /* PUBLIC */ BOOL unit_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (!unit_clause(p->c->literals)) return FALSE; return TRUE; } /* unit_clist */ /************* * * equality_in_clist() * *************/ /* DOCUMENTATION Does the list contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL equality_in_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (contains_pos_eq(p->c->literals)) return TRUE; return FALSE; } /* equality_in_clist */ /************* * * neg_nonunit_in_clist() * *************/ /* DOCUMENTATION Does the list contain a negative nonunit clause ? */ /* PUBLIC */ BOOL neg_nonunit_in_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (negative_clause(p->c->literals) && number_of_literals(p->c->literals) > 1) return TRUE; return FALSE; } /* neg_nonunit_in_clist */ /************* * * clauses_in_clist() * *************/ /* DOCUMENTATION Return the intersection of Plist p of clauses and Clist c of clauses. */ /* PUBLIC */ Plist clauses_in_clist(Plist p, Clist l) { Plist q; Plist result = NULL; for (q = p; q; q = q->next) { Topform c = q->v; if (clist_member(c, l)) result = plist_append(result, c); } return result; } /* clauses_in_clist */ /************* * * clist_swap() * *************/ /* DOCUMENTATION Every clause occurs in a set (maybe empty) of Clists. Given clauses A and B, this routine puts A into the lists in which B occurs and vice versa. */ /* PUBLIC */ void clist_swap(Topform a, Topform b) { Clist_pos p; /* Replace refs to a with refs to b. */ for (p = a->containers; p; p = p->nocc) p->c = b; /* Replace refs to b with refs to a. */ for (p = b->containers; p; p = p->nocc) p->c = a; /* Swap the containment lists. */ p = a->containers; a->containers = b->containers; b->containers = p; } /* clist_swap */ /************* * * clist_move_clauses() * *************/ /* DOCUMENTATION Move all clauses from a to the end of b. */ /* PUBLIC */ void clist_move_clauses(Clist a, Clist b) { while (a->first) { Topform c = a->first->c; clist_remove(c, a); clist_append(c, b); } } /* clist_move_clauses */ /************* * * move_clist_to_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist move_clist_to_plist(Clist a) { Plist p = NULL; while (a->first) { Topform c = a->first->c; clist_remove(c, a); p = plist_prepend(p, c); } clist_free(a); p = reverse_plist(p); return p; } /* move_clist_to_plist */ /************* * * copy_clist_to_plist_shallow() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist copy_clist_to_plist_shallow(Clist a) { Clist_pos pos; Plist p = NULL; for (pos = a->first; pos; pos = pos->next) p = plist_prepend(p, pos->c); return reverse_plist(p); } /* copy_clist_to_plist_shallow */ /************* * * plist_to_clist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Clist plist_to_clist(Plist p, char *name) { Clist a = clist_init(name); Plist q; for (q = p; q; q = q->next) clist_append(q->v, a); zap_plist(p); return a; } /* plist_to_clist */ /************* * * clist_reverse() * *************/ /* DOCUMENTATION Reverse a Clist. */ /* PUBLIC */ void clist_reverse(Clist l) { Clist_pos p = l->first; while (p) { Clist_pos next = p->next; p->next = p->prev; p->prev = next; p = next; } p = l->first; l->first = l->last; l->last = p; } /* clist_reverse */ /************* * * pos_in_clist() * *************/ /* DOCUMENTATION Return the Clist_pos of a Topform in a Clist. */ /* PUBLIC */ Clist_pos pos_in_clist(Clist lst, Topform c) { Clist_pos p = c->containers; while (p && p->list != lst) p = p->nocc; return p; } /* pos_in_clist */ /************* * * clist_append_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clist_append_plist(Clist lst, Plist clauses) { Plist p; for (p = clauses; p; p = p->next) { clist_append(p->v, lst); } } /* clist_append_plist */ /************* * * prepend_clist_to_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist prepend_clist_to_plist(Plist p, Clist c) { if (c == NULL) return p; else { Clist_pos a; for (a = c->last; a; a = a->prev) p = plist_prepend(p, a->c); return p; } } /* prepend_clist_to_plist */ /************* * * clist_number_of_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clist_number_of_weight(Clist lst, int weight) { if (lst == NULL) return 0; else { int n = 0; Clist_pos a; for (a = lst->first; a; a = a->next) { if (a->c->weight == weight) n++; } return n; } } /* clist_number_of_weight */ /************* * * compare_clause_ids() * *************/ static Ordertype compare_clause_ids(Topform c, Topform d) { if (c->id < d->id) return LESS_THAN; else if (c->id > d->id) return GREATER_THAN; else return SAME_AS; } /* compare_clause_ids */ /************* * * sort_clist_by_id() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sort_clist_by_id(Clist lst) { int n = clist_length(lst); Topform *a = malloc(n * sizeof(Topform *)); int i; Clist_pos p; for (p = lst->first, i = 0; p; p = p->next, i++) a[i] = p->c; clist_remove_all_clauses(lst); merge_sort((void **) a, n, (Ordertype (*)(void*, void*)) compare_clause_ids); for (i = 0; i < n; i++) clist_append(a[i], lst); free(a); } /* sort_clist_by_id */ /************* * * neg_clauses_in_clist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist neg_clauses_in_clist(Clist a) { Clist_pos p; Plist negs = NULL; for (p = a->first; p; p = p->next) { if (negative_clause(p->c->literals)) negs = plist_prepend(negs, p->c); } negs = reverse_plist(negs); return negs; } /* neg_clauses_in_clist */ /************* * * fprint_clause_clist() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Clist of clauses in standard prefix form. */ /* PUBLIC */ void fprint_clause_clist(FILE *fp, Clist lst) { Clist_pos p; if (lst->name == NULL || str_ident(lst->name, "")) fprintf(fp, "\nclauses(anonymous).\n"); else fprintf(fp, "\nclauses(%s).\n", lst->name); for (p = lst->first; p != NULL; p = p->next) fprint_clause(fp, p->c); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fprint_clause_clist */ LADR-2009-11A/ladr/std_options.c0000644000175000017500000000440410705744405015461 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "std_options.h" /* Private definitions and types */ /* Flags */ static int Prolog_style_variables = -1; /* delayed effect */ static int Ignore_option_dependencies = -1; /* immediate effect */ static int Clocks = -1; /* delayed effect */ /************* * * init_standard_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_standard_options(void) { /* Flags */ Prolog_style_variables = init_flag("prolog_style_variables", FALSE); Ignore_option_dependencies = init_flag("ignore_option_dependencies", FALSE); Clocks = init_flag("clocks", FALSE); } /* init_standard_options */ /************* * * process_standard_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_standard_options(void) { if (flag(Clocks)) enable_clocks(); else disable_clocks(); if (flag(Prolog_style_variables)) set_variable_style(PROLOG_STYLE); else set_variable_style(STANDARD_STYLE); /* Flag gnore_option_dependencies is handled internally by the options package. It takes effect immediately. */ } /* process_standard_options */ /************* * * clocks_id() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clocks_id(void) { return Clocks; } /* clocks_id */ /************* * * prolog_style_variables_id() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int prolog_style_variables_id(void) { return Prolog_style_variables; } /* prolog_style_variables_id */ LADR-2009-11A/ladr/dioph.h0000644000175000017500000000513311151265364014222 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DIOPH_H #define TP_DIOPH_H #include /* INTRODUCTION This package solves linear homogeneous Diophantine equations, which can be used to compute the set of associative-commutative unifiers for a pair of first-order terms. The way this usually works is that you first call dio() to get a basis of solutions, then call one of the the next_combo routines to (incrementally) get the relevant solutions.

The file dioph.c has a main() program, and it can be compiled and linked by itself for testing. The command for doing so is "gcc -DSOLO dioph.c". */ /* Public definitions */ #define MAX_COEF 250 /* total # of coef. from both sides */ #define MAX_BASIS 100 /* must be <= MAX_VARS, because rows are indexed */ #define MAX_COMBOS 200 /* for superset-restricted AC unif. */ /* End of public definitions */ /* Public function prototypes from dioph.c */ int dio(int ab[MAX_COEF], int m, int n, int constraints[MAX_COEF], int basis[MAX_BASIS][MAX_COEF], int *num_basis); int next_combo_a(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag); int next_combo_b(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag); int next_combo_c(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag); int next_combo_ss(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag, int combos[MAX_COMBOS][MAX_BASIS], int *np, int ss_parm); void p_ac_basis(int basis[MAX_BASIS][MAX_COEF], int num_basis, int m, int n); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/top_input.h0000644000175000017500000000423211151265364015137 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TOP_INPUT_H #define TP_TOP_INPUT_H #include "ioutil.h" #include "std_options.h" #include "tptp_trans.h" /* INTRODUCTION */ /* Public definitions */ /* Types of object that can be input */ enum { TERMS, FORMULAS }; /* What shall we do if we read an unknown flag or parameter? */ enum { IGNORE_UNKNOWN, NOTE_UNKNOWN, WARN_UNKNOWN, KILL_UNKNOWN }; /* End of public definitions */ /* Public function prototypes from top_input.c */ void fprint_top_input_mem(FILE *fp, BOOL heading); void p_top_input_mem(); void init_standard_ladr(void); void set_program_name(char *name); void process_op(Term t, BOOL echo, FILE *fout); void process_redeclare(Term t, BOOL echo, FILE *fout); void flag_handler(FILE *fout, Term t, BOOL echo, int unknown_action); void parm_handler(FILE *fout, Term t, BOOL echo, int unknown_action); void accept_list(char *name, int type, BOOL aux, Plist *l); void read_from_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action); void read_all_input(int argc, char **argv, FILE *fout, BOOL echo, int unknown_action); Plist process_input_formulas(Plist formulas, BOOL echo); Plist process_demod_formulas(Plist formulas, BOOL echo); Plist process_goal_formulas(Plist formulas, BOOL echo); Term read_commands(FILE *fin, FILE *fout, BOOL echo, int unknown_action); Plist embed_formulas_in_topforms(Plist formulas, BOOL assumption); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clauses.h.bak0000644000175000017500000000302711151265364015312 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSES_H #define TP_CLAUSES_H #include "topform.h" /* INTRODUCTION This package contains various functions on Plists of clauses. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from clauses.c */ Topform clause_member_plist(Plist p, Topform c); Plist intersect_clauses(Plist a, Plist b); int max_clause_weight(Plist p); int max_clause_symbol_count(Plist p); Plist nonneg_clauses(Plist clauses); BOOL all_clauses_horn(Plist l); BOOL all_clauses_unit(Plist l); BOOL all_clauses_positive(Plist l); int neg_nonunit_clauses(Plist l); int negative_clauses(Plist l); int most_literals(Plist clauses); BOOL pos_equality_in_clauses(Plist clauses); BOOL equality_in_clauses(Plist clauses); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/btm.c0000644000175000017500000007714310637466321013712 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "btm.h" /* Private definitions and types */ typedef struct ac_match_pos * Ac_match_pos; typedef struct ac_match_free_vars_pos * Ac_match_free_vars_pos; struct btm_state { Btm_state parent, next, prev, first_child, last_child; Term t1, t2; /* terms being matched */ Context c1; /* context for variables of t1*/ int varnum; /* for unbinding when backtracking */ Context cb; /* for unbinding when backtracking */ Unif_alternative alternative; /* type of alternative (position) */ /* for commutative unification */ int flipped; Btm_state position_bt; /* in sequence of alternatives */ /* for AC matching */ Ac_match_pos acm; /* in sequence of AC matchers */ int partial; /* partial match for this pair */ }; struct ac_match_pos { Term t1, t2; /* t1 is pattern, t2 is subject */ Context c1; /* context for variables in t1 */ int n1; /* number of arguments in t1 */ int n2; /* size of set of set of args in t2 */ Term args1[MAX_ACM_ARGS], args2[MAX_ACM_ARGS]; /* the arguments */ /* position in sequence of matches for complex args of args2 */ Btm_state bt1[MAX_ACM_ARGS]; /* flags indicating which of args1 have been matched */ int match1[MAX_ACM_ARGS]; /* integer indicating how many of each of args2 have been matched */ int match2[MAX_ACM_ARGS]; int mults2[MAX_ACM_ARGS]; /* multiplicities for args2 */ /* indicates which of args2 are matched by bound vars in args1 */ int bound_matches[MAX_ACM_ARGS], bound_count; int last_a1_symbol; /* position of last non-variable arg in args1 */ /* list of backtrack positions for free variables of args1 */ Ac_match_free_vars_pos free_first, free_last; /* # args of unmatched term---used for partial match */ int partial_term_size; Ac_match_pos next; /* for avail list only */ }; struct ac_match_free_vars_pos { int varnum; /* the index of the free variable */ int coef; /* # of occurrences of the var in args1 */ int targets[MAX_ACM_ARGS]; /* terms in args2 that can go with variable */ int n; /* number of tragets*/ int combo[MAX_ACM_ARGS]; /* current subset of the targets */ Ac_match_free_vars_pos prev, next; }; /* #define DEBUG */ #define POP 1 #define BACKTRACK 2 #define GO 3 #define SUCCESS 4 #define FAILURE 5 /* Bind a variable, record binding in a bt_node. */ #define BIND_BT(i, c1, t2, c2, bt) { \ c1->terms[i] = t2; c1->contexts[i] = c2; \ bt->varnum = i; bt->cb = c1; } /* The following declaration is due to mutual recursion with match_bt_guts. */ static int match_commute(Term t1, Context c1, Term t2, Btm_state bt); /* * memory management */ #define PTRS_AC_MATCH_POS PTRS(sizeof(struct ac_match_pos)) static unsigned Ac_match_pos_gets, Ac_match_pos_frees; #define PTRS_AC_MATCH_FREE_VARS_POS PTRS(sizeof(struct ac_match_free_vars_pos)) static unsigned Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees; #define PTRS_BTM_STATE PTRS(sizeof(struct btm_state)) static unsigned Btm_state_gets, Btm_state_frees; /************* * * Ac_match_pos get_ac_match_pos() * *************/ static Ac_match_pos get_ac_match_pos(void) { Ac_match_pos p = get_cmem(PTRS_AC_MATCH_POS); Ac_match_pos_gets++; return(p); } /* get_ac_match_pos */ /************* * * free_ac_match_pos() * *************/ static void free_ac_match_pos(Ac_match_pos p) { free_mem(p, PTRS_AC_MATCH_POS); Ac_match_pos_frees++; } /* free_ac_match_pos */ /************* * * Ac_match_free_vars_pos get_ac_match_free_vars_pos() * *************/ static Ac_match_free_vars_pos get_ac_match_free_vars_pos(void) { Ac_match_free_vars_pos p = get_cmem(PTRS_AC_MATCH_FREE_VARS_POS); Ac_match_free_vars_pos_gets++; return(p); } /* get_ac_match_free_vars_pos */ /************* * * free_ac_match_free_vars_pos() * *************/ static void free_ac_match_free_vars_pos(Ac_match_free_vars_pos p) { free_mem(p, PTRS_AC_MATCH_FREE_VARS_POS); Ac_match_free_vars_pos_frees++; } /* free_ac_match_free_vars_pos */ /************* * * Btm_state get_btm_state() * *************/ static Btm_state get_btm_state(void) { Btm_state p = get_cmem(PTRS_BTM_STATE); p->varnum = -1; p->alternative = NO_ALT; Btm_state_gets++; return(p); } /* get_btm_state */ /************* * * free_btm_state() * *************/ static void free_btm_state(Btm_state p) { free_mem(p, PTRS_BTM_STATE); Btm_state_frees++; } /* free_btm_state */ /************* * * fprint_btm_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the btm package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_btm_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct ac_match_pos); fprintf(fp, "ac_match_pos (%4d)%11u%11u%11u%9.1f K\n", n, Ac_match_pos_gets, Ac_match_pos_frees, Ac_match_pos_gets - Ac_match_pos_frees, ((Ac_match_pos_gets - Ac_match_pos_frees) * n) / 1024.); n = sizeof(struct ac_match_free_vars_pos); fprintf(fp, "ac_match_free_vars_pos (%4d)\n %11u%11u%11u%9.1f K\n", n, Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees, Ac_match_free_vars_pos_gets - Ac_match_free_vars_pos_frees, ((Ac_match_free_vars_pos_gets - Ac_match_free_vars_pos_frees) * n) / 1024.); n = sizeof(struct btm_state); fprintf(fp, "btm_state (%4d) %11u%11u%11u%9.1f K\n", n, Btm_state_gets, Btm_state_frees, Btm_state_gets - Btm_state_frees, ((Btm_state_gets - Btm_state_frees) * n) / 1024.); } /* fprint_btm_mem */ /************* * * p_btm_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the btm package. */ /* PUBLIC */ void p_btm_mem() { fprint_btm_mem(stdout, TRUE); } /* p_btm_mem */ /* * end of memory management */ /************* * * flatten_mult * * Flatten an AC term into an array, collapsing multiple occurrences * into one, filling in a parallel array with multiplicities. * Also return a count of the total number of arguments. * * The index (*ip) must be initialized by the calling routine. * *************/ static void flatten_mult(Term t, Term *a, int *m, int *ip, int *totp, int (*comp_proc) (void *, void *)) { Term t1; int sn, i; sn = SYMNUM(t); for (i = 0; i < ARITY(t); i++) { t1 = ARG(t,i); if (SYMNUM(t1) == sn) flatten_mult(t1, a, m, ip, totp, comp_proc); else { (*totp)++; if (*ip > 0 && (*comp_proc)(t1, a[(*ip)-1]) == SAME_AS) m[(*ip)-1]++; else { if (*ip >= MAX_ACM_ARGS) { fprint_term(stdout, t); fatal_error("flatten_mult, too many arguments."); } a[*ip] = t1; m[*ip] = 1; (*ip)++; } } } } /* flatten_mult */ /************* * * macbv_rec -- match (identically) all args of an AC term. * * Called by match_ac_bound_vars. * *************/ static int macbv_rec(int ac_sn, Term t, Term *args2, int *mults2, int *match2, int n2, int *bound_matches, int *bp) { int i, available; if (!COMPLEX(t) || SYMNUM(t) != ac_sn) { for (i = 0; i < n2; i++) { available = mults2[i] - match2[i]; if (available > 0 && term_ident(t, args2[i])) { match2[i]++; bound_matches[(*bp)++] = i; return(1); } } return(0); } else { if (!macbv_rec(ac_sn,ARG(t,0),args2,mults2,match2,n2, bound_matches,bp)) return(0); else return(macbv_rec(ac_sn,ARG(t,1),args2,mults2,match2,n2, bound_matches,bp)); } } /* macbv_rec */ /************* * * match_ac_bound_vars -- match (identically) a set of bound variables. * * For each bound variable of args1, find an identical match in args2. * If bound to an AC term t, (with same AC symbol) find an identical * match for each argument of t. Record the positions of the matched * terms in `bound_matches', so that they can be unmached on backtracking. * *************/ static int match_ac_bound_vars(int ac_sn, Term *args1, int n1, Term *args2, int *mults2, int *match2, int n2, int begin, int *bound_matches, int *bp, Context c1) { int i, ok, vn; Term t; for (i=begin, ok=1, *bp=0; i < n1 && ok; i++) { vn = VARNUM(args1[i]); t = c1->terms[vn]; if (t) ok = macbv_rec(ac_sn,t,args2,mults2,match2,n2,bound_matches,bp); } if (!ok) { /* Subtract any matches that were made before failure. */ for (i = 0; i < *bp; i++) match2[bound_matches[i]] -= 1; *bp = 0; /* Not really necessary, but helpful for debugging. */ } return(ok); } /* match_ac_bound_vars */ /************* * * set_up_free_vars * * Build a list of the set of free variables in args1. Each node * contains the number of occurrences (coef) of the variable. * Sort the list---nonincreasing coef. * * Variables are partitioned into `free' and `bound' according to * their state after all nonvariable terms have been matched. * A variable is called `bound' iff it occurs in a nonvariable term. * * Since the partition does not change during backtracking, this * routine needs to be called only once, after all nonvariable * terms have been matched for the first time. * *************/ static void set_up_free_vars(Ac_match_pos ac, Context c1) { Ac_match_free_vars_pos p1, p2; Term t; int i, temp; ac->free_first = NULL; ac->free_last = NULL; for (i = ac->last_a1_symbol+1; i < ac->n1; i++) { t = ac->args1[i]; if (c1->terms[VARNUM(t)] == NULL) { /* We have a free variable. */ for (p1=ac->free_first; p1 && p1->varnum!=VARNUM(t); p1=p1->next); if (p1 != NULL) (p1->coef)++; else { p1 = get_ac_match_free_vars_pos(); p1->varnum = VARNUM(t); p1->coef = 1; p1->next = NULL; p1->prev = ac->free_last; if (ac->free_last) ac->free_last->next = p1; else ac->free_first = p1; ac->free_last = p1; } } } /* Now sort -- nonincreasing coefficients. */ /* There won't be many, so use a quadratic sort. */ p1 = ac->free_first; if (p1) { while (p1->next) { for (p2 = p1->next; p2; p2 = p2->next) { if (p1->coef < p2->coef) { temp = p2->coef; p2->coef = p1->coef; p1->coef = temp; temp = p2->varnum; p2->varnum = p1->varnum; p1->varnum = temp; } } p1 = p1->next; } } } /* set_up_free_vars */ /************* * * unbind_free_var * * This routine takes an `ac match free variable position' and * unbinds the free variable. If the variable is bound to a * compound AC term that was created just for the binding, * then the new parts of the term are deleted. * *************/ static void unbind_free_var(Ac_match_free_vars_pos pos, Context c) { int i, j; Term t, t1; /* Free the temporary substitution term, if necessary. */ /* First count how many nodes have to be deleted. */ for (i = j = 0; i < pos->n; i++) if (pos->combo[i]) j++; t = c->terms[pos->varnum]; for (i = 0; i < j-1; i++) { t1 = ARG(t,1); free_term(t); t = t1; } /* unbind variable */ c->terms[pos->varnum] = NULL; } /* unbind_free_var */ /************* * * free_var_match * * Find the first or next match for a free variable. If (match_all) * then all remaining arguments of args2 must be matched. * Otherwise, backtracking will produce matches in all combinations. * *************/ static int free_var_match(Ac_match_free_vars_pos pos, Term *args2, int *mults2, int *match2, int n2, Context c1, int symbol, int match_all) { Term t; int i, j, k, n, ok, go, avail; t = c1->terms[pos->varnum]; if (!t) { /* It is not a continuation, so set up everything. * * Loop through args2, collecting targets, combinations of which * can be substituted for the current variable. * Example: current variable is 2x; terms available for * matching are 4a, 3b, 2c, 1d; targets are a,a,b,c. */ n = 0; for (i = 0; i < n2; i++) { avail = mults2[i] - match2[i]; if (match_all && (avail % pos->coef != 0)) return 0; /* Fail, because there will be unmatched term(s) */ j = avail / pos->coef; /* integer division */ for (k = 0; k < j; k++) pos->targets[n++] = i; } pos->n = n; if (n == 0) return 0; else { for (i = 0; i < n; i++) pos->combo[i] = 1; } } else { /* continutation */ unbind_free_var(pos, c1); /* unmark args2 terms */ for (i = 0; i < pos->n; i++) if (pos->combo[i]) { match2[pos->targets[i]] -= pos->coef; } if (match_all) { for (i = 0; i < pos->n; i++) pos->combo[i] = 0; return 0; } else { go = 1; while (go) { /* subtract 1 from combo */ for (i = (pos->n)-1; i >= 0 && pos->combo[i] == 0; i--) pos->combo[i] = 1; if (i < 0) return(0); else { pos->combo[i] = 0; /* Check redundancy condition. */ for (i = 0, ok = 1; i < (pos->n)-1 && ok; i++) if (pos->targets[i] == pos->targets[i+1] && pos->combo[i] < pos->combo[i+1]) ok = 0; go = !ok; } } /* Now make sure that combo is not empty. */ for (i = 0, ok = 0; i < pos->n && !ok; i++) ok = pos->combo[i]; if (!ok) return 0; } } /* All is well---we have a match for the current variable. */ /* Build a temporary substitution term, if necessary. */ /* Note order in which it is built---this makes it AC canonical. */ t = NULL; for (i = pos->n-1; i >= 0; i--) if (pos->combo[i]) { if (t == NULL) t = args2[pos->targets[i]]; else t = build_binary_term(symbol, args2[pos->targets[i]], t); } /* Bind variable. */ c1->terms[pos->varnum] = t; /* Mark args2 terms matched to the current variable. */ for (i = 0; i < pos->n; i++) if (pos->combo[i]) match2[pos->targets[i]] += pos->coef; return 1; } /* free_var_match */ /************* * * build_partial_term * * When partial match has been found, this routine collects the * unmatched arguments of args2 and builds and returns an AC term. * The size of the new term is stored in the AC position so that * it can easily be freed. * *************/ static Term build_partial_term(Ac_match_pos ac) { int i, j, k, n; Term t; t = NULL; k = 0; for (i = 0; i < ac->n2; i++) { n = ac->mults2[i] - ac->match2[i]; for (j = 0; j < n; j++) { k++; if (!t) t = ac->args2[i]; else t = build_binary_term(SYMNUM(ac->t1), ac->args2[i], t); } } ac->partial_term_size = k; return t; } /* build_partial_term */ /************* * * clear_partial_term * * Remove the partial term from the substitution and free the * appropriate parts fo the partial term. * *************/ static void clear_partial_term(Ac_match_pos ac) { int i; Term t, t1; t = ac->c1->partial_term; ac->c1->partial_term = NULL; for (i = 0; i < ac->partial_term_size - 1; i++) { t1 = ARG(t,1); free_term(t); t = t1; } ac->partial_term_size = 0; } /* clear_partial_term */ #define GO_FUNCTORS 1 #define GO_BOUND_VARS 2 #define GO_FREE_VARS 3 #define SUCCESS 4 #define FAILURE 5 /************* * * match_ac -- associative-commutative matching. * * Get the first (bt->alternative == NO_ALT) or next AC matcher. * I intend for this to be called from `match_bt_guts'. * It assumed that the root symbols of the input terms are AC. * * Call match_ac_cancel(ac) if you quit before getting all matchers. * * t1 -- pattern term * c1 -- context (substitution table) for t1 * t2 -- subject term * bt -- backtrack position * *************/ static int match_ac(Term t1, Context c1, Term t2, Btm_state bt) { int status, n1, n2, total2, i, ok, a1_pos, a2_pos; int free_var_forward; Term a1, a2; Ac_match_pos ac; Ac_match_free_vars_pos free_pos, p1, p2; Btm_state bt1 = NULL; a1_pos = a2_pos = free_var_forward = 0; /* to quiet compiler */ free_pos = NULL; /* to quiet compiler */ if (bt->alternative == NO_ALT) { /* initialize, get first matcher */ ac = get_ac_match_pos(); bt->acm = ac; ac->t1 = t1; ac->t2 = t2; ac->c1 = c1; ac->free_first = NULL; ac->partial_term_size = 0; n1 = 0; n2 = 0; total2 = 0; flatten(t1, ac->args1, &n1); flatten_mult(t2, ac->args2, ac->mults2, &n2, &total2, (int (*)(void*,void*)) term_compare_ncv); if (n1 > total2) /* fail if t1 has more arguments */ status = FAILURE; else { /* Assume inputs are ac_canonical, so don't sort. */ /* Don't bother to eliminate common arguments, because */ /* It usually doesn't pay off. */ ac->n1 = n1; ac->n2 = n2; for (i = 0; i < n1; i++) ac->match1[i] = -1; for (i = 0; i < n2; i++) ac->match2[i] = 0; for (i = 0; i < n1 && !VARIABLE(ac->args1[i]); i++); ac->last_a1_symbol = i-1; a1_pos = 0; a2_pos = 0; bt1 = NULL; status = GO_FUNCTORS; } } else { /* continuation, get next matcher */ ac = bt->acm; if (bt->partial) { printf("WARNING: partial match_ac on continuation.\n"); if (c1->partial_term) clear_partial_term(ac); } n1 = ac->n1; n2 = ac->n2; if (n1 == 0 && n2 == 0) /* vacuous success last time */ status = FAILURE; else { free_pos = ac->free_last; free_var_forward = 0; status = GO_FREE_VARS; } } while (status != SUCCESS && status != FAILURE) { while (status == GO_FUNCTORS) { if (a1_pos > ac->last_a1_symbol) status = GO_BOUND_VARS; else if (a1_pos < 0) status = FAILURE; else { if (bt1) { /* remove arrow */ ac->match1[a1_pos] = -1; ac->bt1[a1_pos] = NULL; ac->match2[a2_pos]--; /* Try for another match with this pair. */ bt1 = match_bt_next(bt1); if (!bt1) a2_pos++; } if (!bt1) { /* Look for a match for a1, starting with a2. */ a1 = ac->args1[a1_pos]; while (bt1 == NULL && a2_pos < ac->n2) { a2 = ac->args2[a2_pos]; if (SYMNUM(a1) == SYMNUM(a2) && ac->match2[a2_pos] < ac->mults2[a2_pos]) bt1 = match_bt_first(a1, c1, a2, 0); if (bt1 == NULL) a2_pos++; } } if (bt1) { /* We have a match: a1->a2. */ /* draw arrow */ ac->match1[a1_pos] = a2_pos; ac->bt1[a1_pos] = bt1; ac->match2[a2_pos]++; a1_pos++; a2_pos = 0; bt1 = NULL; } else { /* back up */ a1_pos--; a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } } } /* while GO_FUNCTORS */ if (status == GO_BOUND_VARS) { /* Try to macth (identically) bound variables. */ ok = match_ac_bound_vars(SYMNUM(t1), ac->args1, n1, ac->args2, ac->mults2, ac->match2, n2, ac->last_a1_symbol+1, ac->bound_matches, &(ac->bound_count), c1); if (ok) { free_pos = ac->free_first; free_var_forward = 1; status = GO_FREE_VARS; } else { /* backup */ a1_pos = ac->last_a1_symbol; if (a1_pos >= 0) { a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } status = GO_FUNCTORS; } } else if (status == GO_FREE_VARS) { if (ac->free_first == NULL) { set_up_free_vars(ac, c1); free_pos = ac->free_first; } while (free_pos) { if (free_var_match(free_pos, ac->args2, ac->mults2, ac->match2, ac->n2, c1, SYMNUM(ac->t1), !bt->partial && free_pos->next == NULL)) { free_pos = free_pos->next; free_var_forward = 1; } else { free_pos = free_pos->prev; free_var_forward = 0; } } if (free_var_forward) { /* Check for non-matched a2 terms. */ for (i = 0, ok = 1; i < n2 && ok; i++) ok = ac->mults2[i] == ac->match2[i]; if (!ok) { /* Have at least 1 non-matched a2 term. */ if (bt->partial) { c1->partial_term = build_partial_term(ac); status = SUCCESS; } else status = GO_FUNCTORS; /* set up below */ } else status = SUCCESS; } else status = GO_FUNCTORS; if (status == GO_FUNCTORS) { /* Unmark bound variable matches. */ for (i = 0; i < ac->bound_count; i++) ac->match2[ac->bound_matches[i]] -= 1; a1_pos = ac->last_a1_symbol; if (a1_pos >= 0) { a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } } } /* if GO_FREE_VARS */ } /* while !SUCCESS && !FAILURE */ if (status == SUCCESS) bt->alternative = AC_ALT; else { /* free memory */ p1 = ac->free_first; while (p1) { p2 = p1; p1 = p1->next; free_ac_match_free_vars_pos(p2); } free_ac_match_pos(ac); bt->alternative = NO_ALT; } return(status == SUCCESS); } /* match_ac */ /************* * * match_ac_cancel * * Free an AC match position. This is to be used when you have obtained * one or more AC matchers by calling match_ac, but you do not wish * to backtrack to obtain additional AC matchers. Do not call this * routine if match_ac returned 0. * *************/ static void match_ac_cancel(Ac_match_pos ac) { Ac_match_free_vars_pos p1, p2; int i; for (i = 0; i <= ac->last_a1_symbol; i++) match_bt_cancel(ac->bt1[i]); p1 = ac->free_first; while (p1) { unbind_free_var(p1, ac->c1); p2 = p1; p1 = p1->next; free_ac_match_free_vars_pos(p2); } if (ac->partial_term_size > 0) clear_partial_term(ac); free_ac_match_pos(ac); } /* match_ac_cancel */ /************* * * Btm_state match_bt_backup(bt) * * Back up (freeing nodes) to the most recent node with an alternative. * *************/ static Btm_state match_bt_backup(Btm_state bt1) { Btm_state bt2, bt3; while (bt1 != NULL && bt1->alternative == NO_ALT) { if (bt1->cb) { /* unbind variable */ bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } if (bt1->prev) { bt1 = bt1->prev; while (bt1->last_child) bt1 = bt1->last_child; } else { bt2 = bt1; bt1 = bt1->parent; while (bt2) { bt3 = bt2; bt2 = bt2->next; free_btm_state(bt3); } if (bt1) bt1->first_child = bt1->last_child = NULL; } } return(bt1); } /* match_bt_backup */ /************* * * match_bt_guts * * Main loop for backtracking matching. * *************/ static Btm_state match_bt_guts(Btm_state bt1) { Term t1, t2; Context c1; int vn1, status; Btm_state bt2, bt3; status = GO; while (status == GO) { t1 = bt1->t1; t2 = bt1->t2; c1 = bt1->c1; if (bt1->alternative == COMM_ALT) { if (match_commute(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (bt1->alternative == AC_ALT) { if (match_ac(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (VARIABLE(t1)) { vn1 = VARNUM(t1); if (c1->terms[vn1]) { if (term_ident(c1->terms[vn1], t2)) status = POP; else status = BACKTRACK; } else { BIND_BT(vn1, c1, t2, NULL, bt1) status = POP; } } else if (VARIABLE(t2)) status = BACKTRACK; else if (SYMNUM(t1) != SYMNUM(t2)) status = BACKTRACK; else if (CONSTANT(t1)) status = POP; else { /* both COMPLEX with same symbol (and same arity) */ int arity = ARITY(t1); if (arity == 2 && is_commutative(SYMNUM(t1))) { if (match_commute(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (arity == 2 && is_assoc_comm(SYMNUM(t1))) { if (match_ac(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else { int i; /* Set up children corresponding to args of . */ /* Order not important for correctness. */ /* AC kids last for efficiency, but keep in order otherwise. */ bt3 = NULL; for (i = 0; i < arity; i++) { bt2 = get_btm_state(); bt2->t1 = ARG(t1,i); bt2->t2 = ARG(t2,i); bt2->c1 = c1; bt2->parent = bt1; if (is_assoc_comm(SYMNUM(bt2->t1))) { /* insert at end */ bt2->prev = bt1->last_child; if (bt1->last_child) bt1->last_child->next = bt2; else bt1->first_child = bt2; bt1->last_child = bt2; } else { if (bt3) { /* insert after bt3 */ bt2->next = bt3->next; bt2->prev = bt3; bt3->next = bt2; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; } else { /* insert at beginning */ bt2->next = bt1->first_child; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; bt1->first_child = bt2; } bt3 = bt2; } } bt1 = bt1->first_child; status = GO; } } if (status == POP) { while (!bt1->next && bt1->parent) bt1 = bt1->parent; if (!bt1->next) status = SUCCESS; else { bt1 = bt1->next; status = GO; } } else if (status == BACKTRACK) { bt1 = match_bt_backup(bt1); if (bt1) status = GO; else status = FAILURE; } } return(bt1); } /* match_bt_guts */ /************* * * match_commute() * * There is nothing fancy here. We simply try to unify both ways. * We can get redundant matches if both ways match, for example, * f(a,x) and f(a,a) match twice, both times with the same substitution. * *************/ static int match_commute(Term t1, Context c1, Term t2, Btm_state bt) { Btm_state bt1, bt2; if (bt->alternative == NO_ALT) { /* first call */ bt->alternative = COMM_ALT; bt->flipped = 0; /* Set up 2 subproblems, then match guts. */ bt1 = get_btm_state(); bt2 = get_btm_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt2->c1 = c1; bt1->t1 = ARG(t1,0); bt1->t2 = ARG(t2,0); bt2->t1 = ARG(t1,1); bt2->t2 = ARG(t2,1); bt->position_bt = match_bt_guts(bt1); } else /* continuation */ bt->position_bt = match_bt_next(bt->position_bt); if (!bt->position_bt && !bt->flipped) { /* Set up 2 subproblems, with t2 flipped, then match guts. */ bt1 = get_btm_state(); bt2 = get_btm_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt2->c1 = c1; bt1->t1=ARG(t1,0); bt1->t2=ARG(t2,1); bt2->t1=ARG(t1,1); bt2->t2=ARG(t2,0); bt->flipped = 1; bt->position_bt = match_bt_guts(bt1); } if (bt->position_bt) return(1); else { bt->alternative = NO_ALT; return(0); } } /* match_commute */ /************* * * p_acm -- print an ac match position. * *************/ static void p_acm(Ac_match_pos ac) { int i; Ac_match_free_vars_pos p; printf("Ac_match_pos %p.\n", ac); printf("t1: "); p_term(ac->t1); printf("t2: "); p_term(ac->t2); for (i = 0; i < ac->n1; i++) { fprint_term(stdout, ac->args1[i]); printf(" %d ",ac->match1[i]); } printf("\n"); for (i = 0; i < ac->n2; i++) { fprint_term(stdout, ac->args2[i]); printf(" <%d,%d> ",ac->mults2[i],ac->match2[i]); } printf("\n"); printf("last_a1_symbol=%d.\n",ac->last_a1_symbol); printf("free vars list :\n"); for (p = ac->free_first; p; p = p->next) { printf("<%d,%d>, ", p->varnum, p->coef); for (i = 0; i < p->n; i++) { fprint_term(stdout,ac->args2[p->targets[i]]); printf(":%d ",p->combo[i]); } printf("\n"); } printf("\n"); } /* p_acm */ /************* * * p_btm_state() * *************/ /* DOCUMENTATION This routine prints (to stdout) a Btm_state. It is not pretty. */ /* PUBLIC */ void p_btm_state(Btm_state bt) { printf("\nBtm node %p.\n", bt); printf("t1: "); p_term(bt->t1); printf("t2: "); p_term(bt->t2); printf("c1: "); p_context(bt->c1); printf("varnum: %d\n", bt->varnum); printf("cb: "); p_context(bt->c1); printf("alternative: %d\n", bt->alternative); printf("flipped: %d\n", bt->alternative); printf("position_bt: %p\n", bt->position_bt); printf("partial: %d\n", bt->partial); p_acm(bt->acm); } /* p_btm_state */ /************* * * match_bt_first * * *************/ /* DOCUMENTATION This is backtracking matching, to be used when there can be more than one unifier. This version handles (any number of) commutative (C) and associative-commutative (AC) function symbols.

The flag `partial' says that if the top level is AC, then not all arguments of t2 have to be matched. The non-matched args are put in c1->partial_term. Partial matches are allowed for the top level only. This is useful for AC rewriting.

If any AC terms are in t1 or t2, then both t1 and t2 should be in `ac_canonical()' form before the call, that is, AC terms are right associated and sorted. C terms are in t1 or t2 need not be c_canonical. (Commutatvie matching is primitive, and you can get duplicate unifiers.)

Get first matching substitution. Return position for match_bt_next() calls. Here is an example. Assume we have terms t1 and t2.

  {
    Context c1 = get_context();
    Btm_state bt = match_bt_first(t1, c1, t2, 0);
    while (bt != NULL) {
        Term t3 = apply(t1, c1);
        zap_term(t3);
        bt = match_bt_next(bt);
        }
    free_context(c1);
  }
If you quit before NULL is returned, call match_bt_cancel(bt) to clear substitutions and free memory. */ /* PUBLIC */ Btm_state match_bt_first(Term t1, Context c1, Term t2, int partial) { Btm_state bt; bt = get_btm_state(); bt->t1 = t1; bt->t2 = t2; bt->c1 = c1; bt->partial = partial; return(match_bt_guts(bt)); } /* match_bt */ /************* * * match_bt_next -- see match_bt_first * * Get next unifier. Return position for subsequent calls. * *************/ /* DOCUMENTATION This routine gets the next matching substitution. See match_bt_first() for details. */ /* PUBLIC */ Btm_state match_bt_next(Btm_state bt1) { /* Go to last node in tree, then back up to a node with an alternative. */ while (bt1->next) bt1 = bt1->next; while (bt1->last_child) bt1 = bt1->last_child; bt1 = match_bt_backup(bt1); if (bt1) return(match_bt_guts(bt1)); else return NULL; } /* match_bt_next */ /************* * * match_bt_cancel * * This routine should be called if the rest of a sequence of * unifiers is not called for. It clears substitutions and * frees memory. * *************/ /* DOCUMENTATION This routine clears any substitution and frees memory associated with a backtrack matching state. This should be called if you get some, but not all, matching substitutions in backtrack matching. See match_bt_first(). */ /* PUBLIC */ void match_bt_cancel(Btm_state bt) { Btm_state bt1, bt2; for (bt1 = bt; bt1 != NULL; ) { match_bt_cancel(bt1->first_child); if (bt1->alternative == COMM_ALT) /* match_bt_guts leaves us at the second child. */ match_bt_cancel(bt1->position_bt->prev); else if (bt1->alternative == AC_ALT) { match_ac_cancel(bt1->acm); } else if (bt1->cb) { bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } bt2 = bt1; bt1 = bt1->next; free_btm_state(bt2); } } /* match_bt_cancel */ LADR-2009-11A/ladr/literals.h0000644000175000017500000000632311151265364014740 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_LITERALS_H #define TP_LITERALS_H #include "termflag.h" #include "tlist.h" /* INTRODUCTION */ /* Public definitions */ typedef struct literals * Literals; struct literals { BOOL sign; Term atom; Literals next; }; /* End of public definitions */ /* Public function prototypes from literals.c */ Literals get_literals(void); void free_literals(Literals p); void fprint_literals_mem(FILE *fp, int heading); void p_literals_mem(); void zap_literal(Literals l); void zap_literals(Literals l); Literals new_literal(int sign, Term atom); Literals copy_literal(Literals lit); Literals append_literal(Literals lits, Literals lit); Literals term_to_literals(Term t, Literals lits); Term literal_to_term(Literals l); Term literals_to_term(Literals l); Term lits_to_term(Literals l); void free_lits_to_term(Term t); int positive_literals(Literals lits); int negative_literals(Literals lits); BOOL positive_clause(Literals lits); BOOL any_clause(Literals lits); BOOL negative_clause(Literals lits); BOOL mixed_clause(Literals lits); int number_of_literals(Literals lits); BOOL unit_clause(Literals lits); BOOL horn_clause(Literals lits); BOOL definite_clause(Literals lits); int greatest_variable_in_clause(Literals lits); Plist vars_in_clause(Literals lits); Ilist varnums_in_clause(Literals lits); int number_of_variables(Literals lits); BOOL ground_clause(Literals lits); Literals copy_literals(Literals lits); Literals copy_literals_with_flags(Literals lits); Literals copy_literals_with_flag(Literals lits, int flag); int literal_number(Literals lits, Literals lit); int atom_number(Literals lits, Term atom); Literals ith_literal(Literals lits, int i); BOOL true_clause(Literals lits); BOOL tautology(Literals lits); int symbol_occurrences_in_clause(Literals lits, int symnum); Literals remove_null_literals(Literals l); Literals first_literal_of_sign(Literals lits, BOOL sign); Ilist constants_in_clause(Literals lits); BOOL clause_ident(Literals lits1, Literals lits2); int clause_symbol_count(Literals lits); int clause_depth(Literals lits); BOOL pos_eq(Literals lit); BOOL neg_eq(Literals lit); BOOL pos_eq_unit(Literals lits); BOOL neg_eq_unit(Literals lits); BOOL contains_pos_eq(Literals lits); BOOL contains_eq(Literals lits); BOOL only_eq(Literals lits); int literals_depth(Literals lits); Term term_at_position(Literals lits, Ilist pos); Ilist pos_predicates(Ilist p, Literals lits); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/basic.h0000644000175000017500000000267311151265364014206 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_BASIC_H #define TP_BASIC_H #include "unify.h" #include "termflag.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from basic.c */ void init_basic_paramod(void); void set_basic_paramod(BOOL flag); BOOL basic_paramod(void); void mark_term_nonbasic(Term t); void mark_all_nonbasic(Term t); BOOL nonbasic_term(Term t); BOOL basic_term(Term t); int nonbasic_flag(void); Term apply_basic(Term t, Context c); Term apply_basic_substitute(Term t, Term beta, Context c_from, Term into_term, Context c_into); void clear_all_nonbasic_marks(Term t); void p_term_basic(Term t); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/tlist.c0000644000175000017500000000570410637466323014263 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "tlist.h" /* Private definitions and types */ /************* * * zap_tlist() * *************/ /* DOCUMENTATION Zap each term in the list and free the list. If you want to free the list only, without zapping the terms, use zap_plist(p) instead. */ /* PUBLIC */ void zap_tlist(Plist p) { if (p != NULL) { zap_tlist(p->next); zap_term(p->v); free_plist(p); } } /* zap_tlist */ /************* * * tlist_remove() * *************/ /* DOCUMENTATION Remove a term from a Plist. Term_ident() is used, and the term in the list is zapped. */ /* PUBLIC */ Plist tlist_remove(Term t, Plist p) { if (p == NULL) return NULL; else { p->next = tlist_remove(t, p->next); if (term_ident(t, p->v)) { Plist next = p->next; zap_term(p->v); free_plist(p); return next; } else return p; } } /* tlist_remove */ /************* * * tlist_union() * *************/ /* DOCUMENTATION Return the union of two Plists of terms. If the inputs are sets, the output is a set. Do not refer the inputs after the call. Duplicates are zapped. */ /* PUBLIC */ Plist tlist_union(Plist a, Plist b) { if (a == NULL) return b; else if (tlist_member(a->v, b)) { Plist c = tlist_union(a->next,b ); zap_term(a->v); free_plist(a); return c; } else { a->next = tlist_union(a->next, b); return a; } } /* tlist_union */ /************* * * constants_in_term() * *************/ /* DOCUMENTATION Given a term t, return a plist containing the set of constants in t. */ /* PUBLIC */ Ilist constants_in_term(Term t, Ilist p) { if (VARIABLE(t)) return p; else if (CONSTANT(t)) { if (ilist_member(p, SYMNUM(t))) return p; else return ilist_prepend(p, SYMNUM(t)); } else { int i; for (i = 0; i < ARITY(t); i++) p = constants_in_term(ARG(t, i), p); return p; } } /* constants_in_term */ /************* * * tlist_copy() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist tlist_copy(Plist p) { if (p == NULL) return NULL; else { Term t = p->v; Plist new = get_plist(); new->v = copy_term(t); new->next = tlist_copy(p->next); return new; } } /* tlist_copy */ LADR-2009-11A/ladr/xproofs.h0000644000175000017500000000256711151265364014627 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_XPROOFS_H #define TP_XPROOFS_H #include "clauses.h" #include "clause_misc.h" #include "paramod.h" #include "subsume.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from xproofs.c */ void check_parents_and_uplinks_in_proof(Plist proof); Topform proof_id_to_clause(Plist proof, int id); int greatest_id_in_proof(Plist proof); Plist expand_proof(Plist proof, I3list *pmap); void renumber_proof(Plist proof, int start); Plist copy_and_renumber_proof(Plist proof, int start); Plist proof_to_xproof(Plist proof); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/multiset.c0000644000175000017500000000535610777037432014775 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "multiset.h" /* Private definitions and types */ /************* * * num_occurrences() * *************/ static int num_occurrences(Term t, Term a[], int n) { int i, count; for (i = 0, count = 0; i < n; i++) if (term_ident(a[i], t)) count++; return count; } /* num_occurrences */ /************* * * set_of_more_occurrences() * * Return the list of elements with more occurrences in a1. * *************/ static Plist set_of_more_occurrences(Term a1[], int n1, Term a2[], int n2) { Plist answer = NULL; int i, j; for (i = 0; i < n1; i++) { Term e1 = a1[i]; /* Check if this is the first occurrence of e1. */ for (j = 0; j != i && !term_ident(e1, a1[j]); j++); if (i == j && num_occurrences(e1,a1,n1) > num_occurrences(e1,a2,n2)) answer = plist_prepend(answer, e1); } return answer; } /* set_of_more_occurrences */ /************* * * greater_multiset() * * a1 >> a2 iff * (1) there is an element with more occurrences in a1; and * (2) for each element with more occurrences in a2, * there is a greater element with more occurrences in a1. * *************/ /* DOCUMENTATION Given two arrays of terms, check if the first is greater in the multiset extension of the ordering given by comp_proc. */ /* PUBLIC */ BOOL greater_multiset(Term a1[], int n1, Term a2[], int n2, BOOL (*comp_proc) (Term, Term, BOOL), BOOL lex_order_vars) { Plist s1, s2, p1, p2; BOOL ok; s1 = set_of_more_occurrences(a1, n1, a2, n2); /* more occurrences in a1 */ s2 = set_of_more_occurrences(a2, n2, a1, n1); /* more occurrences in a2 */ /* * return (s1 not empty and foreach p2 in s2 * there is an p1 in s1 such that p1 > p2). */ if (s1 == NULL) ok = FALSE; else { for (p2 = s2, ok = TRUE; p2 && ok; p2 = p2->next) for (p1 = s1, ok = FALSE; p1 && !ok; p1 = p1->next) ok = (*comp_proc)(p1->v, p2->v, lex_order_vars); } zap_plist(s1); zap_plist(s2); return ok; } /* greater_multiset */ LADR-2009-11A/ladr/discrimw.h0000644000175000017500000000305511151265364014741 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DISCRIMW_H #define TP_DISCRIMW_H #include "discrim.h" /* INTRODUCTION Discrimination tree indexing in which all variables variables are represented as wildcards in the index. Matching occurs after retrieval of candidates. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from discrimw.c */ void fprint_discrimw_mem(FILE *fp, BOOL heading); void p_discrimw_mem(void); void fprint_discrim_wild_index(FILE *fp, Discrim d); void p_discrim_wild_index(Discrim d); void discrim_wild_update(Term t, Discrim root, void *object, Indexop op); void *discrim_wild_retrieve_first(Term t, Discrim root, Discrim_pos *ppos); void *discrim_wild_retrieve_next(Discrim_pos pos); void discrim_wild_cancel(Discrim_pos pos); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/btm.h0000644000175000017500000000337111151265364013703 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_BTM_H #define TP_BTM_H #include "unify.h" #include "accanon.h" /* INTRODUCTION This package handles "backtrack matching", that is, matching that allows more than one unifier for a pair of terms, and computes the unifiers incrementally by backtracking. As I write this, we support associative commutative (AC) operations and commutative/symmetric (C) operations. Symbols are declared to be AC with set_assoc_comm() and C with set_commutative(). The use of Terms and Contexts is similar to ordinary matching, except that the means for undoing substitutions is different. */ /* Public definitions */ typedef struct btm_state * Btm_state; /* End of public definitions */ /* Public function prototypes from btm.c */ void fprint_btm_mem(FILE *fp, BOOL heading); void p_btm_mem(); void p_btm_state(Btm_state bt); Btm_state match_bt_first(Term t1, Context c1, Term t2, int partial); Btm_state match_bt_next(Btm_state bt1); void match_bt_cancel(Btm_state bt); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/Makefile0000644000175000017500000003701511272051614014405 0ustar mccunemccune# LADR/ladr CC = gcc # XFLAGS can be specified on the command line (see XFLAGS below) CFLAGS = $(XFLAGS) -O -Wall # CFLAGS = $(XFLAGS) -O6 -Wall # CFLAGS = $(XFLAGS) -g -O -Wall # CFLAGS = $(XFLAGS) -g -O0 -Wall # CFLAGS = $(XFLAGS) -pg -O -Wall # CFLAGS = $(XFLAGS) -Wall -pedantic BASE_OBJ = order.o clock.o nonport.o\ fatal.o ibuffer.o memory.o hash.o string.o strbuf.o\ glist.o options.o symbols.o avltree.o TERM_OBJ = term.o termflag.o listterm.o tlist.o flatterm.o multiset.o\ termorder.o parse.o accanon.o UNIF_OBJ = unify.o fpalist.o fpa.o discrim.o discrimb.o discrimw.o\ dioph.o btu.o btm.o mindex.o basic.o attrib.o CLAS_OBJ = formula.o definitions.o literals.o topform.o clist.o\ clauseid.o clauses.o\ just.o cnf.o clausify.o parautil.o\ pindex.o compress.o\ maximal.o lindex.o weight.o weight2.o\ int_code.o features.o di_tree.o fastparse.o\ random.o subsume.o clause_misc.o clause_eval.o complex.o INFE_OBJ = dollar.o flatdemod.o demod.o clash.o resolve.o paramod.o\ backdemod.o\ hints.o ac_redun.o xproofs.o ivy.o MODL_OBJ = interp.o MISC_OBJ = std_options.o banner.o ioutil.o tptp_trans.o top_input.o OBJECTS = $(BASE_OBJ) $(TERM_OBJ) $(UNIF_OBJ) $(CLAS_OBJ)\ $(INFE_OBJ) $(MODL_OBJ) $(MISC_OBJ) libladr.a: $(OBJECTS) $(AR) rs libladr.a $(OBJECTS) ############################################################################## lib ladr libladr: $(MAKE) libladr.a dep: util/make_dep $(OBJECTS) clean: /bin/rm -f *.o realclean: /bin/rm -f *.o *.a protos: util/make_protos $(OBJECTS) htmls: util/make_htmls $(OBJECTS) cp index.html.master html/index.html tags: etags *.c dio-solo: $(CC) $(CFLAGS) -DSOLO -o dio dioph.c # The rest of the file is generated automatically by util/make_dep order.o: order.h clock.o: clock.h string.h memory.h fatal.h header.h nonport.o: nonport.h fatal.o: fatal.h header.h ibuffer.o: ibuffer.h fatal.h header.h memory.o: memory.h fatal.h header.h hash.o: hash.h memory.h fatal.h header.h string.o: string.h memory.h fatal.h header.h strbuf.o: strbuf.h string.h memory.h fatal.h header.h glist.o: glist.h order.h string.h memory.h fatal.h header.h options.o: options.h string.h memory.h fatal.h header.h symbols.o: symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h avltree.o: avltree.h memory.h order.h fatal.h header.h term.o: term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termflag.o: termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h listterm.o: listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h tlist.o: tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.o: flatterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h multiset.o: multiset.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termorder.o: termorder.h flatterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h parse.o: parse.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h accanon.o: accanon.h termflag.h termorder.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h unify.o: unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h fpalist.o: fpalist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h fpa.o: fpa.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.o: discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrimb.o: discrimb.h discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrimw.o: discrimw.h discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h dioph.o: dioph.h btu.o: btu.h dioph.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h btm.o: btm.h unify.h accanon.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termorder.h flatterm.h mindex.o: mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h basic.o: basic.h unify.h termflag.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h attrib.o: attrib.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h formula.o: formula.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h definitions.o: definitions.h formula.h topform.h clauseid.h just.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h literals.h maximal.h parse.h literals.o: literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.o: topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.o: clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clauseid.o: clauseid.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clauses.o: clauses.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h just.o: just.h clauseid.h parse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h cnf.o: cnf.h formula.h clock.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h clausify.o: clausify.h topform.h cnf.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clock.h parautil.o: parautil.h pindex.o: pindex.h clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h compress.o: compress.h parautil.h maximal.o: maximal.h literals.h termorder.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h lindex.o: lindex.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h weight.o: weight.h literals.h unify.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h listterm.h weight2.o: weight2.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h int_code.o: int_code.h just.h ibuffer.h clauseid.h parse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h features.o: features.h literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h di_tree.o: di_tree.h features.h topform.h literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h attrib.h formula.h maximal.h unify.h listterm.h termorder.h hash.h flatterm.h fastparse.o: fastparse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h random.o: random.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h subsume.o: subsume.h parautil.h lindex.h features.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h clause_misc.o: clause_misc.h clist.h mindex.h just.h basic.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h clause_eval.o: clause_eval.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h complex.o: complex.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h dollar.o: dollar.h clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h flatdemod.o: flatdemod.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h demod.o: demod.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h clash.o: clash.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h resolve.o: resolve.h clash.h lindex.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h maximal.h topform.h literals.h tlist.h attrib.h formula.h hash.h paramod.o: paramod.h resolve.h basic.h clash.h lindex.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h maximal.h topform.h literals.h tlist.h attrib.h formula.h hash.h backdemod.o: backdemod.h demod.h clist.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h topform.h literals.h attrib.h formula.h maximal.h tlist.h hash.h hints.o: hints.h subsume.h clist.h backdemod.h resolve.h parautil.h lindex.h features.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h demod.h clash.h ac_redun.o: ac_redun.h parautil.h accanon.h termflag.h termorder.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h xproofs.o: xproofs.h clauses.h clause_misc.h paramod.h subsume.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h resolve.h clash.h lindex.h parautil.h features.h ivy.o: ivy.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h resolve.h clash.h lindex.h parautil.h features.h interp.o: interp.h parse.h topform.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h std_options.o: std_options.h options.h symbols.h clock.h string.h memory.h fatal.h header.h strbuf.h glist.h order.h banner.o: banner.h nonport.h clock.h string.h memory.h fatal.h header.h ioutil.o: ioutil.h parse.h fastparse.h ivy.h clausify.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h tptp_trans.o: tptp_trans.h ioutil.h clausify.h parse.h fastparse.h ivy.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h top_input.o: top_input.h ioutil.h std_options.h tptp_trans.h parse.h fastparse.h ivy.h clausify.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h options.h LADR-2009-11A/ladr/order.c0000644000175000017500000000672210727607136014237 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "order.h" /************* * * merge_sort_recurse * *************/ /* DOCUMENTATION This is the recursive part of a general-purpose merge sort. You won't ordinarily call this (use merge_sort instead). Use this only if you manage allocation of the work array.

Here is an example of how to use it.

  {
    Term args[MAX_ACM_ARGS], work[MAX_ACM_ARGS];
    int n;

    < put the n terms you wish to sort into args[] >

    merge_sort_recurse((void **) args, (void **) work, 0, n-1,
               (Ordertype (*)(void*,void*)) term_compare_ncv);

    < args[] is now ordered by term_compare_ncv() >
  }
*/ /* PUBLIC */ void merge_sort_recurse(void *a[], /* array to sort */ void *w[], /* work array */ int start, /* index of first element */ int end, /* index of last element */ Ordertype (*comp_proc) (void *, void *)) { int mid, i, i1, i2, e1, e2; if (start < end) { mid = (start+end)/2; merge_sort_recurse(a, w, start, mid, comp_proc); merge_sort_recurse(a, w, mid+1, end, comp_proc); i1 = start; e1 = mid; i2 = mid+1; e2 = end; i = start; while (i1 <= e1 && i2 <= e2) { if ((*comp_proc)(a[i1], a[i2]) == GREATER_THAN) w[i++] = a[i2++]; else w[i++] = a[i1++]; } if (i2 > e2) while (i1 <= e1) w[i++] = a[i1++]; else while (i2 <= e2) w[i++] = a[i2++]; for (i = start; i <= end; i++) a[i] = w[i]; } } /* merge_sort_recurse */ /************* * * merge_sort * *************/ /* DOCUMENTATION This is a general-purpose sorting routine. You give it an array of pointers to sort, the size of the array, and a comparison function.

Here is an example of how to use it.

  {
    Term args[MAX_ACM_ARGS];
    int n;

    < set n and put the n terms you wish to sort into args[] >

    merge_sort((void **) args, n, (Ordertype (*)(void*,void*)) term_compare_ncv);

    < args[] is now ordered by term_compare_ncv() >
  }
*/ /* PUBLIC */ void merge_sort(void *a[], /* array to sort */ int n, /* size of array */ Ordertype (*comp_proc) (void *, void *)) { void **work = malloc(n * sizeof(void *)); merge_sort_recurse((void **) a, work, 0, n-1, comp_proc); free(work); } /* merge_sort */ /************* * * compare_vecs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype compare_vecs(int *a, int *b, int n) { int i; for (i = 0; i < n; i++) { if (a[i] < b[i]) return LESS_THAN; else if (a[i] > b[i]) return GREATER_THAN; } return SAME_AS; } /* compare_vecs */ /************* * * copy_vec() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void copy_vec(int *a, int *b, int n) { int i; for (i = 0; i < n; i++) b[i] = a[i]; } /* copy_vec */ LADR-2009-11A/ladr/pub0000644000175000017500000000004210137775726013464 0ustar mccunemccune/* DOCUMENTATION */ /* PUBLIC */ LADR-2009-11A/ladr/resolve.h0000644000175000017500000000423611151265364014601 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_RESOLVE_H #define TP_RESOLVE_H #include "clash.h" #include "lindex.h" /* INTRODUCTION */ /* Public definitions */ enum { /* literal selection */ LIT_SELECTION_NONE, LIT_SELECTION_MAXIMAL, LIT_SELECTION_ALL }; enum { /* types of resolution (binary, hyper, UR) */ POS_RES, /* positive */ NEG_RES, /* negative */ ANY_RES /* unrestricted by sign */ }; /* End of public definitions */ /* Public function prototypes from resolve.c */ void resolution_options(BOOL ordered, BOOL check_instances, BOOL initial_nuclei, int ur_nucleus_limit, BOOL production_mode); int res_instance_prunes(); void hyper_resolution(Topform c, int pos_or_neg, Lindex idx, void (*proc_proc) (Topform)); void ur_resolution(Topform c, int target_constraint, Lindex idx, void (*proc_proc) (Topform)); Topform instantiate_clause(Topform c, Context subst); void binary_resolution(Topform c, int res_type, /* POS_RES, NEG_RES, ANY_RES */ Lindex idx, void (*proc_proc) (Topform)); void binary_factors(Topform c, void (*proc_proc) (Topform)); void merge_literals(Topform c); Topform copy_inference(Topform c); Topform resolve2(Topform c1, int n1, Topform c2, int n2, BOOL renumber_vars); Topform resolve3(Topform c1, Literals l1, Topform c2, Literals l2, BOOL renumber_vars); Topform xx_resolve2(Topform c, int n, BOOL renumber_vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/formula.h0000644000175000017500000001003611151265364014562 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FORMULA_H #define TP_FORMULA_H #include "attrib.h" #include "tlist.h" #include "termorder.h" #include "hash.h" /* INTRODUCTION */ /* Public definitions */ /* formula types */ typedef enum { ATOM_FORM=0, AND_FORM, OR_FORM, NOT_FORM, IFF_FORM, IMP_FORM, IMPBY_FORM, ALL_FORM, EXISTS_FORM} Ftype; typedef struct formula * Formula; struct formula { Ftype type; int arity; char *qvar; /* quantified variable */ Formula *kids; /* for non-atoms */ Term atom; /* for atoms */ Attribute attributes; /* */ int excess_refs; /* count of extra references */ }; /* formula preference */ typedef enum { CONJUNCTION, DISJUNCTION } Fpref; /* macros */ #define TRUE_FORMULA(f) ((f)->type == AND_FORM && (f)->arity == 0) #define FALSE_FORMULA(f) ((f)->type == OR_FORM && (f)->arity == 0) /* End of public definitions */ /* Public function prototypes from formula.c */ void free_formula(Formula p); void fprint_formula_mem(FILE *fp, BOOL heading); void p_formula_mem(); unsigned formula_megs(void); Formula formula_get(int arity, Ftype type); void zap_formula(Formula f); BOOL logic_term(Term t); void gather_symbols_in_formula_term(Term t, I2list *rsyms, I2list *fsyms); void gather_symbols_in_formula(Formula f, I2list *rsyms, I2list *fsyms); void gather_symbols_in_formulas(Plist lst, I2list *rsyms, I2list *fsyms); Ilist function_symbols_in_formula(Formula f); Ilist relation_symbols_in_formula(Formula f); BOOL relation_symbol_in_formula(int sn, Formula f); Formula term_to_formula(Term t); Term formula_to_term(Formula f); void fprint_formula(FILE *fp, Formula f); void p_formula(Formula c); unsigned hash_formula(Formula f); BOOL formula_ident(Formula f, Formula g); Formula formula_copy(Formula f); BOOL dual_type(int op); Formula dual(Formula f); Formula and(Formula a, Formula b); Formula or(Formula a, Formula b); Formula imp(Formula a, Formula b); Formula impby(Formula a, Formula b); Formula negate(Formula a); BOOL quant_form(Formula f); Formula flatten_top(Formula f); Formula formula_flatten(Formula f); Formula nnf2(Formula f, Fpref pref); Formula nnf(Formula f); Formula make_conjunction(Formula f); Formula make_disjunction(Formula f); void formula_canon_eq(Formula f); int formula_size(Formula f); int greatest_qvar(Formula f); int greatest_symnum_in_formula(Formula f); void subst_free_var(Formula f, Term target, Term replacement); Formula eliminate_rebinding(Formula f); BOOL closed_formula(Formula f); Formula get_quant_form(Ftype type, char *qvar, Formula subformula); Formula universal_closure(Formula f); BOOL free_variable(char *svar, Formula f); Formula formulas_to_conjunction(Plist formulas); Formula formulas_to_disjunction(Plist formulas); Plist copy_plist_of_formulas(Plist formulas); BOOL literal_formula(Formula f); BOOL clausal_formula(Formula f); void formula_set_variables(Formula f, int max_vars); BOOL positive_formula(Formula f); BOOL formula_contains_attributes(Formula f); BOOL subformula_contains_attributes(Formula f); Ilist constants_in_formula(Formula f); BOOL relation_in_formula(Formula f, int symnum); void rename_all_bound_vars(Formula f); void rename_these_bound_vars(Formula f, Ilist vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/dollar.c0000644000175000017500000003075511220245640014367 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "dollar.h" #include "just.h" #include "parautil.h" /* Private definitions and types */ struct rule { Topform c; Term alpha; Term beta; Term condition; struct rule *next; }; enum { SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP, MAX_OP, ABS_OP, NEG_OP, LT_OP, LE_OP, GT_OP, GE_OP, /* arithmetic comparison */ LLT_OP, LLE_OP, LGT_OP, LGE_OP, /* lexical comparison */ AND_OP, OR_OP, AND2_OP, OR2_OP, IF_OP, ID_OP, NID_OP, /* for all terms, including integers */ VAR_OP, CONST_OP, GROUND_OP}; static int Symbols_size; static int *Op_codes; static struct rule **Rules; static int Local_evals; /* * memory management */ /************* * * init_dollar_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_dollar_eval(Clist rules) { Clist_pos p; Symbols_size = greatest_symnum() + 1; Op_codes = calloc(Symbols_size, sizeof(int)); Op_codes[str_to_sn("+", 2)] = SUM_OP; Op_codes[str_to_sn("*", 2)] = PROD_OP; Op_codes[str_to_sn("/", 2)] = DIV_OP; Op_codes[str_to_sn("mod", 2)] = MOD_OP; Op_codes[str_to_sn("min", 2)] = MIN_OP; Op_codes[str_to_sn("max", 2)] = MAX_OP; Op_codes[str_to_sn("abs", 2)] = ABS_OP; Op_codes[str_to_sn("-", 1)] = NEG_OP; Op_codes[str_to_sn("<", 2)] = LT_OP; Op_codes[str_to_sn("<=", 2)] = LE_OP; Op_codes[str_to_sn(">", 2)] = GT_OP; Op_codes[str_to_sn(">=", 2)] = GE_OP; Op_codes[str_to_sn("@<", 2)] = LLT_OP; Op_codes[str_to_sn("@<=", 2)] = LLE_OP; Op_codes[str_to_sn("@>", 2)] = LGT_OP; Op_codes[str_to_sn("@>=", 2)] = LGE_OP; Op_codes[str_to_sn("==", 2)] = ID_OP; Op_codes[str_to_sn("!==", 2)] = NID_OP; Op_codes[str_to_sn("variable", 1)] = VAR_OP; Op_codes[str_to_sn("constant", 1)] = CONST_OP; Op_codes[str_to_sn("ground", 1)] = GROUND_OP; Op_codes[str_to_sn("&&", 2)] = AND2_OP; Op_codes[str_to_sn("||", 2)] = OR2_OP; Op_codes[str_to_sn("&", 2)] = AND_OP; Op_codes[str_to_sn("|", 2)] = OR_OP; Op_codes[str_to_sn("if", 3)] = IF_OP; Rules = calloc(Symbols_size, sizeof(void *)); for (p = rules->last; p; p = p->prev) { /* backward */ Topform c = p->c; Term rule = c->literals->atom; Term alpha = NULL, beta, condition; if (number_of_literals(c->literals) != 1) fatal_error("demodulator has too many literals"); mark_oriented_eq(c->literals->atom); /* ok if not eq */ if (!c->literals->sign) { condition = NULL; alpha = rule; beta = get_rigid_term(false_sym(), 0); } else if (is_term(rule, "->", 2) && (eq_term(ARG(rule,1)) || is_term(ARG(rule,1), "<->", 2))) { condition = ARG(rule,0); alpha = ARG(ARG(rule,1),0); beta = ARG(ARG(rule,1),1); } else if (is_term(rule, "<-", 2) && (eq_term(ARG(rule,0)) || is_term(ARG(rule,0), "<->", 2))) { condition = ARG(rule,1); alpha = ARG(ARG(rule,0),0); beta = ARG(ARG(rule,0),1); } else if (is_term(rule, "<->", 2) || eq_term(rule)) { condition = NULL; alpha = ARG(rule,0); beta = ARG(rule,1); } else { /* Assume it's an atomic formula to be rewritten to $T. */ condition = NULL; alpha = rule; beta = get_rigid_term(true_sym(), 0); } { int symnum = SYMNUM(alpha); if (symnum >= Symbols_size) fatal_error("init_dollar_eval, symnum too big"); struct rule *r = malloc(sizeof(struct rule)); r->c = c; r->alpha = alpha; r->beta = beta; r->condition = condition; r->next = Rules[symnum]; /* insert at beginning */ Rules[symnum] = r; } } } /* init_dollar_eval */ /************* * * evaluable_predicate() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_predicate(int symnum) { if (symnum >= Symbols_size) return FALSE; else if (Rules[symnum]) return TRUE; else if (Op_codes[symnum]) return TRUE; else return FALSE; } /* evaluable_predicate */ /************* * * dollar_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term dollar_eval(Term t) { if (SYMNUM(t) < 0 || SYMNUM(t) >= Symbols_size) return NULL; else { int op_code = Op_codes[SYMNUM(t)]; if (op_code == 0) return NULL; else { int i0, i1; BOOL b0, b1; Term result = NULL; switch (op_code) { /* INT x INT -> INT */ case SUM_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 + i1); break; case PROD_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 * i1); break; case DIV_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 / i1); break; case MOD_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 % i1); break; case MIN_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 < i1 ? i0 : i1); break; case MAX_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 > i1 ? i1 : i1); break; /* INT -> INT */ case ABS_OP: if (term_to_int(ARG(t,0), &i0)) result = int_to_term(i0 >= 0 ? i0 : -i0); break; /* INT -> INT, BOOL->BOOL */ case NEG_OP: if (term_to_int(ARG(t,0), &i0)) result = int_to_term(-i0); else if (term_to_bool(ARG(t,0), &b0)) result = bool_to_term(!b0); break; /* INT x INT -> BOOL */ case LT_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 < i1); break; case LE_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 <= i1); break; case GT_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 > i1); break; case GE_OP: if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 >= i1); break; /* BOOL x BOOL -> BOOL */ /* Ok if one of the args to be non-Bool, e.g., ($T & junk) = junk */ case AND_OP: case AND2_OP: if (term_to_bool(ARG(t,0), &b0)) { if (b0) result = copy_term(ARG(t,1)); else result = bool_to_term(FALSE); } else if (term_to_bool(ARG(t,1), &b1)) { if (b1) result = copy_term(ARG(t,0)); else result = bool_to_term(FALSE); } break; case OR_OP: case OR2_OP: if (term_to_bool(ARG(t,0), &b0)) { if (b0) result = bool_to_term(TRUE); else result = copy_term(ARG(t,1)); } else if (term_to_bool(ARG(t,1), &b1)) { if (b1) result = bool_to_term(TRUE); else result = copy_term(ARG(t,0)); } break; /* Term x Term -> BOOL */ case ID_OP: result = bool_to_term(term_ident(ARG(t,0), ARG(t,1))); break; case NID_OP: result = bool_to_term(!term_ident(ARG(t,0), ARG(t,1))); break; /* INT x INT -> BOOL */ case LLT_OP: result = bool_to_term(term_compare_basic(ARG(t,0),ARG(t,1)) == LESS_THAN); break; case LLE_OP: { Ordertype r = term_compare_basic(ARG(t,0),ARG(t,1)); result = bool_to_term(r == LESS_THAN || r == SAME_AS); break; } case LGT_OP: result = bool_to_term(term_compare_basic(ARG(t,0),ARG(t,1)) == GREATER_THAN); break; case LGE_OP: { Ordertype r = term_compare_basic(ARG(t,0),ARG(t,1)); result = bool_to_term(r == GREATER_THAN || r == SAME_AS); break; } /* Term -> BOOL */ case VAR_OP: result = bool_to_term(VARIABLE(ARG(t,0))); break; case CONST_OP: result = bool_to_term(CONSTANT(ARG(t,0))); break; case GROUND_OP: result = bool_to_term(ground_term(ARG(t,0))); break; /* else error */ default: printf("bad opcode is %d\n", op_code); fatal_error("dollar_eval: bad opcode"); } return result; } } } /* dollar_eval */ static Term rewrite(Term t, int flag, I3list *steps); /* mutual recursion */ /************* * * rewrite_top() * *************/ static Term rewrite_top(Term t, int flag, I3list *steps) { Term t1 = dollar_eval(t); if (t1 != NULL) { zap_term(t); Local_evals++; return t1; } else if (SYMNUM(t) >= Symbols_size) return t; else if (Rules[SYMNUM(t)] == NULL) /* we know it's not a variable */ return t; else { struct rule *r; Context c = get_context(); Trail tr; for (r = Rules[SYMNUM(t)]; r; r = r->next) { Term alpha = r->alpha; Term beta = r->beta; Term condition = r->condition; tr = NULL; if (match(alpha, c, t, &tr)) { BOOL ok; if (condition == NULL) ok = TRUE; else { Term condition_rewritten = rewrite(apply(condition, c), flag, steps); ok = true_term(condition_rewritten); zap_term(condition_rewritten); } if (ok) { Term contractum = apply_demod(beta, c, flag); undo_subst(tr); free_context(c); zap_term(t); if (!i3list_member(*steps, r->c->id, 0, 1)) *steps = i3list_prepend(*steps, r->c->id, 0, 1); /* for just. */ return(rewrite(contractum, flag, steps)); } else undo_subst(tr); } } free_context(c); return t; /* not rewritten */ } } /* rewrite_top */ /************* * * rewrite() * *************/ static Term rewrite(Term t, int flag, I3list *steps) { if (term_flag(t, flag) || VARIABLE(t)) return t; else { int op_code = (SYMNUM(t) < Symbols_size ? Op_codes[SYMNUM(t)] : -1); int i; switch (op_code) { /* There are a few cases where we don't evaluate all args first. */ /* a & b, a && b */ case AND_OP: case AND2_OP: ARG(t,0) = rewrite(ARG(t,0), flag, steps); if (true_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); free_term(t); return rewrite(tmp, flag, steps); } else if (false_term(ARG(t,0))) { zap_term(t); return bool_to_term(FALSE); } break; /* a | b, a || b */ case OR_OP: case OR2_OP: ARG(t,0) = rewrite(ARG(t,0), flag, steps); if (false_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); free_term(t); return rewrite(tmp, flag, steps); } else if (true_term(ARG(t,0))) { zap_term(t); return bool_to_term(TRUE); } break; /* if(cond, then_part, else_part) */ case IF_OP: ARG(t,0) = rewrite(ARG(t,0), flag, steps); if (true_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); zap_term(ARG(t,2)); free_term(t); return rewrite(tmp, flag, steps); } else if (false_term(ARG(t,0))) { Term tmp = ARG(t,2); zap_term(ARG(t,0)); zap_term(ARG(t,1)); free_term(t); return rewrite(tmp, flag, steps); } break; } /* rewrite subterms */ for (i = 0; i < ARITY(t); i++) ARG(t,i) = rewrite(ARG(t,i), flag, steps); /* rewrite top */ t = rewrite_top(t, flag, steps); term_flag_set(t, flag); /* Mark as fully demodulated. */ return t; } } /* rewrite */ /************* * * rewrite_with_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void rewrite_with_eval(Topform c) { int flag = claim_term_flag(); Literals lit; I3list steps = NULL; Local_evals = 0; for (lit = c->literals; lit; lit = lit->next) { lit->atom = rewrite(lit->atom, flag, &steps); term_flag_clear_recursively(lit->atom, flag); if (evaluable_predicate(SYMNUM(lit->atom))) { fprintf(stdout, "Fails to evaluate: "); p_term(lit->atom); fatal_error("rewrite_with_eval: evaluable_formula fails to evaluate"); } } if (steps != NULL) { steps = reverse_i3list(steps); c->justification = append_just(c->justification, demod_just(steps)); } if (Local_evals > 0) c->justification = append_just(c->justification, eval_just(Local_evals)); release_term_flag(flag); } /* rewrite_with_eval */ LADR-2009-11A/ladr/ioutil.c0000644000175000017500000004643211035236212014415 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "ioutil.h" /* Private definitions and types */ /************* * * fwrite_formula() * *************/ /* DOCUMENTATION This routine prints a formula, followed by ".\n" to a file. This version does not print extra parentheses (it first translates the formula to a term, then prints the term, then frees the term). To print the formula directly, with extra parentheses, call fprint_formula() instead. */ /* PUBLIC */ void fwrite_formula(FILE *fp, Formula f) { Term t = formula_to_term(f); if (t == NULL) fatal_error("fwrite_formula, formula_to_term returns NULL."); fwrite_term_nl(fp, t); fflush(fp); zap_term(t); } /* fwrite_formula */ /************* * * read_clause() * *************/ /* DOCUMENTATION This routine reads a clause from FILE *fin. If there are no more clauses in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.

Variables are "set", and upward links are made from all subterms to the clause. */ /* PUBLIC */ Topform read_clause(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Topform c = term_to_clause(t); zap_term(t); clause_set_variables(c, MAX_VARS); /* fatal if too many vars */ return c; } } /* read_clause */ /************* * * parse_clause_from_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform parse_clause_from_string(char *s) { Term t = parse_term_from_string(s); Topform c = term_to_clause(t); zap_term(t); clause_set_variables(c, MAX_VARS); /* fatal if too many vars */ return c; } /* parse_clause_from_string */ /************* * * end_of_list_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL end_of_list_clause(Topform c) { if (c == NULL) return FALSE; else if (number_of_literals(c->literals) != 1) return FALSE; else { Term a = c->literals->atom; if (!CONSTANT(a)) return FALSE; else return is_symbol(SYMNUM(a), "end_of_list", 0); } } /* end_of_list_clause */ /************* * * read_clause_clist() * *************/ /* DOCUMENTATION This routine reads a list of clauses from FILE *fin. If you wish the list to have a name, send a string; othersize send NULL. (You can name the list later with name_clist().) If there are no more clauses in *fin, an empty Clist is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Clist read_clause_clist(FILE *fin, FILE *fout, char *name, BOOL assign_id) { Clist lst = clist_init(name); Topform c; c = read_clause(fin, fout); while (c != NULL && !end_of_list_clause(c)) { if (assign_id) assign_clause_id(c); c->justification = input_just(); clist_append(c, lst); c = read_clause(fin, fout); } if (c != NULL) zap_topform(c); /* end_of_list_clause */ return lst; } /* read_clause_clist */ /************* * * read_clause_list() * *************/ /* DOCUMENTATION Read clauses, up to end_of_list (or EOF), and return them in a Plist. */ /* PUBLIC */ Plist read_clause_list(FILE *fin, FILE *fout, BOOL assign_id) { Clist a = read_clause_clist(fin, fout, NULL, assign_id); return move_clist_to_plist(a); } /* read_clause_list */ /************* * * sb_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. */ /* PUBLIC */ void sb_write_clause_jmap(String_buf sb, Topform c, int format, I3list map) { Term t; if (c->compressed) t = NULL; else t = topform_to_term(c); if (format == CL_FORM_BARE) { if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, "."); } else { if (c->id != 0) { sb_append_id(sb, c->id, map); sb_append(sb, " "); } if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, ". "); if (format == CL_FORM_STD) sb_write_just(sb, c->justification, map); else { /* CL_FORM_PARENTS */ Ilist parents = get_parents(c->justification, TRUE); Ilist p; sb_append(sb, "["); for (p = parents; p; p = p->next) { sb_append_id(sb, p->i, map); if (p->next) sb_append(sb, ","); } sb_append(sb, "]."); } } sb_append(sb, "\n"); if (t) zap_term(t); } /* sb_write_clause_jmap */ /************* * * sb_write_clause() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void sb_write_clause(String_buf sb, Topform c, int format) { sb_write_clause_jmap(sb, c, format, NULL); } /* sb_write_clause */ /************* * * sb_xml_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. It is written in XML format. */ /* PUBLIC */ void sb_xml_write_clause_jmap(String_buf sb, Topform c, I3list map) { sb_append(sb, "\n id, map); sb_append(sb, "\""); if (c->justification && c->justification->type == GOAL_JUST) sb_append(sb, " type=\"goal\""); else if (c->justification && c->justification->type == DENY_JUST) sb_append(sb, " type=\"deny\""); else if (c->justification && c->justification->type == INPUT_JUST) sb_append(sb, " type=\"assumption\""); else if (c->justification && c->justification->type == CLAUSIFY_JUST) sb_append(sb, " type=\"clausify\""); else if (c->justification && c->justification->type == EXPAND_DEF_JUST) sb_append(sb, " type=\"expand_def\""); sb_append(sb, ">\n"); if (c->compressed) sb_append(sb, " clause_is_compressed\n"); else { Literals lit; Term atts; if (c->literals == NULL) { sb_append(sb, " \n"); } else { for (lit = c->literals; lit; lit = lit->next) { Term t = literal_to_term(lit); sb_append(sb, " \n"); zap_term(t); } } atts = attributes_to_term(c->attributes, attrib_sym()); if (atts) { Term t = atts; while (is_term(t, attrib_sym(), 2)) { sb_append(sb, " \n"); t = ARG(t,1); } sb_append(sb, " \n"); zap_term(atts); } } sb_xml_write_just(sb, c->justification, map); sb_append(sb, " \n"); } /* sb_xml_write_clause_jmap */ /************* * * sb_tagged_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. */ /* PUBLIC */ void sb_tagged_write_clause_jmap(String_buf sb, Topform c, I3list map) { Term t; if (c->compressed) t = NULL; else t = topform_to_term(c); if (c->id != 0) { /* BV(2007-jul-13) */ sb_append(sb, "c "); sb_append_id(sb, c->id, map); sb_append(sb, " "); } if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, "\n"); sb_tagged_write_just(sb, c->justification, map); /* sb_append(sb, " *** call to sb_tagged_write_just ***\n"); */ sb_append(sb, "e\n"); if (t) zap_term(t); } /* sb_tagged_write_clause_jmap */ /************* * * fwrite_clause_jmap() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void fwrite_clause_jmap(FILE *fp, Topform c, int format, I3list map) { if (c == NULL) fprintf(fp, "fwrite_clause_jmap: NULL clause\n"); else { String_buf sb = get_string_buf(); if (format == CL_FORM_XML) sb_xml_write_clause_jmap(sb, c, map); else if (format == CL_FORM_IVY) sb_ivy_write_clause_jmap(sb, c, map); else if (format == CL_FORM_TAGGED) sb_tagged_write_clause_jmap(sb, c, map); else sb_write_clause_jmap(sb, c, format, map); fprint_sb(fp, sb); zap_string_buf(sb); } fflush(fp); } /* fwrite_clause_jmap */ /************* * * fwrite_clause() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void fwrite_clause(FILE *fp, Topform c, int format) { fwrite_clause_jmap(fp, c, format, NULL); } /* fwrite_clause */ /************* * * f_clause() * *************/ /* DOCUMENTATION Write a clause to stdout, with id, with justification last. */ /* PUBLIC */ void f_clause(Topform c) { fwrite_clause(stdout, c, CL_FORM_STD); } /* f_clause */ /************* * * fwrite_clause_clist() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Clist of clauses in mixfix form. Example:

list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_clause_clist(FILE *fp, Clist lst, int format) { Clist_pos p; if (lst->name == NULL || str_ident(lst->name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", lst->name); for (p = lst->first; p != NULL; p = p->next) fwrite_clause(fp, p->c, format); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_clause_clist */ /************* * * fwrite_demod_clist() * *************/ /* DOCUMENTATION Similar to fwirte_clause_clist, except that lex-dep demodulators are noted. */ /* PUBLIC */ void fwrite_demod_clist(FILE *fp, Clist lst, int format) { Clist_pos p; if (lst->name == NULL || str_ident(lst->name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", lst->name); for (p = lst->first; p != NULL; p = p->next) { Topform c = p->c; fwrite_clause(fp, c, format); if (unit_clause(c->literals)&& pos_eq(c->literals) && !oriented_eq(c->literals->atom)) { fprintf(fp, " %% (lex-dep)\n"); } } fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_demod_clist */ /************* * * fwrite_clause_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Plist of clauses in mixfix form. Example:
list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_clause_list(FILE *fp, Plist lst, char *name, int format) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", name); for (p = lst; p != NULL; p = p->next) fwrite_clause(fp, p->v, format); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_clause_list */ /************* * * f_clauses() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void f_clauses(Plist p) { fwrite_clause_list(stdout, p, "", CL_FORM_STD); } /* f_clauses */ /************* * * read_formula() * *************/ /* DOCUMENTATION This routine reads a formula from FILE *fin. If there are no more formulas in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Formula read_formula(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Formula f = term_to_formula(t); zap_term(t); return f; } } /* read_formula */ /************* * * end_of_list_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL end_of_list_formula(Formula f) { if (f == NULL) return FALSE; else if (f->type != ATOM_FORM) return FALSE; else { Term a = f->atom; if (!CONSTANT(a)) return FALSE; else return is_symbol(SYMNUM(a), "end_of_list", 0); } } /* end_of_list_formula */ /************* * * read_formula_list() * *************/ /* DOCUMENTATION This routine reads a list of formulas from FILE *fin. If there are no more formulas in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Plist read_formula_list(FILE *fin, FILE *fout) { Plist p = NULL; Formula f; f = read_formula(fin, fout); while (f != NULL && !end_of_list_formula(f)) { p = plist_prepend(p, f); f = read_formula(fin, fout); } if (f != NULL) zap_formula(f); p = reverse_plist(p); return p; } /* read_formula_list */ /************* * * fwrite_formula_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a list of formulas in mixfix form. Example:

list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_formula_list(FILE *fp, Plist lst, char *name) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", name); for (p = lst; p != NULL; p = p->next) fwrite_formula(fp, p->v); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_formula_list */ /************* * * zap_formula_list() * *************/ /* DOCUMENTATION Free a Plist of formulas. */ /* PUBLIC */ void zap_formula_list(Plist lst) { Plist p = lst; while (p != NULL) { Plist p2 = p; p = p->next; zap_formula(p2->v); free_plist(p2); } } /* zap_formula_list */ /************* * * end_of_list_term() * *************/ /* DOCUMENTATION Check if a term is the constant "end_of_list". */ /* PUBLIC */ BOOL end_of_list_term(Term t) { if (t == NULL) return FALSE; else if (!CONSTANT(t)) return FALSE; else return is_symbol(SYMNUM(t), "end_of_list", 0); } /* end_of_list_term */ /************* * * end_of_commands_term() * *************/ /* DOCUMENTATION Check if a term is the constant "end_of_commands". */ /* PUBLIC */ BOOL end_of_commands_term(Term t) { if (t == NULL) return FALSE; else if (!CONSTANT(t)) return FALSE; else return is_symbol(SYMNUM(t), "end_of_commands", 0); } /* end_of_commands_term */ /************* * * read_term_list() * *************/ /* DOCUMENTATION This routine reads a list of terms from FILE *fin. If there are no more terms in *fin, NULL is returned.

None of the returned terms or their subterms will have type VARIABLE, even if it looks like a variable (e.g., x).

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Plist read_term_list(FILE *fin, FILE *fout) { Plist p = NULL; Term t; t = read_term(fin, fout); while (t != NULL && !end_of_list_term(t)) { p = plist_prepend(p, t); t = read_term(fin, fout); } if (t != NULL) zap_term(t); p = reverse_plist(p); return p; } /* read_term_list */ /************* * * fwrite_term_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a list of terms in mixfix form. Example:

list(sos).
a = b.
end_of_list.
If the name of the list is "" or NULL, it is written as list(anonymous). */ /* PUBLIC */ void fwrite_term_list(FILE *fp, Plist lst, char *name) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nlist(anonymous).\n"); else fprintf(fp, "\nlist(%s).\n", name); for (p = lst; p != NULL; p = p->next) { fwrite_term(fp, p->v); fprintf(fp, ".\n"); } fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_term_list */ /************* * * term_reader() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A term is read from stdin (NULL if there are none). Errors are fatal. */ /* PUBLIC */ Term term_reader(BOOL fast) { if (fast) return fast_read_term(stdin, stderr); else return read_term(stdin, stderr); } /* term_reader */ /************* * * term_writer() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The term is written to stdout, with a period and newline. */ /* PUBLIC */ void term_writer(Term t, BOOL fast) { if (fast) fast_fwrite_term_nl(stdout, t); else fwrite_term_nl(stdout, t); fflush(stdout); } /* term_writer */ /************* * * clause_reader() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A clause is read from stdin (NULL if there are none). Errors are fatal. */ /* PUBLIC */ Topform clause_reader(BOOL fast) { if (fast) return fast_read_clause(stdin, stderr); else return read_clause(stdin, stderr); } /* clause_reader */ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The clause is written to stdout, with a period and newline. */ /* PUBLIC */ void clause_writer(Topform c, BOOL fast) { if (fast) fast_fwrite_clause(stdout, c); else fwrite_clause(stdout, c, CL_FORM_BARE); fflush(stdout); } /* clause_writer */ /************* * * term_to_topform2() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform term_to_topform2(Term t) { Formula f = term_to_formula(t); Topform tf; if (clausal_formula(f)) { tf = formula_to_clause(f); tf->attributes = copy_attributes(f->attributes); zap_formula(f); clause_set_variables(tf, MAX_VARS); } else { tf = get_topform(); tf->is_formula = TRUE; tf->attributes = f->attributes; f->attributes = NULL; tf->formula = universal_closure(f); } return tf; } /* term_to_topform2 */ /************* * * read_clause_or_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform read_clause_or_formula(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Topform tf = term_to_topform2(t); zap_term(t); return tf; } } /* read_clause_or_formula */ /************* * * read_clause_or_formula_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist read_clause_or_formula_list(FILE *fin, FILE *fout) { Plist lst = NULL; Topform tf = read_clause_or_formula(fin, fout); while (tf != NULL && !end_of_list_clause(tf)) { lst = plist_prepend(lst, tf); tf = read_clause_or_formula(fin, fout); } if (tf) zap_topform(tf); return reverse_plist(lst); } /* read_clause_or_formula_list */ LADR-2009-11A/ladr/int_code.c~0000644000175000017500000001735211074702707015103 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "int_code.h" /* Private definitions and types */ /************* * * put_ilist_to_ibuf() * *************/ static void put_ilist_to_ibuf(Ibuffer ibuf, Ilist p) { /* size of Ilist, then members */ ibuf_write(ibuf, ilist_count(p)); for (; p; p = p->next) ibuf_write(ibuf, p->i); } /* put_ilist_to_ibuf */ /************* * * get_ilist_from_ibuf() * *************/ static Ilist get_ilist_from_ibuf(Ibuffer ibuf) { /* size of Ilist, then members */ int i; Ilist p = NULL; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) p = ilist_append(p, ibuf_xread(ibuf)); return p; } /* get_ilist_from_ibuf */ /************* * * put_i3list_to_ibuf() * *************/ static void put_i3list_to_ibuf(Ibuffer ibuf, I3list p) { /* size of I3list, then members */ ibuf_write(ibuf, i3list_count(p)); for (; p; p = p->next) { ibuf_write(ibuf, p->i); ibuf_write(ibuf, p->j); ibuf_write(ibuf, p->k); } } /* put_i3list_to_ibuf */ /************* * * get_i3list_from_ibuf() * *************/ static I3list get_i3list_from_ibuf(Ibuffer ibuf) { /* size of I3list, then members */ int i; I3list p = NULL; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) { int i1 = ibuf_xread(ibuf); int i2 = ibuf_xread(ibuf); int i3 = ibuf_xread(ibuf); p = i3list_append(p, i1, i2, i3); } return p; } /* get_i3list_from_ibuf */ /************* * * put_term_to_ibuf() * *************/ static void put_term_to_ibuf(Ibuffer ibuf, Term t) { if (VARIABLE(t)) ibuf_write(ibuf, -VARNUM(t)); else { int i; ibuf_write(ibuf, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) { put_term_to_ibuf(ibuf, ARG(t,i)); } } } /* put_term_to_ibuf */ /************* * * get_term_from_ibuf() * *************/ static Term get_term_from_ibuf(Ibuffer ibuf) { int a = ibuf_xread(ibuf); if (a <= 0) return get_variable_term(-a); else { Term t; int i; int arity = sn_to_arity(a); if (arity == -1) { printf("bad symnum: %d\n", a); fatal_error("get_term_from_ibuf, symbol not in symbol table"); } t = get_rigid_term_dangerously(a, arity); for (i = 0; i < ARITY(t); i++) ARG(t,i) = get_term_from_ibuf(ibuf); return t; } } /* get_term_from_ibuf */ /************* * * put_just_to_ibuf() * *************/ static void put_just_to_ibuf(Ibuffer ibuf, Just j) { /* size of Just, then members */ ibuf_write(ibuf, just_count(j)); for (; j; j = j->next) { ibuf_write(ibuf, j->type); switch (j->type) { case INPUT_JUST: case GOAL_JUST: /* nothing */ break; case CLAUSIFY_JUST: case DENY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case NEW_SYMBOL_JUST: /* integer */ ibuf_write(ibuf, j->u.id); break; case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: /* list of integers */ put_ilist_to_ibuf(ibuf, j->u.lst); break; case DEMOD_JUST: /* list of integer triples */ put_i3list_to_ibuf(ibuf, j->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: ibuf_write(ibuf, j->u.para->from_id); put_ilist_to_ibuf(ibuf, j->u.para->from_pos); ibuf_write(ibuf, j->u.para->into_id); put_ilist_to_ibuf(ibuf, j->u.para->into_pos); break; default: fatal_error("put_just_to_ibuf, unknown type"); } } } /* put_just_to_ibuf */ /************* * * get_just_from_ibuf() * *************/ static Just get_just_from_ibuf(Ibuffer ibuf) { /* size of Just, then members */ Just j_collect = NULL; int i; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) { int type = ibuf_xread(ibuf); Just j = get_just(); j->type = type; switch (type) { case INPUT_JUST: case GOAL_JUST: /* nothing */ break; case CLAUSIFY_JUST: case DENY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case NEW_SYMBOL_JUST: /* integer */ j->u.id = ibuf_xread(ibuf); break; case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: /* list of integers */ j->u.lst = get_ilist_from_ibuf(ibuf); break; case DEMOD_JUST: /* list of integer triples */ j->u.demod = get_i3list_from_ibuf(ibuf); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: j->u.para = get_parajust(); j->u.para->from_id = ibuf_xread(ibuf); j->u.para->from_pos = get_ilist_from_ibuf(ibuf); j->u.para->into_id = ibuf_xread(ibuf); j->u.para->into_pos = get_ilist_from_ibuf(ibuf); break; default: printf("unknown just type: %d\n", type); fatal_error("get_just_from_ibuf, unknown just"); } j_collect = append_just(j_collect, j); } return j_collect; } /* get_just_from_ibuf */ /************* * * put_clause_to_ibuf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void put_clause_to_ibuf(Ibuffer ibuf, Topform c) { /* id is_formula weight number-of-justs justs lits/atts [atomflags] */ ibuf_write(ibuf, c->id); ibuf_write(ibuf, c->is_formula); ibuf_write(ibuf, c->weight); put_just_to_ibuf(ibuf, c->justification); /* literals and attributes */ { Term t = topform_to_term(c); put_term_to_ibuf(ibuf, t); zap_term(t); } if (!c->is_formula) { /* flags on atoms (maximal, oriented, etc.) */ Literals l; for (l = c->literals; l; l = l->next) ibuf_write(ibuf, l->atom->private_flags); } } /* put_clause_to_ibuf */ /************* * * get_clause_from_ibuf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform get_clause_from_ibuf(Ibuffer ibuf) { /* id is_formula weight number-of-justs justs lits/atts [atomflags] */ int id = ibuf_xread(ibuf); int is_formula = ibuf_xread(ibuf); int weight = ibuf_xread(ibuf); Just j = get_just_from_ibuf(ibuf); Term t = get_term_from_ibuf(ibuf); Topform c = term_to_topform(t, is_formula); zap_term(t); c->id = id; c->is_formula = is_formula; c->weight = weight; c->justification = j; if (!is_formula) { Literals l; for (l = c->literals; l; l = l->next) l->atom->private_flags = ibuf_xread(ibuf); } return c; } /* get_clause_from_ibuf */ /************* * * check_ibuf_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void check_ibuf_clause(Topform c) { Ibuffer ibuf = ibuf_init(); put_clause_to_ibuf(ibuf, c); p_ibuf(ibuf); ibuf_rewind(ibuf); { Topform d = get_clause_from_ibuf(ibuf); fprint_clause(stdout, c); fprint_clause(stdout, d); if (!clause_ident(c->literals, d->literals)) fatal_error("check_ibuf_clause, clasues not ident"); zap_topform(d); } ibuf_free(ibuf); } /* check_ibuf_clause */ LADR-2009-11A/ladr/html.tar.gz0000644000175000017500000025335011222161004015030 0ustar mccunemccune‹âHJìýyÜF’(ŠÎ¿Oá}g\¥.Ñ$µø=Ë¢´DÙœ‘(]ŠîezúÖ«P$ZU@@qqŸÏþ2–\‘  Š”Ô­fÍ´E‘KDFfFFÆrQ/æ_ÿÛÇýíˆß7OžÀ¿»ß<Ù1ÿ•¿ÛÝùF€ì>}ôä›ÛÙÝ}$>ÇO>r¿ð·ªê¤Œã[L&«< Ãu}ÿ'ý]ÀøÏæI=MÅtï¼ à§‡Æÿ›Çîø?Þýæé¿Å;wÞÏï_|ü¿ûéôÍëý軟^ŠNN_îüðÝ×ô*úîk‰¾ûáíË?ÿ?íîÿ_Y>™¯¦i¼eÙ »àô"«âeržÆIgù¬(Iy<+‹E<Ëæi}wÿtrøêùÖö¶É†[vöã$ŸÆ~à‰ <àmèÝÞþ‹"¯Ó¼®Dö?ž¯öU-ÿWY¬ê,O«­ýw«³y6‰OøTâÀNÓY®_¦³,Ïl–×e±µÿLW#¨¯¡Ñwï€à'PàøàÍásÙ}‚Ž;½´‹_ jÅšˆÓOE+ÓôZ<>†á;øáõaüâðõëw/_ÿøü¼M¾4qɪI™-ÆPßx’ä“t¾µïy‰ýùІ‹—i]fée:ÎÓëÚ©Åú¨l†'ódU¥b$ÍG»ü!H(°éBIµ;ËÊ*Ø)üêU²\ÎoÆØÑ)ã©2½*³8ÊyqkTæi2 aßÚû•ÔuºXÖº_òEk±•hE >„ÑøyXòeZ'Ù¼b¦d.ßòr±¼ Á»“Ãýï~Ø¿,²i쨾ñGܪ¶ö_2è²@Tbñïð™èÍ¢f¬ÒÛºË Þ^¼1IJl\‚MÊfäÎèåm fpZ,AÈŠ'-2xßd$,&ʦ×09ã8DTuºϳE& /ªì×T>ÿðöíëxž^w¤åX =^ªí!6z°ª€?ë%rAŸ~mGG3!ïÝ0 šBHße5BbþMˆìÙ,›,)øBp|*ÊOG@ÔøªŠÓk±¦Aq«È6 `( v« ^™CCKļ9zoa ÔƒªÕd’VÕl5opF#xWv;к¬%û¯?ÝK{7ï@úË*»89z„;Í“ñEšL» ÇŠ¥dÍQ‚B ® Ûq|ô’‰ZUM¦‹`=X®ê¸ Ú‹5AtIí Bß«¯æóxYgb鹉¯’¼ŽÄšXÂ’TÑzý>KƒcÈYY (±æ»Í˜-f3ÎxÜpÆ©Ãs&¸à3P,â}ʨ%ªFûlå°y :ïÄ;<~îóéýïãþPÿŒ­ƒ»o£]ÿ³»óä›oúŸÝG÷úŸOñóê4?ôUÿèkŒ*¬xt?êóÄý¢5?&–·PüLD¯ÇPÏÖ¾ú3 -ŽP“»Š,RØŠBô¢«Ø¯ÉÒ(#žT ®ä<­Çy6gœÌ§®Æ2£©¬ ˜¥£¿ Ô]jt'ˆŠªšÄY£-zÑÕÇyšŸ×ÆÜá]Åêb\ÃQP¾ 2ÒRHi|kßyÑ@µ[5dð¥+Ö¢l¨¾w¯M©q¶ÊqÆ“‹tòAL¨ xpˆ±å­³j$¤Å¬¾‰÷⫬¾@¡®˜ QNœ¯4®ngÅ\ˆœ±î¾Í…k æfQû¼p0Ÿ8SÁêWÒá!Éc8,Þèõ@w¢Á?kõÃ)ÝNgµjâtž.Ä ã© Q"XRA(ÌâøTò…¤É0pDŽt*€ŽS1Râ0¥ô¼ Y«'uÀvôçbWÅj>Pµ¨eIxOÊóÂ#!·âd&‹'É|b~-ºq×>|˜ÄçE1‡„(@x¨D>¤ü-ÉáØ£çñz³|@ô•$$âáÞ!ÎÅÜ=Ñ ÄëÍËÁpdèN—‹žŸ¥ÑU:Ÿ?„:‚n§lÙùEœ¥ñÌqFGêe:©}lGûÄfLe;¦önÃÕ{a^#v©HéCÓXë«‚´SÛpšzD à-Ù¦‰k¶)¢YÇĪøÈœ…TÙC±.Ñv:\åx E‘JP¨˜™3ØæFŠ y 5dyœqÕH®+Ç?¿~íÃSî)>e‡´ùÊlŽÕåâÑ옔0¼»…Õ_á’^»J{#´ÛPlìâNŽú $’Íø‹¯3h'¬ ±–èƒ8O¯hÝ­êR¼+Ái°â–©Øºh1Asœ;·h‘/ĂܬcV¦þÙ§Eÿ%Fp4Ì.S±ÑÆ´xÔnŸâ¿$£³Ñä¯C5s’ÛŒ œjMÆ+€´%}½^d<^ êñXi²Òâ>-°7@_±ÐWªÓº_aa'˜XîZ7…±Ÿ0^Y¬± z1p î‡yF‘DÉÚ°ý§Ø¢…c†Žmƒ¡Ø˜áÎdê[^WØPëhÐo£td-ÁäƒTÈ1^`-’<9‡ýí /¥ÖÀ±Ðt…Pu„ûŒ“ ìÕE6¹ˆ…(V\U(ªÉLpzU,ÒøõÑûw7(H¿+‹yq~2Z~.Xþ§â Öµ–X¬PÁ+:!®æPÇ4]Æu)zˆËv~Ã2‚¼jŠª ñß)ÖêâÉÍDÐGÔ&Öù«<>OÊ3Ûö?ªzõ“yR]|$åß¿õ°ÿÚ}¢õOÅûÝGöžÜëÿ>ÅÏ«ÿc~è«ücð5²¼n×£ó£o ôEkûŠ·PõÑqrŒUmí›OµNR(1Í3±Â%bÿs^„,…–¥ Õ ÷Ö¾û&PPÈ3²wêÏn-Rˆ.!Nôg ®¼ ç¥Ùïe¨Ëëé²lÂÅs½æní¿]ŒÍƒØeøÀ[e 4ñ` §c=Bö› Apžå ·Àõ%ë:„€£ôKZïDg3¨¾l[¸ÊÑp}M\SÅ f ^ͳõÍ\\åÑIY6'L%0«S&âx|nIèYÆÓ†l)8Œ^|HQ3`" ®/…ÀçolÇèk€åðÑ‹£&£ BPB<¨’ZHšâü«‘ÀÂÕy}³Lãr5Oé¶2x „ÌÉþ#J±1ȰQq0üšÖ¼òÑ¡І÷+à_À2­Šù%,ôÛz‘§*™¥(¶,r4VbU_¾"Ú jH,©ŽŠbž Â+ùD|¼Ö¯XÀ̦¢ÙLp_´,`Û㈨$ÏÑhΉÛ#°ÛÆeªJƒ<{!HV"ȯCêÐZÇ®%‹4泤Ø9ÓÌ&ÊXAÓüŸƒ*¥÷Û\§¨þM§pª†:ð©Bã‹¢¸giS“Ʋî·?rÀ¯ŽÄæô`¶d£°¯-…9Ë ª‰¡‘E‡p -Ê›xU!fm f<¢á4©ÅIK²Š’ª*Äi°â·:!ÒØó‰‚{rL•†—;ØÁ°¦¤@.¨3‚ $›ŒÔ`Œf̳e'Y ˆA/Ü«z*^Þ%檷Æ>ëík¬ÖÛpXÁ '›XXyùFI? lM> : Ñ^‹L´"˜ëâÜ…wCAåŒA5½á!U‰“ú„ äåY#ÂÄí˜?‹"«Àß#^$é§0}æyŸN·³y&6ùé³8þúA|TÁj{œùa-‚? §¿¬ñææûøÁ×¢µÙˆ—ƒÚ;·RÇÍò™S7Ú·WõtZóÁOÿé_uQö¶XDÎ’B" èÁŒÇº|ìÓÍZe (° TW¦äsä­®åca€ðFËyÑ‹$WµKëÍú„©Z)â‹ì«VÚ„*th1V¬%zRW zy`ú' p¿ôÓªPÉÚxè(X¼)&0‚„ÊW t /à’Ü~òÎý¶YF·XÞ¨•Ëx4œåi™ÙTo¾kCõŒ`$a›ïZÔ銬ÆÃZ("G;ܾ÷uí ô`ŠPös]ïÚê{VÇ÷C¦ `¢¥8šŽ§é,ŸÔŸm»•oàÖ@EëÖÈ3Þ| Ù§ç h%¦â]egó\ÝÄùO[·ö{ulͲKöó\š4ä¯ÆÊ¬¼ëÙùeü à´Û"ø­CðÚáÒjˆýSé†ÁðˆÄzÈr@Z" Zäi¹%ât>…ƒzšL.àRH-‹ŒÌb'––ßÚÀÜ¿:ÔÍ[€º«»#ݧ½Ûdk+ìš ù6“ÐFÔtxJ-’ëçÁºLЊ­"= ¸ëá=ÞûÐ5XØÔ‰8BÑÛ Ÿ¥Ê-¹‘ËŸzÞŽã·¹x·\Õ#Ã0â¢èoœÛð§|Ÿ¦Þ‘.é4Ú5ç^¼½½'“ zeŸ“.\!¹Ä¢ ŒÑHa-ž£y:«Éõð ž%u2Ó²,Jö£s%mºF4 •ô3ºÊî‹ ®ªÉÉVPÈ–‘R±V—@1t¸Dóœ˜å ѽs1ubƒf_K*CÄ12ö•Ôƶëòƒu ˜‰ÖØ£Ïze]§%XdRE¤›S3Ó™˜y‘+çtž¤1NÒ*²|@ý˜˜»kœ4¸ËçðîNð¤% Ѐ*µ©<-¨É*ÐY]þëbQ¢ôZ¾PÜ2ìÂÛ3¹[­°›à{ Б˜VV”€[ãêìÔ7eÀ®úš¬‚|O¤V,¼æJ³ Öa³­ Ñ™Lߎ}Ò+;ÀêãÞÙùò.…ŽPëi±c ®ëo;97šÙ£vÂeÌÏÐöˆ¼(æótB‚Ľ»iÌ9µEç#¹µdÊÖZLå\ETõþÏoŽ~SYnA¶kVp$‘  LÿûÎvÞ)ÖTÃ)$¤Ý¦/Õ.Î1Jíõ)µg•š\ˆu±9Éæ¼]ØDR˜/“²2Ö³42ík*ºpJ¨fÉTq ++ã ³.ÒxËÙH-ѪKv85-¢¾ÈßAëÔþÔÈjÄx.÷£Crô’½«ƒÊÏ÷ ê•çm 7ÖI5´—¨²ÖÖ™~ ¨ Ë K,E4®Ð_§J“rr1üZwÜ8rzû¬¾[VTv–‚%X’§(™-VhÉž5b¸æ¤ÖÒÎ=ìñ÷†'@Ÿ¥ßI »ä?é—í÷r Ó³S“e‡e=Ò½I[0ŸÒ‚ÄÚˆU—[õ¸Í¢¥ÌÆ››¬³csk×­®ßßu7·F7õæMÊ\p°µÕÅ·Üê\M©ß9ʆ 0µ]§£Ùòrlpýù¬ƒV%}46Åx::[ÇæH–¼¼áÁ9R‘ÂôÁù¨ãŒ,®†^ J<‡íGèŒLíSô"¹‘ ³mš^ ˆst¯+홬°†´ëƒí’vƒZO/o ;ý2ï€k Oò>žyI~z¸‘ äV(dý³#FCÐ&¥Í³ª«Ã ÉÄ6ÜÚr®…o‡{ì$‚ÕCo%@¦¿ÉîNdfÑz%,Òƒ!@á" VZÐwŸÇ\"#:–ºba¾µ›ž’ ˜^@9-Œ~g•ž®‚îg`´(f+z—}'Q+>e è¤ä›­-"J°Pl¼Ev=Ë®aŒq»jŽÒºÄŸOà”Ã…XÎJÏVçà¸hŽ€{y½¸´q×Ñ=õ$¬¥ Ë­ Ñ:=#²{TL]™ŠNšgæ„åIÊæê‘tŠeKI9w•í"ŸL¡}1Œ´AÆ’NhvÄ¡*`‰Ä93Ziïè“ûÜŽßf@<þËŽ‘ظ§TÔ ¹ã·§jôŒÑéu‡¢Äí/áɇô6×oÖ=»·D/Sw“’«ÁÛ¸éíÁô‹_!ðbU­HàÀÒàß,QXlFVÄÞ–@û£®œ‹¤Ü”g$$˜ò%N°´öË?z9ŠV.ó";{×Ã9DR5¢w‚‹Ž”*&CT jCÃV0häÏ0ñIamÎ/?ý=ŠÐ&ÄYAÆßJ'Æ[[&ø…˵~Zø+1D ëˆ(þªž!œ¨ÿ9¯ãIá¾6ä4ò?Pû ÿôÔ2‚a Ï¬yæëâU Á|à^Œ›¿Z£º™ÍঠTk#ö«"€XvRSKªÈÅ*E_LçüIeÓ3ùB”…ÊQ‡›+ÅkÂÀVÌjVjŒFÔbÈy=|EOÚ3=.èå3=zUºäÄêa]qP᥿RàM²Y¥{ÄQ©”6 ×Ú˜ðj‰–Û Ôj|q|&&Ö6WÀô×Ó3Õ>Hø¸.¤bjƒÌìûÁ%s°¤ãqB—>  Æï,MóØ8à˜ÅWjœ5â(ÓˆE¢†ò ¸ôJýCº¬­Jätgšg Q›™úè%ÝÂXEYw÷Ìl}€@¬¢Uu’º¤®³)ž-¦UHe£òd†5Ë-’z"f,VÆú7=%iVI¤®“MxЄ¯ii² ¬ˆfé3ˆÁ€ Ü¾ÁeëÙÐ;å@ï]¤ð–ƒUÕp¼TLB!CÌ»]ÚÓ4£ÅUr£œá8ÓË}ˆ¦.h<ÏàPIŠQ~}ðòdDÈÙ§ d Ü}¦b=£öþ•+XÝ'Ÿ˜–¸‰å±KÉ\ObÁBâ.fÍû&ÊÓ”‹ ó½„kC˜0‰„¯!ªZ[É%^R£8Dv&ëto/´ÕGÇKQHmÂbkÐCM©l•“¤"w BZÐ5fK–­¼À%MŸ6äz¸‰ÕI0{nªB)Œ5„3Þà’“îMÔÑ ɵv Ky±áȸ˜Iïcѽ´žlQÀŒš}qô8uÖ!gñ 1 S‡˜ì%¯xP ‚Œq+\gcЇ·œ'¤"wë{7£üúÿ˜Þ?BñŸ÷v÷þ?O¿¹÷ÿù$?¯ÿ⇾þ?ªÀÆþ?º³uÿü:Ñ€_´ÿäm2~ µ,nÆ2DÒô¼ ˜þJ €NCO! Q—ªXlX[ûî› ÇŒ„aã±Û˜]ƒ#ï¼ÐL"_´»6Y-7ßµx40y4LuªŒ5s~á!Hw{Ø&nw7i@œ·±ßöó—W=âíÈÄ Ç”ÅÑ °ÐÄ7àî w"§R–ãJ‘ÿyÕ–lÀTø ì\@I†Ò!´bh‚¬æG׆ºLeh#Òóij×CO‡™É¼V̆mQ1ƒ$z» ÷3ÐàvtÛÁ õ)¨ÊmÁè ifGÒa•umpPˆ^ÇBÛ7¾µ©Í´ÓüìáX¸/Û¸ÓZ ý´1@ú°õ2`æÙØÕ:[°Þyæü­Z̼m”o±olì뵤pêñM¦ÔŽô gQV e¿Z7ËloÁtLÝ»5˜jp÷F:lCÞ ê°eKzdçÒêmYêïZc±xÈÀÈY¦0¶*ê»z0G\Qµ‚aÌO,¿Ê¡>ˆ‘Ó«®Ù´Ò5‘AL–`Eƒ°Ò8æ•bDL À‹ÅäRÂý¯PI~Q”5ßV™àÊ’F¦`+å]¿Ð?SS*Jã=z=ñ½@œLÔŠMDyPôù‡îz&öl #–þ;uD°/(ˤ)Œ(Ÿ%yuÆ0ˆxŠã¿¬Òò¦WˆŠíc mEØÃZi$b{,Pƒ±Ñ&ÉœƒäâY’‡bR6fFÍhªw 6Å»ÏX+ Óïbäf. - ”ÖUZ,Œ úVÐ r½üÃÁɈ¯£øåÉÑG/GñÁ‹ñÁÉãÓ?¿;ćã?¨çZ€s,Pt0Æñ@ü÷á>¶úü¹®qxëpC¦“<9x}ôß§Gouš¹/QøboWàNÕJ*ù?>{)#Ö±å̈-[Ø(ƼΙ´œA¤8Þ×SjÉjR²c" 6|ËŒ{L ½œÌ+Φ‘È{„êUÔÊc½(³ªm%·Ãí ß› ÙÕyšc\G4¿@œ4)Ts¤Ì†B·£?‚H¦&6“´RGŠì2}8)‹UM—ƒƒC4e·^Šw|].¤?µHàÄÀäà…ºN¿*J!Ÿ¡Å_%fQ)-ÐhU寖*})¯²HšniN|ˆDF¼jüŽ6f°d(gI˜íhp*³­òè’¡"\bMÈWR ¾lâ{çX…³Æ£¦qR)c:¨u‚þû'ùyõÿÌ}µÿ ¾±î_–×ízôþôm"¾h¿Bñ6¿¦˜à˜,È£«ÝÚ} iþ‹<µÊ;/ZBÂÈúïP¼žœâÌÖ¾ùÔ­ñ‡3˜ossî›`u“žÝØ<ÓU>Mr…“óâVÁO‚Cå7nÀ ”Ne¤ÔMÏËdšº¯ÏÀ“<íáDAuø5CM{;æ‚©á;òç€CTwÂo­Öu™Ï¯c·¡Z}xõ˜|w%@Юd(e$õÁqÆ K[aʬ€ŠóéÜ6Üvl*AóýË*¢ŸÊ€¸,ÓˬXUB’#ÃÍ)Uÿ¨n" {ƒžµ/Ì(¢èOtâz¡UjXÚqm¥¤ü,DB<ò®pÌï@'ÄQð ¾€…¼ãôœèGy*õÚåøÀaâé­'„ÿåé¿Ãcš3]t ³P _Ø ßô8ïäÔjÓû,ÉÛeü×1ºœ|°+ÿ·ùïñÞ“½{ùïSüBñ_%?¬V¹M XU‡ÝXþ>1¿h¹ÐBó6²ád’.ë1åP4ÚD9ðSž‚ïÅ<™–,ÒYïBæä™Oý–¶¨f£ó¼J_ [ˆöPö2»%DHo8UMØ>±áoAó5 FHWý¢ƒ ÅR£^„ÂW"~0IÆ0I_õÜ0Ø¡/qæ#Õ| õ.)º€ùÔŽØaS!É@ˆ¸Æ«@Qp5°B"]ŒÁêvkß}ÓAÄÈ ßÛŽþŸÉÜÔÖë¶A2µÅƒ¤žou0§§ÿ !êèfJØtGó`îwÚf„?l@¸ûŠËO,ÜcŠº3p¯~µ ¶“õ ¿‰›±cÀ[šI³%;yW_ê1ÊŒÂ%¼Tɱ«*;Ç Ê;ó<­­$:¸mÑšÖò_ñ ÒÌ¢Xue–³é䢠áZåòâ*'“±<Á½Lvïï¥A?»ˆêÍG¶ñmTácŽØa7 ­(8"ø ƒ‡!$0ªÜ/#å@}²(/žÁÐ=·ö· Í÷UÚ¿Byý‹ô¢½EWZioÒ†îÙæŽæwÒ9C­R†Óº¬Å$C”ð‘èç¾Oƒ¢Ç²4Æ–ßÚº‚»ËN¸›n  4À¥£<ŸÈ¨ÀÄÃ¥Ùè%”Rl=uÓµ\È­²r*e¹Õ³5ú$£$ñ<=O&7rù°"Ùre˜z èöýR­7?oû.˜!àÜ^Ùb*µÂüaÁ„YXœý‚:%Êb“–KèäôðäÍ{A·'o~~}ð>f»”?RÀ`Pü3\¯Wh˜Î€’H(:€å‘XJR‚5¾7êŽâøèÇã·'‡ãŸÿëøíGâÍñÛSëù'Çæó½~-Ÿ7t4¼¿Êý—ü‘þ/ýxÉŸþ­Kÿ÷t’=9þ_{»îõŸâç×ÿ¥k%Jo—ù)å´Oi8çSÊ ŸÒ/>ÛSzûTOBðN…·j[ûÖc‹gP™gSMd?‡T(题eÈ­ýÆ«@Qø¶Kùۭì½KCWñÔ ñ¼¼K¼PsQ3¿…Ðä¶ ´¢Í—-¨îª{½P­Æ2HœÀÆ»~hϳi_xÙQ„é ‚ŸZ'5y=.ó³sq–Ö)¶öÝ7-ÈKƒ‹­WAEžŠˆY¦}/µ² ñ»6T9p¯þ»¢´~L—¸¿W!TÑ®²ÂèKÐK BØÿ!¤‡²çX¹alíÛÏm袙7£‹o€î¸Jf©g|ß…¸æŽÆ«¥³`ÞÌUÙxÕ†²“¡¤ù®/ V_uw±ÊÕÒ¬ºQµ±lG N%fø°>JÖ ®zé¤É&ÔÔŸíˆ5‡°×ÖÅ8S\KÝZ™xmæÔ‚hµŽûgõAiy3V `ž—¦e¼jÍh|Á@(ê‡e_sî„gM;²rЖ­«¥BÃÁª %p©¿Àj±SÕ§­É]u iÑ®ñÐŽžñìç \þÕðXæq“¶¡—ŒüÙÞ} éæ»ð]¹¿›¸M}UÏa“ :µu3Rå’ºòÓº½“fDuê¦ó¦µ£Ê¬¤“àóÉ3;·²6°õ®NžnóM˜µcË{^yŸi„ƒW?¼ý%µöšñÞ_:_‚»ÚÞŸ‰#KJ®ƒÖŽ®@$ÔöÐ@ÔÒ#¸xò-‘‚hÇ’’Ðt\z6ð°í¯N»&ƒÙ/Vùrëp ‰ê"[Ž"Š0%ÕU¹òü UêPšH`ñíè-Üœ_e†«ÇÒw·-R4ô þo®3úGäù×Z"±¼ñ–º%¬¥cã÷Ñà…Ì›Wpõ=»Áxtæ`7 ¾w¡6s/ƒ€àèò™ÔIÛ@ÎÙ7æÛ:²¹!®! 31ôFbàù><*„µîåñ¦´Ê;¸:Ùí°“}þÍ‘RĈsœiDGœ›`Û”o?AKàU[¥B˜ò»=ö=89>:þñ[˜óU®,~dÕ´xâ³B³ü|nÅbsɦþ½…ˆ|†½%±¾¸¬êò3P´,ÀšîCPŠýxS¬b¸¡$‡hÔ!‘Gøðx¤%F,Îj ]fõM¼7‚ÏÜ”ÊÀϳ¤U«¹±¾Òk ÂB?sGju;n_­Ëì]„_…8™R¥ÉåšHÝκ«M8·¡|¹QÖäÛu‰£™R&¹÷í®Í}] 8/ïõ@ÞM3Ýiƒæ–Ž•!1tUÐ'Át45ãÜczSñl$8V¡ïÔ©a¼´r»†´F~zÀ×Ùmƒmû—o»8í7kÓ£kñ›„y@Ù ÿn©ƒ5M•ÛXnAÓÛJ'Jz ÁAxb`u)i³‡‚0“^×e"C W+]a¼s°oYa¦%Èù -|ÆJïá8þÚŽUÒÄÊp.Ǿ¢$ýe•ÌaÝÀw*Ž2tVFFœ#^®J@FAhªc‡G1ã¥xñz±³LtCm™»ézmuÕx@æ9'4‚‘@pk(ŠŒ®N“bÀ½ú˜ñâÚFH~ï8vçôÀ½CAØH 9¼@i"Xm~Í0XŠØÞe¸{™ƒZL£+݈ÜH»t;ƒÚL¤a¡i(Kü+– Õ¹IQ¡†Çî‰>£r *•Û6¤yQ|ˆáúÙ ¤ÁÀª7fˆ–gœ¨þF¹ @4šžš°œýä "Ï˨ŒlêŒäA +SwC5ãÅ“zÓmÃ5«Xkm· K™ì†¼dIúY;B¥ÁŽÊ% ™YdVQ5CA$Kæ`¾xCÁù“¸ÊÙ<)uM ©EÃjYï ºJ¬ ‚ý]ž^ÇpApzÔäô6‹[PݬˆÎ ,–ö']ƒkX„AòfUdPîè¥5ßIõ‘“Ï “¢ J­v-Ux •h<ç N$sü¨Øã;B™zÃq2$n(’ÌD?)FSQÆðeª*³ï¸\S¡ üŒÀ*a0´­ÂzØ, |k¢‡Û°Ô°±øµÆ<óŒÆ4•±µú"8Æ2k“À*“î—ÄìèV’1~°åA|¥«å$©¬+3³y³Ã¶"Ø…[q&Þ0 %í6Þï˜ø†,f|:ÁðÚc¬„Q¯nõÌ8øâíñûÓƒãSC_¼}óîõáŸD°Ô­1¾¼< q--¸_ ì1§i¥Ç'Q’¢*ëuÑéÔ‡Zv2Þs…±ùpšÁ¬Ý¾¡¤“‰ó3h(òÂuT7 ‹·“«œc³‘Üa™›¬5±’8¥³ÎÌ…zΙ+X—Ö?R‰ Ýã“eGâD¢SXU𬯵 œªe:GP%®~oõ¥…™²ž³¡Mó‹ /1uwa-‘f½»ælq4¤YÊîvvšË…ó8f]í®{s¤Ú±,Öâe£$ò²Ç[ÊÍ™¹J$æaë(Q\Ò¾ëM»Æ“6·óæ©8Y§¬šܘ3 ßbí½uòf1š«±&ëd£‘X<´“ë!ãi¬ÚÏ¢B_PtËlÀ‡­ÐÉÑíß“RÈ4=÷pwÕh¿ûö›€ý­kǨ¸´É £{"Å@ûîßo†kv K 料wP¯ë~ªÞëµ_vÔ©ui…ÅênâîŽ"òG‘§OÈÑÖ`¢¬è?èÊ ^¶y(õ@t±hÀôtÝŠQ8½EØŒñ¾E1µ¼Ý|f%œœÐ”ÎÂûÞÄ_ýOþE}žÍWÕÅ(VÎæêü&èð$„ÌkÎ ŒŠE÷Øfæ9ªêpœÑ#:§¡Ç¥Ó­½ÍúÐ{Þ3MjZHÚ?u@§ÎÒ¤œîFÓYƯkn´kzVüš.èíÖR®¤»c4o”“‰o‚÷TSΫ yÓçc-é¢YAg—ðŒ¼H–ù+ý½H®›‘í5•uæ4õØ f/Ê* ·‚©,jO ˜v–aªN\ÀÄVË*qhÁÑÖ1lvBæ(Uö+×ÇZ êBøWº¿2ì´Ú´aEé8Và´„ZÏRX¡a¦h™aÈ0‚m ®Ò9 )qˆNÒ ¥xJŒ«Êh‘Ü€ž­R6d„§Ì “–*L‘LI>ª¾ªdJÅ ®+Œw³´:î¦:æÈ™kfX:=Øy^ 6F]éÈÕæh<Ž-þyÞ\gaùG§}”•’Á¸`ѯ"-eµ,rÚ  Ì5î;ÛÞ+¨ô8É`‘¬1ÑÞ§Ö¾ÒÓ?hP›m¡ý;³ÃŸ”ô-ÄõÓÖíj7iWA^Êvxí4éz‹µÙ-Þóˆ~ !&ªþ«s•Öë.ÌØ‚iÆ„èýgªéó.Ïgé¤XàQ-ÓÆvšgÜÖ*£ê¼i7 t b ?[͸÷(eŽÅ ✳õ/âê>w¨õúpÇ2­Úu¬>¬‹ÈŸ–Þ¹×ùâðM‰×ôfYoÚ¨‚wq˜îä€dÑpß°wBªŒ$]¯Ò¦ÛÑ>›¸3¸òŠúvJû•s7Ï_Én²zæR\»Ûl@uY¸—iÞBŠ‚îËQ·¡˜IZuù@B†q‹+m±¹ˆ“h*}½ø‡ƒ¤¾HÊY$SÆ‘a HÕjnž”l‡ß¡À„¸“»ˆº¨“¹¡Ö‘¶Oƒl;ÝÙ:Ÿs’ cëb†8¶‰Dðž‰Ö? Ⱥ_Þh9ôøÚ´oÝ™îZÈæ#¨K¤þÚ¸Øqº\µcÙ뫽n1Gâˆå4þRKí¦R’|`tâKÊpmê¦]p QøBk25žPvgÍuËh³©m/]ô¶Ý‹Ý z±kŸ´{ÊsO?M;`°€2ÝXÚå’Ê j!²·"{ë Òi“_ž{­òMS|[Ò¹aO-¼TØŒµ±ã’=DÒ¿Œ`Uз|èï묽ÆRe-Iùúð›[]†øŽK&Ö½zV ðiôÚº¯VC«Né¦9m¤ó¢E­´®-YÕßjPÙzc4¨mèi'L…W(nöZÿ»ÏC¢ã—⬯íq4QýbßpUtÒÆ{†á9jõÙHHá÷FJqAd܆>%Å´£O¡ÝI¬È;#ðØ‹···Áî¨(Õ}z §ŒÞÀF¹£pBè*8ÍÓYM¬ƒx–€Ø–¥ºIáë±2åŨ½IrE;ëP!¢Ð¤ ­ìJ2a„ÆPТô é¿éÁ4m'[“8œ‡Ë´ Nb2´å£/Ê, FænJhÃFE~W: 8»|-ƒw„§;Aôâä$szµ,Pl$Nöh›—ÕÆ§aê€XTÅU-\›ŒDݼ6ŽOO~>Ä"bÑWX¾:xýþPgÓDzøŽˆûh¶TËK![·àÔ9çT0Þ»l“ªVÌ?Y Õí݆3IL ²X ]€ªRkÜáÉt• <1šA ’â;;i$MÑ ÔÑV‚ÈÊ$]Îüµöð'¢Ì3ŸÞ“3}T¢@ /m½°w©÷ôªg‡úôe]9CõÆ«ÂË!MÀF’NC‡œFXcT´{A°'°ž~ÄF¬aGÞyŠüÏbSä}îÉËtF¢ÌLÀ jö½<=#6LËN˜™Q‚e^è7ÿáàä}ïîìPÆj±Ãgàô`‚È’ó5C¬_«&PÄOv *ª)[¬ZÏ–ܘj¼,“Öìczo·?¢'Gǧcñ$óqC¯4X’£Ä5"g¸g“ÙÓ§÷~ã¯MÔÄnìh­òøÚÅNŽNÿÿü⧃®€‹“Ñ2×€ Ȫ€×› l$·v¯^üøž’s+ûHcdúw!‹\ ác a•+W+‹BNŽv¢Ck±g’]ÇÖ„?bYævnZ6[„€Ï°N?‰L_/DÑùkØ¿2ÂôkUí&€ÙÔâ ©üõ¢Í ÉJ&‰Æ¢‰Íö‘ ÏIùA§°l$!\%7\Q+]ô"°Wv߈»x¿A&’èvGTD› (cç—µ©-J¡›äpÞL"(€â¹à—MÞPö—Í>•X¨ðêÝN„Œµ:zp¹|æÔ•¬®³yZÉXð·xõL¥´—‰Íen{wZJ[npõˆÿ<Ü·ÙmÞ‡ \juƒàßÅ;ñüGŒŸhZ>w*@;t(ß·‚}(ÏÈ€^3(žŸÂvî&ž¤tÆfãÁC_ËC«ËMÀàpE0%u ¾úÝêõªÅk–U5ë)hgh¶„ë 5Ä-k» dAµ.µDFC:¡d†÷nyü—ím¬äáî_¶~Ô£Ìjë¼úKöW:¼‘èTñv=ï.ŸWÃM"ʃ“Ÿ’hˆ@dšòä[ˆY *’B~¢ï~|½Gñ‡˜TÌD\©cÚÒÅG!°Ðå*炟ߛLO( νB*7ÊHf°¯¥‹ \sLë8ƒ¬ê°2p^s¶t›À¡œKÁ•W’L;°”Ò½˜rÇ6o¬ö€.X¦ˆÆ¨?àÇBÙáEÑM_¼¡4íÅ,JÎD1J¡/?y²¸—”#0ûá™›ì_ 5“ôœ¼Êª‹m1œ?0®Ò8Í/³ ݘ—”Qå:º§y ÖXdB¼‚·RF‡ÝHj¸@K_3AÈì2›®àö®Eàpš-»oÐÞ£1NªXˆeí2-çE2…±B /’IY ¦F¦¤Ÿª%‹Í¸57–8jeRv•RßRÿR_à5”Ìë@G{ºM×>ÅÔvôÝéé¾±Â~÷µxB»ø¯±ò[ôCÃ/r…Ä‘ÖgI§?1¡„(²ª%”˜K}µ‡%-‘ÙVüe´CïHp)‡:´)Ñ—®(c ”S+)• ¹ÈkÊ,–Ø&qBŸ ‡ÅÏ›ÿƒø¡oþ‚Þ8ÿWzòà§ ƒ|Ñù?$†·ÈÿÁ>èBj¦•/° @ìBŠÝp,v~j+$bhø³ €¬– L <J•û1OëTu Úû4+TŸfE;h%Ä ð¥AÐe“–ýí6†Ç«hu >{OèÈGNÞi µ—(_)\ŽbËgú2™âŸÄ¢òøóú!½²)†ÊËyG2ôkÞíÙÐÖ¨6=ÚvmA¨€|®ôu ’·fG‡—…£ò–ÄrTßµ1à|õ­ë‰ Ò Š=â<’.–õÍ3‡Ô4M¨Á÷^nE™çžD•” dà&]«ª%ŸYV].’|ì->»l#çq6Ñ‹mZP•k˜·HþÜA—]+ˆød™eíEb£K)èK—ûL†õ‡òÿl™àÍûG:´Ëÿ»;{OöÜüßììÜËÿŸâç•ÿ?ô=¨Ÿt fëž³€ü:Ñ€_ô‰À@ò6‡ЧghYªÿȺܤÚUíç@¡<½– ¨? p?/êO.Vhôb?w d¤°h?‘B‰Zš'#ã]Pú‡þq2<õw;zm<ôG å5>ƒP\ºoæS*šË0ökžk s¾ïž©¤xðŠ»Ïü‚Ž;Øã’ ¤ë\/®j£M¯ c´Ø^c« jÝMŽo;l€Ÿý¼É}ùÈGN{ò¸´Qô7Á~Z«_'ó+ØAãS€{–-½da_õï•\HãIKeaÁ|²óCcÐ-³4sǧi ƒªZët[Š®¾¾É)Çp¬ôLUûÖ ö\EL·ã`•UÛ¶ÕÔ»ƒñÑKÛlÊý¦Y?³‘—óÌFZÍü†1X¬¶³)Z@Þú8½^¦esSŽëª’öÉtZB Ï°§;EQŸÀPlé/(e Ìë ¼’•FN.rºreçéy‚þe/â¼AãÆHŽšf³YZb¶¸P«À®Ô …ÿ|¨à†B›/ Ït8¸œ¥ó,½Ä˸«¢üPÉH«óXN@«³(DGÁš®ªS°¢ŒcÈH4ͦ'G”Æ_¾}¿ õÿT\‰Ú0&–¼|Ó.û'tq*–¦Ôñ6§[o®lq¡³ƒ¡vç6‘2x™&He$Üpkçœnv«‘Ž ¢äo6=±Äß­ú¨°¼Q†¨CözÊ h³c‚¡¦OItê0xÊ“‚såÅ…w÷‚îè+u62¬WµÔb÷wf\~Cû÷ ¼äêÿò"£­Ï£ÿÛy´ó´qÿÿÍ£Ç÷ú¿Oñóêÿ?ôÕÿ©ëÿt fëýŸü:Ñ€_´þÏ@òú?8‚1©ˆà¯ÐµxQÕ[hk_þ\ÜŒ…Ð ¡ûÇÙtkßz ‚yIuË¿6¸?טø¼Óå×f,Ç£YÅé¼’ÑAâG{æE£¢Œß©V~o6møÍJ •®Sœ8Vp©+f†0R%Ìü­8À+FŒ¾8Ä÷QÂi탱oÙ>1ÖCè'‚üÞÚ I( 0ýA‚FÑþÞ#kÈm®y#[OXÉðd&fè<#W²N\ `ÉWíhü ÷ïp@GuX[—EކöÚèL_Ñuò×ÞpP<à† ÊÍjkÙ4ÃúÄ©3›Ýèua$ÎgŽƒÚ»“£7G§G8ÿáèäíñ›ÃãSi/˜åš:Ò¶všUd÷ '¾L²}/†ý+üPþ#kîfÚ!ÿ=yòhÏ•ÿž<¹¿ÿý$?¯ü'ù¡¯ø'á7–þTFÓÙ?NØ-ùio!ø±Iú©c}[ûWÁÝ+ˆw;†,“p©«ŸೌԡÿãÆ3¦¨@ž—Ý·¦Y]$+ñß@S¬Çƒˆ"Õz £böËߣÆ-i£k2ƒ$½ýÜBFs¡þ êQ Œæzµ‡[¼—Ÿ 8ެu-c©ÚNŽªøšâ§P\SU ¤@3¡ ¥_´„o”ÈCåTi‹ï–‹A¶¢¶ÄFXùx×é$[ˆÞÀê4”iPɧÊ/'^@ i!×Í!¨¤åðBÔtQ̧FxO*Εû³Y¸¼àÚm˜?}qéhNP?ÕL˜@}'2]³º`Çè’°Äü• Þñ=ßT£#ÕBp‡ÁP^¶b%I»°|V1š´–*´AgŠzoã,‰ '„Ãý™æ-1ü¹ d å«]t ì9 Íã+ª–¾n)ů–šO+¶²žµÞ)£¾ëžs0¦¶´#’9tŽÌNQPÐ1·­Á’4€™æÃ"e-ùLk¼Â# N,=“(]ƒžeº$_ëb>’`µÂ$³Õ|„áÌ)‚„9ÞŒ@JX|&–ªU)ŽB5)0¿œ%;„½†ÑÀ 1zâGæ«Ü]Ƹ•-;p‘ÁL Pm™1Ú;VÓµVÑðâéÝQ}«Œp}ZÌ4-Ü8N>rX!ÊÑ£ñYdªZ03Ý&'}-0ÞÙA_æ XÍÒ+ã¸OQr‹P³ïŸù Œç¿RLÁbñ¹Îßìˆ3ŸcÿûdïéýùïSü¼ç?É}Ï~ãóŸªÀhÚsþãöEŸÿ4Ž·8ÿQ%cŠ )鯡ãÁ±9®VàC{5ˤVÊíàVKVíÁC–Ä©?îk»óe{ÃÅÒ.Y,û ' V®Qã¨ßÝæ(æ œ»ŸK˜U±Fix9Ïäÿ»Ëÿîñ¿Èí(ŽUXW ±«£¼ŠÍ.x²¢À#nºbê‡)¥£Ž-†G˜÷½ßXCþ4 5ŸS0ÜH™{²ÉzÒq”4mî!z ±`LaØË.![íQ<5ô§±‡ÈM²Bø—õˆÃñꬴXŽF: HîƒgVÐ ˆ4¡âïBdŽ´sú$#…I©ãô6iÙ\6¡§[Ë?%MÛ¨Ø$\Š«Ø‡^\ÉÔÄÙmŠV\· ûm€`mó4?¯/Æ‚˜2Ä|•ÂcŸ,ÞTÙCªC;ñb S?Ñr@‘;dÜ .!*ýËîö¶îÃ_u| æ" `·*Y@uò¯M:[+²_ÐDJܪM PX%\±)TûwÏMÓ}P€*9WДðqÇR©)úû‹è/ôú }Lý•Íû/Š+Qq~cD©ÀMò4¾Ü]··‡£H´á¢²D~¤<üá|gt.?pÌ~þ2ÛÍä—î³õ§‹Ñ…ü$ƒ¸ƒñ{ Ù$Pº…ô'‚k9¬ÌHžHû-EFñ†(ÿ/ˆðd(/m“ê?eˆjAEEî'L ¨O[<\täy¼K™àÓ.ç) ·K<© ãZz¿Ýa<­(„^·K9>ÒaÞ u¼TÊMÓ³Õù9*xÄzËyqÅq›&ÅTúǃ$u¯Ä|=Š¯Ê¢F%_…öØUAy¶Ž ÈÎ\°­àRòKÇDõPiš”ó¬)a².’K©Ð„0õ2¢î›äFlG_AÈ´4EæA$VŠ{UˆÝbáá8ãw![ã<¨IYa¼n4‰åÁBâC^\¡98ÔLX¯kˆXŸ ”>ȘE`Õ¹ª‹EÂÖ¢™ÅUÃR¢C‚qR²Çñ‚|rbsL¹ÿ§ÖiÜÿúÿèþuYê>—ÿ÷Î7Oþß{÷öŸŸäç¿ÿ—üÐÛ@ØÜ@Õ`¶î³à¯ øEk $o¡:K&Æ\ÕÖ¾ùr—.JL: Ê8/Z.¤Å×J Nè‚}%(©|z‡nuÙùq‘;èÀ›=C‘cC¹Ä¼Ò°³WhIìÿÔæø¬Ö˜Š‡5L°ÓññÙÍ/E™ÆûP?2!df³›±Ô~ˆÞ¸¯Eëò†šâLp$Õp_­NúËXÈÅ%žé¹é­}ßÛ¾¨ìypÙkã&Ùkƒ˜þ÷·QËÙÉ=™qºf u“QüšâœfSûtýº(>ȦáäHTnD”H. Cj²íïÍŒÖЅܨ—t¡N¹}:Õé” ëC±‚èNƵ-¹JÒ 8ÊS¸çN–ÅIŽçŠÙØ6ºÂíüã) l¡;džŸC³«eÀЊ(ð%H™9€$10,®ÔHRç¬ûO™~#’#jÄ«—¬NÊ(L(†'8A"y´¡¼>¤r@jÝ4ÞC¼^U7„‹{4 I ´ÒN· ÖñO_ïmµÔæF@|³(õ.† ªhæ9­’¨’اL«b¾BñX{ýü:’§-¢E%|ú»a#k£V´=Áz¿¾[îË\MºdŠå²\”Ë(¾Ø Ý>ß±/ì0NêºÌÎVbˆ”oºÀïà³;iP±±i†æŸ¨È7 ²™6ú ïb^‹¢xÓB_Û+4w¯&­§ÙÀ10‚±Eªkîþ÷çVÂTÏê߯ͽ@£»Ûñ‘™Íný9ç“S H™¬ër…YÃího;wüQ[íÕ¿CõWø‚Fß ªQÍ× &†ø¿ >®Fá2 ÈÁÙð\ìPºjEP@|$«%ÄâÿРɃ?[0é”/Ó¯o!Ò‹ƒÏä—«2U9Úˆ;ÄSY,KX”̤eMÑ,´4@9MŽPú±€Ðäw~`¿ÜÀ¡ 06º! c :ôJ¢Ê´•q3Ud÷µ5ÑCš‘»vû†íÎ@–AxG5¶¬-½¯ÂŇ¾È9Ý’–P¢Ÿ—Ó„tŽÜôW•tIg*`f5Y½žý™GéÃô}LÅû_ã‡ú?²åý\ö_OŸŠ¿þ?÷ú¿Oòóêÿ$?ôUÿIøµª£iî?NØ­ùÓ8ÞFñw#¤ýñ’-û·öíçò¯LSŽÈ…œÀÅI>Áþ¿‚a1ŸCšž´†Ë{wú*ã©[ùÇŽªFy÷M Qp Ÿ Jò¯0JÕx¡èe=ö@¥+|ÕZš;˜9/ZSxµ¡Ì$Nîàø+ç?†4„Ë1â½µ/ÿÚÀ]ßå?ßÕ†iL⛤ӳ4Å \<\ES_ªPY4™¾§¥ˆªÊŒÅÞNAQ²°!•7YÏ+‡º`-çìÆˆ{+t ZêÓÓÖ[‘üÌÆ1b“Û¶ýœ$–Âù@20rõA…ø=‰Ã›ÎÌ8€ƒ\NC3¤Äî £STœúoY¦—˜,²“îõªcÚòè8‘'aÔÈïƒÊ?¦uc¼2Gw/ëã·§âù‡?Ÿ¾gß1.ƒì&ÃØS.nQ~ÇékGW?UOá›Ñ[3„³²»}U½³[¸ÓYX½1+LfU^34Tˆ*+Pè ­H¹D ‡g˜%”YÊq`+Pèa°=XFd´½g&-¬µÓ;lŒ ŸЯY _Íe€ $iÚ´`.WñYu‘ÕÒ /Y`f)Í(’A…ˆKZ±©Œ²º¥Ô[аÄBB>J ë=šâÈËÃW?¿ÆP’ã7‡?¾7•UÍí±g„°Äa°j­± ÝŒvåÀ¦&ˆ8¹« d³X¶ÅÁ4ÚéãÕ蟫ò;æ­»>R*·/zFbQ éSäF²à3¸'I„ÌçLSXbiJ6[ (Ir;kûtC¹­`¤x…S®0è£Q0½ÆK#£&wU,]_CO@§©¬¶i‚™ÜæìF¯M MÌÖL¼e…0}qxôZȵƒ|4¥T­ùð ÄŸ§6þ^l<ïáñ[õ×ïã]\¼ñ»·Gǧ‡'1šu3•‰£üá˜@Zn#+¯ ¡rzò^Ô+# ê¾Ø¡¢e-pÉ‘wP}#‡ùGWµàù¿^ F®Ë$¯>Š +þÛ“ÇFü·§âýîãÇvïÏÿŸâç=ÿ›üÐW`–ÙX`Uâtã0&ø­°ñ¼…n`šNæI)ö-¨MNÇœ[ª_B‡Kˆ“]”ã³dJEª›h|¯Cghñiœå/$cói #”y2-1„*¸¸c‹ÜÛÿ>-üí^s¿Âß‚gh„†ÁÐ4ö Wó„ùÕûí6*áAõWà-‚|ˆÊ~Û ?ô€>f*–˜×«ˆ¢3„ŸÑ¾.{X»z@Ž0ðgÀ‹¦eü×óÄVÔ¤$ã%'^AÂ0Nà1¿hÉÏBó6ÙÀȾ„GÊÁ¼ù.t9€¥8¶ÛE7mAÉÃÊ£ŠKš¯ÖöÌÃÞ0Îç6ü² rųŸ»P 79zqÁÍ7(~=~ÐH×ä7†³4eX²ÒÆ/‚»ca0´m§‘;{ÅF·ÖØÅý}E·8°º*ÅÌC[¡…6¨ƒ¤-9úñAT­b±HªQÉ –à­;b5›êlÿO¾Eqx ÿxÖ ‹–÷ŸÇÿ?´ Ì㯾ÿ*‚% ’I¿CP#*pœÉ¢"´×!€*ŠÜˆ$Çu‘ï+ #–$º®ÒhFÕz¢QQ2Å u˜,¡7§2»L^`_ÃLm~CËôVœœÕ¬üÁÎ[ó;hÅê@Êñ©žÿ„”P-*üdÚäÇ# SMØKà:)†"GR³”´ÿýEp#+ò³4â#β ±£/¹Ë®5­!Lª]ÝÞDp3I&Ù—©aÀI½ù?Nob³7èKHš>Ãdo“t¤ßí/ÉèlÿïøÿüÿÌ×Ãç×Ãï¾>ڃ΢ëÿ^&gÿûÿüòžÏ®¯·¥±g|7ð.· o:à<‰±½/£Æç9R ï‘~LÎ8v¡ŸƒtjZ@n6¸«Á`– úÌœð7e÷3O.w”0Û41Ìh&-¿B±B{ ÄçbÒÊXè*„"G]H±ç>K qüÈoUÝFéëeî§„Ç9N®³VâyR i"¥¸7T£(%Îr5åì«ËL¬l@Žhs>¿ÂäÃ0•„H*G{±ä- …BÁPsr‚KÐ+¢Ò›,i„·Æ îòô¾Ry¥Ã¨¹Ä{~Å]É $îM•sªÜÝéT¦¹ÑŘ€†"Kê*Ò»Cc¶³Œ÷“ó¯* …Ë2ÔŠý’ãèíªpîP´ ѪÕXH¡‹òDÔ/c@kËùD…—ò~"] á—ÛU±ù⽡÷Ó"üéoêS?w¥ªž‚¤!þË,QʲAÿ;åÃb.2Q¯}¡Ü¤#KWjUïmÒ{ë½Ûèûš~D¹·m¤ ôÙ­x'‡™xÓ©è1fà¤*&"]Ùs£B§²?RÐúË4TØGR§ÅB>wk'BÖEè–«ÀàУØ:Ü^«ñpr 1â®`ßþ5 iÏvƒç9õl ƒ€j2wâxk6òK„7†N}„YÓ‚ë×5Ú&Ä“™ Õ* B-} f² Áu±”o »ÊVïÌwÆ„¥……c©®ÃÀÿä·<È‹üá™×g³ÉùPŸõŠ2£ áÊ8© ”ØS† ÍÓÄb£}8RbAlñ¬€`‚ða+ ÷©Ï[ÞÌÆâàã:äÀÏÑz• )P%„ŬLÅtq¯ ŽÉ¾p¶޲˜­7±8_›@SziR'd]ð}-Ž^˜˜.*„ÄS¢«4ø¶)Ù¡¢ñ'9°ŒÈky±Ž"ôÆ ‚/ÓI ™î(Çú2³lluµ‹N{Î r(äL“NºD2„m•-2qN„³ÚeýÜ ]+úæÈWh!æÆÉ51/.Lêëºm$Ô@ø@ÂÏ3N¼B ¼˜X=(‚… *uÖîQ1‚bÅ·· 1äPË0š\÷yXÔòˆ‹‹™f=ÍW‹øïñ»ƒ“ƒñÁë×Q¶%–oƇzqøît|úöóQ¼¿=~ýçø·–àñ¼˜l”H»‘¾2q¤‹XÉq¹¾ø§´a¹ÿmþÃóÿU )L?—ÿ÷Þ“½fþ{ÿïOòóžÿ%?ô=þKøOÿª£iÏÙŸ?NØ}ò×8ÞâàO;é˜êÚÚ·]@U0àÒ´Þ‰Øé«Oü¶@f¨±€5¯…Œ÷Œf@°U2l…• ‹®2Œz/¯‰Ü÷Bt_¥û¦ú0•‡ˆ@c8À4Ëó×çɼ¾Ñí‰siã%Æo¼¨Èwv2/å[ÆLǹþ.H,îmãÄôì24î”çîH”Ó«Ê¿œoÇì—ÉGÛüÿ­Óþ÷›Ýo»ûÿÎî}þ¯OòóÛÿ?ô¶üàÍm~±´lÑgç+¾Là‹ÞíÁÛXõ.“ñÔRs$ÿ²d+ FFÀôw[˜È6`ÅyÑ/Bó1Ô,æ*ÿõC·î@1xuÿ "æ™X9ǯsß´önšæUíXÁ"”[gi'2kEͳÆZ”°1ßt#Eax¬çV„˜ËNüáÜ(`=öC %'Etó¹-æ ÷M+jHŠ¥Ÿ En5‡ÁxÑÞ]s㡵“¿¬ÒR±>ÜÊ(ܘÓ~ƒ0 …-¹oí¿2éÿ¶ÌÔÈA&n>Ok̪2ŠÏV(Úb4¢ZQæ_Ñ\ŒˆBF¬ÔŒ¬ÓÿC{Ñï5\h cR‰— —Hx¢¾‡h¤˜¶(©ôC!$酪Žsݾzwðõ»ÒYQ¤É*ƦœîÙdXÏæÖ)~{©z2Šÿo0PUÒСӧÒÅÆ}È4 Ai†{°tïÓaz¿ImgÔ&­„-Ú^E|‡ÓÝd]¦)Y÷£i\'—¼ ‹qfÛš ™áÈuÚ1(_8žÆÍ‚+H^Eêb S‚ƒOcm2“O£Nʉ.—Uìáà—!Ú€B#V ªVl”ÉŽTŒî¹p"‹~>>zõçQ|tüþôàøÅá(þñðøðäàõÑœ½=Å889:8>%ôŽ^Ÿ½8x­¬ê»ùDä¤#Ã…ŽH.ciá%À"B.¨`¨"²È$n´FØÓÂÜBÂ~£&´+ddz8N sXæ4e©¼½“yÉ8×–ND6MÓ%å|‚9/iPmÛ¹¿°Ôó4ܬ48Çæ)‹¢–v‡pÇéÆZ×^0ŒÒ·Ú‚s“OÝOQ9EÍ‘“rupÃ&€þëxë*Œ't± "eL¨âA±|þ\¬‡'§CíTEÛxgkEQ|e®çåáëÃÓCUOÇø«zxùyóîí‰X¶N¿aÚÑÌÀ¤öWÌ`âíøè¥Ø ÒùÔ\hؤۼ’õ•,ðDG;[è¬ìžŠL뙌F7¿‰d2 k Ý#E`$m0Ÿ»ÛZb†J2 õ " T ±~”ýãÁɱ8~ôOvZ@£ë³ì\E•2\ÞðÊ8|U…$/Éèþ Œ«Õù9&É+oЖ›wÐÞG¦ MÝOå–˜…Aa”ë.ȶvMJr ªUj ˜ÈYUg²Ö… Úa£¤ªŠI†Ñ%Uuù>•캥d¨¢¥q—x«¸ºHÑ<.‹K´£V¼ ÔÎ}|óˆÔEZ¶:yÏXíGqËV9(S˜KÙe:Ü”!ÝÅ‘\e`U‰>ÇŽ"…XÄ(¬£4M¿üúí ñ ¨èÑ`žül7´d #Îâ+Fæ-üÅŸ^þðóR¤¡8_S4‡Þ£xÁñ®r’}°oÕÓnUË)¢ö¥HîKI‰Î%+Áõ%ÈISå‰@!JE Í÷'í5Çsöêa&Óˆ–5?4h°Ú‚ƒv-yz%}Ä $#åÆ4U?ní@²%€Œ£yñ[Ι0ëÛœ¶Ú–qbÃ㡇âäqð®ÚËŽ[}¬E§»Z“~²2¦¥§Ñ)‰yOË·Üå'Ò­b%ʘÏw}W *“IŒŠ"TÁ¶=”josX‹­Ýµÿ=ËÑÓ´š”ÙR¦­ZW'h©{–m«%}¬³<X­·8:*To,˜[.0”„ÂXc:â¼.Á{¬¯èiVÀý Ž7V4lcbq8Ð }éDz—“!5õlšÉ±¦"Qü g¾ÂÈ*ናnoH¨Rö*Ga ý&qÍ|ˆr‰LMÉîd€Ú¥.€}4eª·yö!%olTÉ NìÄQ%Ø¡ô-ä¥V+×ËG])žœ¯„¨%Ø5ªÚ(;/oI¾éxÆ<Û²Z¦ñ¶öŽPéIÒN¡/Ø.ìdh¬¬2kÑ*+àV[¡°¦TWð䪯à¥Â"ùN©±Þ¥%Þ/‚&Jyjœ¢fõáªFÑ,ÉJ;£ƒ0Q–E¡ßÛýÛŽ?‹=õe Û"Ë¥A¥Á>¤0Õ\Ä àIJhcB¿ä#_ä5„/OQÁ6DSñààÅ0ž­rdWå |@ÞÚSð(Å´i7±Ô tÓÅA_û‰1?x¡J®.2HyÊEýÑY2WVIi±¿ð¦¹ˆnp@mXŒÜ›•þãþÐþ#¹œãnýyò?ÞÝ}ÚÈÿ½óèÞþãSü¼öŠúÚ€¨ÛèÌÖ=ö òëD~Ñv!’·° µŒqGªÑŸkløNJQ‚¥¿[€1Ê)ÁâŸ- B&@ñG·Êœúï¶n×ébœÔcé`Ã8oÛP± vàs e¨a¼ë‡¦à¬)5 µôpž”pd'X~h‡°÷  ˜,ˆúu÷‚M?õß-}Èë —OmýƒBR>µu^À²•öÝÆDñçÔ÷Á SˆÕo©½wÞ‚Ìz‚Á!£Aä‘aÌI8+æÛÅòJÕxÀ(rXc†xMÊŒbecaÑ8û} v‡ñŽ3®•[<6tq"MwKˆóô,Ž{Ø*u§r%Äù‹l>-Áá-›Í ¸PÆ‹BœvÅáEˆ¦Ó)N…Ù>P‡é*˜Ï9eŽž‰:Q^]sVŠR N$‚àÛ6ÁC‰=‰5Iv&(p“4]X^ò-‘Ý!ŒNÉ€·bg™XJ•òEßâ³ N˜TÏZX’ÌH,L*U ”c è 4ÃɈ|¬‚º îçëÃ÷ïǧ?ˆÓ7s€Š~<9<8=<Á/Û2U¼9“9ï¹YJ·ÍdO¥ýftS¸ ÏnÖb“i±‚£®i§Dv–¾D{+£îÎöNüü÷\0îÎ(r§\ÂÎȲœ2õP–hlƒZ ¡*ˆºµÂ¹RB«¦õ+¹P¹ &Ó u,°Xïå–£rÎñF“4ƒ8ZhãA¼|¸ÛäС«’¨Âäd³ž!ãA 36Сw´» %¤p$Œ5”èÿêKþ“Ðx“bnwÄå=†Áî6 þ¡¥?wí1ë¯PÊc&ŽìM¤”óþYzžå9Þ²Ûœ'™Ô»s{f戮̴v â^WtçÉKl €áD¤AIãêÌ>`¸TãYiÝùâÎÌq-¦±˜Ä×8…Ghª £¨É^̼›(-¸sÖÈ«†f U«ÏW²ãTüOÃPÌ"˜†ñîŽ]lg{—Va‹`t€ ±|í1+u~@€«Ú'£>}„'£„éѶҤåàD| µL¹;s¸Ê3êêQ#£dÍDˆù ¼»4ݲ†Ʋ»8xì¬CW›Ù‚øÙÍw¸/Ù„‡ÓÛIñ­±„ÏÓËÔ‹ôŽš26c}LsKIFlž‚òÚRfðǹ=~ËCgÁ|²‹üÆèltihõ-¤s_˜Hú?ˆåPl~-ˆá•ñ~ŸLä"*ǯ¢a«(L$‡!¯Ò¤„Éß#E>ÜsRW œÒ PTg:¤cÔµ>hði>‚‹¼à…®ñ1¾À`»Ë}%¢·ŽU]”d ¥¦=¾¦;#Éh#ZÅÄð‰¹"o!£(ýÞ¤ŽqsTs,ëW«årž¥Ú•ØG„)™N‹¢eºÙ»ïq¼Ã]îÊ=îro(dÉ0øâfŒÜ÷`¹;ŠïDß}-²to"ØŒ«3 TrÜî-%1h>$Éå©ÔÚ !󊡸Ú.·Å2ѪžÑ‡9ˆ¢/k&ü¡{ZVJ8’’éïoô¾ÞÿÁdçê“ý³;ÿçî7üO»;÷ù??ÉÏ{ÿ§ù¡ï .±ñ  Q…ÕÏ ú<1@¿è[@ËÛDƒájTjçEàŽElÑnÁƫnÄy±†¯SQK5áŽWžž{’Nm¼Æ¥W²v þtMG;Q­Tì*öæŸt©ðô†±/ib-’òC!„¿çxˆÂ$äÁÍç=(¸ð˜Ãf Ñ,š®Ðþÿ'ùyå?⇾²Ao,÷qqÕ¨GÞÃOù¢å<‰ámL½–Ë4ŸŽ¡¦­}ã!dÅ4Ï– ¬þ €þm‘,wÅ(À?!kœ²:‚dÎÕ6ßuA(ñ1Gs%΋v“,€°ì±ä‹Äö±½ˆØ‹ùeʽ1Ÿz"³‚@¨ì8õRÍ.œ§5 #c ï¡£·ö}oChV5HwQú#V™m²éÖ¾ùÔUÔu}$Šö‹ÔdP *ç¾ ¡‹´:ÐßaÄ(/P6­1õ´6b㳤Ž÷u ’¹¤ o=Ê¿º"hë±%æ¼|P‘Añ©ðàÕHȧ "å‡1¥ßªÆI5ÿ@ªù6Œàõbî"i¿ê‰h6»á¬ÇvT¡‹ SÚhÒÊsÙAýw³RÕƒ›O=P)– ùg…B­ÀêÏhž^q..༞®iåâBÖã¨(?!'õ.д-Æll_ÍwA“QÞ˜Ú€®¯ŠÿèFÈÜ®:w*ÕY§ïÝ–f®[Úõµ^ƒõß}Èoyk ÏY¾\Õú9„ijgòË? ¿ªeðWw v?½^ áR†rQçE )þ(ˆeÿGÍÀE½[C±5K „ÂôC°³œ}Dö×x ŠeÙö)ì!ÜTæ¼Z§ÃLæ<æµQtÝ÷:„Ä¥d3ùWX¢,fb[ÊÏ1ò¢ñîp3oSHv5.ÿ ¶ƒÄ_ümwÓ{Íq‚&ËDký5Ü1Ü’.ÑžaÙ×t½q j.ën“8q®ì®Å”=¥(êÝžù¤Öp›Ð¥§V3f]áÓßSJ÷p—íévu"™É¿ó ùFݧ«`<>°¿ìàõÎáœx‘ÜPBÉ3#Z]Ôó“’Ï‹üœ¬.Ä4.±'?Ÿ€×h€0RxíC‚ÅØj&ðÙOœ÷:oS—¬æè%©¦éfV1È`ªu¨¦ÚÙ’T}Æ`&D€çL+MCÓl.ˆy{ ó5·MæÙö|‡<“x𖢫S3=U´k$¤‡êɵ¼fGtµÈêŠ3Ñ60Ó¢©wD,…\=»–”µ[Zþe{‡ä÷»žÝP±¯†„ØÞ!ÈK¶“ôiyã¶m´Ö¹ëïÑ#ì³`ÙeK|˨SšeÓ ÜêQÞ:êû3Ôlt¤!Uy»ã@Ò ªøx7=Ô™¶‰¦ åí£¡™—ð²zWýuGë} f¿ºc¡ÜN«|g>ð®Û.ãlä'†ü>hÚ‘oÂÈ*ýT¼Äò®Ù¨>Á´ÙŒJ¨Ïn0 ùÈÖ¢~­žKº`ôÁöYƒÍ¸îU¥6TUÂW=9"Rô ¼óMdn´ZÍÑ\®*Ðâ]ðѤLHç>„›æ£—hhoXë6¼×ÚðR_i¦Ó  ňƬ&€CH[‡èñÈø»à-ñÊ´âÎ;ä玴æ¬1¸ü%6Áºk#åTIÅ) Â[!Ê_8‹Ü¬^V,~$9…* ‡sŒ0487¡­ÑëÓ^ ¿»È[†¼ÈñÕƒk¨°ü”—ß›ÄÚxɆ:.øMn_hmjfæË‚L`¥yéÐ+F¹g„‹(‰B’U˜B”L¿÷ô­O·nÝ£-§eSglZ­×¶Ù8Öa¶ÞÖ2ò…ÑêÝ1VºmöÂRÃ:bÀ ŒlšbŒx)^&‚ÿïHÜÈU‹‘ÊìÈ‹µžÌYYI—§FN'­–ñãßqMA­QÌãÉ›‹3ä ìvU„Ê¢Úõ|ß3¾ï©ï!Ѝþñ¤ïˆŸ¤d.þ&Y.³ê9@(øŠ¾eñÌh˃H,åñfD£Ç•/sœ¼©•€‡_*úm¤ðc³³à^Ÿ“Ûõ:‰é‚/*SØ'MtIJ'E>eïiJE±w+e ›¯0&€<:>¿9:Å[[6ÚÑû:)Ñ…§òT nÐf¿u°?Œ·þ àöžÒ?߈¶··cÌ{›j©êAB¼è|ø&—I6Ñ)®„<–ª ò$ƒl¦åßpÈËÏÀ€Ðgß¹ñì â(^ñ«a¶bWxt§(ìnÆ †._[zyY}÷uÈëÙf·—Êuèwg¯¨ft×$´§¡8.?›"ÄÑžäY«O?£8ÙºÑZúÕºîY2™ K„Š«+j²zä»2 ô® Úu$2/ê¼+œ¸£C¢(*…é˜ÀÑ2òšŒºü õIgišs”Gƒ»FÙ\ú& nÊ´ë²:M¿ÆUžKê®õ8ºz`ØrAká9‹ãB1};Ž‘à“9¯Ù'EÝU}ÝåõÝØQ!墎ÁÌx~™NšPÌçê®Tvê膀áÍjî2|híÔQ€M2ýîwÒÿhÄ!Âp àžeS©ygç³p¦bËÓn-vÛ7q¾mË„öÒð*0=¶b~6hÞõ‚eµ`Œmõåíœ ÂQ‡Ï-º‹ÿÜzÑF”•ݹ)¾fÅ÷,#ºÿÅ+޳²HnÎR:}›w¶}—w5A´¿~ÎV36A’ÐX¼@“ÍêŒEØ©˜a¼"‚ÙÃ+ÔÒ¿|¢X£-‘Ó¿¦¨äï…ÅØíBIܧ‘¡ž¶ÎMÆ1:ï‹ÚP@6âÁsúX§fµ|Ëc_¢… w—ôP½± £¼³Íiw-™»yƒµÃ…eµämÆ‚èË pÕ-Õ%ˆ^c!ì»eŠäí+½CqõOâÍ•bAȨãs™m[iŒ¥²¢×ÿþüÚêtÇ=¼ðÜÄÜ Ieµk«‡¿¶~~m~Ââxêž~FR}zð ¿+¼ÞÄð‡6H#ÆÄ¡þøÝϧãÿüùýé(–¿¯ÄïHLˆ[¾üøöàµS~½ ^ÿ¹½eú Ž^¼x}ðóû£WV%ëUðöÝízðÃÁ‹ÿ¿<|óö¥®fý ~>>:µHj®UÁñáÇïÿü懷¯7ìÁáŸÞ¿Í¿ U@Û%W0LôPÖC(œüy|rø¾»÷‡üôçw‡'vùõ*øÙ-½n¯^œ¾=éWÐï€ñú—+øÓŸèª`hõàÝÁÉA;'ªÛ? XÁ«?Yu¬_ÁÑm+=0ëX«†?<­›9ONÞ¾{ûþèl0™pI²¦²ìÂ{Ô„b,œx~ÄŠöTöU ApÁÈè±âë£wF0*0p0Ù(V¬è_³‚7‡'?¶Ò µÈ?4VUw /oüŒÀ5ü|ü_ÇoÿxŒµ5ˆó×Yr6¿ÁÈUÑ_Ãoú`õ¬‘BDÞœÆC ÷#l‘€'j²é3~D}=q(ÔoßüÖlܼJ0ZwÂ’! &·m\€ø›aú>”6*çOP¯}ü|†4Æóüˆ«#ÖWŒ¨K5h³Fpã8²ŽÂÄ8Æ­Î3ëqO®y¬§=ì]¤©&qL›X2ŠÿiáBŽß`BRx²»½þŽñ€èDú ÿ¦žÍ«šÕš”`ZЋߘ&G?1¹ÙáÅoñŠL yàÈàaZWòb@ÎÑn-áæPåæíªÒ_VÚi@Ç÷¼ÈSŒp©ç)”¤(r¡P³¸€žrD7û Ž}„ú€ß@Ax1ÓKìãèe…ÑŒäð£T¯„~а$s†lG0Ÿï½ÀÿéèÿM¦ßͼ#þϓǻ\ÿïGîãÿ|’Ÿ×ÿ›ù¡¯8ƒoì.Ëëv=>àôm"¾h/p…â-ÜÀ±Ž]&WÈ]›LšË”´ÒmM>·‚‹Ž¢ä{ ÷MØqªÎ&®$gt›²Þôu²Kê‚H«Ëç®›} õ2›^ „¶ö·q;’ƒâU8ÑGS¦ªuÎÝ›A>ˆšH7€´Á?˜aˆn~Èà>ã=Ñ<½c0Àñeâ˜×¼_¦“LH{ËU¹„ÀBVV2æZÊì&Þ°È@Âî‘nP2aqÂñ%›•äBŠ€¸”2(®”,TÚˆ²FꚊ¹džýU*f?å —Ñå×mlùÂÙ¦מ%Ç@ó–ïŠË†tÛeH´e!¥Qøj©m%“I!vOÒª6º£'g¸;¦GwªÕÚ™­æz”ÖëÏ#·7­Êx]°ÒûF{gˆ7:‡%Ö¥Ù¯=ÁÆzÔÉæ–ÊVw©âñ`õ’I…cpGÖ]ÕÒŒ[pR^K»n_Ðñ¦X}5Ÿëóì•8èDDïwÉ'úÍw2¢ÆšSïKjûçv§9jù 2†Õб§°¨-Ù©pž-˜|U’§>.:~{JúП_œ¾=ÅoOŽO_ŽâׇŸÞ_Ÿè¿O^ãQB>þðöô'ÓÊÐ]b½ë¡åb@9xqg,–:„i '‹nlP~ó¬×’]Cf€º¹|³Gh¿»uú;³K´@bTgö9ö7/´lŸñúm&ýЫ®Q׺5ÖÝM.@”ˆx‹ìN~”ÿq2Ir±È|–ü;5ÏOߟÿ>ÉÏŸÿQòCïü²ÀæùU fë¾üüu¢¿è³ äm‚‚MÆX áôSà„iÞÆv±æ»@áÙ¤Ý"Šá·ŠÔ`uÁ»› ò%ì¿gmu™äð«” iÓ:x«F@½àxøñ"ð8ªB&e™X#¯bt~Ãdšüå¤5¡m Ç­ç“ËÁÐÌΠ~i%_étZ(ñB´oñ²í4þNüùæÀÄ_˜ùZÐùê ³œe'UÚ9»°ãŸßDähw“ód)p„oïÿüF|ãôÞˆ$ˆ>KÑ ›’Mˆ3Åâî_@¢äaÂ$ßpÛ6ößã±¥(1ýý,ÓIÓ•%µh-ˆ/ÏîFHy  ¦µ¦â¼‚~ âœs¡ÆO¥‡£«Ùr ¶–óªÃ%?¤¢9ñSZÅ@~5š`ÏÊÀc1ºÊĘŸ¥~£ølU“CãGJ¥’4C¢¢vs÷L5oŒƒÜ:Áu‘Ç¥÷ªäuNñ€5WÄHSÌDH*Nèí(=ÀÇEGAºj ùdà‚\ÕD Wâˆt>²ÍØÅ\JgâPq‡£AÆÆÁ¤(€–G›¸Šû®\bŽðŒœæà.…²ÜàlB£ùÁPçÖ(ÄtÌàb >›G[µdùý’ékÿëïûƒÄ–×\}6Ìy¢wL-ýæŒx]ª‹Õ…8Óþ,14+ ÁÓù^W¶Ðj Q1x·’¾4pŇä†T| Ú@Ïå$¿â‚œªŽ~ÅÕ 4SÙì&Vlåp„`µ^`âM» MÑþ‘£þ×nt|Ya–ÎyV×ó5–0´iIÁ@-î…5CPSãIÝ;•Édž”¨3…ƪ´ãÊàÅ`8”ƼÉDý…fBÝ^ž¦S©‹TmrÝëÔ©õ›Q KôÁa=¶tßÆÑ£mßq€[· °÷ÇuÚ½Š·Ö[ÒŒb˜^Hu«Ô¢ x•(ŒrÌÏGQ’WWœ¹9‰Y¥%0ô+ýv$Ë〡¾µ€U‹EðtïÓÂP·Î³©­§û–Õ€`ßÃg&¬WŹgÀ”ºa<~Ó‰ žÌâç¬^‚]R‹ÿ¯÷ć[ }=y`ä¬{£xÐÕ¥a bÊHôlÿe Tˆýûsü8dŸ”pgƒ­«”n Ä-ëÿûÿä[C2ý¿ÍÉw ÿMüâ¹Ymæ²l EÅ Røõ¥¯€3q´Nâ¤~[²6Ü+G}ÄbÅò’fð%„)À±U‰‰Ð Õ8JdkBýÐ2Uy°×²#óÖq{“2ä©ÿ&"î¿pL3´ÍédvœÀãjuV™M… ‘¥š[ (`S”ÌÇ‚Õ&¶ÛçÁ²um¢dΦ¨c.¯ëP< XR`Np°2åË/."’”ú:VŒo±=ªž9…ZÆäÛ^’:W¢1 ‰Ž°åþy¤|›k^ŠŸ¢ÚÑËÃãÓ£¯ÝÞõôoá¾·Êê•ò¡¿LJQ•§1ëgÎO¾9{„@ºÔ]»Gcuôˆâ°ÒÈã€x;¥ §åëW“y¿ÙìôäçC^|âêcK]#±A\ázEŽPy¬$%È@ŽfgEQðpsÅfh´ Lci9ŒÀ3B÷*0?iÕG™.à›RÚ¥95`¤Y0R‹f…$æÃ}‰Ûˆâì2ï¥E?É #ÃÍÌ}¼.¢¹®ýüZ[ÿ>ùýÙv÷4°gx< PÑsâP ‘Ò µ¡Á4âÞhL“é3‰#¥0zQONzr­S÷ÞÅœ¿KC¾ˆlZ‘;@šá{µŽç‹ë<1ñž”T8¤®§Ö¤ –ù)m¯Ó8¬Ð‘Úg 'z1Š#Õ¾àäÃËO°xe¤# Qî\gZØ:%*âôQU«E v¸¡µ¯oö%E»òðó d¿ø² å8 4">ìܱPÇ+öäÓ^¼~hHkWp)âØ:Úo×^+y,Žóßÿ^ f¶ØõK@Ór›Þ#ÿ×¥ÅJp# Ǣ䵠 D¼•UÜÁ9Æ/+@åMQáöÚ²6½ënÞMiCÛtÓK•Øa¢Q›åa:ey•‚Gï X>.6ÊÓÓaŒi @¿yøúðôp%M¢yÙ×ì™Ò{%k-ÚÓˆ5ãÜ,‹¼ÊÎ2 ¿+›ÂÏRöÇaËv½5"i•#¹i‘UÇ“U .Ýâ¬I:…¬ ªp0ܲ"9v^€˜ Ÿ,£{DZ‘U¾Š¶Œjj©¤6À¸ÅŽÁúAœÔŸêÁRƒ6Þ‚Š,²¢ükµ0¹—« &–}Ì=ݰu§ª)[ìr“ç¦S>ÓôAÜ[– ŽÒr•ÒNÿÜ(,ô†v\+™aVJòXëøžA° A+зb Õìl™p›¯–ÉXÏ+ЫËR¬Ü¥Ø#Öc.¸4)iýzÖ|?O0Vo×áÚÝ™fÕ¤Ìäªð’ž¨C1×bçÁº;ÜÆ ‚ ¶€q“Éåˆc-¬on%%^ *@jô¯MÞãiãÜÅLHd/ ¶©E¾8q°æ G1šÇ-(gÂŽ¯ààðR¬*Õ6¦cò´·2ïA?‘ÌIÊ…¬ ›µ’C·£?ÂÑeW¾;QزJÓ¼¨Ié!UËà&#%]*#írå[£e¶¡•<‘’1éÚOO÷ûŸ\Õa ï;œŠÖM’ây þ×âീŽMLm~dÑ ÖIôÜœ$ºe:*ù†ÆlwoËûhÿ;Òôü³Åy´÷è±aÿûã¿ì=½·ÿý?¯ý/óC_ó_ߨúW–×ízléÛD}Ñ–¿ Å[þž¥sq6€ÿ†œô ‘1êL™¨ô5 C]g œ¦[ûž—╯¸çeö۔0õ*à“2¸´]éS–гî$Ó¾úŸo¾"=pª•]Ò ˜ßØSC (­ŒTF¯e: ¯õEÊ NLÒî å9éÂc„øVj>uÁ“(«#Žæ¶{2ÞÚÔ‚ýH¢³kZYxÇÞç¢æôè|f«|B! -#ˆ±¨²’WÎäe–GpȈû1/ùM9ÍXç} hç,;õN1êùyÚ#<6E`DN£rœ(9“øº»¡–K­¹· ¨ÀK>©²ŠÏòñ,½Š]æ¢É”ôvx°ÎÆféÆ¦Ú¾?Ûãÿ)¾øR`—ü÷ÍŽëÿõøÉÓ{ùïSüñÿ ~èÐ(t‹X€f-nO¼q5ÄÄ.ðEˈ¢·9•6Èc]ëÖ¾ÿ}@¾Ë*«¬õ IÃb@V 6߆݌z"S…° E dqÉ®Âó²Ù³ <¡B¼†Y´š«{ zÂÙá¯jУä̸ C¹ùÛ;p¥÷ @sÎ(n¾’fpò²E@6Þ= ¤¾÷£ÊN¥ †ÒÍô ˜ŽÃHyºE1Lh'»b/«Z ¢,˜^Ô¦Èj²¡ÿšµ 饦jüN“÷c“Ð?ó²xÔÏ& ,䛼Èáå]!±YÔ2kûŠ]†ò_v¶šÍÒò3Åÿzòøé®«ÿ{úôɽü÷)~^ùOñC_ÙOØXîÓ5˜­{ä=ùu¢¿h9Ï@ò6a Hl2…ÔiPáÖ¾ó"$Õ‰OìÙ¨þl;F–O˜ÚÀ¯¡ wû¿#,‘„ ÒC[32e¥ñÐŽVº Ýø‰”K›‚í]'·Xõg;1Mʤ•”˜ïl^L>˜§7·rÒwùÆÝ¤ˆü±ˆú²ÙÔ/ÕXcèS#>0 ²x×R_‹¿±ú®ë•ø ·æ `Š{z „pW hΕ3¤5 (ý20$Ï~mkª-¿ªЗ,ÄDÁÊàs¸ªÙâ-@e>i©¨úk=„76UºG?üüj|øöU<à”ñÃXù’kõç‡.¸DëHx8 "Üõ“´¢¨WŠA1 -p[ã n ¬¶8Ù©'ž¬ûuæLÔgkÊv4M`žÈb¹¿#IY&7d”„=ªÚ»tÝÁ,×wÎ-ÒGñ…M=hïø Qì8v›É^#L›©TÉ14Xªþu‹mSq­ bôŽƒ]lÄnpÕbø‚€[Éü†,SÓ³Õù9qÙ&GCúÑÇ= Ñ>‚TdïþûN»A‚¶¿Ã¬ãÏ=#б¹§ˆ»¤³Ç30d;`#d<æŠî‰²ñ,9!N?”êQ¸èÊ 6>kàJ,ƒÏ ÓS ¯ AhHÁ=O^Û"þüQÍrØ62{ü—¸”Àó_ gßÏfÿñX<5òÿ|óÍýùïSü¼ç?懾§?ßøì'Ëëv=ç>ú6‘@_ô™O¡x‹Ÿ2’)º.ní7^ŽØü˜Ò>3½ù)PR%#ØÖ¾ús =µ\ekðwkç0ÉŸ„Ƈ;ÑÄ{ˆÖúQ©ØìtBçĈ¶ÄÄYÈ}U¥XHHiêaËV쎪i4Ð5D“Œn¯Iª!X…JÄn1@[]Ó‰¼¯µ,*±'9‘A°2¢÷Jg[mÌÂQ¹u6ñkB1$˜QÚp@&H"ûzJ¥Cé%Á&üª ØJ[ˆ£¹th-Þ´Äæ"ø÷® Þ‰èà=ƒ·ÆCLÿøÏsöðZ,™ ƒW<—ãd¾¼G"õ|–Brù®<›v»&'ú® ÝxàZËÿ0&ð]×T(Ôkö¿1ÝFqPü÷€¤4ÉØâ@@E+<^Ê ÅÁAFðŠ¿ƒ Ëòé 8´Ö²L'©8gOR™ 8dœyÑÁ.9¾ûAðôßß ÂŒÞâONOƧ?CÞÏ÷ïùOÈ ©§N€û3ÝHº—Uïˆv–ëÐ?ìvE}Ù \ 6VDÿ=ÆGl~²/”ð‹öù!ïkužÅéöù¶8©=4ŠÏŸïlGï¥o±8'Êœ›¦÷ó3ñB¾ˆñžrâ-®P_D#ì†fÇEÑKgñ¥’¼´Âô["Ž*ª Ú|Èãû\äEùï­Þ¶®ÆÂÑ>Æþ!nYGp i­³êŽ&´VJb¯½½Ù¸+æ"«p¢×bÒOŠó’&ýI w£àUŽøoyòă×'ïÞGÆ<þWÈb!ht{_'õªŠ¢àûá6I´¯¤W—ô‡gw ‘f¨ÜÓ¢B@Úï‡uñ²ãUX]4¨ÒTùÏOD½Þn>×öàºÎ•Œ8Ô)2½ÌU«;9(†Þú¬Ž4+µ(èVú+µxɃ‚L¥`n½l­Ç_†j´!ø„75ön×ÚðÞ'ª§rO㸠uQ'óo£œçðNöBsïkžcz’\Àþƒ\RIîRÿžä­’›+µ}R‚²}¢ó®}&È'—3¨€¼ÛF.(KVÿ>†%ýd‹Íbÿ×o‡z|âë`#„ºü,T^pXÅ8Ú‹Û‹N¾Ä ®Ø–íñÝôJÆÔÜY¡óZVýæ­/°ž@füæðô§·Fè¼×žw>8A~çÆ¼3ÏÑÿj–BÿÅðKúm´ëÿïzì¾Ù¹ÿòI~þø/’zG€‘6£j0[÷ÅᯠøEëü $o£ñkê$èÁÅ…",=¶êÈ«zü‹Øt¥>œCh A€©þ­}÷M·öw2OVU2×U8/:\¤ç•ÆžºÐ²”Ø|ÀÌG5þ¨ì—U’׳µ¯ÿîƒlQ¥SWó¹UP”©¸ÿgëu  1g/t«æS @™Îqv[dò¼ì²iX¥÷¼íB?û55°O¡{…8Œ‰ÿt¡ÆZ?ŠÍ}P]Þ̸˜Éb ë{ßn]°½šó"ŒôÙ ¢}2´kÁ­jżêF}º‚dîðßv´*@C þßX·¤Ðs?„®¦²ÂÁês^QÏ“E:Næóñ¦Õ€sàìyÝY JLãŸ=Оf•mãC šEò!µÉæ¾iG\œ)ªÔ‡ºû¡ùtNa(Óq™žeùµüž—!‚PúT5~ösúùÜ7‚ÕêLN¶½¬ÆI]—ÙÙª†5´ý{¿«K!ˆA\Ê s|è…¼•ÕØx(œ§ç8Ÿþ #,VÌl€»¸ýÜ!I$KAú‹^~ä›jЄUã)„N>¸ä!GUàH)¹+Ñ^ rúöBȪ r.…OÍ> _Cħ%å–'Ž_Vz™)(Õ¡I€cÝ1{¦×„î‡LhM(žSl¡Àj¹%c«cR5ˆÑ$žƒt¢mAКD%ïä =‚ˆy*Ó­I^Ì‹)ÞÛp¼Ñé³ø(^$Ó¥Kí«Ò=Ä‘$yXÃÚ f" tÏЗ Kó©•òÜ’c7`G£ü-Vž¦ðé5ÏqÁÖoñ¤ô÷˜TðfXbÖå FÚ fk†L ßsEÉd‚~ê yñ>´È–äÖΕ›‡ÛdR¿ñ[¸Äúx¿,8’­d;Ì×EjÈ OC*TV¬›ûÞ‡†Ï5­O·Œ 6\·1‡Ü‹äÄ:GOµYÝÊêä%ا/½äÇó&!(Šy*6ÅCÚP ­4å$~ÀÞd!!à® Ç 6ýeq­‘‘£ôfÚeXEÕÓ ƒ˜ ýðáÃŒÂÀuWì©XhpL8QÀÜÕj?ÅKÑ…Um@Àà‹úßžŒ"h†2þà—£W¯àKËŠDztw\V9)§zͰfPÛ2YŠMñ:ƒ”‰FÄ Q,9»©é¶d¢CQ&d¾Ð¨ŽÖ»uG°`{r0ñ"¹î°ä«ËŽåà­©OL±d„Wrx„°6 5Æ eNõ,„η9¹ˆŽÌu9â²hl—ÛN1 Ë•!a&g$u:vFñî(Þ‹···cc«ºH,Ñ(®•`F2’t”‘iösÄ·ž@,±•?Zgs’4ºªxâ¿äSˆ‘Ž~”r Úz®¡| •‚‹e­NKÁ9%º^Êš¿–t†tjbp&NžIÅ x_à315!Ö_Š*®ºb×$™ ×Kzƒ48Ó?›È7À+X,!ªû°ÙU¥ë.È>û §ôí¯¦r~ó ­«íD(½æßIÛi½MÃ_¸³«ŠäOÙ+Ùc×Z±i…]\9˜kG^øº;ñ­*(Yr£àœ­™cÛk›lRõ¢ xné8ÿr1³»rg7´y'pKjuÝŽÚFEÿ Ô6» ‰É ͰInçÆÁ¿ƒX@*ÃH/£ERã$¨zÏ0Ò8ç]NÒ*e¹¦×b ‚TáBh€;›Jq‘ZÎ5.æ¡ÖO–4¯M@ƒ*(¯]ÐÖÑ+¬JÙr›$°Š62 ,0£”åÔq»%D®ù¼‚ühh«.ú°äà_  UÛu§°o2ü´1@ú,»es¥àŠMÎAS‰ç 8S·Û¦ÿoè÷h) —é)hqEçŽ ä|žNh6/”;ÁLKæÒ´Óªã\T<Âb7.Rs9¯êÍú9ÐK#£a–GjÑÌÔâ+Ž¥¹$‹¨‹Ì¦+Ê  µu u/6Ø,ì*úÌ6Љ±~éËXúléç0Ç–È'„Y ëË.Æ‘CÖÄ jò}Ú!Éõ$¥]uiyüJm’ºaЖ¥X™aÙŽÒG° : ô¤`燸3L5ªë)É•Å\ã@­é×¶V*¬ÐÃ݆/žß¾©•þ ø» –Ë +õìdi¨ôÍ‚fúDÃ!R ‹9;pÎä÷Dž+Ììí•>c@Œ™’‰6Ø\ˆB쀸­*„fDN²ª]49m‹©à¹ØÛP«Cу²Å³‚ a@­)ÐI}2>‚#e6=¯5¢ß #-e*E Bz-ÈŠN^oO¬‹Í»¢ÜG¿ÉcÓ¥ÍzwÖKx«þ5l޼µu‹ÓXÓØgÒ¸•¬ßgAbiÞ:‹°¸j¨ ƒÙšæ:›"`iî Qé¢ij³A·©h/žô>ÚÅlÒp>Û`*“¼âSŸ¢¨¨ Xƒrñ6™ÓÉpp|üjÚ ñ¯ãEQÒtÁ>¹, (V€ ÉS¼A­è`s–¦ ©—Ï 0A—b¿¾Ö°ã·§tŠ„*U`­…Ãf¼ZÆÉ9܂Ԩ_Õ –jèߌ«ÜgÅó¢˜BjyøŒè’ òÏâçF6BÓ8i0~ÇÙØ1ÚÛtözŠË¯„01¯/}ÄŒ›Ö-@wËМ²£ñ‹·Çÿùóñ È< jì—Gïåãýå`þ.Ó ÈI_ÌB¾’×0Ü xgÁ4¹y5§ÜãG¯^U6ãÜžo ‹¯F£ë 6ò¥íÁE/qùV[Þ2¼Ùqœí5¶¹Iý¨ „ v•¢Œ¼µý?ùE,œ ©æb¤³¢ÞµúD›L¹šn‡¤Q ‘Hø9^ê¯ì,¦Ö­^¥Œc¿ÕNrTÅôRº©îVå¢ûÜðýðŠE.ØÛø¹XÑ`¶êã’8MÝ«l¶tÀG΋C6Ô¥wiu¢¨]ZÊ| Ò V!µZS…ÔèçGS!¼ ¼ËöV¼pDhkÝ…îË&HŽp¨.¯ïl/´¡-(5@2Ž®¿ÝöƵð÷ÒÏZ×–ÂAi¤¥¨L—ód’‚,g/áÊÚÁÎeµÀ‹B ëëh Ä‹-‘™ Q!_}+åˆe€!JGòŠ*Áý,ñ´îÈòÿ7ý 6Äœ:Ö‰Wt€yRHÑ•R9ÿ¡Ö$˜'Ø„Be(oe&=µvƒOÁlfhÄã‹°Iµl`§+# ËèÜTaÌî½´¸D’“l&)ÆcjwêHÌ–yåÐà|Ħ‰˜·Ê0DT{ˆ©MC=5dw‘Ì%%AÕ`ZUš'™œˆg2NÀcϤÄɆ íoÅ[¡ëŒýA‰Ó"ŠãƒÓ·oƯޞ¼y¾3“&üΛü„´ ¿Äñþ¥ŽÞ¼“oß¼ûáÏü÷Áë×ü×៎ޟ¾Ç‡ßÈZ­™eFvîA®y9… ët£B?j‚RÞÈËÁK¼náÞºè„8‚H¾ûLŸÓƒ›°ÆÙ´²jI?/ò‡ÈN]¾UBöW€©z¸"£’¹C!°Ü­ž1°JùC¬7¬V9™ˆõ[ÓM3§LdðÌR}õ…1Ú:Dˆ¡)pc„ ~…X$“² n”y—Àd™åç׃Ù0Žâ¿÷q|Ÿ?WlÿÇÄø‚ö‰/;CU"˜•Øu0CÇÞ:þµb–Üÿîî‡ñ_¦Y5)³ÅÕG Óÿ}çÑn#þûΓûøïŸäçÿ¢ù¡o]bã0FV<1`Ôç‰úEG1±¼E®f|•ͧà3I犂æKìNÓqÔ‚,S±§—érü9µXß•±²Ó*‡wìJÚü¨jé­Å÷VUŽÖàÅ-¡CHâÇ>$[-§xQèyÙ‹HWV óea®¤«¯·P_/y5H}¼á,G¾dÐeQ‘ý[ÑbZ¯o{@¯í6àü^‹”òâàÕí|.øÕ•Ì{CWd¿2ЙˆÅè—UZÞi ë½ ½6xp”ʼnTádŽ&ªÛ¢¸,ã%΃–"É´Ú©H𕢍…X+~q¸"úƒeÙG‚š…Œþ{ Â`8‚!ì ‘;F´aàÌÝŽÿSª°2ÎþS÷b‚2ŒEè}pžæ`vA^í„Æ{П_¿6µ£Nã<ó|rFõqû|×`ÙÔ‡’ åå`ÆŠó"â<¼ºäÜRp°ÅX*ø—\°ºÔ ­ÁÝHL„Êrš x§‹ŒB-Và° ³h³ D4  ó4¡ë¥ÈÃÌ¿2±Í:ïmR?ÚuNDbÇuæ!î.+›K1®dv~Æœÿ³Z«¢„Ö%2‡óM‰Zn;zŸ¦“±ßÎ5†È(÷¬îEž ïlù"wèD¯QŒÒN±t]åm޼JK¸Í,–ÏŸ¿?<9Ƙ“yž‚7¾yøúðôp6¯‹¯9aËúÓŽJ#ú!½!òþÍ~žQ$%ô½v$‚¥à6º„›rš$p­€Dç°ÖCbÿì§ÍdØîœuƒNSh©@D2Ö1Ô6_¡ai-Ëô2;ï 9õx ø„°6g&¼Ï“"Ì&Ó^×ÚÚ— kt}È\uû<˜ŸÝéAvæ#{=ø%î€%‚gœïlt¥ÑB¿±uåáöÓˆ6ÜW?¢ýDsô6R§›ÇçÛäÅ|Ù\®´´hŒìÔApPÆØ‘íhj¹Ã¥ŒÑ$)§*øЛ¤ž\ »ÑÊD¾]Zô†´·b™Ì`ƒ©îsWÞáõöHö³ÄÞùf÷É“füç{ýß'ùyõŠúªÿTµº³uîO~hÀ/Zóg y›øÏs¸bÇšÆE™oí»o$,–|kßó2P|QTõ˜}DAë1¤³*ª±·ÕÀ‡n•ž‰ª40´ ߺ„âx%dbݙƫ@Ñ<=çE¾‚aª°ç¥]¼7:P… ¼ FrÍ`l‡6ÆûTêýF)AMëÍÈp³ä0NžÝrb[/»Q’Y¯Bh€ û¹„õF¡GÄÆd󚈹`ÒÐM`"sBœ$H)7q¶úø'QŽ?}ïï€føÎNHÐM:l×ÞbÕÎNØÝuÀË^nN‹%Úý{€¹'â8§€ùed‡{@Z,ø}ˆƒuºÔÁ~0øZÏ@\··‰ŸMŒwôÏɽæ'L/‘m%¬1•¬ CžñªmÐÖ³*ºäÈ. ÷/q/Îó?÷è;ÚùÉ}0RÙ©¤RE0Vs6HÕL–§ÊgÖ$-1ÛÁn6,Á%ÔÅ\Æ òKžj³Áø*ï]Ñq¬¬`䨑õ#l®*}ž·Ëm‰`›w“ÊKª_¤Ée–*v¤dY–ŠC;ÊyM*n[ˆðöÞiaÿ`ÿ£+ôܦ¹!h‘-V #"•¬:6æŠíØÜå}ýôz;5ˆ·Ö˜K©BM¾·úãlÑÎXP={ÂÐý:âl²þ†Údø¬Y÷"ø•êµzm»¤øÍgŠúã.µ›(ŒãÓmt?|‚C5”ì;Åë*V:œb BÏ"}¯¡ù'ùQþ¯4³ç£)€:ô?}ó¸aÿõôѽþçSüüù¿?ôN¦JlžLWauÀ—L~ž _´ÈÄòj ®fÅÏ+ÿ1?ôþ|cÉO–×ízd>ú6‘@_´´§P¼Íßr9¿cM[ûÆC@jÂoVZÿ¼u)? ¯^äÜBãUøÖÅlÊzìq“§ñk¿p ?ã}  h‘jõu ½‡Ì›/md@¯n‡Ö» @ŒP\Ì|ê&um™”É¢˜ÊñâÇ6©Ø)×|×5h³yrn <Š@l}§¹Æ« ü,®:œû 4’ýMTWy6»a\eÈxÝ£l·³E6OÐŒ[w°®ÎjŒWÅ[ŠObä+†#Z>c¦ÉŠ„ì­m/ÎÓoоQIJø¾Ÿ‰!êC¬1¬û莒yk•`Š‹S¡W½Ýk$L”ïfPÞöž,˜æð¨Š}­ÄiösÓïÝÆü1ÿ–ì°þÝQ%^Ð׌=$0à,î<t£ŒÞÈt%pqhµm^´†Uïa!¾N÷í£OÇ€èóOǨ÷fMÎ[in#|{I¸9 p£öœ%Ý{=d‚´ÊÙÒ½ jÁÜ’Ge]›°©½ëαd#Òz¶>oC ¸iµ­ŠßÃeVÉŽ4¾cC+a%mߟ¬ÿu†ýïx‘UE Ðeÿ»³ëÚÿ>~òhçþüÿ)~-ö¿ÌëÙs¡[ÚËZÜží bbø¢u¢·ÐL0/%gÔ‡ÏÀWÚêAÎ&¶Øô½TAŽf²¤ù4"Ö6*F›Þ×݇g£«ãìo‰ÕwxÑÕk€3º Á3÷re™ ë˜Èš´u{\õíråô9¬Ôø A¤˜ÔxuãX“Û‚'X’G>9¬±.:è€LØý.© ´ô8›Ú—/ ógBõ™f+qüŸb;ÈfÙ$©ARÂ@Õ*NÜÜDnî*i þÔgïè¥ibÔàµ é© 8ð[›ª~ÓEŸåvôrÿMu#Õë~cg1 ˆ–¢{/¸Ï*dvAóZ˜¦˜\Õ"7@Ǭ°üŠ›Œì7sá¼–ˆL ×LŒ¡DÓ³JäÖ[C0 ÷6ñª‰cƒÄ~œõÚµ.çûj±MÏdRˆ„ÚÎýªoÎày)L€--‡Hpê7¢9Ö»EˆqáUôÜ9™‚¥¯rê}:õ‚ÚC6½²¤ŒÎá‰ïaØlœ+c7m{€¹âÀ4[¤C(†’†àÞòâ*NÎDítfû‚i›M·/Lzgî&tåeù—ä¡=Ëeðx}ç°¾§E/³ÙíefÈ?ûÙ¡¯d:lÉ ™“mÜ[ ˜hÂŽ £$³‡vyeÀ5F¾ø¼ˆ ñwê#ŠÆ¾Þrô*ËE¡›…ŸèîEV¡êÅIäŒä!k{HZÚ¯oE«>RâU¹Ï é­кÞ6o%–×geAH%Wž'd×\ƒ½µl¼onÙ«C÷j›ûß­¨ÿ‘‚Ëç±ÿýæé7{Íø÷ö¿ŸäçÕÿh~è«üÑ%6ÖüUXðè|Ôç‰úEk{L,o¥êI NÜoнó" (…•ˆÇ(Øx(ª¾éʯLA–Èü†Æ.ðq]ýVç<‰XóeWþt"S¥µÙ}ñx»WÞ‡t4Ý„ì*V%nåéÜà'ß=¢Ô’ŒˆÄO< &—¢9 ee¤'„ÐIB™çHr¨â¸XébY”IyÃùú0€L ¾>W†¦ƒ˜x S€ù_]¤SѦ þÒçv0Ê–8¶`ôA¤7Ö¡ÐsU.¯eäá©¡Ó­ÕÝ+G[î&]ÀšZ§ïŽöÁYVæR›ÆD±£ýˆås¼±¥ŒkÆÑ?Žò>ÇEà@‰ÝÑT%Šge[;‰<ç ui´–ÕAoÒçžgë¦=<,ì=o5à0ìgY jRãN¿Ù ] ìVKûx ÒínÎŽÊcÆ/“ùŠ"'R/!¬$%náä/âe¤BžQâ\Èì‹éçi)ð%$7‰ÿ²oooÇùÃÝ¿Ž "М‚#íLùsõâT0‹&ÅJ„ ¤$j‚ZGÖ_¼Ž<–ë¸w𨻘Ñ|’“-6Èu“í®©AlUköÐâNyh´ŋ>Ô4KlFYO_P:èh]ÀÜÁHViýO=ŽïöÛÃj곪‹’‚Èa'¸ï@`Yf—IŽYù>x]â„2M•¼n¥òR¼€½}Š(œeçvµQVmM%\íé0ÒG)c$$*Px3»6Ì1*³‚WEYǃUµÅd¼ûQF‚º XAA<Ú# ;.l¢u—.BUv–y$Z0¤™ÆÕ è4*éÉ“¿ M®@üý½‡L‡pÛ ÷DÁSµºó-T2¿Jn*LÎUǰ—Õñÿ—˜No •Õy:/Â’Z44Vø M¦Ìs©V¿©,0ïÆ?·Í[tEÃñЛ´T-¨ÿѶwS©ók×ÿôm"¾hmBñ¶þ?ìÐpübqÐÈæ*«> à‰vŒ†¶[ûÆC|•O ²¼ïÁ¸é§¾ž>MŸNïFIh¥ËPo‚9r.oœ‰ö3ð"&ªbN\•½&.{!d %§ê–ùö*¢Ñ\¶¤ Ò;6còoí{_÷±¨Â.Á¥Ø2ÉJÔeÙoÝ'9ñDÎÕeç€"6›‹ÿèF$],ë‡&ÍwAézrÆRâŸq?Ɇ›Ë7ß…ÑÁ¼Á<ÀÖc7j< 4/YÏm(õSçŒ7çûm4Œ¼Œ­¥â!ç«®ÃU·QX¨…2Žîd¥µÈòõ‚ðßÞ;Šëµ§×ËyÂñ·ÍóKc  )Ûb.Š$â ¢Ž] [%ÝÁ²Ñj®»ë“þó9˜Q¶ÆÖ:ïÂÃ̰™gÒVÚ’·*3Hžˆ“<$eMVà¥Æ Àh ú6”ƒW‰ƒÝ„õ…ƒzˆ6N0g³|•VA,'!RÂßPn¸Ý°Z“¿%¦Àg©N%cû“ŒÐoôÑ*ÏSHÆ™”7ñUQ~g.4ÿ!^fiÌ<»¼HžCØÑò/ /¥[@”s2‰‡10WF:ÝÈ èYbÅÂL˜ãœR¦,ÿÍü¦j¢ët ‘¥b^#ßÂá{·dñ½ÏÂã°‰¶,ªÍ˜ù}ØM’Ø–Bôó¸ c¥ÒõØE2zXœ(ƌ̛ŠnqüMç3鮵¨ˆdõ&³o«dé$Å[Ô_X©"Ágâé&®.Ä#›ä^Á¡ão{¨«7°">ÐQc@Æ&}à .!ƒTn RÆç«E/Úû5†>yë?o:Û }º‚€WMiù²²l°ir²tUÙLÍÂP[Ϥ«ß§Rtj»âY§×ªBÖÀ^]ó4¦‰ZQM¾¼9†TÛ†“ûìIf°'9ÃŒ}ôñÓÅéžKÿ|°Î Á T©QºÕ•Þ©ß:¶Ý>o·c£©÷:§ÁƒºlɮŶY—}/§€½{vñ^.Ì]½ƒhƒÚƒC4¨V`f«y/"Úz§™bA'TšSʳ)Mب€¡UN7é#Â87Dn%X›« ¬EEÊð69ß²·5haþ’!ÿqØŒ.·Ä:®r[&m;™?\®Ê%Pû4!… X)/þ^z_æ=°¼œta¹ÙV¨î°õ\Ò⎃§éµèe?.¿œ #mßÞåžófhÚ1àÊ\,1”Ýë(“÷ïÜñ ó¨Vì‹®}íÛ—ïeÿµ»ŸT¡s­!S,[Å þêïáºòCGÿÖ•–‚ƒÑrCw·)ÌÙ@õÖ§ûòNØ&àGUå˜3š–šœ+¼wä{\eà3cÕ9¦ÒË;  “ÊN£ KÝ$­Ðe:)¦xKÜ)é–”p’Ì{šÁ%;Šç¢™Ê‹ûØsŽv°ïuãß¹yˆšÆ™è\0£<§tTìU ›­ÎpŽ[’G¨{ŽJ…Çt9ñ`‘ÜÀñu>’M’9Râ8}!´\UåБ/T)D ±Ðêl¼z ¦¾²ˆ±öX¡˜b8pŽèðF˜=»”÷ëyC~gLº7#9]´)ÎßòÈ.d!Bal¤,(à”+8Œ£ ìB,зbÎø’óä™Xu'Fðôˆ…ÁâMúT汜Eïê€ßîFމ~×¥+ Ê2VM·•«‰Ð –ÎúŠô!ÒÆ%#ËŽtál#Þ2Á⦗”Ê[u2ŠJ*bÌŽÝÇ•šQÀ"*m“ÜÛÀ®Aðo.v TY#ÊùcAbX$Ó”]d©K,7ãq°@S’"¢ ÉWñYzžå9ž gºm2ö Í@t¦~™2udùò…ˆÂ¶”¼²³£èŸeºke1~|«XIõmùˆp“H‰D—bô"qVÖ=¼ÿÃÁÉñÏo—ÃxÿyüæàOâù½¡“¶=ÉdR, ÷Ðf±‰dû‰æhKLÀd‘VZ'FˆüĹÉk€‹â ™«JÛq0²|û´ØÖ¹¨å¢gVI¸km²sM‡«zo;œÚoÝY§bÅyoU)h˜ët .­TšÞi6Ã%Iiê*$,&tc² ƒÂ pÖƒt?ª(.Ä6l¬`÷0Ñ;û€îõï+a{(Ÿtk»ñ­½{wW¯¹Á‰Z!é½.!DžA ßÀb gBX*a%ü±7 uÞÇÔ,D¬G (t×ø¸£FìªS# ‰öl˜òiP?(=- 7Âòl°…©ÈjÌY+¸èíýO¾åԘΫ4X¼*©*}VÒ¼YC¯é†²Yêׄ"˜ ‚__~S5z,{k,»v/ûZ* ¬ì_JŽÒol5§e„€ƒWfðÂn¬@Wfá¶ò;Ò´DÝ3?™V¯¿ÚÍÞ*üŽÖRª}!¯+Þkaa}Æ8´ß™DLý g¯0ƒí°hm\ÝWýnïwo¥íÃK]±s‹³ó:Š>ÇøÃe=u¥Öä¯Ïâ ½äÀw¿‰ÿ‹ Ë݇{H™nŸ(‘ÍQŠ6Òb " êoLWèJŒyÐÙØ³(rÊÀVÞ:™Åp2í„Zžø ܨ{úNyjwzÚGÒ‘t3ê•«ùeŸ‰kyxÂÊa`á·XÍë ô6å3µ¹‰: ;BXªi“‰³y§üÑ–#™ãæúÌ®þài°¡ Q×oσCG«ÀШùú ¹Ý: q–¿B\Á³ #Pm2ªà¸8°öÈæmÎHóÕB0ëñÛñÁëSÁ ;¼ÙˆßÁ x§Ÿ_¼}óÞØÂÌoñÏ¢¡q2Hç˜jåÙ&¶íVš9q$›cvÏr09ùîÇ×û>ß}-ži{HÄðm$§­Î ]ì9§ Y3>‚»¨eÈÇ)¢yq.–‰ø”Þ•8£&un#’,IÏ-Ž[GàðQ¯ZœH=Žà‡1MKÞ”sÔRï£Ù¿Am£šüGÐ5Lp‘ªÍòŠa~Ž>¤é²ŠiÔ { >y£ÓŒ3÷¬<|ø0ôgŠ“ÆS³vš^딪êˆD~D½Ûs"6 N6æ”FZ+8Xˆ&eʦC|®¢›&þCÒIò½ >YFv]ÆË}à BJ% û ¡’¼†ÕᓞzÃc.š¸G#ÛŸç R·£¨,eãp&ÃÙ;"(åd¨SÌõâ% aë"ö_Ñ…ü(äB"ŸÔlƒ¥ ä5ghã ÆN$EFQèê/#Ó­b°s!:ˆÓÂhòx‹ü-J‹¦ N‘8)ìL» gÄJÌü»,ÓÚ9¹ªe`%´fug’f賸ƒÌÅÀ›5%Ó"j¨ fÚ8è$*”ÒU¥q-f‘ ôŒôl@t¸åb_.öãܤÈ&‡/Âõ¶A†@ãÒCÍ•HK9ñí¾øM3¥s¯©É‰”úuO¬ùôĢ*˜tÖ¸Ž ªˆæ¢sÈqåè´ÄÄ6\½ºq¼ûYšJEɌёs­k㞦‚æb& >{_ ^Ó›£ŒóSŽ¥(C—Beu'I“°îøáFWy0‚pžNú<}»7ãB®›CFhšE‹EÑ”÷åòp0¯Š‘hï”U–Úñ’qË·@ôöƒà&)îÔôgÊ #4öB @LðÕ¤ˆ*…î6 Ä÷ˆ†JÌ KL» WqRÕ§t–`"œM2èšTóÇòŠGÕ&±ãàeœê âAô1­“yö+µž”%8ÚÁ¹*H½pЊòиI`ƒ;ª‡hãÎ#ÛŒ0#†-ǹ(ê¿¡ ¢7³™gó7¦62ÜÍptb9¨u(58דѴqÙ6Tܑצ(tN Uc›ØfáÆž,oEEÑzåƒ:ˆ©8ü„ Áø€=E«êî xÁ•­Î™“&®Û?DK?¥£$3]$—v1¥ü°W®ò‡8Fœ¼<·-¢†xÑ›Àbix¡&ÓX°®²êÂr}½"¢Ë>L Zž8­:‚ªié„/| ù "“^©M\Y‚’Á2®Mlüi,m•JÎ-óU+Êô²AÙDâ«NžÉ„DÚÊMç¶gƒŽp‡æíS,‘ˆ&"G’¾Xà°{‚Læ\Vóüûè0Áp Ô9 C)€Åöiœ/ÄY™½¬sH]'Vp“Äa›ÖA"1(`ß4_ŽÈbýg#¿È@·ü@ž†¿WW ÛÑÛ™dÑ÷ D‚«âýX–Eq'brɵžd2GˆƒU>­DëîúŸ˜'H.ólåGEhû9pP‘†ÀhžåB8ƒBØòësåëkl¹2«¶&âJ,ëÂ5‰ÔšJöÅ…¬@´ñ“}—)ûv….fÔ‰‹6=è9©6I4IÒÏWbÑYU‘ÔU n,uÊò:íÜýs ÑÈHzs £HÇ#½sºc—w«b1·¯Vy Þ—¯’›íè —!FHNÊ茾+l0åÔ&6‹\A%@˜3\ Óf 0‚(Æp©ñÅAR™ qYàñŠ1 ´.oø`¿H–µ ‚[š{$Ã? ;àC” æCV5LèŒL{š…!z™1áÀÃÚ ôT‚›xcž¸Ü—´¤c< ÞJ·C7ðiÅÚÌHpŠè†º…ir[’[XìPÒMcØw·‡÷Q ïèÿ_,Éã#Eh÷ÿßûæ›ÇnüÇGß<~rïÿÿ)~^ÿÅ}#¨ÇÐ5˜­{âȯ øEÇ0¼E4¾2òx˜C,¢l ®MB¤ØÚ·Ÿ…¨Oãiº[ |"Ī1Må˜x>ª‚$X8Lþ¥ÃõSY;‹­}ã¡ Eø½ÿ›%bëeLÝ×í“B¢RXòsµº22E‚Öso4E1±±[ÈêW}P¦¸q0æ·!„/Ó’@çÙ"Ôr^´£ŒpÊüÜåÚjÔzlCUÄ3Æþê–cžpa€ÿlGÖ¨Þ@ÙzÛ8Å"“1YåßýQ¶ÇØû­ aVÁx #®8ÒÊA$§Y…fž5bk¿åcˆ ä§ÆË~¡‹½n™:¡]»ÝnôH/ãÇ.ü­rV “îâ‘çI`>u#­Ëy^vùÏžíMcNNb|õgZ\¥æxßÛN4Í-Ï÷¶'¢²Yc÷uêÄêÏ6Ô>zëDãÀ퉉k<¬‰œ½¶ô£4âc®΋64kšï­]Áz1Ešö3‘Œ´8Œ_Nh¥“«/¶ŒT§{QHI[×z–€.HЄstGcÆ*0%¯w…}ϦҳnÎÞÁéä¢%„•¯ðöàË?DþDÓ(¼‘Âë7PóÔÊ (>zHË–Y!ý@ÎwöG ‡*~³¨…³ªˆ~KÀ‰îgÓ.‰šÁ–›¤3y°€N‘‘ryÜŠºV&§~qk¢ÚÆ'%­-¥yí -˜sä*%æäN7‰I><¬}¸+&زL+8ÏÁÖ›FÎé–°Ç@ j‘´¢ãš±TÝÿ‡h“’ÿ:c•xBŠ›‰žÚD*/MZJ´x°·É6ÞfÂZZ±…·^µ43Dp­¶ëkîÑÞ{am¶Á¥Þ„}%MÓÉ<)%sx^¢A…azsý‡¶Äñî…hZn‰¶ðZloo‡ÄXÃôwÏQád èè³,ª*C›0 á!÷“ °88À-ã†DeeUsUlwÄ~jîÎûn?z¯Wèž3´1ÚÑ£m«M¬1¯õ”ñÈÐ36¹aĵ™\Ñr¡éÕná[·î¢ñl˜fe?WbFæ7hÄ[‘)é+ÚFßÑ6*v$sŒÎR1œlGý½¯{½çÇÒ†úHZœe‡h¢¾7ÉÑÆÈ/l.ˆ,{È Ì'‹ºÔ3tŸƒ«œRvR®únŒÿ›Öi©•ÞPå¦Joûö*ÔsëXãÃÀ®¯ŸêÃj©Õou’lè;HÑG’ñÕQ€Ó»Ñr¸wG~-‡ Õ¦åÀ¾öÖrŠvgú×| ]ƒÁb>WÞÜæ”¯ÆFÚXßÄϟǧ'?y\¸M²87LÀÈIãØª ^¼HËÏë(¬$`ÿàêj×$Æ7¹mCöjKØ‹­Š³²$#y§8£Y÷+ ÞFæá®-äºh(›4æÐ@ýh8,-ÈXw€’!ÖÝ5bAùžb †nûªTT Œ†Xáb¡96‡A å™>òôÓÎRBÅÛõÝÐJm€ø–é`öµÖ.“Èݯcá͹ÑAGùèß ýf]u÷Û¬ ë½e™TQ´Œ)¼K·!ÕNbh{²•‹-kú2-ÁV¶b7JJã¡L#K1ù+hƒ1ÏQê(‡èo9 yKôi)ä10Á…éCì‰"¦Úe…$Zºit·™%\^½>øñ}ìüvwv, w'o:ÞŸžÿè€ÐF±¤+ò#µÑqùV›ãyë[yæÄWxöú6>¢Å _éCØ·| cK`ôyFÏhl=eW9j–¡ã äÆR(#ÞDìm&=ùefIYy²%X)3"åãI&ØÒ;£\ù꜕´DÈdÅT=ÕNކJYPIˆ©¼¹µÇ8ä V°ñ–|·%+Ã}'Q? cè”_¡7úˆ¸›•†hc¡T #±Î~.ÇfŠ+ý„¬£ŸbNÀaQ@†òüæŠæìZQw‹sq¸YˆqÙÅ1ä u$iͽÝ`­zRNH ë£yFë‡t•ßMrõQѹƒA62_ßý?®šÅì3ùì<~ºkä|ºƒþîó?~’Ÿ×ÿCñC_ÿU`cÿ]ƒÙºÇÿC~hÀ/ÚÿÃ@òþ¸pÃ:´ šŽWKˆ€ñ°…­ýn˜€Õfz½h®Æ| ™yÂ7–ßÈ]sk¿ù.P¸LI3.Û³Ÿ{˜ÚËÄέ(ð!ÐsˆY“V5tYÓÐ÷¶•Ûk.뼸…kŸáö[ÌuPJ$üÛ/Î ì¶(“+yÁÍvH††…Ú´ÿÇ”uÍ$!aLNé©ÌY’Y ™ƒtR†Hoó­¿w&ŒÝ¥£Gøô`¹H–~=Áñ‘#¡táS¯t*¿‚~¦Lç7 Ž ´Ä% 4¬ÖC°x•ËpÅÑBz9ö!÷Eôd‰‡!P½ù‡C˜|W̧¨*Ëer”¢–9f†—J"•Ïð!$Rƒ ž e Q~‘1*XEÇ·Ï·Gqüôiüp?þnïÑèñ¾86$2î3¦bYæ=Š}ìRòÙãú‚<ÖE‘,g’cL6x³÷HIns&›Xë_Ì)j†®ŸI…­Sˆ™‰ £Šõç„'^‚Ý„ÉhŽ%ë0zÀ¬ ÑY7ˆþ%Á§OñAvO,ß²éÖ~Z,a¯›°Í T˜»+“j8`ÝýïZpúd«À&[C4ÑÛ¬„îkþPþ¯êéXÙïþ Ð!ÿï=ÞÛsäÿÇO¾¹÷ÿþ$?¯üoñCß3€Uhãs€]‹ÛÏyÀ„˜Ø¾èsƒèmÎóbÞ\OùÏv·.1I9Õ÷öÞ×a±‚1{j } W4/À ófžŽUl"D#ø©q:è!Jkêøvrõ¹Åò#@5ïöç…m©;LNÿj¼½…½wó!pO›lÁΊð…lßí‡ûÿY’çiù±ÔûÿîîWÿ÷ø›{ýß'ùy÷É}·~ ¿ñ®¯*0šöìõüq¢À¾è^ãx‹Í,â©*ØõSp[ŽÜ\¨2êES-µ~ÊîU`§Ò xÁ›”çyMÿ@<\’ù­a›+=vÓ²â»4ôÛ'm%ÇÔ ï¤€S¬ÍèZÚÓõ/írÜn´i鹂2\Ô6_ó½Ü8O¯æbè»ú£ª„еé†GX=Áî·Îûíÿëò2ýL÷ß-¦p¬’×Ä…$„îÜ. d.þUïöøÝŸ Õ=(ä#sRõa}˜ÕBúzŽ0«’¼ð.d"?Ž>€èΗòõ2äC…²]4&‰Îš$ƒ=É«º¶ ïƒN7Ò¼O©z9C i‚UÂËí8>a<8¡³ÒGà†‹|2'[LN¾ï°{š9œ5=Eó=ÎLœÕ2“9ä˘gË¥5ó´ìÑ1H¬Az- 8wFJè®÷bÙ'%%Rà-³a¦MTk»âj_"66-XV=–“UÛZ"Î>œ-¸‚Ô?yíYRú®'?‹½÷!%x@›XßÊb ¡±0€ÜþæÎ™ì‰<&¯Ÿ_oG’11áÔ~·œ¿™vÆ8ûhõ çêƒ-]·*…tH°a‚Â×G§ã÷‡¯_œ½=¿=>5Þ¾9øÓÑ›ƒ×ͯ_c^B£eýndÁ2¢ýiÿ|2¤Æ•˜%É3L±€Ÿ”àŸT^ ü$Eü´Ê!R™M(·FŒtät‰÷Ê©ù£ûŸzõÑ.þ­Kÿ³»óÍÓoÜøÿ;Ýë>ÅÏÿüÐûò€7¿ùÁÒ²Eßø2!€/ZÏÃÞBÇÃÑDEV¸h~]÷høe(ŠðfŒC8Sµz›+7鸞P]¦)µ‰vµ9I|n4J/ºŠå˜XÞz¼]µKb¯Àe}öT¢9ú”1žü]ç$—;ÎÖþ‚L*A„è,ËyMú Êl9…1l ¢‘R!c¨ˆbU@øubØQ¨Kt¡s°knõý“û°FTŸÜ©â? ØP}F$Œ¤$£qÆÆímBd‡Ü¹ÞQActÈ?¦Fˆfí”bsý.­;ÉjW ‡Á—a¼Þí¡HçUÐv¶W´×§¢½ð€SÖB4Š©ïË\†Ä•ÞçIÜI¨âøçׯٿ¾”ImÕ)f„Y¡Aàt!Xgcf%ÎEXKE¡le›$sáIÉ“@.¹ÁÁ rÃŽ¬·âeu³8+@ÏRŒgË[P®WpÆÎUÛÛÑàWp™Ù)ê@¦*Ao]r|6é³ ¸LWä°j`1dg\RÉ9µå‚[v*SYån•yÝDŒ#ðüÍÓtŠ)?±›ä&¥œ‚à:Ì) §ØÜVÈD_&Š>¥Då2÷6uãøï˜f¾»ÇÏcV]P¶Óg= îù žÕâýZ LKÐÁ¬ÂIÕ\]€07µýûsdè!cÇõ#Ñåÿ¤¢\D|y¬¿˜• tŽ‹«”D2=6J•"z$ØiŠÉ¥^@ø¯’ï¶÷¹’_“å&å ~¬*¡š9¸ PÑßð_+Õ¬ÂÅ~KxüÆGxË9|½I‹zÿ °$xC¸tû¶2]FœŠT o- =ÅŽÌ}·^Œ„Ùr p"p¢8Ì!ßfÑ"—ÒjƒY˜-rÅáUתÈ>êΊè 3f‰å„Öu ' ñN/“ùgðÿz´óä‘£ÿ{üdoï^ÿ÷)~^ýŸÅ}õ€V¡õv-nO<úAbbø¢õ…¢·ñÿ+³¨qlÔ8.Ws4ó Å€ï ›å\‡çeÈi5'Ù1ɸJ`V0,ÿ‡@5 í6Qñ½ÝÄ,H+Wz¡!âP©Žc Ênëa¬ iÞ§š=t#ý›Á ®RZÖ™ 8,vîùTyÕSý| ?ãlçÅc—B$+ ®+¥èdA¡nàü"¶ÊocŽ“7¾À›ç«4;¿ÿª6oðCÌáÅ<=£¬ò³W—æmkb©ÑYƒÒ£?0úpzÿkû¡ü–%åò3ùÿ=Þ}"þvìÿŸ<º·ÿÿ$?¯ü'ù¡¯è'á7–úTFÓY?NØ-áio!ÜqzËiVM@ƒœƒûØíþ*•NÜ÷±EÄ[af?m—Ù|²S•å˜Ð ‘Òº¯‚×Ô7ÆôW·Eý$É‹\•3Ÿ:‘«±sösÐø¾/‹+ðcTv !¯ÛõSd„™”©FÇzîFˆÄ> 'zF ú&]%åŒS/ºPB#LsM~ÓU–MTõs a²ÇÏ!@«?ÛQ+ÓEq™’écb¢è~¡ ÚüË*+S:a=÷AÍÞ%Žê!„ Y¨a(>@£¾·ë¡=¦kõ4ˆ¾h!ê֣e?÷ †ÂÒüb?÷"†iíâ™SmdÀ„“¡§· ªd‘ÖÓà§n2àæãjžð¡™Ÿz‘¢0«]:È÷k#Äö×6âðØI‚ÈÇžD°7–®=ÅF·L®\ ˆWíÈWÙ¯Wx€£%ðRiÇd»µï¾YÁñLü'Õ^LÂîç^¾â.äûvR0 ™O!+ŠuΠûV †J5ïû¸.‰Äá¶…Bö×µ´¢PÈý-«Š1¥R·“G-jösO"€Ð1>âb>eÄ7½#(ÒE•_· Š{ቶ¨Ú亯ÿ)’tH#NÿÓëJ ‡ÐYåò"›0,áå¼[ÃzQKPb·$*xî…À5èù¯Es8<Í)BÛÏuÜÚg¬W=$w[hoí´ÓçÎ.wë_[3^%]K ­~5 xã^ÆÉ(¦”Vñʯ9´ÏÁ«ñP[fñ=sœ^TZ‹% R}` £Â—¸>¼–ÌrHAoŒl@`Ááf‡±Jç6ðN§4šXí¶­7O(.Þ‚/¦,°!{B'Ì™EÔ9ÅÁßä­I…!ú+§`º½ŒÞâONOƧ?c.½×‡ïßãÓvó`ó‘¶*è¸`³a¼t% ì<­[RîÔì$ µéÔ{ È礚h¤w¶Ê@ŸÕ)©“W%Så»~0'‰i±Àrh…ƒ¾†˜‰’*¾Ú.·ëmƒÑdK^+1Q Z`O%“6:©M܃G£ø/l“ÏV9j^àû ¿¿ìüu8j|}0ÆCQng´;ÚÃÿíàÿv è2SKY—øÚøøË*‚T\ˆ¿ {'òâkbgÒ5]¨7æ3Uº{’µäzF/èÊ32qüÇ4žùW5g£Lýe^ݸ'<ï2mÝñÊl®Âwe ¢[çÜü+½GƳkR Iy.áDÌ ¶i…ÚcL¼ë™ûè .Ð\ ù.’¡Š‚Ma»²H²\¦Š•sI~Y_°¨™1½ šö|áZc)ÛÔ4ƒ•SôgJV©d§ñ}¡DsP—¥¿ŒxÁê”tó«ä¦Šaq‚-j‘0¸+¨pÝ„·&Ñ2ÜO³ey/ˆ¯Ñ&6G±3E889DpöàÒS9>Œ“~Y%)½Dâ©Å•èŽUE\UüâíñûÓƒãS°Åµø0ìЮQù³kG㬮î’åÐà×ÏjG”²]«ÄP]¦”qˆÈ’%dÁ¡t÷_q@“Åk!‘¢•¾ s‡ÂȆaÈñ <Š_¼~è${\y\Ô¼Oe¾áíÃ4NçhaVɘî{ñ5ºÔéhGI›çôÿ¹4v;42Èf7Fñ/hJ2=>ÂŒô2~SïáNQMÜZä–ó"Ð/WÙÐÝ-»Äg™­˜ÌÙ× Œ©kN™gÕ–Ëš=ú2ï ÷ µ¹;Ž–^"H#ªSÂí&y…=·mñJ¥^YDÙÁÔëoäV›¦& تj'EŸƒNg_ºå îã;ž~õØ÷lÀ»œäæµ^GótÛÙ—N^µàî„aK2·Õy!ˆ«œbÅ #¯ÚΘb—y`6ÏNn³³Ýð‘Íì‹*¯Ðï5üeo³~z½hyôž:Ëè¶BjÅD™Þf&–Á½áóÝ z^Àî³;³¢çãú‡®¥zÐH>=pU[žK¦ø¸;C%­ë›F ¥Ž@D4ÝŽƒ¾'êˆþ|£B ÓäD–N!—*ç ÊÙÎ’S ¹yO¢ì÷þÉзGè†Òr‹)¹/¢MQšó×SÙ*H;u¥Ôƒr û9&m¨yŠÞ—&U6¿Á³0Çà[Aü„¼ï±k]Í„±‡›§>˜§×Ÿ[Ò¥R"4°¨¦¬µél5Ñ´þ¢¾×Éiú§ ªxGÕU÷χª}Ÿå•ÀLqEqP6î#âÔ Ä?hçÞڸƒ!L ìÒ°€,ä.Ë|6úú5ûûqg+¼N ÜQr6#Uî.fF0aM:™©[§ÐÁ÷ ½ª Ž È„"ŒºóMÓU[úNÄê3ÉÓD‚ôzé»ÄËÿñµpâ_¼à¸iJÚ~¸»ÍNÁ1…Û¨º(Ä"Ž.ǶXð²¨ÊŸB8»Û©eå¼cðƒœÒ·¸´”Uø/€â8nt¹i½ç]«Ðë8ÞÁ2“ùÃÐBSí¨4U-4‰6¼Û„è¡ÚÚ1+–ÕÇÄMZÓõ í:†dÝX“$À-f.ë¯q¡ì=ygBÜL·–*©ÊÍ‚VÕDHu7Þ|¼´jãrŽ@j]¤H¦¥ÅÓ¯sª5¿Ú5'²™ïÌ ›Öت}©ZÐ%*¸¡¿§yVÄÒ»QT€kÀÆÀTµ ïÇà×)X']ÃRâ[)Í¢™‹u¡lwuã€=Ñ0öåJœCÁ§+ ÒáÁÏêNÃ8Ë/Œ4ïLÁú‰Ø=´Œî|wà*ÿlzÄ ›“J úÜõuBÇŽ!]xáÅä<9çÀ¥J•Ö*¦‡)¡œ‰9Î=œâñ N0žˆ›¤Ëöj0|†Á¤q„ÕÂPÌ‹ìW÷âÆ5>[ÛÁ®àŽïõL7ì܆6WÖÙEGº¢:År8U‘è=·6ÇÊå1˜¼$‚Å-SñÇjÙœE¯_ˆ2BR.Gx?¤£Ø¨‹¿šo7íùª×º@›ñE)1¦ Ô”àÚþð±+js|7Ö+ÈÖFQ"Öë -¸Æ•¤½| |ËäFÞ"àFÁbå˜gÒø/ߌžŽÿu„q/(ªÂàˆ8ß8¸D;£øéÈEpw?vßíQßï)ñºÑM´ÔÉ1jI¹ÑG¾kgˆº•G‰e'ǃcýX©%š¬õžÑþ}•U©8×zÆ:¾’qŸê2»Ì’9‡øýÜ“í¸Œ„ç"4p{ ®W“$‡Žœ9G¤SAå¯Ì`odás•bâ½?Â!KwQ*‹¯ /SëêÁÕ;šŇXŒ¤µsgæ©ßÀ€/ί0ŒZ¤²{›Ã#¦L:§E#åuj2ÙŽÉþ¬ú–¸¸QÁt¢5ÕÓ"Ÿßr›u}+/JQ|z4‚ÀWªCÅäVþÕ4–µïîѧö†‘E#6ÓîÞNjošÞXÞ9ç‚­£ø¹•Uõ`šÒX‹Ãçüf¨;R™Bš#=‘‰š´0•GOé—7®Òùü!¬·hH÷gŽŠ[sd|gÈŠ·ó³Œiè£C·ë­·Í Ì;-%zö[‡O‹˜°:\:ç9·×틵 äMiÔÂÕ¸:AXB¶ ÿúA|™Nª¿¶dÌ‚ö_ÿÂÕƒ u)äñŠ’cÀ/¦uË×ënú¯ Pepgß0è¡lº%r o«ºº«3”¼?|sp|zôâýøøíéøð¯>8=|©ì÷}ßx}èùF¨ž×hnÅÿ ÙG8ÿÇâsæÿx¼ÓÌÿqÿïÓüù?ëäÿXÜ*ÿÇ‚ò,‚ù?”ÿcñeG{aï"ÿÇÂÉÿ±h ‡€ c#®ý(´Ô,ýõ·:¢ª6dðdçEWW)ö°õØÚQ ›+»ªbèÞ:È¢OÅ?„éŸèÇG¶ûkŒ©—,”ZJs?˜cÔš}〓WÊLÑÈJI­¥ zŒ=º˜¤=EÈB¡+±ñæž†Ü ÔÝй]ðà;DQ»‚»I<ÑáßÈ©-—I ¹y›*þß û¬H5¢Èˤ ¿â”p»Ò–EGð2-+3{ÃØD©¿‡\ ¨¤nËð ôéÚøã¹xâõÍÿËØ}%ÎÀ7•å”9eæ©8¢/È6%bæQ3œÐöØÒñ¦è˜SD u ùM$ ±:p‹1x¸Ï@ûuQä=Ê›>¢8¬vÏ@µ)Iù/È„ à^ˆ)DàV7ì¦%>Ô©Teƒbd|Œ`°Ñöo«T~=£@Cøÿ&“±rO ¿"+.Þ·±8­Tr³©¨Ä›c•ƒª¢¬‘RNE¬"f=·Ñ8èåͬj&[)7¢Þ)7~é|í]0*ÞžRžD‹DÿúïqÁ¹÷ÄëOÝ̲Qì,áuÛJ/Ñc‘3³iìt'Óˆ;Öœ`® 3Æ#ãm¨Ç¡0b´¥ÄPÉ/8óÄ/«¬–œNùn´‡ÖùÞ׉A :¡p7t6 ¹òFèÛF:ó8tì"n‡;ôÎãàŸ7lš$‘ç¤ój“ÜÔ÷O˜Îká½T0D×–ž"Äí)ï OWÊŠÒ2›Þ,1Æ¢#1ÆÂ—ÃÛ«’C²¤™C¾»O‰ñ‰Rb(¡ðãæÃøWû¡þo‘\g‹“û~ù?ž>Ùyâêÿž~óø^ÿ÷)~^ýŸâ‡¾:@U`c= ®ÁlÝ£”_'ð‹Ö HÞ*ÇÇòfLIãÓ©ô°/’,Z[>Uqå‡1÷Ìpìö¾Vq B'N?… `½dÀ «W\à¼W•„Ãá] ­jཱུøÐFŠf%Þ×-¤Ð½7(â¼ '­Æ¸˜yF$ü­›@Àì²ÕOë¢ Ð¢…/Ì~êñm§as‚Ä_'ÛKˬñÊä-%t8ƒd«¿æ Aæôš] í þ†ìA8nh¦5¸q¤ô® =°¶Ow³-ÜH+MÖh£“°º‚} B%Ú5WDï@› nAÄN!Ï-й{ 3ñÑhXâð}äK"¡)¤•³Ó ï`Qrž\©eUVRPM‚QKÙàYß‚ø9ŸMvüÛI{Ý !hBµ!GJs4á±c[¢n ¢FP<#©xgYMg/ué³…µoׯ^ü8~ñÓá‹ÿŠdð«@E<ŒÄ)ëÕϯ_K˜iÁÆæó9‡õÌDsC]Üm»•<6ðç ’Fs_rY‘Ã:Ã$Ïï²ÖÌroÛ•}ŽOax}?Â^¯‰¯¬Jªø-¬Hùo˜#öÛtÖXY7Ñ §­b °§âôÒ:+YRi†;ͺѿ‚qOžÿçœ(>Sþ§ÝG;OÝóÿ“½Ýûóÿ§øyÏÿ’úÿ%üƧUÑ´çìÏ' ì‹>ùkooDuYvAúUàHÅhÈ\ÜHšËçöB@.UÚÁÙÚ–os;½ Ú!™°ôÑ~m$³Æ6$ ÷Ùͨ+Ù©É^ñÅâ v.›^7 ";©Œ@X€ò%ŸŠøð †|¡·Ô­ý7M\ŽýŽ–Þ‚¬ËBHsyz>g6ÃÆLÿÝDLÍGï Û@©¹)²‘‚gºEql¥¤‡'U!$Ç—J½e:KK¸q†R\22—ò'¨ jöŸ'ZÛ  H¯Q¶`j<ÄKY°Š±"ãÖ¶£¼ˆ gEÂ<†=Eý xð ‘ 4ûMKšÛmI` 3 ÑÆ Ðb„Ç økÿ,ÆT½[Ñ;´Š³e"FlY_Œ¢ßý.Žc£ÁàQ<ª“î('QL¤”:!"Lu#ðo¤ï.©_àL ÷›0áÉŒå2UR7ÝlÊÏ2t>€ÅZÈÔ`š>€‹´–“¥i’[qçÌ"#<À§â,7åêÍ:eoÈŒIK§§ûšâ߯}t|xp2Š_½;Å/Þ¿89z£þÿptüò7±LŸêÒrd¾c÷÷·'b7>8ùóøçã£Wb¥=xñ_§'â?øìTÃömŒðo ´hš®˜Á¶d NÄEIá)IsÁ†«-°+J`&qxÐ_’EÄlUri%•5y]îmmK Á+Ì(6¼dPT)–qÑâ£ÇÜðê–Ÿ†¸"©CxìéˆÛÞn†L!›e›Ç»ï²ö’–ìêï÷²{×6A>™ Š»1otb×¢{ДƒÛyÀK´8‚ÛÀº«s KÃ3ò©¢BÞuˆNÿu‰%¡QWcÑ¢º˜kÀHé–@»ŽK! Åè£+€6Ó)H£Kˆ´€iQ¤) é¥ÈØUÛÀ‚Z3Òºa4æJ¹@×^¡#KE$ÖJЂ2Êd`±em[Fè‘Ü]L©``îŠCÑ'0¡®–éDFÒ7×þ «!ÏY\°¯ í!.ñÚÖ fy•–ç ½ +ŽŽDO]À&1rœš´O ?º1W m Fo€Ö¦ß6‰Ô¤µG)¡NV%[‡¦ìdÕ¡¾ª:”a1Ç·È Ø¬Ë S»6<¨ÃÔ†K ÎP¬€0KDÑá<å‰ÞX“^ŠÓÉrYbudÄŠŠÄBÔ`•î˜ú,7Y#Ϻ-OS PÈŒ˜(sÔ™Èä’P¿7ß¹ëŸÌÿ>žÓô#i;ìöă£ÿ{¼³÷ͽþïSüBùß™ÖÈÏ%n“^VauÀŸž>O Ð/Zhby3 8&³³ÕlL»ÝÖ~ãU@……^0†Ä[û¾·!ØJÖo¾»gž;¿‘† §Ýûý7ó~Üݺe%>èÁ‘øÏ Ž]âß@(}ü'„ U»q¦¹ý-œ9µToöÅühÿ¿¼ù|þÿ;{{Oû¿§;èÿÿøÉýþÿ)~þýø¡÷ÖÀ›ïúXZ¶èÛëÅ— |Ù;ÂÞ‰â=úFTíîÀõïÍÑå ˆÿîÍFÒÍê{Áá÷‡û2—ét•žóÿÓÇ{ýÿñÎîÓûýÿSü¼û¿æ‡¾B€.±±$`TauÀ#¨Ïô‹–L,o!"hÿÐ îà­ÇÀžnÁP Nm¹8ë¡nMõ¦iÕ_ûy-d= à|lC».@ðè=ÆÝxÓMmäÔa¹e#hó{¾"vöèöS¹ýQª4N¡0AÜc«pßô@Ç¿”€À±vI÷Í:]gƒ•Y`<ºÍ’ªvϘ7Ū„{îó2Y ðy=‹Ò&†à†¬…_s9»ôæ‡Yh!OP¸: ô­øƒjü‡gëøÓF7ðn&Ù{çzv••ÎDÅf¤ëyzýpš.cì„ØYj) á Q«àNfb$716}·3#$1—Å ¾dT†ÂëQœôº.Áâv_¤‚{¢A&sk`2Í9Æ2 khlŒj†}ŽS¬podÆVNLBa/äKò'C‹˜uM³2Ôó™¿ØíÍópÈ+’ŽC™¯98=¦§ Ù5?מ“rJr#ÿ¨sÒ8×µ‘J}4:ÑõÕÇ'ÈúpúY‹Xaµkè*1à¥~!ÊÒq†ª6€ähdùH"´$kN¦•ÞûðD¨ªØfÂiwhL³`ì)Ô›MÅJV”Â鑲±ƒ|¼H+ “ÉÀo[¾è%ƒ¢cæØ,IUþ!)3ˆ9DËïV•Ö[t‡¾Z^%%†œø@ßâ°NØÀZQ­Îˆ›Èõ;jD‡ðèV]bwl6ü#aïðxÊH*ˆ¹9v‚ûzGÉÝÕ=Ã…®üYu¡™\à|A‡`jTPhLÜÇ—ÛUökJ`,!5“LdŒsFÕEF ¸.ÃÆt¸=ìÉ)`ẶîÎL¾÷;-j.\ht[FôT.L‘‘àX謱Xa`“÷¯†##JÐtA!tßñŠæë¹©î±Hð=Ö‹Ž{“Í)²vËA {Nf›.‘R>éµFš›ü§\$}ë¡5Ç¥umR˜ÿóЩEä1ˆÔx6¥mE½È£d 6ÚCDkä.Iá·²Rï€W™ØÉ&šýáàäˆ2t§—BæÉf Í‹â?`Ó¸ä=7¤ÛçÛ£øzøqG¤qMò¸²TG›x}ZÍ’ÿ¶rû·$65$ô"àgfáí‚áÀA•dÄqH§¿>ý³É¸“ ‘Ä ~—nŸ„GÖCTú§7¯yx êX—³ÁýΫ…Ö%ÿ¹ïª¤ÖüŽnªš÷¾!AÉ…\Gëo7×z-f@t´ðOS&‡rÃ{²æå¯— .Ø@©#,ª½ÂØ”ZC*% Cïi«¹F¬ü¯Ç¯Þž¼¿?}9’ùJå»N/߉—ǧïïÅÑxwô‡?ÿFÁðx"E­$ïÞ&÷ü‡ö¿E)ê¤Ãÿ÷É“'†ÿï“§`ÿûèé}üÿOòóÚÿ2?ô5ÿeð­eyÝ®Çö—¾M$Ðmù«P¼UÆ?ÈÆ“Ž/Ó ¦øÓOA÷Ûå |ç|€â¯à"-ÏÓ1d\ßÚ×w yY©YH¾ÛÄnÊÂÏÝ‹ßñli `szСëÁ‡ÏùIrøí‰øó:Uš„óVª0Ïš¨÷/QxÚ¤,“”Y ϯØY÷;liÄ;²Aõ)ÄFPÑd<B@H”É0æÚG1ý;l@0íyšƒ×ÔÃåª\bs‡¦ÁK†vã?Ë誜ª#jYtaYˆÎA Oîðˆ|¸ƒè ¤dL"ÎU:Â>ï›9î¡<§þÁ³oÌiïuË*Ï«¿¼9øÓøàÅ›ñÁÉïÿJ9Ü‘”Ï"ªRÇ9vm¹¢[Áœ5Z¯Íq\±Ö¿Æû‘Ý–‰2àx0ÄÂ#Ç9XCx0Âÿ‡$§KVÎ'—CÕYnq_ÑÊAG·È`ï› é=l©§h{J@›M|ú;ºÒ@WEùÁdSde؇k A¡iA0Æ ßtޱ è4ŸŽç+h°!r€o3H—˜ BÖ×ÛHÄx;ú3F1οªeêê ²ˆQ–Qå`%áÇÌ@x_<ÜŽ~–§!Ì;–Ñ%Ê"Éa#åèÊ;—æ&á§š)#l³{öÜÕœéÚ/sH?CGGñŽ˜VwÕ™Eþ>ù<Ûä@§$!}ž|~–T¿ ¾œs@g8fÉ8ë|è;~{:~ñö8Ê‘ZõwŒû{щñÁ{ýâõáû÷ãÓŸŽõ«ONOœ· püödܨÆ,ã€yÚ‚×fY{¬~‹ÕPmX]£ž•…Œ¥GxPy> ÊÊ .Réô†O Ð/úDhby‹CáÙ*›OÅ&:›C–¥_¶ö!g›BMÓ<ƒd ÆC“í8þ#Ì.ÈÄ%¸¬àÒÐ篳UáQ¸&Å"-ˆLI( Sm¶H'IžU ¸Ò^¢¡#~þ<>:>¿9øÓˆ›¦PPTŸ8[“vM0γXżE\Zá<©dÈ,(¯ÓÞSb-Y±1¢áÍËt ¸†Ç0hä®cl›ùWEI„WC)ƒ¿…³h¶R¬Gb9eÄ­žÉižÎÐpç¼LÁz„ÜŒ¶ä’›åœ#Í:C5fv~a—…¾SYÙNô¡‹S>eˆIoóäüÜWá7’#@]’FjÙ¶{O¥^=wO\Gvqb×{ND=Õî÷¾‘³g³è*%2á‚Þ;`nCzBXiTb§Èk1Ï!(Ÿ² S§õìÿ¸XÇ([8þ˜íoŸÁ¥ ©ÕÑyÁ ‘5³M×U¡—IÅÖ“b™ÁR„¹"§°;’ß9ø½úxµòçËt„Ÿ¡WUAº`k‘V­ °¥µÚ§åðMµ ÷1åøæ¡6hÉÖGìdS6¹ÍMpÁ›³´cIæ+Õö&<Ä}ÁQ2:"«ÚкÎÔFÞ&Ú¤uÁ§—Š¡~´õÅœ­tlXÑ ÎOåö‹wãww¿€úÿɼ˜|ø\ö_ìa§aÿµw¯ÿÿ$?¯þŸù¡¯òŸÁ7ÖüËòº]Ο¾M$ЭíW(Þ&ÕÃYUÌWu:¾[V¸µß|²ƒoã*‹Ô´b’ËÇ@!e€Œ‡ c3Cjÿ±·.t3ös·f•ºã#»·£F& !x]yc?Î|jG¦Î©Âú¢±ÛÌ¡¸ù®-ð¬ÿ!%¶Çÿ{ïÞÝ6r$ŽÞŸ«Ýs†ôR²%Íãn<ãí™è®Çöµ5›ÍÙÍá$! 10iYÉÉýì·ëÑÝÕî(ÙždV:ɘªUýª®§AÉüŽ ùÛrmÇF> Ei]‚oôñB¢ÒœYp ó)i6A@HIHáW ós0 ÛºF‡zç1ÒТj5à>§PbºÏ‘B¾ ºC>‘ÀáócÛ܈AØÒNˆ5åÒôk| ßr ¡clÖq±IÎÞP°?zæ‡ìKž‰ èæ.€÷‡LÁzCèÝ8 (ƒJI¼QmŒ^ È©»ý¥NÀ¡Á5BäTç„æÔ/¿%\†íH£ñ$Ù]ä .¾m‡j²ïŒØ|Ø9)(D§XxDÔO¸ÈéBúo× EÝs—[2…åQ%I[-Ý ¬j»_½î3žaC` 1¤³ ¬µÝ*Zvv½TWLL-1+Ñ!OÏvuÄ í%ŠcaF×%˜ÉZ·5„ÕÀf©ûWµžo¯(ÁD+…6Þ†d80ýèlÊå’ ü\?,F=稲M£³aÑlgšš~üiàÌê%Rº=AJã]ßeš˜ÑßQkuË’ŲͻâÆê™vÅüoò‹&HÁ`V§GÍjH‡š•éd/ ©Âd $èP÷pQÛ áÛ¦XªçT-]ÅÌ·ì‰")œÀ›¦ÓÕ-ºÔ5`µÛl/.©Éož*þmIR¬JðÐ>¦‚3ˆÏZ”8•ü:H;(¥®û+s`u¹ìfXÁ*@D¸£¾ñ:QÁý…[0ÁYc*²œ—_ ä¹è"\³úè¶g´«çååŒÚ`”Uªi)æˆÏAÅÕ±–sÆi ¡µ*³O«Ú]K±w‰ìd.X¢i¹‡Q¡üé럱Y¹uMHú¨.×.¶vÔÑ, ¬ÜÕÊTÇÇ[ª ×òUY´[H®´l®÷—åûÒábÚíü2SG·Y–&p“G¯] üéÃWVôÉ%Õ¸Q·g È^Ës=~º+ãåˆ)²êT“'û¯€tîµ,2å$Ð@ÒA‘ÔtÈU.…P¾ƒ,qÛäç…\âÎ^së†v·n¹÷ Ù4d7­ZlÜɼ­[–írûU=-Î(ÔÏ¡OJ»]"Û {yKɶ¸Y±¶ö$ ó蘹»~En5‚0ùAÕl[™å+Ïß*FXJâsíÌIÚöš¯~ä„*q›Ä@àµ]Æ/ÃÈ7M ™\”Àˆ–«°Þ*,R‡*P'Z— ‚m5KÔ:²›pù9ƒ‘Ì•è}£;ƒéžxR«1ܶ[–P Áãµok¨Z3µo¤ÿAVÕ`ÝðÖIIˉÐ|&.î™@™ðš•j§BS*d—;õjA":.SÖ Ê¨uMÕÇcD®%ò!}+h3ø¢‡âmA÷Œ0èóÄû°ºÛ¬8¬¬Åwžô8X¥€c¡¹·›µ†:3Ó4c+Ÿ6zèž6‹Üñ˜º‚˜ÙbØ›k@€ôêM…Gà>Dªx+µÅ̇§X÷¶þb“½/×706çÛ%5uÕ@$в, ¿Z¬Q©ÚÀ–Ãö5&„H Æ4zq¡¨y‡Ç„ÞÊè¸xèm…Y¹,V-ïU‚Y¡>hNþ!0PÿH¾)÷Ÿþõ‹jºQ ôSiûò¿õõ¡çÿsüõ}ü‡ÏóÔÿ™ù0Th ÜZhk­ô€úëÜþªuÉ»8þ(þkʇִÝÎÚ-°æ¡·i}÷fzU^­˜xóm(/ ¨Š÷"pè•Ï‘B+·±U°¨úFSžZ3Wø9¥cHÖñSÌÓ©©ÁRw:dÀ|L!×}—ð¶0‰‡áÈ)°©¤ûœÒ—éæÄCjçÔÎ#¨¥ý`š5„GîÎÂȇ”¾Ìà!Ÿú摘Cñnðk .%ÿúH‘½B°Ò”øuGñ|M$„›?ƒPhtŠm¿/Eufàä ¯ØÀíUº5=±"R t‡Ö¢3"î°,`(ºBÑÐN–¸ @!vEº_–ÅBqç;îT5xM€ã±Yg»©æÄïƒû8ÆDm3,Øz4þ¿4‡¾N“ãû¦Y–`̦ˆº[¬žÑª™NsP}áõ'(6‹&.*f‘¦yJ\«M—@ 1¹»øcuI¨4Ö([Â!ŠÍE¹ÞW³{Ó¬³EÕÎ× ºàäñpK§ï˜‹Š”\À¾¡ó%ä[Ö…PéùÀJχTºê™0æ{|¿€6åjsÙÓBbÉ:0=C/Ö&Åü¸+Ó1wMÓF@Œ‘ä6¢>ÁUG…}‰zdg™÷é¯6Þt£Â×zä´NroP3г,fåò±ó¡ªÂw ÆÁ:T"ÏëòÃæ±ˆr¥PT{©ù©ê§p6ºÀ»jÑZp:ŒEáH¡ö–Jæ{†õ±è À«Ýô½†û[¾}œýíV‚ÏA ÞÿMAãO#è¹ÿyôÕ×^þ÷/¿ºÏÿþYþ‚÷1†JD‘[Ëdnrû}.ղͻJ(›ò0`YÑ}¹O @‘\¬²ô*zwSëÀé¶\ã‚"Õ¬Kˆá̆:ñº÷êÖ!ª$®u¤½‚À[:¸ápövWÄ.’ÿÊOd™Y| øx¥€è4}_¬Û!¶Ø¥ßú»Ü˜l7¬è~Ï>™Œ^EÔ‚ ØÈ¿8}7yð M“ŒO©tBAû¤®_ 6ŽïÔýM³®¦N`ûc«)+¼\ƒÅSKž´:‹ÜgˆÆÆŠÓ$“À®`صlv£êŸÖzÿç§Ï‚ƒ©giïX ?”fùýt‚= w8u‘-1¸`k2Y–ÉÜZº%\c3@b̪å~âçñ³ñ£ë ×þ!øtTÞ¶ÔûÁ·¹úUóùÅ;ðøª¤UL½S~Ø@ÔÚY3AŒ>ûÔ_ mí.Z Q®pj)úÛ;báéWÓb>…H¹-(|ôï»h|”! ©ú€ñß‹†E~úêùT¼<¼Òa®ø£ë¬ 8v@±øöû“·§oÿØxPo¯‹8_£ƒæõ;‰.[xB³ÿesÕ,˜Ý¿›g8ÝŠëÑç?úUÕht5›6쪀w‹ßmËÍÀ¹_(>bsy•NÅ*M¶JÀ™¿(7þ›Ññ8?ü÷oþï±eóMK—…M㜇óËÔ‹«Wyþ]žÏoìÛY}ì‰^æ@ý?æûXË1gPy~^ÍË[¸ÃƒŠ¢~ ›üêßàÕ¿á5f¦~ΠJ¨ PåÚ¬uYÛÑÌ­•àåÈB7™Â($ÑHGUz¨¹¹ñºc÷9Y;R4þ¨ŠÔh®@½/PQÿÞQžct CÙ¸ã0Éf[ô°`y:»O¨[ø'Q±„yÕØYÅ’åö =˜ä×àÕ Nâùý¨˜¢ÌÛµ „ŒÒÄ[‚3)ÔY&ç7ºŒÓ8€dÓÇÃé^ÕVÚ-O=S‹3Å(_B¸5 ‚UâõAGÄÄPw»¥huÏ%üÒ\»©™¾y£Y,Iƒ'iwÈ1Ô4J glâE¡6åÕ <{Ödõ¨=!VÎGÿBÓUU^Q”i=;x/ኘœƒgþßÔuõþFJ'"&L`Ô¿ÿvß`|í>ç"<ËoggÄ2<+ýÿʽ“뮫iyôÕ#4·¡%ù/z5ˆp¦6F.F#Y‰ îž¨ø…ÌÈ¿ý¿þçÉ›·æº¡ð½¦ÉÆ:Z¿.ÞËŽ¸.šÍ´[îëy¨J<Å»ÈÁ-ÓÙ:`YÄ‚)‹yÁ´¬Áɼ¤C°tË‘Ñyùk“4µÝî«ÏWÛ þÖw°6#&aUTk“UmŸIÑµŠ¶`PÉâRBDp‚C×»ŠÕÇ7®Ó%ˆ¿ÐÛ¼#CSˆ†0œGØ´¡¦‘8Ζ7ãLû]®Ku…èÔrz² é\ˆL9¡¬XÕ5ÎIÍÁúè§ÊP¦g5ïH£\mÚryN›’~¹AT‚(š6èµÝÀf³w1ŸçûÏÞ¾zñJ·¿÷æ_ÇñÕ‚©Îo~‘üO¾~tøU'ÿ“úç^ÿóþ"ñõ|R—¸CHS…Ó`,Hþ< ¿jÄò.IÉÈbÓèõL?ù*æÅIí 6}è¼ê/Ê!²ün%’¦†‡…x3‰6€EÌ_«Ûå6„ÇTMò¹DÓ!†`c˜,ây§–H¶ÖPÄÿJ±7 OWìuË!xؘʇ èìy"¾Øº¨Û%¹gäCªâÜ¢lÅL%(G çêÈww®6û®Q×åê/ÝZÛFßd!Â…]Ë€÷ªé®K²ôêükÝ×Ì.Ø(ëU¡ ž­‹€]—tS,9v‚•¸_5xËUƒ¡YÙLÖdŒ” kÆyls¹^ƒ†~;4ŒF:$~Q_8‘ÎK<á‰å‚Þu¤‹wÃÙqÕ16Onð(´?4¸rš„‰I>ÉÉKáOÚÆ róòE¦53†oÄÁÕy….÷SŠøŠÅü—ýñO4&¢»WñN€êµ^`Óô3Þ%8ñDêøT5M‘\ìs?2ù@–wŸûа]ÏñBŠ][óÒ–’/vÀ`ˆÙkïEo·+H©é<Æ‹´Õ_J†;tr…Ó~Ÿñ4gõÜ2mLÓb½.n¼©k?ÜEü#Vk*$I;‘HLOÅ)¾÷ä­3y;ëÕ¬'±Lº=K2‰ûÅcªPW>qH‘G…z)⻕ô…I¹ss^-:MÇÎÁTͬ‰Lz¡jMQ@3ù¬©¿@±j›P¿ô"Œ1ƒ`Û0«ìÞD2ˆ…9j邛߽hØþ@gÐé™xÏ¡Ö6ÑÈôÆ©öñîü8¥u€w4†þ[…¿=ë¨-ùU_g\Ï„2O¼+Ë•ÎÀÐÍ¿`gŸZÕ«'z+4V&¶Û¡–V~ùê »‡ãÏŒ­CÓS§«è$~7œpaAƒCfö ¢­/ 63Ž+r£6¦nÐ&p£¸ ßy=H¶hØžKW;51Ž_:W¸çÞJÝh¥ñј‘ÿüÁ .ß*–â‰X ¨ôÍÕT¥û 3Î:(Òź¹‘Yu¡ó¹©D¤×·˜¹žLÂ;€™Ž-™Oƒ99œItÃ|! DULß¶Þò5Y\ C–«ׂÈ;Î)u½@3±Ÿà€¾~bp' Lkªäû-xQ¢¿.ŽèÿS¼/Œ…B6'Â!>ÍV­á%¾W‹å PQW—üÅO'OÏ ÛÎïÁÀz{mõ ä{-Q ÍWàë?ÉÁK‰¬š®á?”’q9ÅÌ:à|t©–j¦3Ÿ KÓ?šÝô¯åõ¿«bÝ~²ì½ú߯¿<îÄÿùê>þÏgù êy> Uÿ2ø­µ¿º¼m7 û¥os ô«Öüïÿ§Tÿºœb]S8´÷žtßEt^ ñf‰/£Îc¤dª‚/ãäŸ1Úji4 êŽ#žúµ¥…?oÁY |›¦«u©tˆ`1 ~N ûçm³)¶ö9Š®nŠ\8§ˆ=›Õ —è=(F"AζKÏ^ò@”¤J°CÝZꄾF:¢9䩎dcÆ-ö%®F…@…¥FJ>FŠóïi]^LÁ+NÍ” ‰}l:@ˆKËó&j!ʬzÁ[wµñ”Ùy/ÅT¯ÔFxY’,E>%º)ç~›˜ûC;:­—N_Õs¼»-ÃÀÑ`¦Vø} …wÕ dЪý}-|hë Þÿº€ZIºY“ÐÍn>“üµ^ó¨ Š$`IooÉ^ËŒt/Òí…÷‹ds¡"ý®Å"JÙ°_Ü<{ò©®ÈU&‹…™~À{¾lŸñîoziT ï¯G*ŃÀyƒn.À¹MÈõ—ÜËÕÅÐ[—N` `Õ€^ ìÅ<œ¹ÙyÀõæøT ¹Û²vï´ßž>©› ä§iKo~ÑÌ‘¾l&ù~?@ÐcÙ˜Ú›<öåF.Äq˜¾¸Mô‘XýãQ옌èœ|ð?jä“ÐÓcƒc&±/øÜW´2 ”¨-ήøõânÚº놾]L@|Ö,4Þfe{ìðá. §¥Ü³DŽî¨¥Qhñ„+I_0Æ;µeÊé•]Õ½ ì %E±°«¯°¦5¿‘7QÖYÚ9/mÝáò©ãźÎ뚣ñ“D •Ô…ò^£Ð»ã0ƒ®…à‚y‚ßàUÙ¶œ†»ÅA Éc®…}tƒ ®Ú%y2sŘA²n¡œ_6Ñi õd½'´3\3ûq—Áf#¿Êã½MG4<ÎqP„;µ¥$S8’õ‰ûI¸.`˜ÏK»XHí.Eã²1º4ÍGjÅ>õƒCGÒâ·NΙF/›zy0\CÈÖš0ö „>+!òцŒ¯/ÕBhÕ1TN2öÈÖJÖ:¨êÄ:‡Z-«þžEÌ$n»ûۂ׿-‡Aõ?hg÷gÇíW|\2\a1pâsÒñ1Î]j4Š×Ëb¢Qn ºñÖ 5yÅvÓ€À›4‰¦í¼X®.‹þnV ×äÿß_àó˜Õ“l»t¿d¬@L† ¬ ‹/CvÊWø¨Ã1Œ'lšÍÕLa"eo£6âú»x¢:ñ±@a`ÂA¿»æ‹3Ntu¼Ò-fKUg—Û«¢ÞwŒš½ß“FߤOá-JbÖmÌg¥>ô`uBZC¡¡ÊsŒ‰©Qlˆ-ÅMd&Ímë¹æt+ÍädÅô3ÙP'2¯¼U»¸°×ùªi7êçAvZCŒ¼Šxu/›‹ývs£Ð„!ÛW+-"è§ü,´g2šeívµjÖé@Íñ©}±‰ÐÅa½]²s»§P† ÑÍ"ÃdjG¬_c§Tí¦Tã¡f3ìC¨ßS•«ZÝcj5uê4ÀÚšöûç7“üæüüg’—›ùÞ ýË08F±(i”»ÂkoAH÷º És ¡$8ºmHI(?ÿ_ e5¶ѰÁ>@­Àðþ& 1x! ¬PÕãîb6DHñ^}Ç™X.Ûù(Kx´ïi9o–¢ê¶eŹ활í`Ö>4Q€ëßÀD#˜˜AŸ %–L(ݘ¾¢žZ[Wω¹fw¨MóŽ04‘`¥hbûdø±?hõë¢ý«I~¯ÂÿüCý¿:Ð6†kúømôèÿ}yxÔÿvt¯ÿÿAý¿CMl‰[[ˆ*œlÌç¹ýU[H,ïÿ „$º®½'ÎcD½¦?OÑðsÊ· ÌNi‰ø«Žô;¦ TÁÊ—1¡¸÷Ä} þUSuXn*à#,î»>R¨ü‡Üç„uí¯|Ši½¡FÝf ùo¢I7°iU3Šæ¹=–ªá˜ ,å먒\ M¢`=kÁåÓ@Mx4= †ÍÈ¿õ!®hÌšvïM/ºÚ, >…wŒè.TÿVûɸ‘y}ÑÁf¿_õé뀫]Lº ìÖ²un'¹}8J´õxkÁ¶åB4ñIî!•DAd”»L1 t;dÜežDC‚GÀ,§Du~ñþöBGJʸ@Bþâöº3Ÿ!Á€ýD‚%Ô¬«D]¬¼)ù›hO}ŸÕ_¼;8¶Û'î¶ÔKŠîÑ(t”\S½–{G]\zûá¡dñ£Î%†þ̶ö8ËüÍrì7¹þStâ^Ú·CxÔðc¾‡«u¹xøMIÚtú bûç̵º¨ÙçC-½jsóØT uˆ„€[Z—-•4„QU¿Ÿ`pû ùPeXÐφq^•ËIÚ`’ÃäºÜ¬«ò=¤Ôªnjj%ã\6Õ_JÑ/ù§š2EÀM ‹1¹$R¤,–(Íü¹Ìv¶÷ÝPæ, Í)BaŠ UáB͸Çnsû”¼Ê‚Êi5ív^.0…Èc¿›ç[Ž$);Ãßnå¤Elg¤H™¯›6ÿÏ“7§ÀcÎÇ“üé«—oÏN^žñÃO¯_<ÿ/üýö?½üù'ø™©ü3WEÏþ ~áð È0ÔCŒiî J(K,m«ÙÉ›G›I5x¬u˲Ïè¯úü—XÞÅ)˜ª™Î*°˜†„ÚKCAù2¢ïp Y\6u6^-η´&Ð)‡‚£ì~ŠêaBµ„Þð  â‡q Iü8„dÛÕBä^5ôr‘fŽºT¾ì#ÌL+¨‚…vp M °›`ÒrYü‘Y©g ºjZr iQ3¿=}Y?Ѭr9’Ý#‡ƒ°L`ÄE†]˜yd¹ÌŠº½.)×r‘o ‡°¦B‡Ô–ôçm öKg2b¤Î¼áâ~B39‘ÍåµÚÕˆÏb¹3…FcD dHšœ– ›U†%ÙBRÍ9mXnÂm”ü@0i7ìQpø$ŠôÈš¿grÇiš ybäý$•]oµfús6Ælp岄èxøþÙóÏÏž3±—Ôlœ'÷ß4bª­Ìß•7D@¿Àß,kñ*†)HIÇØm­ ­ „™USæçZlk Up3¦)Þ˜èÐeK÷“€— ³?›\-µÍ‘Ä‹3µ.2PQVÍb#"‘Ý»'~wôn%€•‚»`Ÿu·+")Ì ÕÝi,‹îC À¶¾ØRÜI>¤ÉTƒ×+–Uþ ÅÓÐVà³Ø¢$Ú0e÷Î!Ÿ”ÿ¯i?]ôÇ~ùï£/AÿûÕ££Gß|ó諯 þ㣣ã{ùïçø çÿƒù08ùß>ó–Ö-†rþ©/søUKxÁ»8w?à´9Ÿ^—಺÷¤ó*"'$N2ž4SÕHçæ¼ˆŠÕ·)&˜fG€¯7Ð NMù#¼ŒþÆftzrÿM¤é% ^ze/#Å׊ 6CÔu¼ ÿ¨›Y*ç±YÓƒÁ?“Ãǵø†Æ'¢ÿæN~ Ý92,ï€a˜ºë éêÛ2b¯Ú~å&?½iÙÔ9¸7èKÿ’é”/ÛM@I_ @ìjµ¹ÉÓå',Â"83—‚|²ù®+Êçá‘pf’´è- Ñ‡-£è ;iÛíU™?Ê¿ýKÿ‡AÈVƒ4óÂQ¼Ã¼ms‰EHèÅÇÃTlt|J¹Ø’æsnœ¾<›þtò_~Ë=D3 L`ß*åqâVØPÖÛ«ü¯ù÷˜žüø|ÿþþùé¿;ßoNÎN_å{¬¡Þ¾z{8ÿå·3æO‡ƒ)ÏÏ«y¥øþ%!).pÃ-—%Ö1áI-믒·z•`Ô JÐa ÷ :+–ͺÚ\^‘°õ÷ʤÐ%¼¢Ô–õçm5§zq^±n7à ù¡ØÅdU d¿Ã¨jëRF82@¶5LG“Œf^­çÛ+ˆG9ÇÕ¨/7ÞI8Õ«Xn5O)¦)bToW ”a@Þ! €^Ç~…Ž8,H3QÐ_À÷‹6¿l®)Kd¥bÒ¤3ðýÀ\J:ÝÞ»ZAB@”±KyÅ„m?TËJÑ%£Vö^p÷r…çºäÚtb•)`ÀË‚4UWevM¹è(×”3EÔ‚ßàqÇêü Ô|º\ªÊT‰„PPœ¯(ƒc‘çÜ[{À«+µ®®ÔŠ abT\ ÙÄ'/ÚLÏ ô i˜Ñ¡.!ßÒÊÌ¢9éXôo0<×\«$ ÂŒ·Âö@Õ¬˜è,“jJ ^ìÅý šlÍêDR)G*„!NîiXŠfN§ó@+Ý=\“"-áRËÑtIÍÁª¸Õ97jÈ…)¸ìÂ3G5BtrF‘6\ôšÉh˜ÏxDåùK5ÿ*D$Ø*ÊÒãªKP/~lšD?D)k.1¨O;¿,A†]kÉ¢÷Ε `!m¼sº€¦źZBB*Ä>ÎMtF/HáŠæÎúiñ< œEuÚ Ø?X1”ëQmÊú^Fû¿ïä¿ìSÉ€Óò߯¾úÒ÷ÿ9þæËÃ{ùïçø Ëõ|,Ön/65ÈÖCò`þ:·€¿n¹°Eò²áb±˜ª¢NÞ‹˜ù)Qœ6ëéº$gäi eÂ"Õ¨k4´÷„DÀ8Òª §ì’¸ïúE§€[û®Y–W-¸È¯TQõ¹¾q’i ë# ÑO„^¤ ¡îJ†êwŒØ·):Ajû4€ËåÔë zàm¤ñ‹²óÉçH!5p˜éß4ZëýÁäÓ0´ìt“hùo£hm¦&~®@®û6‰" ù™FÔtÓ}†,’“$Pâø,3Ý{WÜ Exb¤jXAõÞ> î:à9]®W $‹Ùl[ƒŠÿ!†z¾µvÍx/R¨µŒ[¬nÂçÝlz½ÑÈáÃäê ýˆ4 ¾©é¯Üw"bȘX§ÐÅv³6é‘ì«$ŠàŠø¾Xj$ùqš0Ôz÷1âù9Q…Äл,t<‹5èÃҨɩÕy5Å~„G)þ-F€+^Rü#J £œæ‚¯“È£éE§ÕÈ‹Wƒ‡ÔæÍ•Ø¢ºïâÈÎn ºô3‰ð»Yê¾V#+^%Å9o~@l³YW3^¢æw ‘vj‘VÈÈÇ$Bëð®‡`³ÞLg7bmº/ú‘œ1£"R”u^ÅQì¶ î8‹ç(Ò „ùÅ.IÓ콉¡º*çU±tzÚ}×0Úo;µøoâè–6G½|êA•Ïk[ñ2Š0ec‡égïŽ mŸŠó²‹°'õ±§ŸPŒ$N]7?chnÖÓò(šæ÷4 gÈVÓÊÁKŽœÇ‚br9€§ƒîÃæR&øs"¸Õ¶òȇ8z[u=^.$–Λ´UнišF>Ä÷zét/:ûaäCÌDÇùÄdNï= ¿O\ ånî>Ç ¬2¬%M2-Zp^ö“Bg%‚àóv8Bo‡áè0Lõ>Ag÷^¤ÉPÕSÔó:ÃQ×·Ës2éå'¨H„µ^Å9DAL±4ùÚZ"N&A(`ùÙNÉyL ¬¼mþâλAäRRµ-îMÞ=1ñ1A&Ô*5ðgiËu؇8Âêž…†Zúè½éG–ÎÛ½'ôo¤¡«bý—›#¥ ½M!æÜÜq[;KÿÕñð‹Jš’ŸcQKÏtI<$Ðï 6Bo#lÖÛ’ÆIÿŒ6®ù“}éyP''‚›ßƒPèåñ¶fØ3Àº´X¶Ló3ŠÊµÍ i2ÔæƒÙ‡"¨jÎÌþŽ›ãÒ©ì=q '˜Òó.SÚEO iÚJMÑ)¬C®û¾9!ë¼ëC–¥À»J€-Š­Ä7Ö8£ºÛ{Ò}—BTÊßÚAò·.ßeØâh®ËöÒŠ ÅSBþ¬¶’Ø>•üœ@ßc`;¯"EÿR®›é5œº{OìïÚýVÇíFÐZʃq¤s˜aó³z„hc½e»&[2[æ£Ò¥œLâªr²þÀLr)ŒÞ©MMù—Í5XU\7yþ˜O5Ì[Y½ªá߯'TKƯƒÝ%ÛˆYyÞ¬¥uÕÆW—Šu*9rn>‚,HÚú­¬Ò/9¬žð yJFØ„±fXE¯Ú‡í©wP¿6ʚȟGÉÂ]‘xxú„¡G/ìïœþqZ;A¡%ÚÚpiaõp¡ßd/Þ¼~5}ñfúöìäìç·`Õ„o~úùÅÙéÛçgü^™–zG§Ï1ä¥,92dDoàþÜNrzX'–iBŠ&n´"‡m«#4õÛ@wá.`ÄýÔä©#^0‘«ÎÑW((Ðg¥?7iœñ:Uc»/®wÅ AhdÔ DdàbÆ º¸‘Í·‹f¾äþõZ§éÍÀã6ÏWÅdW|H.Í–¯B›Ð‚gz¡=´K[¨óm’Ÿ½ùù¹ýD‡Ö•bTîŠÂ Õ^uùïô‡“oZ¤CŒ/¶ NIÌ’/<.ýÂÂAÍøÅ›ß€9ÿ)g»˜á’º1\x‰€Gæ~T²•®|=¨ò°¬(8h!ÐÄ@õŠb’DJí¸%'å±öc%º¸^†'¶®¥'´œœÀ¼ªÐ¢.)å"Ûã«Ö$ßÖð ¾ÂêoÙŽ÷#5Ùö¶5ê' Ÿæž˜kúúÞIékd°{ÄÁÅ”,3zkïyg õÛMuÛ@Dº.nÅá @¬qó Ž¼!7"çpÀ œ”žº=«Õù k¹N›ÍÁúmŠònÏc“V@„Swì¯;oѨ€ˆ1Ú§Nêí†ÌËÅä—v®ƒ~1¡€à#†rÏÅ‘KFpRÇ[+ É'0Só;™Î «t“»â’\€ÿ`î8lp\º¸GŽú˜µL—kŹB 3ÎÂ–Ñ ŸírƒÖrN/Fëò¢X/T9 õBç˜åv®è2“# Ú¬ÿtò_S ¤H¶.©³… : 9ÖÝ[Ÿ9#1#ì²YŒõN‡S%sIÍÓÞqE¥%ô8o úëª-3þ¸±àd»Wt©ƒ A5›s,ººÌÎ1µ‡äpÆÂÄfe¬r¡z9mß-De&6¡õy?®ÂVaáý.Ë-›×ñVA‘߀ÜÔ=à~rù¦RAz¹@}<š^ï8Ÿ(w"™-`¬9Œ(•[§gNf‚ø8>§ööYÜÔÅUÍÒÕš9Eì£è°çQäª6×YºåÚ¨}±.£vVÁi1o Ï þ9iP¤0}ŽÖ¦6Ñâ«À5q ’Å!bÔ‰™×t ;&ÏàÝaÇŽÜLõë=m6%íà»ho!Šbñ®h™Þì(·8¤@œõyþ¦œcm¯½ˆÚ4Σó¨tÇäΞ•›k¸·àö|Ý`RnÇÙݳº‰ ƒºã8äAÚg1Ò÷éŒ-ñóñ³Aü|(ñ³ˆ/l€b¤7 ±Ý‰¯#°é 'Ç€b3‰(RºÐÑøáÑAö *‚DòèõØoü2¢ÞMzªžäG¥ Ý”ÅÂWF9ëacY†âV ±vé¥S1bÑ÷þ}³í%{‡æ“ÜEøÒ]FâªØ¨Ï­þ’xSÕùª¨<ü=F¬óX/5bV.~í¯@ƒ|@¸ßÿòœ­ùg$gj̦d§&U‰›ì³ÚÞ§ú ŽúX9a m¿G%“Œ¹ä:.¼5¹i&úõÚ}mJYBº)fÞ²´þåöŠÝØžä!¬öwÖùão„ýÈf¹ & rmÎyKn1Ê'Gøl—Æ¥¹ÉP”%Lhk¦6ñn†QÑ“ŸaØd£G(´õeÓêK¶ÚdAƒÙgÐIz½]B€Ó¶,s‹}>sêT…Í>‚#MˆÁû‰3,ÕÔi±O”ûDí‚F C\ÀiWà•+|}ƒÇ¸ݘaT6˜aó;Í@LrcñôZ×LŽïF¸úr^}¹Y}âÒ³èÈFi±„Á“tïªäC£Ø…í$É@‰ˆ='& ³j1<³ºvh4^c (â(Pƒ“YÙ)抔ó#õÿã d$$ êDå#KL`t²s{®`Ï;°ÿü]þˆ†\±g9®;ÝÐRÝb7$'ÌÐ|DR¯ú†©—ús¸}W­VŽÀ«Ç: ,öNÛµÞøúd–ÆW0²àèslÁ5é °ýÞzo|±‰Çº…œóv(¨ýßÂ]§¯‘ž ¿²PÇÍçÝûÝuÊ#–Ó4¹›êøH7Q&/(ÝÔ±s?¢ VûsÅ{S7%bû¦¯Ä¹kÀE+<:€#« ¯ˆ¨ËTœ…‹Ñ<\aX87GüSëÈ[7µU®0œxÃ1%Ö#s²¡Äù Ì‘ ¶Í·¢j5"YúC"`Ž,BÛ ”y®ºì-ªóóPYëV™'ªT3m ©€OÞ€q…óà•ôâù۷ӳ߼œä?¾y~röü ?½UÃ1=y;éö’‚·= C™Ü… «¼ú_ªDÝnP½½ŠNQ·¯åì«ß÷ŠTí‚^S\!NHC+e¹CO” ?O²}É]Іۋóø=DxÒ„÷9:¾,Á¨Õ{:„÷x즣f¾6[3+,®hÇn°ÁX ¹¦f LS#ÇeB‘‹Õå ƒcèI3$X2Ä+Á­ˆ‹ÅÏE>"“±¯åʖ͈±|-ß‹H?÷PûQ14¤HN“<Í!‰ª Fó!J+Tû+µº6 AËFœŒæºRüª ï¯Ê•Ô2D½¹Øø Ø/Ë–ïb"I¿}õh|0Î\ª'%—†ìRtùùé>”ÖR,šõÝ!‚ð‰’ÀÀ8â, Sˆ¯Ã«Òqʈ֭/«~Íü>‘L…‘‡ügZР !ýTÁmI™Ñ4_×z͈d‘ƒ°uí§Îês3Ç ÎAµ×üуrPî1tZêWê™æútzF(Iâ›h“½¦^.o'6“K[ɵ=Vr˜9‰mÖÔüß:ÖrglúB’j†ªjЋ;mvúò‡Óÿš¾xþÃÙ„¿Á ôàWÃ*vÙU£ú®À'üïTqPÏ_v 7í&RúÕÛ3*N?tyÎÕEv|†ÍS‚½Pa¿ÆgÿýÓéË©jøéógÏ_>}Ž×mPùÛWœdE ½Ž·Ä$ãftÓ¢ñð·â5s1ª„œÁ({Fz¥ã`Ÿz$h]@{ãéÔBª;¨¯ʦ ¢- ’ºBûž)Ñ.º€£ÿtsüoª·™ ã@AM'/ ­r²\íÞ•Ý AáÞ Ùf,‹‹È 8ÁzRÕ!HH:¡íë\¿ƒy³…ÌX­ˆQ< }ØÅ«‡_í3²Í¢¾ýÃO/þ©…]óuY@Xرvg[TgwsBb0hÖJ ’ &e)^G8¸M¼#°sGþ£Þn.÷¿/ë…Ú¤MìÑáÝJJå¨<Ô-—£IvΛEy^l—WuêÌ8TH‡H †ß ´ZLðôe6øD¦ññt8|'œÁgƒ™ [`ìú€€H¦äè´—F‘ 3:eX¬í'Ï£ˆ%| jM|°ç§(»Ó¼Lî ÀΑ"ÐÞnøQa"›œ ÆgxDò ¿${.f«èâÅ\šeC-f£òàâ@1´Èõ0rãßâdjÇf÷¹°É¢ UŸU±°‘èUŸgÛsEOâÇ©zåóv6Ì蘳ELr™ò¶¯â¸,ERHg¿·áG˜þž0é Nìszªn㎪ÛO৺ì¦êE ÎÑT ñ†ÄD”Ø~‹!®¶Ë‚<Д ²ÞgVº1‚n‹œí¨#CG¼ñ’}\—T¬@330k9j…”Y‹hœ„FäWÅLÏ®d u˜ÎXŽIÌûdˆ‡Ò!ußæ_üÏ£/Æùƒ‡Yááa¬Ûþ}u˜A qQ¼¨öUKNÙ“_ñ»Ó—?Nß¾~þôôä…1)ÅËÒ$תöç ¼ü޲ù|BßoßI^¯Ë߈ïR?ÁïªxçûD´¯ŠËïR?¡úßEùúžË¿¿ÙÍö± ®+³Ç¿C‡ôî×ÿ÷GúÿÀ÷›‡Æƒnè(ä?¿Äøáôù³éÛ?üôý+;ù?¿|zvúêeçƒêųӧŠ_ä/>nBþ;ø³Õ<ïÚóŸ^ŸýAq¡Ï_½ùƒm[ñ¢?ý|öܾ8yûöÕÓ)¿ö{ OÕ²kÖ7Ô)D ´éJ‰l#¡x!~[BÒEmý§Ë0šS½|vòF‘þì/žO씟ÜLþ2XŠê¯^¼úÑEà“É÷“§>ðé˳ç?>CÐøÑäpr¤=Ü3à±í­Ú&¶ssÃzÀã{û”gófÉYÌðf¢³@`’3>I.–ͬXº7šì¹tƒÇ˜Apõ¼0Ë_A\Fõçm B;ÚúÈ|»üP\­à‚ªïš‹&Þ2ƒ÷ËÌÞ/15˜8ö°( ¸jZ8Òáôçƒy’[3dRf” XZÔÐj•òÆñ%VJhDTI2=ß\¢ñWÑfØÊtÆ5Š5”E§¤+ô=dŸ#`FÔÏE¥ø¿ $¶‚Â/Nž½üO „`â´t£ÍjÊÇúÞ=ûGÌŸ„ùÈÈñ“¥€Oçÿ9úæð«oüü?_sŸÿçsüóÿèùðíÀô?þÖÙL¢é@îþ87`¿êÌ?Ç»$þÑöËxk™iµÐäsßbwºAúæÍêf òŸ©)a»;/#Å«ZmÍî½ î]”×ÒšG>EªÈôE?:¯LÑhÌDkÐ=e†‘+µ‚0¯‘néÈ9.9¦;ý8%• 0˜zôâ~û`%FÁ§©ÿv'²ªÙx:ÄäwQ.Ë‹TçU¤è²˜•KÛ{b~&Ðõ'r÷]?ª˜A 0žÞ‹HójG4\1ÄôªÄ„=ö)¨šµ­CÐÀË~T7F´å‘9ŽìfçU¤èº¼¨ÀùXÒ¥û.†¨7M§”¨]ÊC ›$›÷"Ò‘‹îÖÔy%qâÝ‹}‰T„Ó¬KDÝwIà!Ó}— DwK ½’cµ,æ¥ßàëHH.µqKBtß $D™àë9ü-§û®‡~á÷‘J E¸$„ûÜ!€X»A†"¤ A²Ø^„„–µ-„òc×0À|R×W£š„‹W¦õ²cgÙF0ÖÛËõn‹(ØŽ@+»¡… 8T¸À¡bBï-QÄböÁw¬AüTCD°4€©ÕºsKM›ç” þª¸t^þüâÅA.ìJ)"ì¥ÏR$zë‚F×3ŽXU‘•à÷Â;T{:â@‹¾´Ív ºQûf‰Þõž?‡ ¨=Ýð |´žøçjO?\ðÑ‹!7Ç ñHA4³I)(¯xûÄåo6›ü °˜urp0fö`„xB¦­Zݶ[\¸WeQ³êðú’â1e6I=Õíî$°o6ÅüöݵèêHºTÕ$Cõ)üÌõ{5z3·Þ…­;”A5 he@º÷º½V«vY)$ÀÅÆ`£» ÷D.™À­4>E:Àî–Ó7 {n1n»8Aœè˜ xÑh;·É »áƒíÖ+Ç6pMŽÓhó7¬kap:wàD X Ú§&"ØåïZ•¥öÛ‘ „[9™b,ŠMA.G™o"lç§øÓI¨£MéÃK÷ŠCY«ùNZíšY€Fíä \Clt,4†ôoÂjÜØ§Ôû Ǻ_@ßP {8+ëUÖ¬–OÏm¾¤8µ[k¢Mè=uÄŸ¼ª4®˜ùð·À„¯Ës¶j3æ—8J™Ø¡ ´P—-{„í?fl8ÏÄ ówF`à6>u›í­hÛwp&Ønÿ ȤÈÇO¨h!—þ¦«à}Ã}EÝʇ ´ogí&hqÔe@'nlNbU'òìnéž ]&DG]ÎváÞùrI±~9zðlê/xgòÉym{,Û¡SÁ|N:¹ >Ë5bÇâÎMáÃå›É‹Œƒ¿8¾«þ]‚ŒÛ:,ÏG<´EЋ®Œ9DÓ.œW þ>âÉêú‰è¶]©™jëWhRñ=€ý„|ñJì¡ …­„ 65bðŸr3;ˆÉ˜ƒ£—3]ýjÙLýªXý÷é÷Uñ ¥|£¨îÖ±@×N&áµ—”ÖÁ'($Ž €9ê´è={¸J¾èàäÈ;q²Gìž1w`…†žð®rvUYVK–ÝlhÎïx ÅDÎIÊ9Í“à-iî]]-ѵÃ# |e¯³&àý_À•k11–Õuya v½"Ÿ—_ôÈ¿Û`ôåqî œ\"½þq0k¿=}6Aæë ¥!Y‚BªÏ~Ck¾ÓÔvK cQ½}4:u<³RÎf&œÝFú˜e,Ùai¡­küùï!E|šöc‹ù¸sÖì/<»E7RÅ€³>Ù=æyRïÒ?êMXš[žòQí~Ìí5Z¥‰¾³ä«9k˜„ú ªùvY¬í=Ä)ôùVÈ ¾°ºÐ£ô4Ü]9ç*—ÈaœÉ™ rŒʩ6ºÖªz¶ÀP(Üœä~ðv’ŸÚì¼Ì8ºÃ“ òçL(ê8S*[D³Ëƒã•i´wYÑqüÏ{ãü_X¬<ú¯ÿc„êcxy éõft|4fspŒÕ a3€ šU7A¡'ÜPÈ”ÁÐ×Ú;ȃô—ñÀx%’_ød¡Ý862Ö®à‘ºð ò¬‚[ 4LÙÅròˆÖ—„ÓöjH—IuxÖb™’;>n6ˆÃE’Á:±†·ó9¢º\—#ÏÇä¤'ggoN¿wÜ6Þª7/”_r÷ïìù›ŸìgßWÁ½Ÿv}ìVòÀÂÞÞcA[ÃÃJœA ­ˆº„BÝÝÙGÁ¼Ü‡-Ù>áæ9îUPàßèaĬNn0‡†«ú†È‰”ΊBØ7dÿ¸ñ'ÈV;TCDpºýã5nê¾2œö' ƒâÞÒÉ­QÐ.Eš£`Wƒ;M OFØ£&/ †ö&Ù¢M1ÍÔÅRÊ¿ 3¯ ›äNŤ¨›퉪ø¤TÕ%å…[Ç!®\DäÏâåúÌëóOæüñõù>:üÊ÷ÿxôèèÞÿãsüý?p> uþ@à[{~PiÝbÀç¾Ì àWííÁÞÁÕ÷ïêCS€xÿMÌü¾>ß{¢þù|¥¨Ñªû­ªÐüŒdcd¼ê/`Y¯0´…öçÑöÏ)lÀ”¬.³î»¾ÎO¹ˆ@B¿Š%_É© B€÷ݽ'á÷ƒÐœÂ­™ÎÙQ–/zÐGIŸ¿xµ"ÆÞªÓïËu[,m¿×hcÿêV¸›•pw.F•ÄŒ ß6°C’û•Œ”9ïQ9—͉ÿñZs.9ت0 qwm©FbÊóf_ËE»ýpDà/ëò‚j«t‰Í>& p÷nZÜaÀŸ·RüŸñg0ÏBÒŒŒCÜÏh6r1³è0”Þ6Ï‹z~“ÃuÌ@ÝÔœ‹1Ÿ(~P=¼Y˜@û(BÜ7÷ù})ØQ(_¨ë Ú¼~ìEUõ'4}_JºP;SlV´j{L‘$¸ÙÂÈÌ)3Çs)öþ¯‡\]M0±Ñ† >ÎNÔm¼Q,{qcîjÆ|{vöä\±¼»î­£ó±ZgrÀÖv›©_Ÿï>Ûe«îNÒvz@»7gLŒ_¾üA“Ø1ØDÙ ¶È½Ú ²~…ç(XîÎD¡K”Ê¢¨¬n¼ %"Õâ–„^܉С£éèVsË­®“º×µ™tVÃAv¢f{»ñs+3àÐ ·ðU”›¥Û>âΡ”Ë !'úq¨€I 6Ó 8äÌ ƒÐ"å™Zõ´Ëé%FñÛhlŠsN’o4W­/€i‘9Ó'\罿¿/*`'UŸÖÙº¬‹«bV-¹Ææ×6ûæ$_©.l7âäå3P¾z3É()ßU QÕ—Ó~€/ê„*–nÒÁ¸ÝbRšÒwXîë.=ѵ œ@Ûš €¯ÔY<=¯SØà§ø0™%Â,Ý¢ë© w§+Ê‹@(ÖÃh=‹³Þ'~0mdÓo“)}G~ì­®§õZAnˆ“»ÊåÀ@ ¥¾V¾ ‡¹Ö—²Ö¼—‰2"»ÌsPà—5µ¡#N>\ù5†™°«.m$ãà‚k6ËÑs°¡‚@±0u³`á2M‰…<¼b7[ N¸ªÝGê b¤ÖÏä2%ë ̆F83+Í‘røëfýŽ£ßÕ7v€9cƒLhCtS'VhB75d—G5•6s†Uu¡¢±…v3à=t8Z=%9]ئœ®ËYUÃQ82 ”©×#×c(“- U0ÉuÛ¦»šýÄ92lŽ{ Sà6–XõÂîü{éìýþ‘üÙòjñ‰„Àiù¾9~äÉ¿|tüå½ü÷sü…å¿f> ›·—Û*œ„dÂúó\€þº¥ÃË»DÂÀ»|å§H@Þ›ˆ‘¿¯@Çkìp/ÓBL+Suµ11Bœ·Ñ(^ÙU¤X\úªÁÛ©?l0/c(n@79»AÒu^EŠrF{ÝV½iˆd¹'ø%*îŽ_÷Ýmb:tª lø`£³f…Æ8ó¤¼*#B G–Ñ`U*v Y8ª]1ð`Þ¨XK¢ÇÒ%WR6°¯\rT?Í‚^h‘TµÈtÒs,hâØ¢»'UÓÉn÷çm5§øÌ‘›1qèÐÆÒ+8ß‚r¸.`×§ã÷lÅŒbµ3sÎ1 "_r«Óg¿ítÂ]¶A1M’SŸ®&¹göÇ©’øŽê1ù$ Lb¢:=B£å± VlÄîZŽ£.vŠe¿‚ôùžmxÏw»ÔÑ1ÐæUC¬dQê')¿êŽ©Ot´×·ZÏ(gÒz&i&gÙÆÈÃXzS‚†v öºXZN¬ð^šr¬u@Ùzû½iA4nÑ1¦œ »]‡«È¦¶_‹ÁßmêÍ£ð¶Ž_föTc»Z íÒk n} ÙÄ[÷ÔsY˜÷D–Œ;YCfƒµ›_ÖŽÃ:ª‚ê9UH†"ÆyÊN‡Ø« ‘3þØ8DV>Ât+q]‚tÙ=· g“ÛÝâûË]åñþ§£"ü"÷¿ãÃo¾>êÜÿ¾þúþþ÷9þ‚÷?;†Þÿl‰[ßÿDN÷?óy.@Õ÷?‰å]îõ o´êæg~Ç®<ª½’cTÙß`ÕAL>Ånt¨Þ_N5jêNç¿ê¿Õ‘ëŽ. rž£w¹µbròéÀnL}àuÔ¬èC¹0¤”Oi3œz‹ (qèí¤7ÍÕ”¸G²jÒ—o]¿ŸS¾Œ¯Ë‹iùç½'ôoÌð‹ÒˆÔ‹àŒ é“ú:øæ¾(W#¢§ÂëRN+ç1‰$èé6S|ˆ€oŠíò[Ýì=1?wA¨­IÈÔS"beu^Å ÷f ¼1ÄÈÑnªo8„¨x3MtŒÌa°•/#];s;xò©U[ªó*….ä_5%ý7ÐÕæQrÆ^ÆÐU<>XØìf¢šÄÇ(1®ín(b€´Zº5ñ0mtýAïO| R¤>DÚ iSJ} )âeW60õç —Í£øiÃe{RÝ0m$ŒU„æ]ñj²V›±d‡YåÚ#´Ýpž¸TEð"à­‡êUF~hæ§ëÙÚRrÉ‹˜(0t”ˆtuÒ©eQ~ ë!c$æ›L\q‚I~‚· OÜ>˜DßM¥Žü/X¥€¸ ‹„y6dÖ¿O:Ò»è|P¡ÃºŠÅ® §fËÄ 5ɽ«äAÆ¥(œöy^ÁØ@Ä Èt žb||]h¦¹0ƒïñ¡ë±®+yAf˜uGÖ4»Ý5¹#Ò‹: …ö&¯´ ]xfû¶Äp´½󰋪ô6íDåeø‰ƒ¢¹¾c\%TÓa—p·Í[åBº;´ÕÛŽ—¨~φnàxtµÚÜt¨mß°A2ϧ8 ¨pP]ݯøäp"‰V]^cÉŒÙÐKßÅ Z.ÿÕ5¶¿;JµiV®ÍÕAös+¸ÖqŽÆpt§À‘Éœˆ¥ˆã+UõÁÝY‚|„íYñ=þþ )Éœ/ú–nvnÛa­pv•>Æ/¥ñ>êm§ _°ïv±vô牎#Ä­H¬§³=·p¶k2j<ÀÌ|ãvÌÕƒÇ:'¡nÓÁåÒ;.Zy(ÒnÅ­„ºgÜ00¶v«]ÖÆaðg_ë²U¢{×8…¶Ñ°?ï*»†…Šòß$Æ|b÷Ö;‘W謼љ–PûA{ ¾•sp<:pw¾qiŒÓ³Y%wd¾m§F ¸ª~ݾÍopyñ×"Ä“Ç ¶¨c#=àní}¶ÌþýÙv:%z H\ÿŽG¿šèøÇ> :xàQpwdªþãÃúDLJn%Ô½ôvÕ»ãnå_;c»BØè1zŽ„À{Ùì´åaˆ©¡0é‚­ CÀàÌ0ßwÝ…A!îº w9o X,ÈÓ ðµ&RFi"ª q õ3‰t‚ü_Ï&ùþ¿þÀÌÿ¢áCï«°L>|÷Á&î˜ît‡ñ‹û”%½ú!lÇ2/:m|ÐÞ(æ$:Ž]\xd-DJÚ¸^`6[³Þƒÿõì·SÂÞÂ̈„‡GsƒÀˆ Kaôïó®LáÓ#ì΂õ ˆ»^£¤6 {E X…õÂÀÛˆ"½˜è$ˆÔ¡ÑkšÉãÈè‚ùÝt£·´>vã¶úæXpù!1Haóû#æšQõ5Ýö“Áà­¨èVY¦x0t;Q7ë³<Î2ÿã_³œ>ø×ˆ¨\tø—€4Ø+VöÃæqö·[…iâ†þ_8¡?]èžø_>ñ?¾~ñŸïã|ž¿oÿùÙ«§gxý<‡áÏ_ÿüý‹Ó§ùÞþÇ¿?~úðá³³g9L›ü˃G‡>¹§&@Â?e±PÿlªÍ²|òâäÙ›\UõöÛ‡ôBÍ7Ⱦ5‹ø÷òÁÔ‡Ã'ôTÍÖE±;Q|ÒÞŠž•<‰…OøOVžl/Ô˜í©‰s•®ÁÙ¬Y™¥Í¾ÝB÷–Õ“üÛ"¿\—çjÅ5«)¦áegž¿}Xø°4»d@z@Í ÿÅPô€R—Ãi³¢ÿ*ÞüCèmv z‚•ÚÑ‹(¨JXé~áƒ[Ãy‰ìlþf‹¾uÞ댔êW ·Vë¦9×=å§\1Ÿ®Õ(Õ ¨—˜S›Àðw’ówxý2Ääç,ßÜ’Ÿpë²m–êªDpü€Sgb{ÉPø;#ûë×¹º9J8ó,Gè{R]8Ÿ’_h˜ØØîªjç¶kúMh’mgíöJ#ËO!¢¨v}ðÐC•¢Ý(¶º>ó"M5ݨCX‡žBu–(ôLСÅñ šEi§9> ¯ËêâR¯gz@-íÙêsr™ì@¡þ©ÐkžŸBÓEñãªßý“Æ,ø&ô}%ûµŠõ &¸ØŒôcx"c8b9aÔc’“=pÈõÎ÷?©Ý•àg¬-3˜ü…«`Z>s`á XluCaìOÁ×l9=†f¥ у—[ª æçÚÄ-Zö‡vD|îum57ûœúšŒrj\ŦÆl£I¡~¿oÍ÷mpé6«K³pÕï L;_WW׌ã32Dþä†gefU„¿‹IÃO8™‡Ëî;¸óyQ7ö€Ã§ð5el“nm³õÔÕÏ‘sDÜôc¨Vý&‚;¼µéÇHÁ Pt‘ÜŠ‚JRó{ Ý®¹¶YIôfvFz 4â²L»äÀ]"\Dˆ îf³­Þòè! ¦ñJ=„ØË-\†™N9Æ‹B§œêĹ™ü<‹7æTÂß51WÍZSŸ‚{l3göXõ;Dw1MÅÅá%NûÛ‡ÄÍ+žo¿ôýåþïnxÿ·Ëè“´‘¾ÿyüõ—~ü—ããoïïÿŸã/ÿ…çÃÐà/ ~ëÈ/º¼m7ó…¾Í5Я:Ú‹Añ.¡^ Ž£)E@S,Œ|Œy{9qÇXY—WÓÅv¥Èæ>ÇÜTH]„Á×ü÷„p 5¡A‰{PÚ.7•—}ׇh%©»WIu‹Á©i4Ý6n€ÜþË‹$½€d±\º(ªIWÍJc§~@ Œ0èl3O#YuÊzaáç$„¸þ™î¸®~¬=ÀQÁ(ÅR‡q§%U‘•{¯Q<%ÑÑKB> Ef¦‘‰ÅÞ­Ž±Vò|V’}hlÖÅ\"‚ÏPqv‡ÐrK >r<zH#Ç®¯ò)‰šºI‚F\<$‘Òº h*“~Dìº9²n6— vÔáˆÅS:<°«ðÀ¦QZ ”RUî¼ëŸv˦¾NSk1‹|H†Qhj€còw^õ£Ê~Zzï71·Ì›$Úó¬õ3JÛ{©È²P’O}¨—šO¥ÄÇÁè2½äSšGÏ£ˆNkÕilí­K0p/Ínà>@ ìÐiãf£tzH#¤fµAHýîCH˜! ´ÄÛ>ä<ÜvAíX¢–Ü%M²w4hl:”½=(­\”†N@ÄBbÔ‹Þ®4RæEb¼ÿ»Ï‘BlXãdDh%êß+Q+Ø–öÈ5/bûÜŸV½[ï ÄÉœº/û‘/D½´ìï4r­äðè)Š–®{•®lN4¨ý=°ûÇ¢ûý«G^ R7sä$'0vöXt|àž†ýîí¶¹5õ_WÎy-ŸRH†£°²(ô¯ g‹í¼J"ƒ§°ù™@ceѸøF`Ø›£~zUöÒe~öuÿHôß;]‡tOïùâ)Ý9Ã`?W²‰U¬…ãTA5VîÑ1 Äu’;P#~ÉîóïÊúQÐ?3ÇíK‚yÙñƒ\ ^Q¸•UQ­Ñè6Þ µõd§ØÔúðÛ÷År[îúwö„à²ßƒ'@ú–9RŒÑMu]‚é5W)ë^êÂegè‘Z@ÏPRwÕ¬!ZQ£Ñ%Â`ÿ&~Ö /lý†ë`§öc% OòÓ—gÓŸN_ºeNjþ®“pÀùÆCö¸•–þžp(=îÕ÷°á«+éÔ|dk6ê(8¡M»s©Í¥à²ÃÒäyhì…x%8îý£>`ÀëØˆ÷ xÿxcï1[®s³åùy5¯T÷dÖ=Œþ*{4¨®ËÇù²iÞmWä/¼¬ê²XËYC ¹ à§îH:ø¶,÷k> $<5u=ÐÔ~«>êÁV?»CõŽ%²–Œi)墼ªÐZ—AG0e®/›e™Óœ—o(Øê¦Ó¥HD‡¨?ûã÷fxg’ M,„Na2 3¯oÕ™®¤!h_탉¨1£âs‡¹ º|Ú¨1ŽX"Eš8–&á)Tks½=ÃNƒ5P¼J]‚{W¢OúoòÑ—ùWùa~<žd€<„¾×åë¥ë©îÈÂ]µfgJ͉-`QWbùzuõV]xnE‘Uc+Š/S‘¼=FÎc ’ r#®q‘]΂ôÕ“Úš @O%É-Å$*ñnâ8Pz&-áôÆ/ôÏŸDA­õ2 0¨T{ZëTGô2 ‡3q¯¡ÃLB„'}Ô)fYÖ:žw­Ór,+šK)Έ֡Tr­cÐaª ¨›˜9Cá ;móo«IýDa%JšZ•Ï~ÛETª{{C€º7ê&¤û•ÄØÜþÒÔd°[L<“ÐKL¼uµ‚TO4ä‹-·±ß’‘;]å]è1‹~ä$€"G_+|Àƒ„Kcp}쩞íaŒ°íjOví8½ºiËr ôÞÞ!23…·XäÇ¡E~œZäǽ‹üX.ò^f2ºÈýE~Ü3/Š™yy[’Ýfz¦çqjz¦§•t&@jÏ6â¡O7 f= €æ ¿å<~ÚÔ ª„”ìùæº! #“Ò·—­Ú³¸ƒô@Á@M„ Ì$ˆÓK¬ÅÄõ‹¯’ëòœp-+ä/udl ›çNó7W+X/XŽ=kÔü°ê¢\¼é£^²}Tºd§5GâxOöUôYP›"t*D*Z-‹9ü¤NjJ Óÿ!˜q^:{Ô$›m¡“|7ïbZ±$Ö "Í=:J¨à&"÷[o!þ"®÷¨)J!aÀtûi6ËMºj㪠=3fþÄ`gTŒÑ§ d‰<‚!y,wTíâòu×´ÖÁ„ù¢{™Âœ4")¤Âî_©ºÒl–ÃÃõn‡!ßt»#b°g§3B±„G3É1±%'¬5…TOumÅâ¦âI¶qv¯mvÕ ŒýQpñ• ÀRóñwÍu~A#€“ä0_ÞA-¿õ»ƒ ‰Ô0*€þ©ƒ>™vXbbs}Ö öø¶)P;Uu³F!Á†©<žtÄ&ª¦ÜiÖ6ÔJ`©Çy‰‘æŸ­Ö ÎX‚^ŽÀa¦:®¡¸ç^.5ŸÞH8ˆÈ¿ª²Kð‚‚$¹´}ˆ8‚{˜Vm’Îéê©5ñêé¬r4¤8öN­È¯jvÛ n˜²Cv»¼ÓpàPÌ)l.oô´+ðeY¼/qTšå‚_Cè×üºP%Ÿ5õªql®Æ”âÛ+ò¹É‹H«°àZ¬ÍYø¨&¯—$}ˆukes³$ªu!liÍQH¨CÊ osS¨r·9!Ù2$ÕSÙåÇ¡ó{å÷®µ å)† í$w•Þ† &Ðrlƒb»ÆfìN°>QK½ÐiŠyt!þ3ÍT“hÔ±‹\ñ%†t1;Y,òC±Uà‚……É‘¶§¡ÙÒm}Zûí‡DCк³cõ÷£—£Aê]%‡ºc ^˜©»§ÒØróÈK.-ÍŠÞóÀí1»Ãíq×›ãªW·# >[ÔBO}#z›Ôa¬’ ŒêzB¿¢v¹/þ§þBÜ_ÝÞ¥;G}ûEº–”ìðn'%;¯-÷Iûðû!‰Ëô-E;¯¢× ÑŽ0‹JuD;¯Í9üzˆãõß³h‡ÖæBBëæ&L€TÇ£ÈÑG%IRª³ÚAªãblo$ m´¢ÐHÓ…Ê6’áÜ/Õµæ}ˆ"q9è×Çä4¯½Ë›t* 3)"­\t}·‚¬¬´ ƒáîŒ8À—(„q ^³åƒkv/=;×ìןûšíy`%1âkö.¹húFïÙ¯»÷lÃ.F÷¾˜…™ì7Û—N8Ôi¾aÚž¹Ì£í>îo±I‘¼Kw»4xú'or„++ô–¹ÉùŽC©®š›\ÏvùÉnr à>惘/qOa»ãÄ!õvn¯)I„9/ˆNºî$»×-0R8¯ó­!ì.]¥º¼Þú³Ó÷½‰(Þ\°Aš?,ÐúzH¡1CH*¹'rê7Í6o/›írá2’`N¸Úåd:‰“ü¢ió[Ü@1Ì6„ÍYVãE®òï„Ic¿ ҈Ų]êEˆçÒ.Á±F('÷wN7lƒ¨–4¢q€†°†j¯ÿa¨s  RMº'…If!˜^ÍìOå\±Ùÿô d‚pCÌG š:°›ù8Ñy§Ï½q$rwÈ™(xÞ Ó;˜iCš¹B 0À¶ˆÎÖZ|àjzñn“æw`À®§#Ývmgƒíö5;lÃ0i3%4ßû—›n3lË‹oÞ˜Iïú²š_f’@¦Éíhf~ËpÀ&I40]²Pgm`z !€™íƒˆ¾„æëUUqU§nU•© ù¨è´§¢#]Ó‘WÕQ·.4jÁJzj=Öµ{µ'jEc¬þØ«~÷XÆTeM¹bØD†gI«¦Ãòf_í£ïÊ…Ñ<‡xhuMÉNSÀZžpG)Àoµ¶–ÿe(w¼K9[ž „ ëxÍûã?Ùð‹Ÿ¤tü§£oŽ»ñŸ¾~tÿésüã?ÍõÖ7,þƒß:þ“.oÛ Ä¢os ô«ŽÿdP¼Cü'ËJYðlößDœ2ñÛ”DmLm~JP‡¼†V?# ®Û±ÐÛ~ÿYjKKËåS²ŸZ®'ŸbÀ…‡à6Í”e—Šao®9zIøcùº©1I†‹¼ÿv7ä§hñà¿I¡1ÉŠZC ñ.RXgVÝ*ºµsÕ­P\é)ì¿K¢i³¡Q|h]ÿ>R ;qðmîàee[Á< EEÅºËøDÖTÇ>Ô\œÈè™®‡ÑyŠJœuñ!‰’µÊ§9ÑvºdïDÄÓY> E .ºçÿ¼%¹dí›HAÎý³¿cèа{;“B,ø~(Š&s³¿¢èo1Ý/‘Š®ŠÓk¹Kz/"ÅPPAMÍÔŽ´àx+âÍp„Ñe4qû®‡(w±Xãc UÚvÝÑ ¼Œç”KXÊþÞÍY©x´ÒÓ^&m¯í¡¿c_qe¶OûÛÞ-ÈC—‡ˆ8ázpV#cz'CÏ?Õýò²ɬçÒ¢ZÝë¸BøÉ¹œk¸ú¹€—^ÅK”¥HÑÁÏç;â1 ÐÕ¡a@ºÂH§§AãËNÇlÔ×ãÃ~¤\uÐ Ö—ÅüRhù–G€Ô¦†¯Y”zuçÏ<ó€åQÖ±¢˜’tu{Ѧ3YÂL‡%H´½&\ÑI?­§úÅi¢:²gBä9Ø¿×7y¹^7kÔ®eçͶ³5-©†Z}S”èQH´{B³£r¶½¸€hìþ0û” ˆ4¨¡)Î|ÿåÏ/^ŒûæbÀÀPr‰€¾‘I“6È(Áàö£ƒ!6 ÎI¦~bLKœÙÝ« æzíÛMQ–åÃÑØ¦ÔÍjN¦ÍÂÞ` Þ–£¥…šw³®€NK anšùÍ6¿€È)xì³âs„ 6ñFÌõZCŒ¶‚F1µêõЦ/Ça6××U{ -"Œ˜À"Yä0ï²ô¢¦8 ù²€½Ê  ?hGcéEâq3T;s ë'MÜ&‘¿ÐZjèJi.æµQ`SúÂ$µéG ?-~ÔÆÇAPKhBª ±Ûaà5³‚²°ÔXõÃ;„p ÖwŒ¤v$—+òHL ØG»¢[׿'íS¢yE¶íaÝ0ÛäÍ:ï 2ââÃâ@ 8§fCÔfKO›l}Þ4°CÄl¹vœ1+. q}DŒuÎqË?ô¸Ö@±6“A»æÆß°ï ô¢z-o˜¾ê´¶gd÷ ½]¨æOrL;CL·®í€Äʆ@·‡ð½ÁÎi e‡cgb«e•¡˜m6ºkÉÐ&8'8,f ¯ C˜ˆ}`\üÑ;Ë$ø¸wƒyw‹¡ºOsQU“èå«3Åp/Ë Ø÷–p(ÑèÞ°ßgÝ\_– ®\:©ƒ=AG?„Ù ©7Th÷eM‰DwÀÌ!µ}›“Ùiÿ¹jþFÏ=ëkòžÊGWÅͬ$¾s ³»áø~ÄS]“÷9ÕïÁ¯Wú`l7ðIÍíÆpsbJ~¯›ƒ²ï+µ¸EÑ¿ô੾ïFòÔúÆ«³¦ÈÈî ã! Š6!Vk…l‚)#=ïXª‚ºÉ4Áï«nßh4ÂIþFc8 i–Šdê8™ë Þ€vÜzRŠˆ$)^¤—I©eJðbÛÛm\MzFCçŸçÉÍN)ĉªÁÓ­é\ÖÂÙ;¨ NÁ¤¬v›Ûy2]ßÌ”Â9…{»Q³³X/Àyá¼úcVÉšðÛ ±ÑÂÕÈÃ4è‚0ìjY°ùÿ>ݜᢨnœÅ ¸žAô¼=ä2¾íbÁ}üO½']ž £CEƒƒäKñžØ4CËëâÆ ú>uõ7½”ÿ»ˆaˆ=ùÄ1 ¥(¸EX€Ýö†ÓŽ|{Ò1 ‡(ùïT­üEìÕLˆkó€vëÕ[vôŸ6žW&íÝ^™} /3ê¼.kéïR¶„7üè-7z)• Nj Ð+œäCdeðµÍÕäU§7þìß;ÄFëåíj¥î­× ¼è`×Ò.AÙ°eG˜´!ØÛÒ6hS\$!Ðs”ªš <<¹z=ŪY%'Àê6½éóìÝùø€xÀC-FÒþwÕ»m ˆÏæžìí̶·zMGF¤o :Å­B1².m³Mja 5Ÿ· Ó ß”….s@£#‚ÛIJ³Dï aèÁúÚy˜è]ƒ€àôôÁvU ™ö¤6>¸ Y€yR‹Mç··3vç>$ŒÝçz^äLœÇÁâÉ¢T,sàÁ®ýáòƒò3—xÓIÚÿè(#KôvX½š°ï'dÒžçàsÕlé⯅t²g¨<Øf­.Ó5ªM¯>‘ç$r§+¦J‘"êIV së’#”™y†µé½þl_ˆ6®€½¤C©gñÏ¢­vCŸüŽ6½@GZŸ—mš±QèYm3ôp¯Á År=­@ò¾­–ȉ›zŒ*»g„vÔ¹£.OͺXߨ«ü碄æ (À.Åó Ôp¯Ÿ@>„ *PWQØûš¸QYYõP]”ä!þ®n®áú ^TFNaM râZÑj­ÎÆí²XOœrtá9Ýk½gÆ“ÖÄ F>iAýŽà­–Á7kE*E*—ZÃ,Ìþù ìòs¸ÿ ÿ¡ÿÇ Üõ?|2´ÿÇáá×_wü?¾:>¾÷ÿøAÿ=†:€hø[{€˜ DÓþ87`¿j/‹ãÜ@Hj>'µ)Ö·÷¤ó*b¶Év²hçU¤(úÄMË—êR§ˆ/÷EÜö3–W”ˆáXvÛW±^8¥Vý QR¥ølDü§Åã]†¹â‘­H´i±\+.áf ÖpD6çU¤(zØŠÝçx×û-mó'x…êÀI½9ZlÄ%N8j‘9M;ã÷hÑõ’ˆKñHŠAÓ)ˆ×b DÃÞ(­%ûziÉÁ/_ªÃ¯ ­%e¸(q}%XÞdVѾf½˜¬XkaÕùy¹.-FW>.'tJ@ná~q 9uå‹È;K.*`IM=¯–Q7¾bÂ$OˆbYýÅ•·&§äk3ë¼]•óê¼bãbÒäòƒƒ¼Þ?Fš¦„ºÏÀàºZ.aêžÀ¦·F4àÏ+*˜©N·Õ‚-UØ…”jÚÍQ‚ÉbsÊ0þÝuƒ WÃò&²ê˜3ã"8C;pŸb§°†CF`âZµ'‡…id¤Ç$‹Ö-EihþÆçùm$²Z_,í.CU¨¦w;FcˆH kR;cn®“R Û»9HÏ&‡õ׿íp÷¼ é’:`v¾JõÃIöOÿDÂp$Ž,Àm§WÊPú)5Í#¤À¼Y¯ËvÕÔ°{ñ¶cº“NjHÕѼÆÂ#ÃEÅÈ#€F·@íÛS–¶˜ÕÓægo~~®5#ÚBà g2÷qL£q¦ ¥rmE޲†OR¾ÔKNd0;W[a¸ld£“eÛL¸KÖò º§ê¡*®ÑHé=×§Óš$-/4QÞ'/Þ>ÇC{VÚJô¿†w ¿SgV¼W 4O@CÖÁµæÀ +³0‡¨gâé(ÅQK´÷ LçâÎÌ /ïYjv.jâ¶¥”‚ ±›ºÃ-˘õ˜…^Ô­:˜†¨ý×Tœ E;{†`q5V~™¾ÓúÍlÆ›¡Îbªÿ'޶öë¸\Ý^gãQdLg¥x<ÏǦ‚Wñ”f–x=È&zžZé3;½`´2“xVMˆåPî¦g&€ªÀª¥X‚}éì&o·WZ¸Ì›¢~Ä¡ØßÏ—Íu©øs21Éó·jÝ^—¸Udf:Zö¦ÍíïI‚j½'ði7 Ž˜Š¡ìu­Ñ£É£1ü÷Pý÷Pý7ÏÕÃ>Ññz8¢‡Cõ€ï¾ÄwÇôŽéáˆà¿_Â9ÞÖSî3«Ôå…€í/Ùûa­)…Ã4+/¶õcº¢\Áúl7v_"Z!šlc#°Õ£D®\0½*0ÃÓLêbb<ÝT£¨ï¯x)hæå¥øZÌ7[5v<®Ä9“GÓú‘bŠ^îjw0‹§FëZ†Ö¤eHBWÊ ãùrßD­%i>ˆúUO䄨LADR-2009-11A/ladr/demod.h0000644000175000017500000000312611151265364014207 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DEMOD_H #define TP_DEMOD_H #include "parautil.h" #include "mindex.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* types of demodulator */ enum { NOT_DEMODULATOR, ORIENTED, LEX_DEP_LR, LEX_DEP_RL, LEX_DEP_BOTH }; /* Public function prototypes from demod.c */ int demodulator_type(Topform c, int lex_dep_demod_lim, BOOL sane); void idx_demodulator(Topform c, int type, Indexop operation, Mindex idx); int demod_attempts(); int demod_rewrites(); Term demodulate(Term t, Mindex demods, Ilist *just_head, BOOL lex_order_vars); void demod1(Topform c, Topform demodulator, int direction, Ilist *fpos, Ilist *ipos, BOOL lex_order_vars); void particular_demod(Topform c, Topform demodulator, int target, int direction, Ilist *fpos, Ilist *ipos); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/README.ac-redundancy0000644000175000017500000000244610144707771016352 0ustar mccunemccuneNov 11, 2004. Flag ac_redundancy (default set). This is related to AC unification, but it does not use the AC unification code. If this flag is set, usable and sos are scanned for AC axioms. For example, say there are A and C axioms for ^ and v. Then, when a generated clause is processed, if it contains an equality atom alpha=beta, in which alpha is AC-equal to beta, it is reduced to TRUE. For example, if x ^ (y ^ c) = c ^ (x ^ y) will be treated as if it is an instance of x=x, and it will be deleted. Annoying clauses like the following will not be kept. x ^ (y ^ (z ^ u)) = z ^ (y ^ (x ^ u)) Otter does something similar if you set lex_order_vars and have the appropriate lex-dep demoulators. In that example, both sides will be demodulated to the same term, so it will be deleted. However, LADR's demoulation does not allow lex_order_vars (because it doesn't obey LRPO's rules). The main difference between LADR's ac_redundancy and Otter's lex_order_vars is that LADR does not actually rewrite AC expressions with A and C (unless LRPO says it can). For example, LADR can keep both of the following x ^ (y ^ x) = x ^ y x ^ (x ^ y) = x ^ y and Otter with lex_order_vars will canonicalize and keep only one. The tradeoff is simple: Otter's is more restrictive, but it can block all proofs. LADR-2009-11A/ladr/formula.c0000644000175000017500000011220411140523260014543 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "formula.h" /* Private definitions and types */ /* * memory management */ #define PTRS_FORMULA PTRS(sizeof(struct formula)) static unsigned Formula_gets, Formula_frees; static unsigned Arg_mem; /* memory (pointers) for arrays of args */ /************* * * Formula get_formula() * *************/ static Formula get_formula(int arity) { Formula p = get_cmem(PTRS_FORMULA); p->kids = get_cmem(arity); p->arity = arity; Formula_gets++; Arg_mem += arity; return(p); } /* get_formula */ /************* * * free_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_formula(Formula p) { if (p->excess_refs != 0) fatal_error("free_formula: freeing shared formula"); free_mem(p->kids, p->arity); Arg_mem -= p->arity; free_mem(p, PTRS_FORMULA); Formula_frees++; } /* free_formula */ /************* * * fprint_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the formula package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_formula_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct formula); fprintf(fp, "formula (%4d) %11u%11u%11u%9.1f K\n", n, Formula_gets, Formula_frees, Formula_gets - Formula_frees, ((Formula_gets - Formula_frees) * n) / 1024.); fprintf(fp, " formula arg arrays: %9.1f K\n", Arg_mem * BYTES_POINTER / 1024.); } /* fprint_formula_mem */ /************* * * p_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the formula package. */ /* PUBLIC */ void p_formula_mem() { fprint_formula_mem(stdout, TRUE); } /* p_formula_mem */ /* * end of memory management */ /************* * * formula_megs() * *************/ /* DOCUMENTATION Return the approximate number of megabytes in use for storage of formulas. */ /* PUBLIC */ unsigned formula_megs(void) { unsigned bytes = (Formula_gets - Formula_frees) * sizeof(struct formula) + Arg_mem * BYTES_POINTER; return bytes / (1024 * 1024); } /* formula_megs */ /************* * * formula_get() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula formula_get(int arity, Ftype type) { Formula f = get_formula(arity); f->type = type; return f; } /* formula_get */ /************* * * zap_formula() * *************/ /* DOCUMENTATION Free a formula, including all of its subformulas, including its atoms. If a subformula as excess references, the refcount is decremented instead. */ /* PUBLIC */ void zap_formula(Formula f) { if (f == NULL) return; else if (f->excess_refs > 0) f->excess_refs--; else { if (f->type == ATOM_FORM) zap_term(f->atom); else { int i; for (i = 0; i < f->arity; i++) zap_formula(f->kids[i]); } if (f->attributes) zap_attributes(f->attributes); free_formula(f); } } /* zap_formula */ /************* * * logic_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL logic_term(Term t) { return (is_term(t, true_sym(), 0) || is_term(t, false_sym(), 0) || is_term(t, not_sym(), 1) || is_term(t, and_sym(), 2) || is_term(t, or_sym(), 2) || is_term(t, imp_sym(), 2) || is_term(t, impby_sym(), 2) || is_term(t, iff_sym(), 2) || is_term(t, quant_sym(), 3)); } /* logic_term */ /************* * * gather_symbols_in_term() * *************/ static void gather_symbols_in_term(Term t, I2list *rsyms, I2list *fsyms) { if (!VARIABLE(t)) { if (is_term(t, "if", 3)) { gather_symbols_in_formula_term(ARG(t,0), rsyms, fsyms); gather_symbols_in_term(ARG(t,1), rsyms, fsyms); gather_symbols_in_term(ARG(t,2), rsyms, fsyms); } else { int i; *fsyms = multiset_add(*fsyms, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) { gather_symbols_in_term(ARG(t,i), rsyms, fsyms); } } } } /* gather_symbols_in_term */ /************* * * gather_symbols_in_formula_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void gather_symbols_in_formula_term(Term t, I2list *rsyms, I2list *fsyms) { if (logic_term(t)) { int i; for (i = 0; i < ARITY(t); i++) { if (is_term(t, quant_sym(), 3) && i != 3) ; /* skip quantifier and quantified variable */ else gather_symbols_in_formula_term(ARG(t,i), rsyms, fsyms); } } else { int i; *rsyms = multiset_add(*rsyms, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) gather_symbols_in_term(ARG(t,i), rsyms, fsyms); } } /* gather_symbols_in_formula_term */ /************* * * gather_symbols_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void gather_symbols_in_formula(Formula f, I2list *rsyms, I2list *fsyms) { if (f->type == ATOM_FORM) { if (is_term(f->atom, "if", 3)) { gather_symbols_in_formula_term(ARG(f->atom,0), rsyms, fsyms); gather_symbols_in_formula_term(ARG(f->atom,1), rsyms, fsyms); gather_symbols_in_formula_term(ARG(f->atom,2), rsyms, fsyms); } else gather_symbols_in_formula_term(f->atom, rsyms, fsyms); } else { int i; for (i = 0; i < f->arity; i++) gather_symbols_in_formula(f->kids[i], rsyms, fsyms); } } /* gather_symbols_in_formula */ /************* * * gather_symbols_in_formulas() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void gather_symbols_in_formulas(Plist lst, I2list *rsyms, I2list *fsyms) { Plist p; for (p = lst; p; p = p->next) gather_symbols_in_formula(p->v, rsyms, fsyms); } /* gather_symbols_in_formulas */ /************* * * function_symbols_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist function_symbols_in_formula(Formula f) { Ilist p; I2list rsyms = NULL; I2list fsyms = NULL; gather_symbols_in_formula(f, &rsyms, &fsyms); p = multiset_to_set(fsyms); zap_i2list(rsyms); zap_i2list(fsyms); return p; } /* function_symbols_in_formula */ /************* * * relation_symbols_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist relation_symbols_in_formula(Formula f) { Ilist p; I2list rsyms = NULL; I2list fsyms = NULL; gather_symbols_in_formula(f, &rsyms, &fsyms); p = multiset_to_set(rsyms); zap_i2list(rsyms); zap_i2list(fsyms); return p; } /* relation_symbols_in_formula */ /************* * * relation_symbol_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL relation_symbol_in_formula(int sn, Formula f) { Ilist p = relation_symbols_in_formula(f); BOOL found = ilist_member(p, sn); zap_ilist(p); return found; } /* relation_symbol_in_formula */ /************* * * term_to_formula() * *************/ /* DOCUMENTATION Assume that no subterm (of t) representing a formula is a term of type VARIABLE. The given Term is not changed. */ /* PUBLIC */ Formula term_to_formula(Term t) { Formula f = NULL; Ftype type; Attribute attributes = NULL; if (is_term(t, attrib_sym(), 2)) { attributes = term_to_attributes(ARG(t,1), attrib_sym()); t = ARG(t,0); } if (is_term(t, quant_sym(), 3)) { /* example: $quantified(all,x,p) */ Term quant = ARG(t,0); Term var = ARG(t,1); Ftype qtype = (is_term(quant, all_sym(), 0) ? ALL_FORM : EXISTS_FORM); f = formula_get(1, qtype); f->kids[0] = term_to_formula(ARG(t,2)); f->qvar = sn_to_str(SYMNUM(var)); } else { if (is_term(t, true_sym(), 0)) type = AND_FORM; else if (is_term(t, false_sym(), 0)) type = OR_FORM; else if (is_term(t, not_sym(), 1)) type = NOT_FORM; else if (is_term(t, and_sym(), 2)) type = AND_FORM; else if (is_term(t, or_sym(), 2)) type = OR_FORM; else if (is_term(t, iff_sym(), 2)) type = IFF_FORM; else if (is_term(t, imp_sym(), 2)) type = IMP_FORM; else if (is_term(t, impby_sym(), 2)) type = IMPBY_FORM; else type = ATOM_FORM; if (type == ATOM_FORM) { f = formula_get(0, ATOM_FORM); f->atom = copy_term(t); } else if (type == NOT_FORM) { f = formula_get(1, NOT_FORM); f->kids[0] = term_to_formula(ARG(t,0)); } else if (ARITY(t) == 0) { f = formula_get(0, type); } else { f = formula_get(2, type); f->kids[0] = term_to_formula(ARG(t,0)); f->kids[1] = term_to_formula(ARG(t,1)); } } f = flatten_top(f); f->attributes = attributes; return f; } /* term_to_formula */ /************* * * formula_to_term() * *************/ /* DOCUMENTATION Returns an entirely new term. */ /* PUBLIC */ Term formula_to_term(Formula f) { Term t = NULL; switch (f->type) { case ATOM_FORM: t = copy_term(f->atom); break; case NOT_FORM: t = get_rigid_term(not_sym(), 1); ARG(t,0) = formula_to_term(f->kids[0]); break; case IFF_FORM: t = get_rigid_term(iff_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case IMP_FORM: t = get_rigid_term(imp_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case IMPBY_FORM: t = get_rigid_term(impby_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case AND_FORM: case OR_FORM: if (f->arity == 0) t = get_rigid_term(f->type == AND_FORM ? true_sym() : false_sym(), 0); else { int i = f->arity-1; t = formula_to_term(f->kids[i]); for (i--; i >= 0; i--) { Term t1 = get_rigid_term(f->type == AND_FORM ? and_sym() : or_sym(), 2); ARG(t1,0) = formula_to_term(f->kids[i]); ARG(t1,1) = t; t = t1; } } break; case ALL_FORM: case EXISTS_FORM: { /* transform to: $quantified(all,x,f) */ t = get_rigid_term(quant_sym(), 3); ARG(t,0) = get_rigid_term(f->type == ALL_FORM ? all_sym() : exists_sym(), 0); ARG(t,1) = get_rigid_term(f->qvar, 0); ARG(t,2) = formula_to_term(f->kids[0]); } break; } if (f->attributes) t = build_binary_term(str_to_sn(attrib_sym(), 2), t, attributes_to_term(f->attributes, attrib_sym())); return t; } /* formula_to_term */ /************* * * fprint_formula() * *************/ /* DOCUMENTATION This routine prints a formula to a file. If you wish to have a formula printed without extra parentheses, you can call fprint_formula_term() instead. */ /* PUBLIC */ void fprint_formula(FILE *fp, Formula f) { if (f->type == ATOM_FORM) { /* fprintf(fp, "("); */ fprint_term(fp, f->atom); /* fprintf(fp, ")"); */ } else if (f->type == NOT_FORM) { /* fprintf(fp, "(%s ", not_sym()); */ fprintf(fp, "%s ", not_sym()); fprint_formula(fp, f->kids[0]); /* fprintf(fp, ")"); */ } else if (f->type == IFF_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", iff_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMP_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", imp_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMPBY_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", impby_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (quant_form(f)) { fprintf(fp, "(%s %s ", f->type==ALL_FORM ? all_sym() : exists_sym(), f->qvar); fprint_formula(fp, f->kids[0]); fprintf(fp, ")"); } else if (f->type == AND_FORM || f->type == OR_FORM) { if (f->arity == 0) fprintf(fp, "%s", f->type == AND_FORM ? true_sym() : false_sym()); else { int i; fprintf(fp, "("); for (i = 0; i < f->arity; i++) { fprint_formula(fp, f->kids[i]); if (i < f->arity-1) fprintf(fp, " %s ", f->type == AND_FORM ? and_sym() : or_sym()); } fprintf(fp, ")"); } } } /* fprint_formula */ /************* * * p_formula() * *************/ /* DOCUMENTATION This routine prints a formula, followed by ".\n" and fflush, to stdout. If you wish to have a formula printed without extra parentheses, you can call p_formula_term() instead. If you don't want the newline, use fprint_formula() instead. */ /* PUBLIC */ void p_formula(Formula c) { fprint_formula(stdout, c); printf(".\n"); fflush(stdout); } /* p_formula */ /************* * * hash_formula() * *************/ /* DOCUMENTATION This is a simple hash function for formulas. It shifts symbols by 3 bits and does exclusive ORs. */ /* PUBLIC */ unsigned hash_formula(Formula f) { if (f->type == ATOM_FORM) return hash_term(f->atom); else if (quant_form(f)) return (f->type << 3) ^ (unsigned) f->qvar[0]; else { unsigned x = f->type; int i; for (i = 0; i < f->arity; i++) x = (x << 3) ^ hash_formula(f->kids[i]); return x; } } /* hash_formula */ /************* * * formula_ident() * *************/ /* DOCUMENTATION This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality. */ /* PUBLIC */ BOOL formula_ident(Formula f, Formula g) { if (f->type != g->type || f->arity != g->arity) return FALSE; else if (f->type == ATOM_FORM) return term_ident(f->atom, g->atom); else if (quant_form(f)) return (str_ident(f->qvar,g->qvar) && formula_ident(f->kids[0],g->kids[0])); else { int i; for (i = 0; i < f->arity; i++) if (!formula_ident(f->kids[i], g->kids[i])) return FALSE; return TRUE; } } /* formula_ident */ /************* * * formula_copy() * *************/ /* DOCUMENTATION This function returns a copy of the given formula. All subformulas, including the atoms, are copied. */ /* PUBLIC */ Formula formula_copy(Formula f) { Formula g = formula_get(f->arity, f->type); if (f->type == ATOM_FORM) g->atom = copy_term(f->atom); else { int i; if (quant_form(f)) g->qvar = f->qvar; for (i = 0; i < f->arity; i++) g->kids[i] = formula_copy(f->kids[i]); } return g; } /* formula_copy */ /************* * * dual_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL dual_type(int op) { switch (op) { case AND_FORM: return OR_FORM; case OR_FORM: return AND_FORM; case ALL_FORM: return EXISTS_FORM; case EXISTS_FORM: return ALL_FORM; default: return op; } } /* dual */ /************* * * dual() * *************/ /* DOCUMENTATION Change a formula into its dual. This is destructive. */ /* PUBLIC */ Formula dual(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = dual(f->kids[i]); f->type = dual_type(f->type); return f; } /* dual */ /************* * * and() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula and(Formula a, Formula b) { Formula f = formula_get(2, AND_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* and */ /************* * * or() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula or(Formula a, Formula b) { Formula f = formula_get(2, OR_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* or */ /************* * * imp() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula imp(Formula a, Formula b) { Formula f = formula_get(2, IMP_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* imp */ /************* * * impby() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula impby(Formula a, Formula b) { Formula f = formula_get(2, IMPBY_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* impby */ /************* * * not() * *************/ static Formula not(Formula a) { Formula f = formula_get(1, NOT_FORM); f->kids[0] = a; return f; } /* not */ /************* * * negate() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula negate(Formula a) { return not(a); } /* negate */ /************* * * quant_form() -- is it a quantified formula? * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL quant_form(Formula f) { return (f->type == ALL_FORM || f->type == EXISTS_FORM); } /* quant_form */ /************* * * flatten_top() -- applies to AND and OR. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula flatten_top(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { BOOL operate = FALSE; int n = 0; /* count new arity */ int i; for (i = 0; i < f->arity; i++) { if (f->type != f->kids[i]->type) n++; else { n += (f->kids[i]->arity); operate = TRUE; } } if (!operate) return f; else { Formula g = formula_get(n, f->type); int i, j; j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]->type != f->type) g->kids[j++] = f->kids[i]; else { int k; for (k = 0; k < f->kids[i]->arity; k++) g->kids[j++] = f->kids[i]->kids[k]; free_formula(f->kids[i]); } } free_formula(f); /* If the new formula has just one argument, return that argument. */ if (g->arity == 1) { Formula h = g->kids[0]; free_formula(g); return h; } else return g; } } } /* flatten_top */ /************* * * formula_flatten() * *************/ /* DOCUMENTATION This routine (recursively) flattens all AND and OR subformulas. */ /* PUBLIC */ Formula formula_flatten(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = formula_flatten(f->kids[i]); return flatten_top(f); } /* flatten */ /************* * * nnf2() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

The argument "pref" should be either CONJUNCTION or DISJUNCTION, and it specifies the preferred form to use when translating IFFs.

This rouine is destructive; a good way to call it is f = nnf2(f, CONJUNCTION). */ /* PUBLIC */ Formula nnf2(Formula f, Fpref pref) { if (f->type == ATOM_FORM) return f; else if (quant_form(f)) { f->kids[0] = nnf2(f->kids[0], pref); return f; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = nnf2(f->kids[i], pref); return f; } else if (f->type == IMP_FORM) { Formula g = nnf2(or(not(f->kids[0]), f->kids[1]), pref); free_formula(f); return g; } else if (f->type == IMPBY_FORM) { Formula g = nnf2(or(f->kids[0], not(f->kids[1])), pref); free_formula(f); return g; } else if (f->type == IFF_FORM) { Formula g; Formula a = f->kids[0]; Formula b = f->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(imp(a,b), impby(ac,bc)), pref); else g = nnf2(or(and(a,b),and(not(ac),not(bc))), pref); free_formula(f); return g; } /* NOT */ else if (f->type == NOT_FORM) { Formula h = f->kids[0]; if (h->type == ATOM_FORM) return f; else if (h->type == NOT_FORM) { Formula g = nnf2(h->kids[0], pref); free_formula(h); free_formula(f); return g; } else if (quant_form(h)) { Formula g = formula_get(1, dual_type(h->type)); g->qvar = h->qvar; g->kids[0] = nnf2(not(h->kids[0]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == AND_FORM || h->type == OR_FORM) { Formula g = formula_get(h->arity, dual_type(h->type)); int i; for (i = 0; i < h->arity; i++) g->kids[i] = nnf2(not(h->kids[i]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMP_FORM) { Formula g = nnf2(and(h->kids[0], not(h->kids[1])), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMPBY_FORM) { Formula g = nnf2(and(not(h->kids[0]), h->kids[1]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IFF_FORM) { Formula g; Formula a = h->kids[0]; Formula b = h->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(or(a,b),or(not(ac),not(bc))), pref); else g = nnf2(or(and(a,not(b)),and(not(ac),bc)), pref); free_formula(h); free_formula(f); return g; } else return f; } /* NOT */ else return f; } /* nnf2 */ /************* * * nnf() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

This routine is destructive; a good way to call it is f = nnf(f). */ /* PUBLIC */ Formula nnf(Formula f) { return nnf2(f, CONJUNCTION); } /* nnf */ /************* * * make_conjunction() * *************/ /* DOCUMENTATION If the formula is not a conjunction, make it so. */ /* PUBLIC */ Formula make_conjunction(Formula f) { if (f->type == AND_FORM) return f; else { Formula h = formula_get(1, AND_FORM); h->kids[0] = f; return h; } } /* make_conjunction */ /************* * * make_disjunction() * *************/ /* DOCUMENTATION If the formula is not a dismunction, make it so. */ /* PUBLIC */ Formula make_disjunction(Formula f) { if (f->type == OR_FORM) return f; else { Formula h = formula_get(1, OR_FORM); h->kids[0] = f; return h; } } /* make_disjunction */ /************* * * formula_canon_eq() * *************/ /* DOCUMENTATION For each equality in the formula, if the right side greater according to "term_compare_ncv", flip the equality. */ /* PUBLIC */ void formula_canon_eq(Formula f) { if (f->type == ATOM_FORM) { Term a = f->atom; if (eq_term(a)) { Term left = ARG(a,0); Term right = ARG(a,1); if (term_compare_ncv(left, right) == LESS_THAN) { ARG(a,0) = right; ARG(a,1) = left; } } } else { int i; for (i = 0; i < f->arity; i++) formula_canon_eq(f->kids[i]); } } /* formula_canon_eq */ /************* * * formula_size() * *************/ /* DOCUMENTATION How many nodes are in the formula. (Atomic formulae count as 1.) */ /* PUBLIC */ int formula_size(Formula f) { if (f->type == ATOM_FORM) return 1; else { int i; int n = 0; for (i = 0; i < f->arity; i++) n += formula_size(f->kids[i]); return n+1; } } /* formula_size */ /************* * * greatest_qvar() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a quantified variable in Formula f.

Recall that in Formulas, a quantified variable is represented as a constant (which is bound by the quantifier). If the formula has no quantified variables, return -1. */ /* PUBLIC */ int greatest_qvar(Formula f) { if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_qvar(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_qvar(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_qvar */ /************* * * greatest_symnum_in_formula() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a any subterm. This includes quantifed variables that don't occur in any term.

This routine is intended to be used if you need malloc an array for indexing by SYMNUM. */ /* PUBLIC */ int greatest_symnum_in_formula(Formula f) { if (f->type == ATOM_FORM) { return greatest_symnum_in_term(f->atom); } if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_symnum_in_formula(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_symnum_in_formula(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_symnum_in_formula */ /************* * * subst_free_var() * *************/ /* DOCUMENTATION In formula f, substitute free occurrences of target with replacement. The function term_ident() is used, and the target can be any term. */ /* PUBLIC */ void subst_free_var(Formula f, Term target, Term replacement) { if (f->type == ATOM_FORM) f->atom = subst_term(f->atom, target, replacement); else if (quant_form(f) && str_ident(sn_to_str(SYMNUM(target)), f->qvar)) { ; /* Do nothing, because we have a quantified variable of the same name. */ } else { int i; for (i = 0; i < f->arity; i++) subst_free_var(f->kids[i], target, replacement); } } /* subst_free_var */ /************* * * elim_rebind() * *************/ static Formula elim_rebind(Formula f, Ilist uvars) { if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Ilist uvars_plus; if (ilist_member(uvars, SYMNUM(var))) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = gen_new_symbol("y", 0, uvars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } uvars_plus = ilist_prepend(uvars, SYMNUM(var)); f->kids[0] = elim_rebind(f->kids[0], uvars_plus); free_term(var); free_ilist(uvars_plus); /* frees first node only; uvars still good */ return f; } else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = elim_rebind(f->kids[i], uvars); return f; } } /* elim_rebind */ /************* * * eliminate_rebinding() * *************/ /* DOCUMENTATION This routine renames quantified variables so that no quantified variable occurs in the scope of a quantified variable with the same name.

If you wish to rename variables so that each quantifer has a unique variable, you can use the routine unique_quantified_vars() instead.

The argument f is "used up" during the procedure.

(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.) */ /* PUBLIC */ Formula eliminate_rebinding(Formula f) { f = elim_rebind(f, NULL); return f; } /* eliminate_rebinding */ /************* * * free_vars() * *************/ static Plist free_vars(Formula f, Plist vars) { if (f->type == ATOM_FORM) vars = free_vars_term(f->atom, vars); else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Plist vars2 = free_vars(f->kids[0], NULL); vars2 = tlist_remove(var, vars2); vars = tlist_union(vars, vars2); zap_term(var); } else { int i; for (i = 0; i < f->arity; i++) vars = free_vars(f->kids[i], vars); } return vars; } /* free_vars */ /************* * * closed_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL closed_formula(Formula f) { Plist vars = free_vars(f, NULL); /* deep (returns new terms) */ BOOL ok = (vars == NULL); zap_tlist(vars); return ok; } /* closed_formula */ /************* * * get_quant_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula get_quant_form(Ftype type, char *qvar, Formula subformula) { Formula f = formula_get(1, type); f->qvar = qvar; f->kids[0] = subformula; return f; } /* get_quant_form */ /************* * * uni_close() * *************/ static Formula uni_close(Formula f, Plist vars) { if (vars == NULL) return f; else { Formula g = uni_close(f, vars->next); Term v = vars->v; return get_quant_form(ALL_FORM, sn_to_str(SYMNUM(v)), g); } } /* uni_close */ /************* * * universal_closure() * *************/ /* DOCUMENTATION Construct the universal closure of Formula f. The Formula is consumed during the construction. */ /* PUBLIC */ Formula universal_closure(Formula f) { Plist vars = free_vars(f, NULL); /* deep (returns new terms) */ f = uni_close(f, vars); zap_tlist(vars); return f; } /* universal_closure */ /************* * * free_var() * *************/ static BOOL free_var(char *svar, Term tvar, Formula f) { if (f->type == ATOM_FORM) return occurs_in(tvar, f->atom); else if (quant_form(f) && str_ident(svar, f->qvar)) { return FALSE; } else { int i; for (i = 0; i < f->arity; i++) { if (free_var(svar, tvar, f->kids[i])) return TRUE; } return FALSE; } } /* free_var */ /************* * * free_variable() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL free_variable(char *svar, Formula f) { Term tvar = get_rigid_term(svar, 0); BOOL free = free_var(svar, tvar, f); free_term(tvar); return free; } /* free_variable */ /************* * * formulas_to_conjunction * *************/ /* DOCUMENTATION Given a Plist of formulas, form a conjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty conjunction is TRUE. */ /* PUBLIC */ Formula formulas_to_conjunction(Plist formulas) { Plist p; int n = plist_count(formulas); Formula f = formula_get(n, AND_FORM); int i = 0; for (p = formulas; p; p = p->next) { f->kids[i++] = p->v; } return f; } /* formulas_to_conjunction */ /************* * * formulas_to_disjunction * *************/ /* DOCUMENTATION Given a Plist of formulas, form a disjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty disjunction is FALSE. */ /* PUBLIC */ Formula formulas_to_disjunction(Plist formulas) { Plist p; int n = plist_count(formulas); Formula f = formula_get(n, OR_FORM); int i = 0; for (p = formulas; p; p = p->next) { f->kids[i++] = p->v; } return f; } /* formulas_to_disjunction */ /************* * * copy_plist_of_formulas() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist copy_plist_of_formulas(Plist formulas) { if (formulas == NULL) return NULL; else { Plist tail = copy_plist_of_formulas(formulas->next); Plist head = get_plist(); head->v = formula_copy(formulas->v); head->next = tail; return head; } } /* copy_plist_of_formulas */ /************* * * literal_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL literal_formula(Formula f) { if (f->type == ATOM_FORM) return TRUE; else if (f->type == NOT_FORM) return f->kids[0]->type == ATOM_FORM; else return FALSE; } /* literal_formula */ /************* * * clausal_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL clausal_formula(Formula f) { if (f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) { if (!clausal_formula(f->kids[i])) return FALSE; } return TRUE; } else return literal_formula(f); } /* clausal_formula */ /************* * * formula_set_vars_recurse() * *************/ static void formula_set_vars_recurse(Formula f, char *vnames[], int max_vars) { if (f->type == ATOM_FORM) f->atom = set_vars_recurse(f->atom, vnames, max_vars); else { int i; for (i = 0; i < f->arity; i++) formula_set_vars_recurse(f->kids[i], vnames, max_vars); } } /* formula_set_vars_recurse */ /************* * * formula_set_variables() * *************/ /* DOCUMENTATION This routine traverses a formula and changes the constants that should be variables, into variables. On input, the formula should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input formulas that are built without regard to variable/constant distinction. */ /* PUBLIC */ void formula_set_variables(Formula f, int max_vars) { char *a[MAX_VARS], **vmap; int i; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; formula_set_vars_recurse(f, vmap, max_vars); /* Now do any answer attributes (with the same vmap). */ if (f->attributes) { set_vars_attributes(f->attributes, vmap, max_vars); #if 0 /* Make sure that answer vars also occur in formula. */ Plist attr_vars = vars_in_attributes(c->attributes); Plist formula_vars = vars_in_formula(c); if (!plist_subset(attr_vars, formula_vars)) { Plist p; printf("Variables in answers must also occur ordinary literals:\n"); p_formula(c); for (p = attr_vars; p; p = p->next) { if (!plist_member(formula_vars, p->v)) { Term t = p->v; printf("Answer variable not in ordinary literal: %s.\n", vmap[VARNUM(t)]); } } fatal_error("formula_set_variables, answer variable not in literal"); } zap_plist(formula_vars); zap_plist(attr_vars); #endif } if (max_vars > MAX_VARS) free(vmap); } /* formula_set_variables */ /************* * * positive_formula() * *************/ /* DOCUMENTATION Ignoring quantifiers, does the formula consist of an atomic formula or the conjunction of atomic formulas? */ /* PUBLIC */ BOOL positive_formula(Formula f) { Formula g = f; while (quant_form(g)) g = g->kids[0]; if (g->type == ATOM_FORM) return TRUE; else if (g->type != AND_FORM) return FALSE; else { int i; for (i = 0; i < g->arity; i++) if (!positive_formula(g->kids[i])) return FALSE; return TRUE; } } /* positive_formula */ /************* * * formula_contains_attributes() * *************/ /* DOCUMENTATION Does the formula or any of its subformulas contain attributes? */ /* PUBLIC */ BOOL formula_contains_attributes(Formula f) { if (f->attributes != NULL) return TRUE; else if (f->type == ATOM_FORM) return FALSE; else { int i; for (i = 0; i < f->arity; i++) if (formula_contains_attributes(f->kids[i])) return TRUE; return FALSE; } } /* formula_contains_attributes */ /************* * * subformula_contains_attributes() * *************/ /* DOCUMENTATION Does any proper subformula contain attributes? */ /* PUBLIC */ BOOL subformula_contains_attributes(Formula f) { if (f->type == ATOM_FORM) return FALSE; else { int i; for (i = 0; i < f->arity; i++) if (formula_contains_attributes(f->kids[i])) return TRUE; return FALSE; } } /* subformula_contains_attributes */ /************* * * constants_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist constants_in_formula(Formula f) { Ilist p = function_symbols_in_formula(f); p = symnums_of_arity(p, 0); return p; } /* constants_in_formula */ /************* * * relation_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL relation_in_formula(Formula f, int symnum) { if (f->type == ATOM_FORM) return SYMNUM(f->atom) == symnum; else { int i; for (i = 0; i < f->arity; i++) if (relation_in_formula(f->kids[i], symnum)) return TRUE; return FALSE; } } /* relation_in_formula */ /************* * * rename_all_bound_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void rename_all_bound_vars(Formula f) { if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); free_term(newvar); } else { int i; for (i = 0; i < f->arity; i++) rename_all_bound_vars(f->kids[i]); } } /* rename_all_bound_vars */ /************* * * rename_these_bound_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void rename_these_bound_vars(Formula f, Ilist vars) { /* Rename each quantified variable in "vars" to a new symbol. */ if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); if (ilist_member(vars, SYMNUM(var))) { /* Rename this variable. */ int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); } rename_these_bound_vars(f->kids[0], vars); } else { int i; for (i = 0; i < f->arity; i++) rename_these_bound_vars(f->kids[i], vars); } } /* rename_these_bound_vars */ LADR-2009-11A/ladr/a.out0000755000175000017500000002475611117536552013740 0ustar mccunemccuneELF°ƒ4\4 (&#44€4€àà€€4 4 4 4™4™ H H™H™ÐÐ((( Qåtd/lib/ld-linux.so.2GNU €( ¬KãÀgUa ;yH²A¯49)úüˆ.Lš__gmon_start__libc.so.6_IO_stdin_usedexitstdinprintffgetsstrlen__libc_start_mainGLIBC_2.0ii ZšLš(š,š0š4š8š<šU‰åSƒìè[Ë“üÿÿÿ…ÒtèèÝèxX[ÉÃÿ5 šÿ%$šÿ%(šhéàÿÿÿÿ%,šhéÐÿÿÿÿ%0šhéÀÿÿÿÿ%4šhé°ÿÿÿÿ%8šh é ÿÿÿÿ%<šh(éÿÿÿ1í^‰áƒäðPTRh@ˆhPˆQVhÒ†è›ÿÿÿôU‰åƒì€=Pšt ëƒÀ£HšÿÒ¡Hš‹…ÒuëÆPšÉÃU‰åƒì¡D™…Àt¸…Àt Ç$D™ÿÐÉÃU‰åƒì(ÇEüÇEøÇEôÇEðÇEìÇEèé ‹EðEôÁàE‹‹EðEøÁàE‹9Âtj‹Eð‰EØ‹Eì‰EÜ‹EØ9EÜ}‹E؉EÜ‹E܉EìƒEô‹Eô;Eøu5ƒEü‹EìEø‹EøƒÀ;E ~ ÇEèë6ÇEôÇEðÇEìëÇEðëƒEð‹EðEø;E ~ÇEèƒ}è„VÿÿÿÛEüÛE ÞùÉÃU‰åƒì(ÇEüÇEøÇEì‹Eì‰Eð‹Eð‰Eôë{‹EðEôÁàE‹‹EðEøÁàE‹9ÂuƒEðëU‹Eð‰EØ‹Eì‰EÜ‹EØ9EÜ}‹E؉EÜ‹E܉EìƒEô‹Eô;Eøt ÇEðë ƒEü‹EìƒÀEøÇEì‹Eì‰Eð‹Eð‰Eô‹EðEø;E ŒvÿÿÿÛEüÛE ÞùÉÃU‰åƒì,ÇEüÇEøÇEôé§ÇEðÇEìë\ÇEèëƒEè‹EèEø;E } ‹EèEðÁàE‹‹EèEøÁàE‹9ÂtÑ‹Eè‰EÔ‹Eì‰EØ‹EÔ9EØ}‹EÔ‰EØ‹E؉EìƒEð‹Eð;Eø|œ‹Eì‰E܃}ÜÇEÜ‹EÜEøƒEüƒ}ì~‹EƒÀ¯Eì+EEô‹Eø;E ŒMÿÿÿÛEô‹UƒÂ‹E ƒè¯Â+EPÛ$d$ÞùÙèÞáÉÃL$ƒäðÿqüU‰åQì´‹A‰…Xìÿÿe¡‰Eø1À¡Lš‰D$ÇD$è…üÿÿ‰$èCüÿÿ‰… üÿÿƒ½ üÿÿu Ç$èhüÿÿ…üÿÿ‰$è:üÿÿ‰…üÿÿƒ½üÿÿ~‹…üÿÿÆ„üÿÿƒ­üÿÿÇ…üÿÿë(‹•üÿÿƒÂ‹…üÿÿ¶„üÿÿ¾À‰„•`ìÿÿƒ…üÿÿ‹…üÿÿ;…üÿÿ|Ê‹…üÿÿ‰D$…`ìÿÿ‰$ètüÿÿÝ\$Ç$‰è¼ûÿÿ…`ìÿÿP‹…üÿÿ‰D$‰$è2ýÿÿÝ\$Ç$‰è‘ûÿÿ…`ìÿÿPÇD$‹…üÿÿ‰D$‰$è¼ýÿÿÝ\$Ç$ ‰è^ûÿÿéÇþÿÿU‰å]Ãt&¼'U‰åWVSèOÃÁƒì è£úÿÿ»ÿÿÿƒÿÿÿ)ÇÁÿ…ÿt$1ö‹E‰D$‹E ‰D$‹E‰$ÿ”³ÿÿÿƒÆ9÷uÞƒÄ [^_]Ë$ÃU‰åSƒì¡4™ƒøÿt1ÛÿЋƒ0™ƒëƒøÿuðƒÄ[]ÃU‰åSƒìè[Ã4èìúÿÿY[ÉÃcomplex1: %.5f complex2: %.5f complex3: %.5f ÿÿÿÿÿÿÿÿ ƒ ܈Hõþÿo€4‚¤ d š0܂̂þÿÿo¬‚ÿÿÿoðÿÿo˜‚H™Rƒbƒrƒ‚ƒ’ƒ¢ƒ@™GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)$ ƒ"܈4„ÿ$ù8ƒôˆ!u_IO_stdin_usedß main‰Q¦uÔƒÔƒC61Eint­,²L‡üˆO‰K'/build/buildd/glibc-2.7/build-tree/i386-libc/csu/crti.S/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuGNU AS 2.18.0€Û]GNU C 4.2.3 (Ubuntu 4.2.3-2ubuntu7)complex.c/home/mccune/LADR/ladr4„3ˆ­size_tÖlunsigned intunsigned charshort unsigned intlong unsigned intsigned charshort intintlong long intlong long unsigned int__quad_t8Û__off_t%long int__off64_tŽMchar_IO_FILE”-Õ_flagsÔ#_IO_read_ptrG#_IO_read_endG#_IO_read_baseG# _IO_write_baseG#_IO_write_ptrG#_IO_write_endG#_IO_buf_baseG#_IO_buf_endG# _IO_save_baseG#$_IO_backup_baseG#(_IO_save_end G#,_markers"&#0_chain$,#4_fileno&Ô#8_flags2*Ô#<_old_offset,#@_cur_column0#D_vtable_offset1¸#F_shortbuf22#G_lock6B#H_offset?1#L__pad1HE#T__pad2IE#X__pad3JE#\__pad4KE#`__pad5L^#d_modeNÔ#h_unused2PH#l _IO_lock_t´_IO_marker º& _next»&# _sbuf¼,# _posÀÔ#ãU MB BÕ MX B' complexity14ã4„…ãs3í‘n3Ô‘c6Ô‘tl7Ô‘pi8Ô‘lk9Ô‘hkmax:Ô‘dstop;Ô‘`doubleÔ complexity2lã…Ú…,oskí‘nkÔ‘cnÔ‘tboÔ‘papÔ‘lkpÔ‘hkmaxpÔ‘d complexity3•ãÚ…Ò†X s”í‘n”Ô‘adjustment”Ô‘c—Ô‘tb˜Ô‘px™Ô‘lú…¡†a›Ô‘hfmaxœÔ‘d †f†fžÔ‘`mainŽÔÒ†3ˆ„§argcÔqargv§‘ÐXs­‘ˆxa¾‘ØXt‘G‘„xi’Ô‘€xn’Ô‘üwG M¾Bç ÔÏBèstdin‘,‰{× /build/buildd/glibc-2.7/build-tree/i386-libc/csu/crtn.S/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuGNU AS 2.18.0€% $ > $ > $ > 4: ; I?  &IU%% : ; I$ > $ >   I : ;  : ;I8 : ; : ; I8 I !I/ .: ; ' I@: ; I 4: ; I  .? : ;' I@: ;I 4: ;I !I/4: ; I? < U%#û init.c‚Nû /build/buildd/glibc-2.7/build-tree/i386-libc/csucrti.S ƒ!/!=Z!gg//܈(!/!=Z!&–û /usr/lib/gcc/i486-linux-gnu/4.2.3/include/usr/include/bits/usr/includecomplex.cstddef.htypes.hlibio.hstdio.h4„3huuuuuuYååKƒOg­’uu”“K°dt$žƒ .huv//åiåKƒ’K‘t.äƒ.huuuYuu/u/I+åE‰ƒKgsòº#ä.º´%‘»=‘×v»ñM(+3xNû /build/buildd/glibc-2.7/build-tree/i386-libc/csucrtn.S8ƒ !!!ôˆ!!!ÿÿÿÿ| ˆ4„é… …½… Ú…ø… 8Ò†a   … „short unsigned intshort int_IO_stdin_usedlong long unsigned intunsigned charGNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu1)/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuinit.clong long intttéuéêtêìtì¦u¦§t§©t©žuž¢t¢¨Q¨©t©«t«ÿuÿÿÿÿ ƒ.ƒ܈ïˆÿÿÿÿ8ƒ<ƒôˆøˆ.symtab.strtab.shstrtab.interp.note.ABI-tag.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.eh_frame.ctors.dtors.jcr.dynamic.got.got.plt.data.bss.comment.debug_aranges.debug_pubnames.debug_info.debug_abbrev.debug_line.debug_frame.debug_str.debug_loc.debug_ranges#(( 5HH81öÿÿo€€$; ¤¤C4‚4dKÿÿÿo˜‚˜Xþÿÿo¬‚¬ g Ì‚Ìp Ü‚Ü0 y ƒ 0t<ƒ<p°ƒ°,…܈Ü‹øˆø8“0‰0 4™4 ¤<™< «D™D °H™H Ð¹š ¾š $Ç@š@ ÍLšL ÒL &Ûx pêè @ú( †®;S °-0@»8ûÇCÈ@QL"0%< |'r(H€¤4‚˜‚¬‚Ì‚ Ü‚ ƒ <ƒ °ƒ ܈øˆ0‰4™<™D™H™šš@šLš !"ñÿñÿñÿ4™,<™:D™Gàƒ ]PšlHšs„ ñÿ8™Œ@™™0‰§D™³°ˆ ñÿÉñÿÓ4„é ß…½ ëÚ…ø ÷š 4™4™1H™:@š E@ˆ U°ƒ \ k øˆ†܈Œy²ºüˆÉ@šÖ¯èDšõPˆZ 9Lšñÿ#Lš4Tšñÿ9Lšñÿ@úPªˆ gÒ†a l ƒ init.cinitfini.ccrtstuff.c__CTOR_LIST____DTOR_LIST____JCR_LIST____do_global_dtors_auxcompleted.5843p.5841frame_dummy__CTOR_END____DTOR_END____FRAME_END____JCR_END____do_global_ctors_auxcomplex.ccomplexity1complexity2complexity3_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICdata_start__libc_csu_fini_start__gmon_start___Jv_RegisterClasses_fp_hw_finifgets@@GLIBC_2.0__libc_start_main@@GLIBC_2.0_IO_stdin_used__data_startstrlen@@GLIBC_2.0__dso_handle__libc_csu_initprintf@@GLIBC_2.0__bss_startstdin@@GLIBC_2.0_end_edataexit@@GLIBC_2.0__i686.get_pc_thunk.bxmain_initLADR-2009-11A/ladr/lindex.c0000644000175000017500000001176110637466322014406 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "lindex.h" /* Private definitions and types */ /* * memory management */ #define PTRS_LINDEX PTRS(sizeof(struct lindex)) static unsigned Lindex_gets, Lindex_frees; /************* * * Lindex get_lindex() * *************/ static Lindex get_lindex(void) { Lindex p = get_cmem(PTRS_LINDEX); Lindex_gets++; return(p); } /* get_lindex */ /************* * * free_lindex() * *************/ static void free_lindex(Lindex p) { free_mem(p, PTRS_LINDEX); Lindex_frees++; } /* free_lindex */ /************* * * fprint_lindex_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the lindex package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_lindex_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct lindex); fprintf(fp, "lindex (%4d) %11u%11u%11u%9.1f K\n", n, Lindex_gets, Lindex_frees, Lindex_gets - Lindex_frees, ((Lindex_gets - Lindex_frees) * n) / 1024.); } /* fprint_lindex_mem */ /************* * * p_lindex_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the lindex package. */ /* PUBLIC */ void p_lindex_mem() { fprint_lindex_mem(stdout, TRUE); } /* p_lindex_mem */ /* * end of memory management */ /************* * * lindex_init() * *************/ /* DOCUMENTATION This routine allocates and returns a literal index (Lindex), which is a pair of Mindexes, one for positive literals, and one for negative literals. The first three parameters are for the positive literal Mindex, and the second three are for the negative.

  • Mindextype: {LINEAR, FPA, DISCRIM, DISCRIM_BIND}
  • Uniftype: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
See the routine mindex_init() for further information. */ /* PUBLIC */ Lindex lindex_init(Mindextype pos_mtype, Uniftype pos_utype, int pos_fpa_depth, Mindextype neg_mtype, Uniftype neg_utype, int neg_fpa_depth) { Lindex ldx = get_lindex(); ldx->pos = mindex_init(pos_mtype, pos_utype, pos_fpa_depth); ldx->neg = mindex_init(neg_mtype, neg_utype, neg_fpa_depth); return ldx; } /* lindex_init */ /************* * * lindex_destroy() * *************/ /* DOCUMENTATION This frees all the memory associated with a Lindex. Do not refer to the Lindex after calling this routine. */ /* PUBLIC */ void lindex_destroy(Lindex ldx) { mindex_destroy(ldx->pos); mindex_destroy(ldx->neg); free_lindex(ldx); } /* lindex_destroy */ /************* * * lindex_update() * *************/ /* DOCUMENTATION This routine indexes (or unindexes) all literals of a clause. */ /* PUBLIC */ void lindex_update(Lindex ldx, Topform c, Indexop op) { Literals lit; for (lit = c->literals; lit != NULL; lit = lit->next) { if (lit->sign) mindex_update(ldx->pos, lit->atom, op); else mindex_update(ldx->neg, lit->atom, op); } } /* lindex_update */ /************* * * lindex_update_first() * *************/ /* DOCUMENTATION This routine indexes (or unindexes) the first literal of a clause. */ /* PUBLIC */ void lindex_update_first(Lindex ldx, Topform c, Indexop op) { Literals lit = c->literals; if (lit) { if (lit->sign) mindex_update(ldx->pos, lit->atom, op); else mindex_update(ldx->neg, lit->atom, op); } } /* lindex_update_first */ /************* * * lindex_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an Lindex is empty, that is, has no atoms. It must exist (be non-NULL). */ /* PUBLIC */ BOOL lindex_empty(Lindex idx) { return mindex_empty(idx->pos) && mindex_empty(idx->neg); } /* lindex_empty */ /************* * * lindex_backtrack() * *************/ /* DOCUMENTATION This Boolean function checks if either of the Mindex components (pos, neg) uses backtrack unification. */ /* PUBLIC */ BOOL lindex_backtrack(Lindex idx) { return (idx->pos->unif_type == BACKTRACK_UNIF || idx->neg->unif_type == BACKTRACK_UNIF); } /* lindex_backtrack */ LADR-2009-11A/ladr/dollar.c.save0000644000175000017500000001711011137112665015321 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "dollar.h" /* Private definitions and types */ static int Sum_sn, Prod_sn, Div_sn, Mod_sn; static int Neg_sn; static int EQ_sn, NE_sn, LT_sn, LE_sn, GT_sn, GE_sn; static int And_sn, Or_sn; static int If_sn; static int ID_sn; static int Var_sn; /* * memory management */ /************* * * init_dollar_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_dollar_eval(void) { Sum_sn = str_to_sn("+", 2); Prod_sn = str_to_sn("*", 2); Div_sn = str_to_sn("/", 2); Mod_sn = str_to_sn("mod", 2); Neg_sn = str_to_sn("-", 1); EQ_sn = str_to_sn("=", 2); NE_sn = str_to_sn("!=", 2); LT_sn = str_to_sn("<", 2); LE_sn = str_to_sn("<=", 2); GT_sn = str_to_sn(">", 2); GE_sn = str_to_sn(">=", 2); And_sn = str_to_sn("&&", 2); Or_sn = str_to_sn("||", 2); If_sn = str_to_sn("if", 3); ID_sn = str_to_sn("==", 2); Var_sn = str_to_sn("variable", 1); } /* init_dollar_eval */ /************* * * dollar_eval() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term dollar_eval(Term t) { int operation = SYMNUM(t); int i0, i1; BOOL b0, b1; Term result = NULL; /* INT x INT -> INT */ if (operation == Sum_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 + i1); } else if (operation == Prod_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 * i1); } else if (operation == Div_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 / i1); } else if (operation == Mod_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = int_to_term(i0 % i1); } /* INT -> INT, BOOL->BOOL */ else if (operation == Neg_sn) { if (term_to_int(ARG(t,0), &i0)) result = int_to_term(-i0); else if (term_to_bool(ARG(t,0), &b0)) result = bool_to_term(!b0); } /* INT x INT -> BOOL */ else if (operation == EQ_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 == i1); } else if (operation == NE_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 != i1); } else if (operation == LT_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 < i1); } else if (operation == LE_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 <= i1); } else if (operation == GT_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 > i1); } else if (operation == GE_sn) { if (term_to_int(ARG(t,0), &i0) && term_to_int(ARG(t,1), &i1)) result = bool_to_term(i0 >= i1); } /* BOOL x BOOL -> BOOL */ /* We allow for one of the args to be non-Bool, e.g., ($T & junk) = junk */ else if (operation == And_sn) { if (term_to_bool(ARG(t,0), &b0)) { if (b0) result = copy_term(ARG(t,1)); else result = bool_to_term(FALSE); } else if (term_to_bool(ARG(t,1), &b1)) { if (b1) result = copy_term(ARG(t,0)); else result = bool_to_term(FALSE); } } else if (operation == Or_sn) { if (term_to_bool(ARG(t,0), &b0)) { if (b0) result = bool_to_term(TRUE); else result = copy_term(ARG(t,1)); } else if (term_to_bool(ARG(t,1), &b1)) { if (b1) result = bool_to_term(TRUE); else result = copy_term(ARG(t,0)); } } /* Term x Term -> BOOL */ else if (operation == ID_sn) result = bool_to_term(term_ident(ARG(t,0), ARG(t,1))); /* Term -> BOOL */ else if (operation == Var_sn) result = bool_to_term(VARIABLE(ARG(t,0))); return result; } /* dollar_eval */ /************* * * rewrite_top() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term rewrite_top(Term t, Clist rules, int flag) { Term t1 = dollar_eval(t); if (t1 != NULL) { zap_term(t); return t1; } else { Clist_pos p; Context c = get_context(); Trail tr; for (p = rules->first; p; p = p->next) { Term rule = p->c->literals->atom; Term condition, eq, alpha, beta; if (is_term(rule, "->", 2)) { condition = ARG(rule,0); eq = ARG(rule,1); } else { condition = NULL; eq = rule; } alpha = ARG(eq,0); beta = ARG(eq,1); tr = NULL; if (match(alpha, c, t, &tr)) { BOOL ok; if (condition == NULL) ok = TRUE; else { Term condition_rewritten = rewrite(apply(condition, c), rules, flag); ok = true_term(condition_rewritten); zap_term(condition_rewritten); } if (ok) { Term contractum = apply_demod(beta, c, flag); undo_subst(tr); free_context(c); zap_term(t); return(rewrite(contractum, rules, flag)); } else undo_subst(tr); } } free_context(c); return t; /* not rewritten */ } } /* rewrite_top */ /************* * * rewrite() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term rewrite(Term t, Clist rules, int flag) { if (term_flag(t, flag) || VARIABLE(t)) return t; else { int i; /* There are a few cases where we don't evaluate all args first. */ /* a & b */ if (SYMNUM(t) == And_sn) { ARG(t,0) = rewrite(ARG(t,0), rules, flag); if (true_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); free_term(t); return rewrite(tmp, rules, flag); } else if (false_term(ARG(t,0))) { zap_term(t); return bool_to_term(FALSE); } } /* a | b */ else if (SYMNUM(t) == Or_sn) { ARG(t,0) = rewrite(ARG(t,0), rules, flag); if (false_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); free_term(t); return rewrite(tmp, rules, flag); } else if (true_term(ARG(t,0))) { zap_term(t); return bool_to_term(TRUE); } } /* if(cond, then_part, else_part) */ else if (SYMNUM(t) == If_sn) { ARG(t,0) = rewrite(ARG(t,0), rules, flag); if (true_term(ARG(t,0))) { Term tmp = ARG(t,1); zap_term(ARG(t,0)); zap_term(ARG(t,2)); free_term(t); return rewrite(tmp, rules, flag); } else if (false_term(ARG(t,0))) { Term tmp = ARG(t,2); zap_term(ARG(t,0)); zap_term(ARG(t,1)); free_term(t); return rewrite(tmp, rules, flag); } } /* rewrite subterms */ for (i = 0; i < ARITY(t); i++) ARG(t,i) = rewrite(ARG(t,i), rules, flag); /* rewrite top */ t = rewrite_top(t, rules, flag); return t; } } /* rewrite */ /************* * * production_rewrite() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term production_rewrite(Term t, Clist rules) { int flag = claim_term_flag(); Term result = rewrite(t, rules, flag); term_flag_clear_recursively(result, flag); release_term_flag(flag); return result; } /* production_rewrite */ LADR-2009-11A/ladr/dollar.h0000644000175000017500000000233411151265364014374 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DOLLAR_H #define TP_DOLLAR_H #include "clist.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from dollar.c */ void init_dollar_eval(Clist rules); BOOL evaluable_predicate(int symnum); Term dollar_eval(Term t); void rewrite_with_eval(Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/discrim.h0000644000175000017500000000650011151265364014550 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DISCRIM_H #define TP_DISCRIM_H #include "unify.h" #include "index.h" /* INTRODUCTION This package implements two kinds of discrimination indexing for first-order terms. Both kinds support GENERALIZATION retrieval only (e.g., for forward demodulation and forward subsumption).

The "wild" kind is an imperfect filter, and it does not bind variables. The caller must also call a routine, say match(), to check if the answers are really more general than the query term and to construct the substitution. Wild indexing supports associative-commutative (AC) and commutative (C) symbols. Indexing terms with AC symbols works by considering the number of arguments and the number of nonvariable arguments of AC terms that do not occur in other AC terms. (The term "wild" is used because all variables in the discrimination tree are treated as the the wildcard symbol *).

With the "bind" kind, every answer is more general than the query term, and the matching substitution is constructed during the retrieval. Wild indexing supports commutative (C) symbols, but it does not support associative-commutative (AC) symbols. Retrieval with C symbols can produce duplicate answers.

There is probably a higher-level package (mindex ?) which provides a uniform interface to these and other indexing methods. */ /* Public definitions */ typedef struct discrim * Discrim; struct discrim { /* node in a discrimination tree */ Discrim next; /* sibling */ union { Discrim kids; /* for internal nodes */ Plist data; /* for leaves */ } u; short symbol; /* variable number or symbol number */ char type; /* term type and for ac indexing type */ }; typedef struct discrim_pos * Discrim_pos; struct discrim_pos { /* to save position in set of answers */ void *query; Context subst; /* substitution */ Plist data; /* identical terms from leaf of discrim tree */ void *backtrack; /* data for backtracking */ }; /* type of discrimination tree node */ enum { DVARIABLE, DRIGID, AC_ARG_TYPE, AC_NV_ARG_TYPE }; #define DVAR(d) ((d)->type == DVARIABLE) /* End of public definitions */ /* Public function prototypes from discrim.c */ Discrim get_discrim(void); void free_discrim(Discrim p); Discrim_pos get_discrim_pos(void); void free_discrim_pos(Discrim_pos p); void fprint_discrim_mem(FILE *fp, BOOL heading); void p_discrim_mem(void); Discrim discrim_init(void); void discrim_dealloc(Discrim d); void destroy_discrim_tree(Discrim d); BOOL discrim_empty(Discrim d); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/weight.h0000644000175000017500000000253711151265364014413 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_WEIGHT_H #define TP_WEIGHT_H #include "literals.h" #include "unify.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from weight.c */ void init_weight(Plist rules, double variable_weight, double constant_weight, double not_weight, double or_weight, double sk_constant_weight, double prop_atom_weight, double nest_penalty, double depth_penalty, double var_penalty, double complexity); double weight(Term t, Context subst); double clause_weight(Literals lits); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/cycle0000644000175000017500000000154110225616100013754 0ustar mccunemccuneclauseid.h:#include "clause.h" compress.h:#include "clause.h" compress.h:#include "parautil.h" clause.h:#include "tlist.h" clause.h:#include "termflag.h" clause.h:#include "attrib.h" parautil.h:#include "termflag.h" parautil.h:#include "termorder.h" parautil.h:#include "unify.h" parautil.h:#include "just.h" parautil.h:#include "parse.h" termflag.h:#include "term.h" termorder.h:#include "order.h" termorder.h:#include "glist.h" termorder.h:#include "term.h" unify.h:#include "term.h" just.h:#include "clauseid.h" just.h:#include "compress.h" just clauseid compress clause clause parautil tlist termflag attrib ... unify just parse term cid comp LADR-2009-11A/ladr/discrimb.c0000644000175000017500000004115411167750125014712 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "discrimb.h" /* Private definitions and types */ /* * memory management */ typedef struct flat2 * Flat2; struct flat2 { /* for building a stack of states for backtracking */ Term t; Flat2 prev, next, last; Discrim alternatives; int bound; int varnum; int place_holder; }; #define GO 1 #define BACKTRACK 2 #define SUCCESS 3 #define FAILURE 4 /* * memory management */ #define PTRS_FLAT2 PTRS(sizeof(struct flat2)) static unsigned Flat2_gets, Flat2_frees; /************* * * Flat2 get_flat2() * *************/ static Flat2 get_flat2(void) { Flat2 p = get_cmem(PTRS_FLAT2); Flat2_gets++; return(p); } /* get_flat2 */ /************* * * free_flat2() * *************/ static void free_flat2(Flat2 p) { free_mem(p, PTRS_FLAT2); Flat2_frees++; } /* free_flat2 */ /************* * * fprint_discrimb_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrimb package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_discrimb_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct flat2); fprintf(fp, "flat2 (%4d) %11u%11u%11u%9.1f K\n", n, Flat2_gets, Flat2_frees, Flat2_gets - Flat2_frees, ((Flat2_gets - Flat2_frees) * n) / 1024.); } /* fprint_discrimb_mem */ /************* * * p_discrimb_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the discrimb package. */ /* PUBLIC */ void p_discrimb_mem(void) { fprint_discrimb_mem(stdout, TRUE); } /* p_discrimb_mem */ /* * end of memory management */ /************* * * check_discrim_bind_tree(d, n) * *************/ /* DOCUMENTATION */ /* PUBLIC */ void check_discrim_bind_tree(Discrim d, int n) { if (n > 0) { int arity; Discrim d1; for (d1 = d->u.kids; d1; d1 = d1->next) { if (DVAR(d1)) arity = 0; else arity = sn_to_arity(d1->symbol); check_discrim_bind_tree(d1, n+arity-1); } } } /* check_discrim_bind_tree */ /************* * * print_discrim_bind_tree(fp, d, n, depth) * *************/ static void print_discrim_bind_tree(FILE *fp, Discrim d, int n, int depth) { int arity, i; for (i = 0; i < depth; i++) printf(" -"); if (depth == 0) fprintf(fp, "\nroot"); else if (DVAR(d)) fprintf(fp, "v%d", d->symbol); else fprintf(fp, "%s", sn_to_str(d->symbol)); fprintf(fp, "(%p)", d); if (n == 0) { Plist p; for (i = 0, p = d->u.data; p; i++, p = p->next); fprintf(fp, ": leaf has %d objects.\n", i); } else { Discrim d1; fprintf(fp, "\n"); for (d1 = d->u.kids; d1 != NULL; d1 = d1->next) { if (DVAR(d1)) arity = 0; else arity = sn_to_arity(d1->symbol); print_discrim_bind_tree(fp, d1, n+arity-1, depth+1); } } } /* print_discrim_bind_tree */ /************* * * fprint_discrim_bind_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a tame discrimination index. */ /* PUBLIC */ void fprint_discrim_bind_index(FILE *fp, Discrim d) { print_discrim_bind_tree(fp, d, 1, 0); } /* print_discrim_bind_index */ /************* * * p_discrim_bind_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) a tame discrimination index. */ /* PUBLIC */ void p_discrim_bind_index(Discrim d) { fprint_discrim_bind_index(stdout, d); } /* p_discrim_bind_index */ /************* * * Discrim discrim_bind_insert_rec(t, d) * * Return node of d corresp. to end of term t. If it does * not exist, add nodes to t so that it does exist. * *************/ static Discrim discrim_bind_insert_rec(Term t, Discrim d) { Discrim d1, d2, prev; int symbol, i; if (VARIABLE(t)) { d1 = d->u.kids; prev = NULL; symbol = VARNUM(t); while (d1 && DVAR(d1) && d1->symbol < symbol) { prev = d1; d1 = d1->next; } if (d1 == NULL || !DVAR(d1) || d1->symbol != symbol) { d2 = get_discrim(); d2->type = DVARIABLE; d2->symbol = VARNUM(t); d2->next = d1; if (prev == NULL) d->u.kids = d2; else prev->next = d2; return d2; } else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; prev = NULL; /* arities fixed: handle both NAME and COMPLEX */ symbol = SYMNUM(t); while (d1 && DVAR(d1)) { /* skip variables */ prev = d1; d1 = d1->next; } while (d1 && d1->symbol < symbol) { prev = d1; d1 = d1->next; } if (d1 == NULL || d1->symbol != symbol) { d2 = get_discrim(); d2->type = DRIGID; d2->symbol = symbol; d2->next = d1; d1 = d2; } else d2 = NULL; /* new node not required at this level */ for (i = 0; i < ARITY(t); i++) d1 = discrim_bind_insert_rec(ARG(t,i), d1); if (d2 != NULL) { /* link in new subtree (possibly a leaf) */ if (prev == NULL) d->u.kids = d2; else prev->next = d2; } return d1; /* d1 is leaf corresp. to end of input term */ } } /* discrim_bind_insert_rec */ /************* * * discrim_bind_insert(t, root, object) * *************/ static void discrim_bind_insert(Term t, Discrim root, void *object) { Discrim d; Plist gp1, gp2; d = discrim_bind_insert_rec(t, root); gp1 = get_plist(); gp1->v = object; gp1->next = NULL; /* Install at end of list. */ if (d->u.data == NULL) d->u.data = gp1; else { for (gp2 = d->u.data; gp2->next != NULL; gp2 = gp2->next); gp2->next = gp1; } } /* discrim_bind_insert */ /************* * * Discrim discrim_bind_end(t, d, path_p) * * Given a discrimination tree (or a subtree) and a term, return the * node in the tree that corresponds to the last symbol in t (or NULL * if the node doesn't exist). *path_p is a list that is extended by * this routine. It is a list of pointers to the * nodes in path from the parent of the returned node up to imd. * (It is useful for deletions, because nodes do not have pointers to * parents.) * *************/ static Discrim discrim_bind_end(Term t, Discrim d, Plist *path_p) { Discrim d1; Plist dp; int symbol, sym; /* add current node to the front of the path list. */ dp = get_plist(); dp->v = d; dp->next = *path_p; *path_p = dp; if (VARIABLE(t)) { d1 = d->u.kids; symbol = VARNUM(t); while (d1 && DVAR(d1) && d1->symbol < symbol) d1 = d1->next; if (d1 == NULL || !DVAR(d1) || d1->symbol != symbol) return NULL; else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; sym = SYMNUM(t); /* arities fixed: handle both NAME and COMPLEX */ while (d1 && DVAR(d1)) /* skip variables */ d1 = d1->next; while (d1 && d1->symbol < sym) d1 = d1->next; if (d1 == NULL || d1->symbol != sym) return NULL; else { int i; for (i = 0; d1 && i < ARITY(t); i++) d1 = discrim_bind_end(ARG(t,i), d1, path_p); return d1; } } } /* discrim_bind_end */ /************* * * discrim_bind_delete(t, root, object) * *************/ static void discrim_bind_delete(Term t, Discrim root, void *object) { Discrim end, d2, d3, parent; Plist tp1, tp2; Plist dp1, path; /* First find the correct leaf. path is used to help with */ /* freeing nodes, because nodes don't have parent pointers. */ path = NULL; end = discrim_bind_end(t, root, &path); if (end == NULL) { fatal_error("discrim_bind_delete, cannot find end."); } /* Free the pointer in the leaf-list */ tp1 = end->u.data; tp2 = NULL; while(tp1 && tp1->v != object) { tp2 = tp1; tp1 = tp1->next; } if (tp1 == NULL) { fatal_error("discrim_bind_delete, cannot find term."); } if (tp2 == NULL) end->u.data = tp1->next; else tp2->next = tp1->next; free_plist(tp1); if (end->u.data == NULL) { /* free tree nodes from bottom up, using path to get parents */ end->u.kids = NULL; /* probably not necessary */ dp1 = path; while (end->u.kids == NULL && end != root) { parent = (Discrim) dp1->v; dp1 = dp1->next; d2 = parent->u.kids; d3 = NULL; while (d2 != end) { d3 = d2; d2 = d2->next; } if (d3 == NULL) parent->u.kids = d2->next; else d3->next = d2->next; free_discrim(d2); end = parent; } } /* free path list */ while (path) { dp1 = path; path = path->next; free_plist(dp1); } } /* discrim_bind_delete */ /************* * * discrim_bind_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a tame discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted. */ /* PUBLIC */ void discrim_bind_update(Term t, Discrim root, void *object, Indexop op) { if (op == INSERT) discrim_bind_insert(t, root, object); else discrim_bind_delete(t, root, object); } /* discrim_bind_update */ /************* * * check_flat2 * *************/ static Flat2 check_flat2(Flat2 f) { Flat2 last; int i, arity; if (f->next != NULL && f->next->prev != f) fprintf(stderr, "check_flat2: next-prev error\n"); if (f->place_holder) arity = 0; else arity = ARITY(f->t); last = f; for (i = 0; i < arity; i++) last = check_flat2(last->next); if (f->last != last) fprintf(stderr, "check_flat2: last is wrong\n"); return last; } /* check_flat2 */ /************* * * p_flat2 * *************/ void p_flat2(Flat2 f) { while (f != NULL) { if (VARIABLE(f->t)) printf("v%d", VARNUM(f->t)); else printf("%s", sn_to_str(SYMNUM(f->t))); if (f->place_holder) printf("[]"); f = f->next; if (f != NULL) printf("-"); } printf("\n"); } /* p_flat2 */ /************* * * discrim_bind_retrieve_leaf(t_in, root, subst, ppos) * *************/ static Plist discrim_bind_retrieve_leaf(Term t_in, Discrim root, Context subst, Flat2 *ppos) { Flat2 f, f1, f2, f_save; Term t = NULL; Discrim d = NULL; int symbol = 0; int match = 0; int bound = 0; int status = 0; f = *ppos; /* Don't forget to reset before return. */ t = t_in; f_save = NULL; if (t != NULL) { /* if first call */ d = root->u.kids; if (d != NULL) { f = get_flat2(); f->t = t; f->last = f; f->prev = NULL; f->place_holder = (COMPLEX(t)); status = GO; } else status = FAILURE; } else status = BACKTRACK; while (status == GO || status == BACKTRACK) { if (status == BACKTRACK) { while (f && !f->alternatives) { /* clean up HERE??? */ if (f->bound) { subst->terms[f->varnum] = NULL; f->bound = 0; } f_save = f; f = f->prev; } if (f != NULL) { if (f->bound) { subst->terms[f->varnum] = NULL; f->bound = 0; } d = f->alternatives; f->alternatives = NULL; status = GO; } else status = FAILURE; } if (status == GO) { match = 0; while (!match && d && DVAR(d)) { symbol = d->symbol; if (subst->terms[symbol]) { /* if already bound */ match = term_ident(subst->terms[symbol], f->t); bound = 0; } else { /* bind variable in discrimb tree */ match = 1; subst->terms[symbol] = f->t; bound = 1; } if (!match) d = d->next; } if (match) { /* push alternatives */ f->alternatives = d->next; f->bound = bound; f->varnum = symbol; f = f->last; } else if (VARIABLE(f->t)) status = BACKTRACK; else { symbol = SYMNUM(f->t); while (d && d->symbol < symbol) d = d->next; if (!d || d->symbol != symbol) status = BACKTRACK; else if (f->place_holder) { int i; /* insert skeleton in place_holder */ f1 = get_flat2(); f1->t = f->t; f1->prev = f->prev; f1->last = f; f_save = f1; if (f1->prev) f1->prev->next = f1; t = f->t; for (i = 0; i < ARITY(t); i++) { if (i < ARITY(t)-1) f2 = get_flat2(); else f2 = f; f2->place_holder = COMPLEX(ARG(t,i)); f2->t = ARG(t,i); f2->last = f2; f2->prev = f1; f1->next = f2; f1 = f2; } f = f_save; } /* if f->place_holder */ } if (status == GO) { if (f->next) { f = f->next; d = d->u.kids; } else status = SUCCESS; } } } /* while */ if (status == SUCCESS) { *ppos = f; return d->u.data; } else { /* Free flat2s. */ #ifdef SPEED Flat2count = 0; #else while (f_save) { f1 = f_save; f_save = f_save->next; free_flat2(f1); } #endif return NULL; } } /* discrim_bind_retrieve_leaf */ /************* * * discrim_bind_retrieve_first(t, root, subst, ppos) * * Get the first object associated with a term more general than t. * * Remember to call discrim_bind_cancel(*ppos) if you don't want the * whole sequence. * *************/ /* DOCUMENTATION This routine, along with discrim_bind_retrieve_next(), gets answers from a tame discrimination index. This routine retrieves the first object associated with a term, say ft, more general than Term t. (NULL is returned if there is none.) The substitution for variables of ft is placed into Context subst.

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_tame_cancel() to clear the substitution and free memory associated with the Discrim_pos. */ /* PUBLIC */ void *discrim_bind_retrieve_first(Term t, Discrim root, Context subst, Discrim_pos *ppos) { Plist tp; Flat2 f; Discrim_pos gp; tp = discrim_bind_retrieve_leaf(t, root, subst, &f); if (tp == NULL) return NULL; else { gp = get_discrim_pos(); gp->subst = subst; gp->backtrack = f; gp->data = tp; *ppos = gp; return tp->v; } } /* discrim_bind_retrieve_first */ /************* * * discrim_bind_retrieve_next(ppos) * * Get the next object associated with a term more general than t. * * Remember to call discrim_bind_cancel(*ppos) if you don't want the * whole sequence. * *************/ /* DOCUMENTATION This routine retrieves the next object in the sequence of answers to a query of a tame discrimbination tree. You must not explicitly clear the Context you gave to discrim_bind_retrieve_first()---that is handled internally. See discrim_bind_retrieve_first(). */ /* PUBLIC */ void *discrim_bind_retrieve_next(Discrim_pos pos) { Plist tp; tp = pos->data->next; if (tp != NULL) { /* if any more terms in current leaf */ pos->data = tp; return tp->v; } else { /* try for another leaf */ tp = discrim_bind_retrieve_leaf(NULL, NULL, pos->subst, (Flat2 *) &(pos->backtrack)); if (tp != NULL) { pos->data = tp; return tp->v; } else { free_discrim_pos(pos); return NULL; } } } /* discrim_bind_retrieve_next */ /************* * * discrim_bind_cancel(pos) * *************/ /* DOCUMENTATION This routine must be called if you get some, but not all answers to a tame discrimbintaion query. The Context (which was given to the discrim_bind_retrieve_first() call) is cleared, and the memory associated the retrieval state is freed. */ /* PUBLIC */ void discrim_bind_cancel(Discrim_pos pos) { Flat2 f1, f2; f1 = pos->backtrack; while (f1) { if (f1->bound) pos->subst->terms[f1->varnum] = NULL; f2 = f1; f1 = f1->prev; #ifndef SPEED free_flat2(f2); #endif } #ifdef SPEED Flat2count = 0; #endif free_discrim_pos(pos); } /* discrim_bind_cancel */ LADR-2009-11A/ladr/ivy.h0000644000175000017500000000220711151265364013725 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_IVY_H #define TP_IVY_H #include "xproofs.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from ivy.c */ void sb_ivy_write_just(String_buf sb, Ivyjust j, I3list map); void sb_ivy_write_clause_jmap(String_buf sb, Topform c, I3list map); Plist expand_proof_ivy(Plist proof); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/fpalist.c0000644000175000017500000002700610772016137014557 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "fpalist.h" /* Private definitions and types */ /* April 2004. This if the new code for inserting/deleting/traversing FPA lists. It should function exactly the same as the old code, except that deletions should be much faster, and memory usage will be somewhat different (not much). Instead of a (singly-linked) list of pointers to terms, we have a (singly-linked) list of *arrays* of pointers to terms. As before, the terms are kept in decreasing order. Recall that in practice, terms being inserted will usually be greater than anything already in the list. The design is determined by the following properties of the application: (1) items will usually be inserted in increasing order, (2) the lists will be traversed, and the items must be kept in decreasing order, and (3) deletions will be arbitrary and occasionally extensive. March 2005. Code changed so that the size of the chunks starts small and increases as needed. When the number of chunks in an fpa list grows to be the same as the chunksize, the list is reconstructed, doubling the chunksize (and halving the number of chunks). (Chunk sizes are never made smaller.) */ #define F_INITIAL_SIZE 4 /* initial size of chunks (they double as needed) */ #define F_MAX_SIZE 512 /* maximum size of chunks */ /* * memory management */ #define PTRS_FPA_CHUNK PTRS(sizeof(struct fpa_chunk)) static unsigned Fpa_chunk_gets, Fpa_chunk_frees; #define PTRS_FPA_LIST PTRS(sizeof(struct fpa_list)) static unsigned Fpa_list_gets, Fpa_list_frees; static unsigned Chunk_mem; /* keep track of memory (pointers) for chunks */ /************* * * Fpa_chunk get_fpa_chunk() * *************/ static Fpa_chunk get_fpa_chunk(int n) { Fpa_chunk p = get_cmem(PTRS_FPA_CHUNK); p->d = get_cmem(n); Chunk_mem += n; p->size = n; Fpa_chunk_gets++; return(p); } /* get_fpa_chunk */ /************* * * free_fpa_chunk() * *************/ static void free_fpa_chunk(Fpa_chunk p) { Chunk_mem -= p->size; free_mem(p->d, p->size); free_mem(p, PTRS_FPA_CHUNK); Fpa_chunk_frees++; } /* free_fpa_chunk */ /************* * * Fpa_list get_fpa_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Fpa_list get_fpa_list() { Fpa_list p = get_cmem(PTRS_FPA_LIST); p->chunksize = F_INITIAL_SIZE; Fpa_list_gets++; return(p); } /* get_fpa_list */ /************* * * free_fpa_list() * *************/ static void free_fpa_list(Fpa_list p) { free_mem(p, PTRS_FPA_LIST); Fpa_list_frees++; } /* free_fpa_list */ /************* * * fprint_fpalist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpalist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_fpalist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct fpa_chunk); fprintf(fp, "fpa_chunk (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_chunk_gets, Fpa_chunk_frees, Fpa_chunk_gets - Fpa_chunk_frees, ((Fpa_chunk_gets - Fpa_chunk_frees) * n) / 1024.); n = sizeof(struct fpa_list); fprintf(fp, "fpa_list (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_list_gets, Fpa_list_frees, Fpa_list_gets - Fpa_list_frees, ((Fpa_list_gets - Fpa_list_frees) * n) / 1024.); fprintf(fp, " fpa_list chunks: %9.1f K\n", Chunk_mem * BYTES_POINTER / 1024.); } /* fprint_fpalist_mem */ /************* * * p_fpalist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the fpalist package. */ /* PUBLIC */ void p_fpalist_mem() { fprint_fpalist_mem(stdout, TRUE); } /* p_fpalist_mem */ /* * end of memory management */ /* First and last items in chunk. Items are right-justified. */ #define FLAST(f) (f)->d[(f)->size - 1] #define FFIRST(f) (f)->d[(f)->size - (f)->n] /************* * * double_chunksize() * *************/ static Fpa_chunk double_chunksize(Fpa_chunk f) { if (f == NULL) return NULL; else if (f->next == NULL) { fatal_error("double_chunksize, parity error"); return NULL; } else { int newsize = f->size * 2; Fpa_chunk g = f->next; Fpa_chunk new = get_fpa_chunk(newsize); /* put f and g terms into new, free f and g, return new */ int i = newsize - (f->n + g->n); int j; for (j = f->size - f->n; j < f->size; j++) new->d[i++] = f->d[j]; for (j = g->size - g->n; j < g->size; j++) new->d[i++] = g->d[j]; new->n = f->n + g->n; new->head = f->head; new->next = double_chunksize(g->next); free_fpa_chunk(f); free_fpa_chunk(g); return new; } } /* double_chunksize */ /************* * * flist_insert() * * If the item is greater than any in the list, insertion should * be constant time. * *************/ static Fpa_chunk flist_insert(Fpa_chunk f, Term x, Fpa_list head) { if (f == NULL) { f = get_fpa_chunk(head->chunksize); head->num_chunks++; FLAST(f) = x; f->n = 1; } else if (f->n == f->size) { /* chunk is full */ if (FLT(x,FLAST(f))) f->next = flist_insert(f->next, x, head); else if (x == FLAST(f)) fatal_error("flist_insert, item already here (1)"); else if (FGT(x,FFIRST(f))) { /* This special case isn't necessary. It is to improve performance. The application for which I'm writing this inserts items in increasing order (most of the time), and this prevents a lot of half-empty chunks in that case. */ Fpa_chunk f2 = flist_insert(NULL, x, head); f2->next = f; f = f2; } else { /* split this chunk in half (new chunk has same size) */ Fpa_chunk f2 = get_fpa_chunk(f->size); int move = f2->size / 2; int i, j; head->num_chunks++; for (i = 0, j = f->size - move; i < move; i++, j++) { f2->d[j] = f->d[i]; f->d[i] = NULL; } f2->n = move; f->n = f->size - move; f2->next = f; f = flist_insert(f2, x, head); } } else { /* chunk not full */ if (f->next && FLE(x,FFIRST(f->next))) f->next = flist_insert(f->next, x, head); /* insert into next chunk */ else { /* insert into this chunk */ int n = f->n; int i = f->size - n; while (i < f->size && FLT(x,f->d[i])) i++; if (i < f->size && x == f->d[i]) fatal_error("flist_insert, item already here (2)"); if (i == f->size - n) { f->d[i-1] = x; f->n = n+1; } else { /* insert at i-1, shifting the rest */ int j; for (j = f->size-n; j < i; j++) f->d[j-1] = f->d[j]; f->d[i-1] = x; f->n = n+1; } } } return f; } /* flist_insert */ /************* * * fpalist_insert() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void fpalist_insert(Fpa_list p, Term t) { p->chunks = flist_insert(p->chunks, t, p); p->num_terms++; #if 0 printf("insert %p, %d chunks of size %d, %d terms\n", p, p->num_chunks, p->chunksize, p->num_terms); #endif if (p->num_chunks == p->chunksize && p->chunksize < F_MAX_SIZE) { #if 0 printf("doubling %p chunksize from %d to %d (%d chunks, density=%.2f)\n", p, p->chunksize, p->chunksize * 2, p->num_chunks, p->num_terms / (double) (p->num_chunks * p->chunksize)); #endif p->chunks = double_chunksize(p->chunks); p->chunksize = p->chunksize * 2; p->num_chunks = p->num_chunks / 2; } } /* fpalist_insert */ /************* * * consolidate() - try to join f and f->next; not recursive * *************/ static Fpa_chunk consolidate(Fpa_chunk f, Fpa_list head) { if (f->next && f->n + f->next->n <= f->size) { Fpa_chunk f2 = f->next; int i; for (i = 0; i < f->n; i++) f2->d[f->size - (f2->n + i + 1)] = f->d[f->size - (i+1)]; f2->n = f->n + f2->n; free_fpa_chunk(f); head->num_chunks--; return f2; } else return f; } /* consolidate */ /************* * * flist_delete() * *************/ static Fpa_chunk flist_delete(Fpa_chunk f, Term x, Fpa_list head) { if (f == NULL) fatal_error("flist_delete, item not found (1)"); if (FLT(x,FLAST(f))) f->next = flist_delete(f->next, x, head); else { int n = f->n; int i = f->size - n; int j; while (i < f->size && FLT(x,f->d[i])) i++; if (x != f->d[i]) fatal_error("flist_delete, item not found (2)"); /* delete and close the hole */ for (j = i; j > f->size-n; j--) f->d[j] = f->d[j-1]; f->d[j] = NULL; f->n = n-1; if (f->n == 0) { /* delete this chunk */ Fpa_chunk next = f->next; head->num_chunks--; free_fpa_chunk(f); f = next; } else { /* try to join this chunk with the next */ f = consolidate(f, head); } } return f; } /* flist_delete */ /************* * * fpalist_delete() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void fpalist_delete(Fpa_list p, Term t) { p->chunks = flist_delete(p->chunks, t, p); p->num_terms--; #if 0 printf("delete %p, %d chunks of size %d, %d terms\n", p, p->num_chunks, p->chunksize, p->num_terms); #endif } /* fpalist_delete */ /************* * * first_fpos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ struct fposition first_fpos(Fpa_list f) { return next_fpos((struct fposition) {f->chunks, -1}); } /* first_fpos */ /************* * * next_fpos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ struct fposition next_fpos(struct fposition p) { if (p.f == NULL) return (struct fposition) {NULL, 0}; else if (p.i == -1) return (struct fposition) {p.f, p.f->size - p.f->n}; else { int i = p.i+1; if (i < (p.f)->size) return (struct fposition) {p.f, i}; else return next_fpos((struct fposition) {(p.f)->next, -1}); } } /* next_fpos */ /************* * * zap_fpa_chunks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_fpa_chunks(Fpa_chunk p) { if (p != NULL) { zap_fpa_chunks(p->next); free_fpa_chunk(p); } } /* zap_fpa_chunks */ /************* * * zap_fpalist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_fpalist(Fpa_list p) { zap_fpa_chunks(p->chunks); free_fpa_list(p); } /* zap_fpalist */ /************* * * fpalist_empty() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL fpalist_empty(Fpa_list p) { return !p || p->chunks == NULL; } /* fpalist_empty */ /************* * * p_fpa_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_fpa_list(Fpa_chunk c) { for (; c; c = c->next) { int i; /* terms right justified in chunk */ for (i = c->size-c->n; i < c->size; i++) { Term t = c->d[i]; printf(" : "); fprint_term(stdout, t); } } } /* p_fpa_list */ LADR-2009-11A/ladr/symbols.h0000644000175000017500000001534211151265363014611 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_SYMBOLS_H #define TP_SYMBOLS_H #include "strbuf.h" #include "glist.h" /* INTRODUCTION This collection of routines manages the global symbol table. Each symbol is a pair (string,arity) and has a unique ID number. For example, ("f",2), sometimes written f/2, is a different symbol from f/3.

These symbols are used mostly as constant, function, and predicate symbols, but they can be used for variables and other things as well.

The symbol table routines call malloc() and free() directly. The LADR memory package (tp_alloc()) is not used. */ /* Public definitions */ /* maximum number of chars in string part of symbol (includes '\0') */ #define MAX_NAME 51 /* parse/print properties of symbols */ typedef enum {NOTHING_SPECIAL, INFIX, /* xfx */ INFIX_LEFT , /* yfx */ INFIX_RIGHT, /* xfy */ PREFIX_PAREN, /* fx */ PREFIX, /* fy */ POSTFIX_PAREN, /* xf */ POSTFIX /* yf */ } Parsetype; #define MIN_PRECEDENCE 1 #define MAX_PRECEDENCE 999 /* Function/relation properties of symbols */ typedef enum { UNSPECIFIED_SYMBOL, FUNCTION_SYMBOL, PREDICATE_SYMBOL } Symbol_type; /* Unification properties of symbols */ typedef enum { EMPTY_THEORY, COMMUTE, ASSOC_COMMUTE } Unif_theory; /* LRPO status */ typedef enum { LRPO_LR_STATUS, LRPO_MULTISET_STATUS } Lrpo_status; /* Variable style */ typedef enum { STANDARD_STYLE, /* x,y,z,... */ PROLOG_STYLE, /* A,B,C,... */ INTEGER_STYLE /* 0,1,2,... */ } Variable_style; typedef struct symbol * Symbol; /* End of public definitions */ /* Public function prototypes from symbols.c */ char *true_sym(void); char *false_sym(); char *and_sym(); char *or_sym(); char *not_sym(); char *iff_sym(); char *imp_sym(); char *impby_sym(); char *all_sym(); char *exists_sym(); char *quant_sym(); char *attrib_sym(); char *eq_sym(); char *neq_sym(); void set_operation_symbol(char *operation, char *symbol); char *get_operation_symbol(char *operation); BOOL symbol_in_use(char *str); int str_to_sn(char *str, int arity); void fprint_syms(FILE *fp); void p_syms(void); void fprint_sym(FILE *fp, int symnum); void sprint_sym(String_buf sb, int symnum); void p_sym(int symnum); BOOL str_exists(char *str); int greatest_symnum(void); char *sn_to_str(int symnum); BOOL is_symbol(int symnum, char *str, int arity); int sn_to_arity(int symnum); int sn_to_occurrences(int symnum); void set_unfold_symbol(int symnum); BOOL is_unfold_symbol(int symnum); void declare_aux_symbols(Ilist syms); char *parse_type_to_str(Parsetype type); void clear_parse_type_for_all_symbols(void); void clear_parse_type(char *str); void set_parse_type(char *str, int precedence, Parsetype type); BOOL binary_parse_type(char *str, int *precedence, Parsetype *type); BOOL unary_parse_type(char *str, int *precedence, Parsetype *type); int special_parse_type(char *str); void set_assoc_comm(char *str, BOOL set); void set_commutative(char *str, BOOL set); BOOL assoc_comm_symbols(void); BOOL comm_symbols(void); BOOL is_assoc_comm(int sn); BOOL is_commutative(int sn); BOOL is_eq_symbol(int symnum); int not_symnum(void); int or_symnum(void); void declare_base_symbols(void); void set_variable_style(Variable_style style); Variable_style variable_style(void); BOOL variable_name(char *s); void symbol_for_variable(char *str, int varnum); Ilist variable_symbols(Ilist syms); Ilist remove_variable_symbols(Ilist syms); void set_symbol_type(int symnum, Symbol_type type); Symbol_type get_symbol_type(int symnum); BOOL function_symbol(int symnum); BOOL relation_symbol(int symnum); BOOL function_or_relation_symbol(int symnum); void declare_functions_and_relations(Ilist fsyms, Ilist rsyms); int function_or_relation_sn(char *str); Ilist all_function_symbols(void); Ilist all_relation_symbols(void); void set_lrpo_status(int symnum, Lrpo_status status); void all_symbols_lrpo_status(Lrpo_status status); Lrpo_status sn_to_lrpo_status(int sn); void set_kb_weight(int symnum, int weight); BOOL zero_wt_kb(void); int sn_to_kb_wt(int symnum); void print_kbo_weights(FILE *fp); void set_skolem(int symnum); void skolem_check(BOOL flag); int next_skolem_symbol(int arity); Ilist skolem_symbols(void); BOOL is_skolem(int symnum); void skolem_reset(void); void decommission_skolem_symbols(void); void set_skolem_symbols(Ilist symnums); void set_lex_val(int symnum, int lex_val); int sn_to_lex_val(int sn); Ordertype sym_precedence(int symnum_1, int symnum_2); Ilist syms_with_lex_val(void); BOOL exists_preliminary_precedence(Symbol_type type); Ordertype preliminary_lex_compare(Symbol a, Symbol b); Ordertype lex_compare_arity_0123(Symbol s1, Symbol s2); Ordertype lex_compare_arity_0213(Symbol s1, Symbol s2); void lex_order(Ilist fsyms, Ilist rsyms, I2list fsyms_multiset, I2list rsyms_multiset, Ordertype (*comp_proc) (Symbol, Symbol)); Ilist sort_by_lex_val(Ilist p); Ilist current_fsym_precedence(); Ilist current_rsym_precedence(); Ilist not_in_preliminary_precedence(Ilist syms, Symbol_type type); void print_fsym_precedence(FILE *fp); void print_rsym_precedence(FILE *fp); int min_lex_val(void); void assign_greatest_precedence(int symnum); BOOL has_greatest_precedence(int symnum); void lex_insert_after_initial_constants(Ilist syms); void add_skolems_to_preliminary_precedence(void); int fresh_symbol(char *prefix, int arity); int gen_new_symbol(char *prefix, int arity, Ilist syms); void mark_for_new_symbols(void); I2list new_symbols_since_mark(void); void add_new_symbols(I2list syms); void new_constant_properties(int sn); Ilist arity_check(Ilist fsyms, Ilist rsyms); int symbol_with_string(Ilist syms, char *str); void process_skolem_list(Plist skolem_strings, Ilist fsyms); void process_lex_list(Plist lex_strings, Ilist syms, Symbol_type type); Ilist symnums_of_arity(Ilist p, int i); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/demod.c0000644000175000017500000002702011065022363014173 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "demod.h" #include "dollar.h" /* Private definitions and types */ /* These are just statistics. */ static int Demod_attempts = 0; static int Demod_rewrites = 0; /************* * * demodulator_type() * *************/ /* DOCUMENTATION Return NOT_DEMODULATOR, ORIENTED, LEX_DEP_LR, LEX_DEP_RL, or LEX_DEP_BOTH. */ /* PUBLIC */ int demodulator_type(Topform c, int lex_dep_demod_lim, BOOL sane) { if (!pos_eq_unit(c->literals)) return NOT_DEMODULATOR; else { Term atom = c->literals->atom; Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); int n_alpha = symbol_count(alpha); int n_beta = symbol_count(beta); if (oriented_eq(atom)) return ORIENTED; else if (sane && n_alpha != n_beta) return NOT_DEMODULATOR; else if (lex_dep_demod_lim != -1 && n_alpha + n_beta + 1 > lex_dep_demod_lim) return NOT_DEMODULATOR; else { Plist alpha_vars = set_of_variables(alpha); Plist beta_vars = set_of_variables(beta); BOOL lr = plist_subset(beta_vars, alpha_vars) && !VARIABLE(alpha); BOOL rl = !renamable_flip_eq(atom) && plist_subset(alpha_vars, beta_vars) && !VARIABLE(beta); zap_plist(alpha_vars); zap_plist(beta_vars); if (lr && rl) return LEX_DEP_BOTH; else if (lr) return LEX_DEP_LR; else if (rl) return LEX_DEP_RL; else return NOT_DEMODULATOR; } } } /* demodulator_type */ /************* * * idx_demodulator() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void idx_demodulator(Topform c, int type, Indexop operation, Mindex idx) { Term atom = c->literals->atom; Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (type == ORIENTED || type == LEX_DEP_LR || type == LEX_DEP_BOTH) mindex_update(idx, alpha, operation); /* index for left->right */ if (type == LEX_DEP_RL || type == LEX_DEP_BOTH) mindex_update(idx, beta, operation); /* index for right->left */ } /* idx_demodulator */ /************* * * demod_attempts() * *************/ /* DOCUMENTATION Return the number of rewrite attempts so far (for the whole process). */ /* PUBLIC */ int demod_attempts() { return Demod_attempts; } /* demod_attempts */ /************* * * demod_rewrites() * *************/ /* DOCUMENTATION Return the number of successful rewrites so far (for the whole process). */ /* PUBLIC */ int demod_rewrites() { return Demod_rewrites; } /* demod_rewrites */ /************* * * demod() * * For non-AC terms. * *************/ static Term demod(Term t, Mindex demods, int flag, Ilist *just_head, BOOL lex_order_vars) { if (term_flag(t, flag) || VARIABLE(t)) ; /* leave it alone */ else { Discrim_pos dpos; Term found; Context c; /* allocate after we demoulate the subterms */ int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = demod(ARG(t,i), demods, flag, just_head, lex_order_vars); c = get_context(); Demod_attempts++; found = discrim_bind_retrieve_first(t, demods->discrim_tree, c, &dpos); while (found != NULL) { Topform demodulator = found->container; Term atom = demodulator->literals->atom; Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); BOOL match_left = (found == alpha); Term other = (match_left ? beta : alpha); Term contractum = apply_demod(other, c, flag); BOOL ok; if (oriented_eq(atom)) ok = TRUE; else ok = term_greater(t, contractum, lex_order_vars); /* LPO, RPO, KBO */ if (ok) { discrim_bind_cancel(dpos); Demod_rewrites++; zap_term(t); *just_head = ilist_prepend(*just_head, demodulator->id); *just_head = ilist_prepend(*just_head, match_left ? 1 : 2); t = demod(contractum, demods, flag, just_head, lex_order_vars); found = NULL; } else { zap_term(contractum); found = discrim_bind_retrieve_next(dpos); } } free_context(c); term_flag_set(t, flag); /* Mark as fully demodulated. */ } return(t); } /* demod */ /************* * * contract_bt * *************/ static Term contract_bt(Term t, Mindex demods, int flag, Topform *demodulator_ptr) { Mindex_pos pos; Term contractum, alpha; Topform demodulator = NULL; Context c = get_context(); alpha = mindex_retrieve_first(t,demods,GENERALIZATION,NULL,c,TRUE,&pos); if (alpha == NULL) contractum = NULL; else { Term atom; demodulator = alpha->container; atom = demodulator->literals->atom; contractum = apply_demod(ARG(atom,1), c, flag); if (c->partial_term) { /* Get copy, including marks that indicate normal terms. */ Term partial = apply_demod(c->partial_term, NULL, flag); contractum = build_binary_term(SYMNUM(t), contractum, partial); } mindex_retrieve_cancel(pos); } free_context(c); *demodulator_ptr = demodulator; return(contractum); } /* contract_bt */ /************* * * demod_bt * *************/ static Term demod_bt(Term t, Mindex demods, int psn, int flag, Ilist *just_head) { if (term_flag(t, flag) || VARIABLE(t)) ; /* leave it alone */ else { int i; int sn = SYMNUM(t); for (i = 0; i < ARITY(t); i++) ARG(t,i) = demod_bt(ARG(t,i), demods, sn, flag, just_head); if (sn == psn && is_assoc_comm(sn)) ; /* t is part of an AC term, so leave it alone. */ else { Term contractum; Topform demodulator; ac_canonical(t, flag); Demod_attempts++; contractum = contract_bt(t, demods, flag, &demodulator); if (contractum) { Demod_rewrites++; zap_term(t); ac_canonical(contractum, flag); *just_head = ilist_prepend(*just_head, demodulator->id); t = demod_bt(contractum, demods, psn, flag, just_head); } } } /* Mark as fully demodulated. This also means ac_canonical. */ term_flag_set(t, flag); return(t); } /* demod_bt */ /************* * * demodulate() * *************/ /* DOCUMENTATION This routine demodulates a term. ID numbers of demodulators are put on the front of just_head, so you'll probably want to reverse the list before putting it into the clause justification. */ /* PUBLIC */ Term demodulate(Term t, Mindex demods, Ilist *just_head, BOOL lex_order_vars) { int flag = claim_term_flag(); Term result; if (demods->unif_type == ORDINARY_UNIF) result = demod(t, demods, flag, just_head, lex_order_vars); else result = demod_bt(t, demods, -1, flag, just_head); term_flag_clear_recursively(result, flag); release_term_flag(flag); return result; } /* demodulate */ /************* * * demod1_recurse() * * For non-AC terms. Similar to demod(), but do at most one rewrite * and return a position. * *************/ static Term demod1_recurse(Term top, Term t, Topform demodulator, int direction, Ilist *ipos, BOOL lex_order_vars) { if (VARIABLE(t)) ; /* leave it alone */ else { int i; for (i = 0; i < ARITY(t) && *ipos == NULL; i++) ARG(t,i) = demod1_recurse(top,ARG(t,i),demodulator,direction,ipos, lex_order_vars); if (*ipos == NULL) { Context c1 = get_context(); Trail tr = NULL; Term atom = demodulator->literals->atom; BOOL match_left = (direction == 1); Term t1 = ARG(atom, match_left ? 0 : 1); Term t2 = ARG(atom, match_left ? 1 : 0); if (match(t1, c1, t, &tr)) { Term contractum = apply_demod(t2, c1, -1); BOOL ok; if (oriented_eq(atom)) ok = TRUE; else ok = term_greater(t, contractum, lex_order_vars); /* LPO, RPO, KBO */ if (ok) { undo_subst(tr); *ipos = position_of_subterm(top, t); zap_term(t); t = contractum; } else zap_term(contractum); } free_context(c1); } } return(t); } /* demod1_recurse */ /************* * * demod1() * *************/ /* DOCUMENTATION Special purpose demodulation routine.

Given a clause and a demodulator that rewrites the clause, rewrite the innermost leftmost subterm to which the demodulator applies. Return the rewritten term and the position vectors of the from and into terms. */ /* PUBLIC */ void demod1(Topform c, Topform demodulator, int direction, Ilist *fpos, Ilist *ipos, BOOL lex_order_vars) { Term result; Literals lit; int n = 0; for (lit = c->literals, *ipos = NULL; lit && *ipos == NULL; lit=lit->next) { n++; result = demod1_recurse(lit->atom, lit->atom, demodulator,direction,ipos, lex_order_vars); } if (*ipos == NULL) fatal_error("demod1, clause not rewritable"); else { *fpos = ilist_prepend(NULL, direction); /* side of demodulator */ *fpos = ilist_prepend(*fpos, 1); /* literal number */ *ipos = ilist_prepend(*ipos, n); /* literal number */ } } /* demod1 */ /************* * * part_recurse() * *************/ static Term part_recurse(Term top, Term t, Topform demod, int target, int direction, int *sequence, Ilist *ipos) { if (VARIABLE(t)) return t; else { int i; for (i = 0; i < ARITY(t) && *ipos == NULL; i++) { ARG(t,i) = part_recurse(top, ARG(t,i), demod, target, direction, sequence, ipos); } if (*ipos != NULL || *sequence >= target) return t; else { (*sequence)++; if (*sequence != target) return t; else { Term alpha, beta; Context subst = get_context(); Trail tr = NULL; if (direction == 1) { alpha = ARG(demod->literals->atom, 0); beta = ARG(demod->literals->atom, 1); } else { alpha = ARG(demod->literals->atom, 1); beta = ARG(demod->literals->atom, 0); } if (match(alpha, subst, t, &tr)) { Term result = apply(beta, subst); undo_subst(tr); *ipos = position_of_subterm(top, t); zap_term(t); t = result; } else { printf("demodulator%s: ", direction == 1 ? "" : " (R)"); fprint_clause(stdout, demod); printf("target=%d: ", target); p_term(t); fatal_error("part_recurse, not rewitable"); } free_context(subst); return t; } } } } /* part_recurse */ /************* * * particular_demod() * *************/ /* DOCUMENTATION Special purpose demodulation routine.

Given a clause and which applies to the clause, return the rewritten clause and the position vectors of the from and into terms. */ /* PUBLIC */ void particular_demod(Topform c, Topform demodulator, int target, int direction, Ilist *fpos, Ilist *ipos) { Literals lit; int n = 0; int sequence = 0; for (lit = c->literals, *ipos = NULL; lit && *ipos == NULL; lit=lit->next) { n++; part_recurse(lit->atom, lit->atom, demodulator, target, direction, &sequence, ipos); } if (*ipos == NULL) fatal_error("particular_demod, clause not rewritable"); else { *fpos = ilist_prepend(NULL, direction); /* side of demodulator */ *fpos = ilist_prepend(*fpos, 1); /* literal number */ *ipos = ilist_prepend(*ipos, n); /* literal number */ upward_clause_links(c); } } /* particular_demod */ LADR-2009-11A/ladr/attrib.h0000644000175000017500000000667111151265364014414 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_ATTRIB_H #define TP_ATTRIB_H #include "unify.h" /* INTRODUCTION This package is about lists of attributes. Each attribute is a pair (attribute-id, attribute-value). Each attribute-id is associated with a data type.

To use an attribute, you first have to call register_attribute(), giving and ID, name, and type of the attribute. The ID is used with the "set" and "get" operations.

For example,

  register_attribute(label_attr, "label", STRING_ATTRIBUTE);
  ...
  Attribute a = set_string_attribute(NULL, label_attr, "clause_32");
  ...
  char *s = get_string_attribute(a, label_attr, 1);
*/ /* Public definitions */ typedef enum { INT_ATTRIBUTE, STRING_ATTRIBUTE, TERM_ATTRIBUTE } Attribute_type; typedef struct attribute * Attribute; /* End of public definitions */ /* Public function prototypes from attrib.c */ void fprint_attrib_mem(FILE *fp, BOOL heading); void p_attrib_mem(); int register_attribute(char *name, Attribute_type type); void declare_term_attribute_inheritable(int id); Attribute set_int_attribute(Attribute a, int id, int val); int get_int_attribute(Attribute a, int id, int n); BOOL exists_attribute(Attribute a, int id); Attribute set_term_attribute(Attribute a, int id, Term val); void replace_term_attribute(Attribute a, int id, Term val, int n); void replace_int_attribute(Attribute a, int id, int val, int n); Term get_term_attribute(Attribute a, int id, int n); Term get_term_attributes(Attribute a, int id); Attribute set_string_attribute(Attribute a, int id, char *val); char *get_string_attribute(Attribute a, int id, int n); BOOL string_attribute_member(Attribute a, int id, char *s); void zap_attributes(Attribute a); Attribute delete_attributes(Attribute a, int id); Attribute cat_att(Attribute a, Attribute b); Term build_attr_term(Attribute a); Term attributes_to_term(Attribute a, char *operator); int attribute_name_to_id(char *name); Attribute term_to_attributes(Term t, char *operator); Attribute inheritable_att_instances(Attribute a, Context subst); Attribute copy_attributes(Attribute a); void instantiate_inheritable_attributes(Attribute a, Context subst); void renumber_vars_attributes(Attribute attrs, int vmap[], int max_vars); void set_vars_attributes(Attribute attrs, char *vnames[], int max_vars); Plist vars_in_attributes(Attribute attrs); int label_att(void); BOOL attributes_contain_variables(Attribute a); Attribute copy_int_attribute(Attribute source, Attribute dest, int attr_id); Attribute copy_string_attribute(Attribute source, Attribute dest, int attr_id); Attribute copy_term_attribute(Attribute source, Attribute dest, int attr_id); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/maximal.c0000644000175000017500000001505310702323241014532 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "maximal.h" /* Private definitions and types */ int Maximal_flag = -1; /* termflag to mark maximal literals */ int Maximal_signed_flag = -1; /* to mark maximal literals within sign */ int Selected_flag = -1; /* to mark selected literals */ /************* * * init_maximal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_maximal(void) { if (Maximal_flag != -1) fatal_error("init_maximal, called more than once"); Maximal_flag = claim_term_flag(); Maximal_signed_flag = claim_term_flag(); Selected_flag = claim_term_flag(); } /* init_maximal */ /************* * * greater_literals() * *************/ static BOOL greater_literals(Literals l1, Literals l2) { Term a1 = l1->atom; Term a2 = l2->atom; Ordertype p = sym_precedence(SYMNUM(a1), SYMNUM(a2)); if (p == GREATER_THAN) return TRUE; else if (p == LESS_THAN) return FALSE; else if (SYMNUM(a1) != SYMNUM(a2)) return FALSE; else if (is_eq_symbol(SYMNUM(a1))) return greater_multiset_current_ordering(a1, a2); else return term_greater(a1, a2, FALSE); /* LPO, RPO, KBO */ } /* greater_literals */ /************* * * max_lit_test() * *************/ /* DOCUMENTATION Test if a literal is maximal in a clause (w.r.t. others literals of the either sign). This version does not use a flag. */ /* PUBLIC */ BOOL max_lit_test(Literals lits, Literals lit) { /* If there is a greater literal of ANY sign, return FALSE. */ Literals l2 = lits; BOOL maximal = TRUE; while (l2 && maximal) { if (lit != l2 && greater_literals(l2, lit)) maximal = FALSE; else l2 = l2->next; } return maximal; } /* max_lit_test */ /************* * * max_signed_lit_test() * *************/ /* DOCUMENTATION Test if a literal is maximal in a clause (w.r.t. others literals of the same sign). This version does not use a flag. */ /* PUBLIC */ BOOL max_signed_lit_test(Literals lits, Literals lit) { /* If there is a greater literal of the same sign, return FALSE. */ Literals l2 = lits; BOOL maximal = TRUE; while (l2 && maximal) { if (lit != l2 && lit->sign == l2->sign && greater_literals(l2, lit)) maximal = FALSE; else l2 = l2->next; } return maximal; } /* max_signed_lit_test */ /************* * * mark_maximal_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_maximal_literals(Literals lits) { Literals lit; if (Maximal_flag == -1) fatal_error("mark_maximal_literals, init_maximal() was not called"); /* Note: we mark the atom, not the literal. */ for (lit = lits; lit; lit = lit->next) { if (max_lit_test(lits, lit)) term_flag_set(lit->atom, Maximal_flag); if (max_signed_lit_test(lits, lit)) term_flag_set(lit->atom, Maximal_signed_flag); } } /* mark_maximal_literals */ /************* * * maximal_literal() * *************/ /* DOCUMENTATION Check if a literal is maximal in the clause that contains it. The argument "check" should be FLAG_CHECK (check the flag only) or FULL_CHECK (do the full comparicon). */ /* PUBLIC */ BOOL maximal_literal(Literals lits, Literals lit, int check) { if (check == FLAG_CHECK) return term_flag(lit->atom, Maximal_flag); else return max_lit_test(lits, lit); } /* maximal_literal */ /************* * * maximal_signed_literal() * *************/ /* DOCUMENTATION Check if a literal is maximal in the clause that contains it. This only checks a flag. It does not compute maximality. */ /* PUBLIC */ BOOL maximal_signed_literal(Literals lits, Literals lit, int check) { if (check == FLAG_CHECK) return term_flag(lit->atom, Maximal_signed_flag); else return max_signed_lit_test(lits, lit); } /* maximal_signed_literal */ /************* * * number_of_maximal_literals() * *************/ /* DOCUMENTATION Return the number of maximal literals. This checks a flag only. */ /* PUBLIC */ int number_of_maximal_literals(Literals lits, int check) { int n = 0; Literals lit; for (lit = lits; lit; lit = lit->next) { if (maximal_literal(lits, lit, check)) n++; } return n; } /* number_of_maximal_literals */ /************* * * mark_selected_literal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_selected_literal(Literals lit) { term_flag_set(lit->atom, Selected_flag); } /* mark_selected_literal */ /************* * * mark_selected_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_selected_literals(Literals lits, char *selection) { Literals lit; if (Selected_flag == -1) fatal_error("mark_selected_literals, init_maximal() was not called"); /* Note: we mark the atom, not the literal. */ for (lit = lits; lit; lit = lit->next) { if (!lit->sign) { if (str_ident(selection, "all_negative")) mark_selected_literal(lit); else if (str_ident(selection, "max_negative")) { if (maximal_signed_literal(lits, lit, FLAG_CHECK)) mark_selected_literal(lit); } } } } /* mark_maximal_literals */ /************* * * selected_literal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL selected_literal(Literals lit) { return term_flag(lit->atom, Selected_flag); } /* selected_literal */ /************* * * exists_selected_literal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL exists_selected_literal(Literals lits) { Literals lit; for (lit = lits; lit; lit = lit->next) if (selected_literal(lit)) return TRUE; return FALSE; } /* exists_selected_literal */ /************* * * copy_selected_literal_marks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void copy_selected_literal_marks(Literals a, Literals b) { if (!a || !b) return; else { copy_selected_literal_marks(a->next, b->next); if (selected_literal(a)) mark_selected_literal(b); } } /* copy_selected_literal_marks */ LADR-2009-11A/ladr/paramod.c0000644000175000017500000003546111035236420014534 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "paramod.h" /* Private definitions and types */ static BOOL Ordered_inference = FALSE; static BOOL Positive_inference = FALSE; static BOOL Para_from_vars = TRUE; static BOOL Para_into_vars = FALSE; static BOOL Para_from_small = FALSE; static BOOL Check_instances = FALSE; /* non-oriented from lits */ static int Para_instance_prunes = 0; /* counter */ static int Basic_prunes = 0; /* counter */ /************* * * paramodulation_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void paramodulation_options(BOOL ordered_inference, BOOL check_instances, BOOL positive_inference, BOOL basic_paramodulation, BOOL para_from_vars, BOOL para_into_vars, BOOL para_from_small) { Ordered_inference = ordered_inference; Para_from_vars = para_from_vars; Para_into_vars = para_into_vars; Para_from_small = para_from_small; Check_instances = check_instances; Positive_inference = positive_inference; set_basic_paramod(basic_paramodulation); Para_instance_prunes = 0; Basic_prunes = 0; } /* paramodulation_options */ /************* * * para_instance_prunes() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int para_instance_prunes() { return Para_instance_prunes; } /* para_instance_prunes */ /************* * * basic_paramodulation_prunes() * *************/ /* DOCUMENTATION How many paramodulants were killed because they failed the "basic" test. */ /* PUBLIC */ int basic_paramodulation_prunes(void) { return Basic_prunes; } /* basic_paramodulation_prunes */ /************* * * basic_check() * *************/ static BOOL basic_check(Term into_term) { if (basic_paramod() && nonbasic_term(into_term)) { Basic_prunes++; return FALSE; } else return TRUE; } /* basic_check */ /************* * * apply_lit_para() * *************/ static Literals apply_lit_para(Literals lit, Context c) { if (basic_paramod()) return new_literal(lit->sign, apply_basic(lit->atom, c)); else return new_literal(lit->sign, apply(lit->atom, c)); } /* apply_lit_para */ /************* * * apply_substitute_para() * *************/ #if 0 static Term apply_substitute_para(Term t, Term beta, Context from_subst, Term into, Context into_subst) { if (basic_paramod()) return apply_basic_substitute(t, beta, from_subst, into, into_subst); else return apply_substitute(t, beta, from_subst, into, into_subst); } /* apply_substitute_para */ #endif /************* * * paramodulate() * * Construct a paramodulant. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform paramodulate(Literals from_lit, int from_side, Context from_subst, Topform into_clause, Ilist into_pos, Context into_subst) { Topform from_clause = from_lit->atom->container; Topform p = get_topform(); Term beta = ARG(from_lit->atom, from_side == 0 ? 1 : 0); Literals into_lit = ith_literal(into_clause->literals, into_pos->i); Literals lit; for (lit = from_clause->literals; lit != NULL; lit = lit->next) { if (lit != from_lit) p->literals = append_literal(p->literals, apply_lit_para(lit, from_subst)); } for (lit = into_clause->literals; lit != NULL; lit = lit->next) { if (lit != into_lit) p->literals = append_literal(p->literals, apply_lit_para(lit, into_subst)); else p->literals = append_literal(p->literals, new_literal(lit->sign, apply_substitute2(lit->atom, beta, from_subst, into_pos->next, into_subst))); } inherit_attributes(from_clause, from_subst, into_clause, into_subst, p); upward_clause_links(p); return p; } /* paramodulate */ /************* * * para_from_right() * * Should we paramoulate from the right side? * If it is oriented, then NO; * else if it is a renamable_flip unit, then NO; * else YES. * *************/ static BOOL para_from_right(Term atom) { /* Assume atom is an eq_atom. */ if (Para_from_small) return TRUE; if (oriented_eq(atom)) return FALSE; else if (renamable_flip_eq(atom) && unit_clause(((Topform) atom->container)->literals)) return FALSE; else return TRUE; } /* para_from_right */ /************* * * from_parent_test() * *************/ static BOOL from_parent_test(Literals from_lit, int check) { Topform from_parent = from_lit->atom->container; if (Positive_inference) return pos_eq(from_lit) && positive_clause(from_parent->literals) && (!Ordered_inference || maximal_literal(from_parent->literals, from_lit, check)); else return pos_eq(from_lit) && !exists_selected_literal(from_parent->literals) && (!Ordered_inference || maximal_literal(from_parent->literals, from_lit, check)); } /* from_parent_test */ /************* * * into_parent_test() * *************/ static BOOL into_parent_test(Literals into_lit, int check) { Topform into_parent = into_lit->atom->container; if (into_lit->sign) { /* into positive literal */ if (Positive_inference) return positive_clause(into_parent->literals) && (!Ordered_inference || maximal_literal(into_parent->literals, into_lit, check)); else return !exists_selected_literal(into_parent->literals) && (!Ordered_inference || maximal_literal(into_parent->literals, into_lit, check)); } else { /* into negative literal */ if (Positive_inference) { if (exists_selected_literal(into_parent->literals)) return selected_literal(into_lit); else return (!Ordered_inference || maximal_signed_literal(into_parent->literals,into_lit,check)); } else { if (exists_selected_literal(into_parent->literals)) return selected_literal(into_lit); else return (!Ordered_inference || maximal_literal(into_parent->literals, into_lit, check)); } } } /* into_parent_test */ /************* * * check_instance() * *************/ static BOOL check_instance(Literals lit, Context subst, BOOL is_from_parent) { Topform c = lit->atom->container; if (number_of_maximal_literals(c->literals, FLAG_CHECK) == 1 || variable_substitution(subst)) return TRUE; else { Literals a; BOOL ok; int n = literal_number(c->literals, lit); Topform d = instantiate_clause(c, subst); copy_selected_literal_marks(c->literals, d->literals); a = ith_literal(d->literals, n); if (is_from_parent) ok = from_parent_test(a, FULL_CHECK); else ok = into_parent_test(a, FULL_CHECK); zap_topform(d); if (!ok) Para_instance_prunes++; return ok; } } /* check_instance */ /************* * * check_instances() * *************/ static BOOL check_instances(Literals from_lit, int from_side, Context cf, Literals into_lit, Term into, Context ci) { if (!Check_instances) return TRUE; else { return check_instance(from_lit, cf, TRUE) && check_instance(into_lit, ci, FALSE); } } /* check_instances */ /************* * * para_into() * * Paramodulate from a given side of a given literal into a given * term and/or its subterms. * *************/ static void para_into(Literals from_lit, int from_side, Context cf, Ilist from_pos, Topform into_clause, Literals into_lit, Term into, Context ci, Ilist into_pos, BOOL skip_top, void (*proc_proc) (Topform)) { if ((!VARIABLE(into) | Para_into_vars) && basic_check(into)) { int i; if (COMPLEX(into)) { Ilist last = ilist_last(into_pos); Ilist new = get_ilist(); last->next = new; new->i = 0; for (i = 0; i < ARITY(into); i++) { new->i += 1; para_into(from_lit, from_side, cf, from_pos, into_clause, into_lit, ARG(into,i), ci, into_pos, FALSE, proc_proc); } free_ilist(new); last->next = NULL; } if (!skip_top) { Trail tr = NULL; Term alpha = ARG(from_lit->atom, from_side); if (unify(alpha, cf, into, ci, &tr)) { if (check_instances(from_lit, from_side, cf, into_lit, into, ci)) { Topform p = paramodulate(from_lit, from_side, cf, into_clause, into_pos, ci); p->justification = para_just(PARA_JUST, from_lit->atom->container, copy_ilist(from_pos), into_clause, copy_ilist(into_pos)); (*proc_proc)(p); } undo_subst(tr); } } } } /* para_into */ /************* * * para_into_lit() * *************/ static void para_into_lit(Literals from_lit, int from_side, Context cf, Literals into_lit, Context ci, BOOL check_top, void (*proc_proc) (Topform)) { Term alpha = ARG(from_lit->atom, from_side); if (!VARIABLE(alpha) || Para_from_vars) { /* Position vectors are constructed FORWARD. */ Ilist from_pos = ilist_prepend(ilist_prepend(NULL,0),0); Ilist into_pos = ilist_prepend(ilist_prepend(NULL,0),0); Term into_atom = into_lit->atom; Term from_atom = from_lit->atom; int i; Topform from_clause = from_atom->container; Topform into_clause = into_atom->container; BOOL positive_equality = pos_eq(into_lit); from_pos->i = literal_number(from_clause->literals, from_lit); from_pos->next->i = from_side+1; /* arg of from_lit, counts from 1 */ into_pos->i = literal_number(into_clause->literals, into_lit); for (i = 0; i < ARITY(into_atom); i++) { BOOL skip_top = (check_top && positive_equality && (i == 0 || (i == 1 && para_from_right(into_lit->atom)))); into_pos->next->i += 1; /* increment arg number */ para_into(from_lit, from_side, cf, from_pos, into_clause, into_lit, ARG(into_atom,i), ci, into_pos, skip_top, proc_proc); } zap_ilist(from_pos); zap_ilist(into_pos); } } /* para_into_lit */ /************* * * para_from_into() * *************/ /* DOCUMENTATION Paramodulate from one clause into another (non-backtrack unification version).

For oriented equality atoms, we go from left sides only and into both sides. For nonoriented equality atoms, we go from and into both sides. */ /* PUBLIC */ void para_from_into(Topform from, Context cf, Topform into, Context ci, BOOL check_top, void (*proc_proc) (Topform)) { if (exists_selected_literal(from->literals)) return; /* cannot para from clause with selected literals */ else { Literals from_lit; for (from_lit = from->literals; from_lit; from_lit = from_lit->next) { if (from_parent_test(from_lit, FLAG_CHECK)) { Literals into_lit; for (into_lit = into->literals; into_lit; into_lit = into_lit->next) { if (into_parent_test(into_lit, FLAG_CHECK)) { para_into_lit(from_lit,0,cf,into_lit,ci,check_top,proc_proc); /* from L */ if (para_from_right(from_lit->atom)) para_into_lit(from_lit,1,cf,into_lit,ci,check_top,proc_proc); /* from R */ } } } } } } /* para_from_into */ /************* * * para_pos() * *************/ /* DOCUMENTATION Construct a paramodulant from the given data. A fatal error occurs if it does not exist. In building the justification, the position vectors are copied. */ /* PUBLIC */ Topform para_pos(Topform from_clause, Ilist from_pos, Topform into_clause, Ilist into_pos) { Context cf = get_context(); Context ci = get_context(); Trail tr = NULL; Topform paramodulant; BOOL ok; Literals from_lit = ith_literal(from_clause->literals, from_pos->i); Literals into_lit = ith_literal(into_clause->literals, into_pos->i); int from_side = (from_pos->next->i == 1 ? 0 : 1); Term alpha = ARG(from_lit->atom, from_side); Term into_term = term_at_pos(into_lit->atom, into_pos->next); if (into_term == NULL) fatal_error("paramod2_instances, term does not exist"); ok = unify(alpha, cf, into_term, ci, &tr); if (!ok) fatal_error("para_pos, terms do not unify"); paramodulant = paramodulate(from_lit, from_side, cf, into_clause, into_pos, ci); paramodulant->justification = para_just(PARA_JUST, from_clause, copy_ilist(from_pos), into_clause, copy_ilist(into_pos)); renumber_variables(paramodulant, MAX_VARS); undo_subst(tr); free_context(cf); free_context(ci); return paramodulant; } /* para_pos */ /************* * * para_pos2() * *************/ /* DOCUMENTATION Construct a paramodulant from the given data. A fatal error occurs if it does not exist. In building the justification, the position vectors are copied. This is similar to para_pos(), except that it allows the into_term to be a variable. */ /* PUBLIC */ Topform para_pos2(Topform from, Ilist from_pos, Topform into, Ilist into_pos) { Context from_subst = get_context(); Context into_subst = get_context(); Trail tr = NULL; BOOL ok; int from_side; Term alpha, into_term; Topform p; Term beta; Literals lit; Literals from_lit = ith_literal(from->literals, from_pos->i); Literals into_lit = ith_literal(into->literals, into_pos->i); from_side = (from_pos->next->i == 1 ? 0 : 1); alpha = ARG(from_lit->atom, from_side); into_term = term_at_pos(into_lit->atom, into_pos->next); if (into_term == NULL) fatal_error("paramod2_instances, term does not exist"); ok = unify(alpha, from_subst, into_term, into_subst, &tr); if (!ok) fatal_error("para_pos2, terms do not unify"); p = get_topform(); beta = ARG(from_lit->atom, from_side == 0 ? 1 : 0); for (lit = from->literals; lit; lit = lit->next) { if (lit != from_lit) p->literals = append_literal(p->literals, apply_lit_para(lit, from_subst)); } for (lit = into->literals; lit; lit = lit->next) { if (lit != into_lit) { p->literals = append_literal(p->literals, apply_lit_para(lit, into_subst)); } else { p->literals = append_literal(p->literals, new_literal(lit->sign, apply_substitute2(lit->atom, beta, from_subst, into_pos->next, into_subst))); } } inherit_attributes(from, from_subst, into, into_subst, p); upward_clause_links(p); p->justification = para_just(PARA_JUST, from, copy_ilist(from_pos), into, copy_ilist(into_pos)); renumber_variables(p, MAX_VARS); undo_subst(tr); free_context(from_subst); free_context(into_subst); return p; } /* para_pos2 */ LADR-2009-11A/ladr/parautil.h0000644000175000017500000000343511151265364014743 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_PARAUTIL_H #define TP_PARAUTIL_H #include "just.h" /* INTRODUCTION This package contains a few utilites for paramodulation and demodulation. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from parautil.c */ void init_paramod(void); void mark_renamable_flip(Term atom); BOOL renamable_flip_eq(Term atom); BOOL renamable_flip_eq_test(Term atom); void mark_oriented_eq(Term atom); BOOL oriented_eq(Term atom); BOOL same_term_structure(Term t1, Term t2); void flip_eq(Term atom, int n); void orient_equalities(Topform c, BOOL allow_flips); BOOL eq_tautology(Topform c); Term top_flip(Term a); void zap_top_flip(Term a); Literals literal_flip(Literals a); void zap_literal_flip(Literals a); Topform new_constant(Topform c, int new_sn); Topform fold_denial(Topform c, int alpha_max); BOOL equational_def_2(Term alpha, Term beta); int equational_def(Topform c); Ordertype unfold_order(Term alpha, Term beta); Topform build_reflex_eq(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/pindex.h0000644000175000017500000000461611151265364014413 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_PINDEX_H #define TP_PINDEX_H #include "clist.h" /* INTRODUCTION This package has code for indexing clauses that are to be retrieved in pairs. When a clause is inserted, its weight is given. Retrieval is by sum of the weights of the pair -- lowest first. Say we have clauses with weights 0--4. Then pairs will be returned in this order:

(0,0)
(0,1)
(1,1)  (0,2)
(1,2)  (0,3)
(2,2)  (1,3)  (0,4)
(2,3)  (1,4)
(3,3)  (2,4)
(3,4)
(4,4)
Clauses can be inserted or deleted after retrieval has begun; the smallest available pair will always be returned. When the index is initialized, the caller supplies a parameter N, and the actual weight range for indexing will be 0...N-1. If an inserted clause has weight outside of this range, the weight will be changed to 0 or N-1.

This is intended to be used for binary inference rules such as paramodulation and resolution. It is similar to the method in ``A Theorem-Proving Language for Experimentation'' by Henschen, Overbeek, Wos, CACM 17(6), 1974. */ /* Public definitions */ typedef struct pair_index * Pair_index; /* End of public definitions */ /* Public function prototypes from pindex.c */ void fprint_pindex_mem(FILE *fp, BOOL heading); void p_pindex_mem(); Pair_index init_pair_index(int n); void zap_pair_index(Pair_index p); int pairs_exhausted(Pair_index p); void insert_pair_index(Topform c, int wt, Pair_index p); void delete_pair_index(Topform c, int wt, Pair_index p); void retrieve_pair(Pair_index p, Topform *cp1, Topform *cp2); int pair_already_used(Topform c1, int weight1, Topform c2, int weight2, Pair_index p); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/parautil.c0000644000175000017500000003037310637466322014744 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "parautil.h" /* Private definitions and types */ int Oriented_flag = -1; /* termflag to mark oriented equality atoms */ int Renamable_flip_flag = -1; /* termflag to mark renamable-flip eq atoms */ /************* * * init_paramod() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_paramod(void) { if (Oriented_flag != -1 || Renamable_flip_flag != -1) fatal_error("init_paramod, called more than once"); Renamable_flip_flag = claim_term_flag(); Oriented_flag = claim_term_flag(); } /* init_paramod */ /************* * * mark_renamable_flip() * *************/ /* DOCUMENTATION This routine marks an atom as "renamable_flip". */ /* PUBLIC */ void mark_renamable_flip(Term atom) { if (Renamable_flip_flag == -1) fatal_error("mark_renamable_flip, init_paramod() was not called"); term_flag_set(atom, Renamable_flip_flag); } /* mark_renamable_flip */ /************* * * renamable_flip_eq() * *************/ /* DOCUMENTATION This function checks if an atom is a renamable_flip equality atom. (The terms are not actually compared. Only the mark is checked.) */ /* PUBLIC */ BOOL renamable_flip_eq(Term atom) { if (Renamable_flip_flag == -1) /* Nothing has ever been marked renamable_flip. */ return FALSE; else return term_flag(atom, Renamable_flip_flag); } /* renamable_flip_eq */ /************* * * renamable_flip_eq_test() * *************/ /* DOCUMENTATION Test if a term is a renamable-flip equality atom. This does not check the flag; it does the complete test. */ /* PUBLIC */ BOOL renamable_flip_eq_test(Term atom) { if (eq_term(atom)) return FALSE; else { BOOL result; Term a1 = copy_term(atom); Term a2 = copy_term(atom); Term tmp = ARG(a2,0); ARG(a2,0) = ARG(a2,1); ARG(a2,1) = tmp; term_renumber_variables(a1, MAX_VARS); term_renumber_variables(a2, MAX_VARS); result = term_ident(a1,a2); zap_term(a1); zap_term(a2); return result; } } /* renamable_flip_eq_test */ /************* * * mark_oriented_eq() * *************/ /* DOCUMENTATION This routine marks an atom as an oriented equality. */ /* PUBLIC */ void mark_oriented_eq(Term atom) { if (Oriented_flag == -1) fatal_error("mark_oriented_eq, init_paramod() was not called"); term_flag_set(atom, Oriented_flag); } /* mark_oriented_eq */ /************* * * oriented_eq() * *************/ /* DOCUMENTATION This function checks if an atom is an oriented equality atom. (The terms are not actually compared. Only the mark is checked.) */ /* PUBLIC */ BOOL oriented_eq(Term atom) { if (!eq_term(atom)) return FALSE; else if (Oriented_flag == -1) /* Nothing has ever been oriented. */ return FALSE; else return term_flag(atom, Oriented_flag); } /* oriented_eq */ /************* * * same_term_structure() * *************/ /* DOCUMENTATION Do terms t1 and t2 have the same structure? That is, if we rename all variables to x, are t1 and t2 identical? */ /* PUBLIC */ BOOL same_term_structure(Term t1, Term t2) { if (VARIABLE(t1) || VARIABLE(t2)) return VARIABLE(t1) && VARIABLE(t2); else if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; else { int i; for (i = 0; i < ARITY(t1); i++) if (!same_term_structure(ARG(t1,i), ARG(t2,i))) return FALSE; return TRUE; } } /* same_term_structure */ /************* * * flip_eq() * *************/ /* DOCUMENTATION Flip an equality and update the justification of the containing clause. */ /* PUBLIC */ void flip_eq(Term atom, int n) { Topform c = atom->container; Term t = ARG(atom,0); ARG(atom,0) = ARG(atom,1); ARG(atom,1) = t; c->justification = append_just(c->justification, flip_just(n)); } /* flip_eq */ /************* * * orient_equalities() * *************/ /* DOCUMENTATION For each equality literal (positive or negative) of Topform c, compare the arguments; if the left is greater, mark the atom as oriented, and if the the right is greater, flip the arguments (add an entry to the justification), and mark the atom as oriented. */ /* PUBLIC */ void orient_equalities(Topform c, BOOL allow_flips) { Literals lit; int i; for (lit = c->literals, i = 1; lit != NULL; lit = lit->next, i++) { Term atom = lit->atom; if (eq_term(atom)) { Term alpha = ARG(atom,0); Term beta = ARG(atom,1); if (!term_ident(alpha, beta)) { Ordertype ord = NOT_COMPARABLE; /* Check if it is a pos_eq_unit that should be unfolded. */ if (i == 1 && lit->next == NULL && lit->sign) ord = unfold_order(alpha, beta); /* If not oriented, check the primary ordering (LPO, RPO, KBO). */ if (ord == NOT_COMPARABLE) ord = term_order(alpha, beta); if (ord == GREATER_THAN) mark_oriented_eq(atom); else if (ord == LESS_THAN) { if (allow_flips) { flip_eq(atom, i); mark_oriented_eq(atom); } else { #if 0 /* disable, because this happens regularly during uncompression */ fprintf(stderr, "WARNING: orient_equalities, backward eq1:"); fwrite_term_nl(stderr, atom); #endif } } else { /* Not orientable by the primary ordering. */ /* We could call renamable_flip_eq_test, but we might need a1 and a2 for the secondary test. */ Term a1 = copy_term(atom); Term a2 = copy_term(atom); Term tmp = ARG(a2,0); ARG(a2,0) = ARG(a2,1); ARG(a2,1) = tmp; term_renumber_variables(a1, MAX_VARS); term_renumber_variables(a2, MAX_VARS); if (term_ident(a1,a2)) /* The renumbered flip is identical to the renumbered original. */ mark_renamable_flip(atom); /* We won't para from both sides. */ else { /* Flip if the right side is greater in the secondary ordering. */ ord = term_compare_vcp(a1, a2); if (ord == LESS_THAN) { if (allow_flips) flip_eq(atom, i); else { fprintf(stderr, "WARNING: orient_equalities, backward eq2:"); fwrite_term_nl(stderr, atom); } } } zap_term(a1); zap_term(a2); } } /* not identical */ } /* eq_atom */ } /* foreach literal */ } /* orient_equalities */ /************* * * eq_tautology() * *************/ /* DOCUMENTATION This routine returns TRUE if the clause has any literals of the form t=t. */ /* PUBLIC */ BOOL eq_tautology(Topform c) { Literals l1; for (l1 = c->literals; l1; l1 = l1->next) { Term a = l1->atom; if (l1->sign && eq_term(a) && term_ident(ARG(a,0), ARG(a,1))) return TRUE; } return FALSE; } /* eq_tautology */ /************* * * top_flip() * *************/ /* DOCUMENTATION Given a binary term (or atom), return the flip. The two arguments are not copied. When done with it, call zap_top_flip(t) instead of zap_term so that the arguments are not zapped. */ /* PUBLIC */ Term top_flip(Term a) { Term b; if (ARITY(a) != 2) fatal_error("top_flip, arity != 2"); b = get_rigid_term_like(a); ARG(b,0) = ARG(a,1); ARG(b,1) = ARG(a,0); b->private_flags = a->private_flags; return b; } /* top_flip */ /************* * * zap_top_flip() * *************/ /* DOCUMENTATION Free a term created by top_flip. */ /* PUBLIC */ void zap_top_flip(Term a) { free_term(a); } /* zap_top_flip */ /************* * * literal_flip() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals literal_flip(Literals a) { Literals b = get_literals(); b->sign = a->sign; b->atom = top_flip(a->atom); return b; } /* literal_flip */ /************* * * zap_literal_flip() * *************/ /* DOCUMENTATION Free a literal created by literal_flip. */ /* PUBLIC */ void zap_literal_flip(Literals a) { free_term(a->atom); free_literals(a); } /* zap_literal_flip */ /************* * * clause_with_new_constant() * *************/ static Topform clause_with_new_constant(Topform c, Term arg, int new_constant_sn) { Term atom = get_rigid_term(eq_sym(), 2); Literals lit = get_literals(); Topform new = get_topform(); lit->sign = TRUE; lit->atom = atom; ARG(atom,0) = copy_term(arg); ARG(atom,1) = get_rigid_term_dangerously(new_constant_sn, 0); new->literals = append_literal(new->literals, lit); upward_clause_links(new); new->justification = new_symbol_just(c); return new; } /* clause_with_new_constant */ /************* * * new_constant() * *************/ /* DOCUMENTATION If the Topform is a positive equality unit a(x) = b(y) with two variables in which one variable occurs in each side, infer a clause a(x) = c with a new constant c. We could also infer b(y)=c, but that will come by other inference mechanisms.

If new_sn == INT_MAX, a new symbol will be generated; otherwise, new_sn will be used as the symbol number of the new symbol. */ /* PUBLIC */ Topform new_constant(Topform c, int new_sn) { if (!pos_eq_unit(c->literals)) return NULL; else { Term a = ARG(c->literals->atom,0); Term b = ARG(c->literals->atom,1); Plist va = set_of_variables(a); Plist vb = set_of_variables(b); if (va && !va->next && vb && !vb->next && !term_ident(va->v, vb->v)) { if (new_sn == INT_MAX) { new_sn = fresh_symbol("c_", 0); new_constant_properties(new_sn); /* type, weights, prec */ } return clause_with_new_constant(c, a, new_sn); } else return NULL; } } /* new_constant */ /************* * * fold_denial() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform fold_denial(Topform c, int alpha_max) { static BOOL done = FALSE; if (done || !neg_eq_unit(c->literals) || !ground_clause(c->literals)) return NULL; else { /* assume it's already oriented */ Term alpha = ARG(c->literals->atom,0); Term beta = ARG(c->literals->atom,1); if (!CONSTANT(beta) && (alpha_max == -1 || symbol_count(alpha) <= alpha_max)) { int new_constant_sn = fresh_symbol("c_", 0); Topform ca = clause_with_new_constant(c, alpha, new_constant_sn); new_constant_properties(new_constant_sn); /* type, weights, prec */ done = TRUE; return ca; } else return NULL; } } /* fold_demial */ /************* * * equational_def_2() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL equational_def_2(Term alpha, Term beta) { return (!VARIABLE(alpha) && args_distinct_vars(alpha) && variables_subset(beta, alpha) && symbol_occurrences(beta, SYMNUM(alpha)) == 0); } /* equational_def_2 */ /************* * * equational_def() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int equational_def(Topform c) { if (!pos_eq_unit(c->literals)) return 0; else { Term left = ARG(c->literals->atom,0); Term right = ARG(c->literals->atom,1); if (equational_def_2(left, right)) return 1; else if (equational_def_2(right, left)) return 2; else return 0; } } /* equational_def */ /************* * * unfold_order() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype unfold_order(Term alpha, Term beta) { if (!VARIABLE(alpha) && is_unfold_symbol(SYMNUM(alpha)) && equational_def_2(alpha, beta)) return GREATER_THAN; else if (!VARIABLE(beta) && is_unfold_symbol(SYMNUM(beta)) && equational_def_2(beta, alpha)) return LESS_THAN; else return NOT_COMPARABLE; } /* unfold_order */ /************* * * build_reflex_eq() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform build_reflex_eq(void) { Term alpha = get_variable_term(0); Term beta = get_variable_term(0); Term atom = build_binary_term(str_to_sn(eq_sym(), 2), alpha, beta); Literals lit = get_literals(); Topform c = get_topform(); lit->sign = TRUE; lit->atom = atom; c->literals = append_literal(c->literals, lit); upward_clause_links(c); return c; } /* build_reflex_eq */ LADR-2009-11A/ladr/temp0000644000175000017500000000000011150564135013617 0ustar mccunemccuneLADR-2009-11A/ladr/features.c0000644000175000017500000001161210637466321014733 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "features.h" /* Private definitions and types */ static Ilist Feature_symbols; /* list of featured symbols (symnums)*/ /* The following are work arrays, indexed by symnum, used for calculating the features of a clause. They are allocated by init_features() and left in place throughout the process. */ static int Work_size; /* size of following arrays */ static int *Pos_occurrences; static int *Neg_occurrences; static int *Pos_maxdepth; static int *Neg_maxdepth; /************* * * init_features() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_features(Ilist fsyms, Ilist rsyms) { Work_size = greatest_symnum() + 1; /* printf("init_features: size=%d\n", Work_size); */ Feature_symbols = ilist_cat(ilist_copy(rsyms), ilist_copy(fsyms)); Pos_occurrences = calloc(Work_size, sizeof(int)); Neg_occurrences = calloc(Work_size, sizeof(int)); Pos_maxdepth = calloc(Work_size, sizeof(int)); Neg_maxdepth = calloc(Work_size, sizeof(int)); } /* init_features */ /************* * * fill_in_arrays() * *************/ static void fill_in_arrays(Term t, BOOL sign, int depth) { if (!VARIABLE(t)) { int sn = SYMNUM(t); int i; if (sn >= Work_size) { /* Assume it's a symbol that was added after the start of the search. If we ignore symbols in features, we may get less discrimination, but all answers should be returned. */ ; } else if (sign) { Pos_occurrences[sn]++; Pos_maxdepth[sn] = IMAX(depth, Pos_maxdepth[sn]); } else { Neg_occurrences[sn]++; Neg_maxdepth[sn] = IMAX(depth, Neg_maxdepth[sn]); } for (i = 0; i < ARITY(t); i++) fill_in_arrays(ARG(t,i), sign, depth+1); } } /* fill_in_arrays */ /************* * * features() * *************/ /* DOCUMENTATION Given a clause, build the feature vector. Features: positive literals negative literals foreach relation symbol positive occurrences negative occurrences foreach function symbol positive occurrences negative occurrences positive maxdepth negative maxdepth */ /* PUBLIC */ Ilist features(Literals lits) { Ilist f = NULL; Ilist p; Literals lit; /* Build it backwards, then reverse it. */ f = ilist_prepend(f, positive_literals(lits)); f = ilist_prepend(f, negative_literals(lits)); for (lit = lits; lit; lit = lit->next) { fill_in_arrays(lit->atom, lit->sign, 0); } for (p = Feature_symbols; p; p = p->next) { f = ilist_prepend(f, Pos_occurrences[p->i]); f = ilist_prepend(f, Neg_occurrences[p->i]); if (function_symbol(p->i)) { f = ilist_prepend(f, Pos_maxdepth[p->i]); f = ilist_prepend(f, Neg_maxdepth[p->i]); } Pos_occurrences[p->i] = 0; Neg_occurrences[p->i] = 0; Pos_maxdepth[p->i] = 0; Neg_maxdepth[p->i] = 0; } f = reverse_ilist(f); #if 0 printf("Features for clause "); f_clause(c); p_features(f); #endif return f; } /* features */ /************* * * feature_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int feature_length(void) { int n = 2; /* pos lits, neg lits */ Ilist p; for (p = Feature_symbols; p; p = p->next) { n += 2; if (function_symbol(p->i)) n += 2; } return n; } /* feature_length */ /************* * * features_less_or_equal() * *************/ /* DOCUMENTATION Return TRUE if Ilists c and d are thr same length and each member of c is <= the corresponding member of d. */ /* PUBLIC */ BOOL features_less_or_equal(Ilist c, Ilist d) { while (c && d && c->i <= d->i) { c = c->next; d = d->next; } return !c && !d; } /* features_less_or_equal */ /************* * * p_features() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_features(Ilist f) { Ilist p; printf(" pos_lits=%d, neg_lits=%d\n", f->i, f->next->i); f = f->next->next; for (p = Feature_symbols; p; p = p->next) { printf(" symbol %s: ", sn_to_str(p->i)); printf("pos_occ=%d, neg_occ=%d", f->i, f->next->i); f = f->next->next; if (function_symbol(p->i)) { printf(", pos_max=%d, neg_max=%d", f->i, f->next->i); f = f->next->next; } printf("\n"); } } /* p_features */ LADR-2009-11A/ladr/top_input.c0000644000175000017500000007313211150613612015127 0ustar mccunemccune /* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "top_input.h" #include "nonport.h" #include "clausify.h" #include "definitions.h" #include /* for toupper, tolower */ /* Private definitions and types */ typedef struct readlist * Readlist; struct readlist { char *name; /* name, as it appears in the input file */ int type; /* FORMULAS, TERMS */ BOOL auxiliary; Plist *p; /* *pointer* to the Plist */ Readlist next; }; static Readlist Input_lists = NULL; static Plist Lex_function_list = NULL; static Plist Lex_predicate_list = NULL; static Plist Skolem_list = NULL; /* temp store of user-declared skolems */ static char *Program_name = ""; /* * memory management */ #define PTRS_READLIST PTRS(sizeof(struct readlist)) static unsigned Readlist_gets, Readlist_frees; /************* * * Readlist get_readlist() * *************/ static Readlist get_readlist(void) { Readlist p = get_cmem(PTRS_READLIST); Readlist_gets++; return(p); } /* get_readlist */ /************* * * free_readlist() * *************/ #if 0 static void free_readlist(Readlist p) { free_mem(p, PTRS_READLIST); Readlist_frees++; } /* free_readlist */ #endif /************* * * fprint_top_input_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the top_input package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_top_input_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct readlist); fprintf(fp, "readlist (%4d) %11u%11u%11u%9.1f K\n", n, Readlist_gets, Readlist_frees, Readlist_gets - Readlist_frees, ((Readlist_gets - Readlist_frees) * n) / 1024.); } /* fprint_top_input_mem */ /************* * * p_top_input_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the top_input package. */ /* PUBLIC */ void p_top_input_mem() { fprint_top_input_mem(stdout, TRUE); } /* p_top_input_mem */ /* * end of memory management */ /************* * * init_standard_ladr() * *************/ /* DOCUMENTATION This routine initializes various LADR packaages. */ /* PUBLIC */ void init_standard_ladr(void) { init_wallclock(); init_paramod(); init_basic_paramod(); init_maximal(); declare_base_symbols(); declare_standard_parse_types(); translate_neg_equalities(TRUE); init_standard_options(); } /* init_standard_ladr */ /************* * * fatal_input_error() * *************/ static void fatal_input_error(FILE *fout, char *msg, Term t) { bell(stderr); if (t) { fprintf(fout, "\n%%%%ERROR: %s:\n\n", msg); fprintf(fout, "%%%%START ERROR%%%%\n"); fwrite_term_nl(fout, t); fprintf(fout, "%%%%END ERROR%%%%\n"); fwrite_term_nl(stderr, t); } else fprintf(fout, "%%%%ERROR: %s.\n\n", msg); fatal_error(msg); } /* fatal_input_error */ /************* * * set_program_name() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_program_name(char *name) { Program_name = name; } /* set_program_name */ /************* * * condition_is_true() * *************/ static BOOL condition_is_true(Term t) { return is_term(t, Program_name, 0); } /* condition_is_true */ /************* * * process_op2() * *************/ static void process_op2(FILE *fout, Term t, int prec, Term type_term, Term symb_term) { if (ARITY(symb_term) != 0) { fatal_input_error(fout, "Bad symbol in op command (quotes needed?)", t); } else { Parsetype pt = NOTHING_SPECIAL; if (is_constant(type_term, "infix")) pt = INFIX; else if (is_constant(type_term, "infix_left")) pt = INFIX_LEFT; else if (is_constant(type_term, "infix_right")) pt = INFIX_RIGHT; else if (is_constant(type_term, "prefix")) pt = PREFIX; else if (is_constant(type_term, "prefix_paren")) pt = PREFIX_PAREN; else if (is_constant(type_term, "postfix")) pt = POSTFIX; else if (is_constant(type_term, "postfix_paren")) pt = POSTFIX_PAREN; else if (is_constant(type_term, "ordinary")) pt = NOTHING_SPECIAL; else fatal_input_error(fout, "Bad parse-type in op command", t); declare_parse_type(sn_to_str(SYMNUM(symb_term)), prec, pt); } } /* process_op2 */ /************* * * process_op() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_op(Term t, BOOL echo, FILE *fout) { Term prec_term, type_term, symb_term; int prec; BOOL ok; if (ARITY(t) == 3) { prec_term = ARG(t,0); type_term = ARG(t,1); symb_term = ARG(t,2); ok = term_to_int(prec_term, &prec); } else { type_term = ARG(t,0); symb_term = ARG(t,1); if (!is_constant(type_term, "ordinary")) fatal_input_error(fout,"If no precedence, type must be \"ordinary\"",t); ok = TRUE; prec = MIN_PRECEDENCE; /* checked, but not used */ } if (echo) fwrite_term_nl(fout, t); if (!ok || prec < MIN_PRECEDENCE || prec > MAX_PRECEDENCE) { bell(stderr); fatal_input_error(fout, "Precedence in op command is out of range", t); } else if (proper_listterm(symb_term)) { while (cons_term(symb_term)) { process_op2(fout, t, prec, type_term, ARG(symb_term, 0)); symb_term = ARG(symb_term, 1); } } else process_op2(fout, t, prec, type_term, symb_term); } /* process_op */ /************* * * process_redeclare() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_redeclare(Term t, BOOL echo, FILE *fout) { if (ARITY(t) != 2) { fatal_input_error(fout, "The redeclare command takes 2 arguments " "(symbol, operation)", t); } else { Term operation = ARG(t, 0); Term symbol = ARG(t, 1); if (ARITY(symbol) != 0 || ARITY(operation) != 0) { fatal_input_error(fout, "The redeclare command takes 2 arguments " "(symbol, operation)", t); } else { BOOL ok; if (echo) fwrite_term_nl(fout, t); ok = redeclare_symbol_and_copy_parsetype(sn_to_str(SYMNUM(operation)), sn_to_str(SYMNUM(symbol)), echo, fout); if (!ok) { fatal_input_error(fout, "The new symbol for the redeclared operation" " is already in use", t); } } } } /* process_redeclare */ /************* * * execute_unknown_action() * *************/ static void execute_unknown_action(FILE *fout, int unknown_action, Term t, char *message) { if (unknown_action == KILL_UNKNOWN) { fatal_input_error(fout, message, t); } else if (unknown_action == WARN_UNKNOWN) { bell(stderr); fprintf(fout, "WARNING, %s: ", message); fwrite_term_nl(fout, t); fprintf(stderr, "WARNING, %s: ", message); fwrite_term_nl(stderr, t); } else if (unknown_action == NOTE_UNKNOWN) { fprintf(fout, "NOTE, %s: ", message); fwrite_term_nl(fout, t); } } /* execute_unknown_action */ /************* * * flag_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void flag_handler(FILE *fout, Term t, BOOL echo, int unknown_action) { int flag = str_to_flag_id(sn_to_str(SYMNUM(ARG(t,0)))); if (flag == -1) execute_unknown_action(fout, unknown_action, t, "Flag not recognized"); else { update_flag(fout, flag, is_term(t, "set", 1), echo); if (is_term(ARG(t,0), "arithmetic", 0)) { if (is_term(t,"set",1)) { printf("\n %% Declaring Mace4 arithmetic parse types.\n"); declare_parse_type("+", 490, INFIX_RIGHT); declare_parse_type("*", 470, INFIX_RIGHT); declare_parse_type("/", 460, INFIX); declare_parse_type("mod", 460, INFIX); } } } } /* flag_handler */ /************* * * parm_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void parm_handler(FILE *fout, Term t, BOOL echo, int unknown_action) { char *name = sn_to_str(SYMNUM(ARG(t,0))); Term tval = ARG(t,1); int id = str_to_parm_id(name); if (id != -1) { int val; if (term_to_int(tval, &val)) assign_parm(id, val, echo); else { execute_unknown_action(fout, unknown_action, t, "Parm needs integer value"); } } else { id = str_to_floatparm_id(name); if (id != -1) { double val; if (term_to_number(tval, &val)) assign_floatparm(id, val, echo); else execute_unknown_action(fout, unknown_action, t, "Floatparm needs integer or double value"); } else { id = str_to_stringparm_id(name); if (id != -1) { if (CONSTANT(tval)) { char *s = sn_to_str(SYMNUM(tval)); assign_stringparm(id, s, echo); } else execute_unknown_action(fout, unknown_action, t, "Stringparm needs constant value"); } else execute_unknown_action(fout, unknown_action, t, "Parameter not recognized"); } } } /* parm_handler */ /************* * * process_symbol_list() * *************/ static void process_symbol_list(Term t, char *command, Plist terms) { Plist strings = NULL; Plist p; for (p = terms ; p; p = p->next) { Term c = p->v; if (!CONSTANT(c)) fatal_input_error(stdout, "Symbols in this command must not have " "arguments (arity is deduced from the clauses)", t); strings = plist_append(strings, sn_to_str(SYMNUM(c))); } if (str_ident(command, "lex") || str_ident(command, "function_order")) Lex_function_list = plist_cat(Lex_function_list, strings); else if (str_ident(command, "predicate_order")) Lex_predicate_list = plist_cat(Lex_predicate_list, strings); else if (str_ident(command, "skolem")) Skolem_list = plist_cat(Skolem_list, strings); else fatal_input_error(stdout, "Unknown command", t); } /* process_symbol_list */ /************* * * readlist_member() * *************/ static Readlist readlist_member(Readlist p, char *name, int type) { if (p == NULL) return NULL; else if (p->type == type && str_ident(p->name, name)) return p; else return readlist_member(p->next, name, type); } /* readlist_member */ /************* * * readlist_member_wild() * *************/ static Readlist readlist_member_wild(Readlist p, int type) { if (p == NULL) return NULL; else if (p->type == type && str_ident(p->name, "")) return p; else return readlist_member_wild(p->next, type); } /* readlist_member */ /************* * * accept_list() * *************/ /* DOCUMENTATION name: name of list type: type of list (FORMULAS, TERMS) aux: Is it an auxiliary list? FALSE: the formulas are part of the logical theory. TRUE: the formulas are not part of the logical theory, e.g., hints. When Skolem symbols are generated, it's ok if the symbols already exist in aux lists. l: pointer to (pointer to) list where objects should be placed (later, when they are actually read). */ /* PUBLIC */ void accept_list(char *name, int type, BOOL aux, Plist *l) { Readlist p = readlist_member(Input_lists, name, type); if (p) fatal_error("accept_list, duplicate name/type"); else { p = get_readlist(); p->name = name; p->type = type; p->auxiliary = aux; *l = NULL; p->p = l; p->next = Input_lists; Input_lists = p; } } /* accept_list */ /************* * * input_symbols() * *************/ static void input_symbols(int type, BOOL aux, Ilist *fsyms, Ilist *rsyms) { I2list fsyms_multiset = NULL; I2list rsyms_multiset = NULL; Readlist p; for (p = Input_lists; p; p = p->next) { if (p->type == type && p->auxiliary == aux) { gather_symbols_in_formulas(*(p->p), &rsyms_multiset, &fsyms_multiset); } } *rsyms = multiset_to_set(rsyms_multiset); *fsyms = multiset_to_set(fsyms_multiset); *fsyms = remove_variable_symbols(*fsyms); zap_i2list(fsyms_multiset); zap_i2list(rsyms_multiset); if (FALSE) { Ilist p; printf("RSYMS: "); for (p = *rsyms; p; p = p->next) printf(" %s", sn_to_str(p->i)); printf("\n"); printf("FSYMS: "); for (p = *fsyms; p; p = p->next) printf(" %s", sn_to_str(p->i)); printf("\n"); } } /* input_symbols */ /************* * * symbol_check_and_declare() * * Make sure that symbols are being used in reasonable ways. * * Look at the clauses and formulas in the Input_lists. * Make sure that (1) no symbol is used as both a relation * and a function symbol, and (2) that no symbol has multiple * arities. Also tell the symbol package which symbols are * relations and which are functions. * *************/ static void symbol_check_and_declare(void) { Ilist fsyms_theory, fsyms_aux, fsyms_all, fsyms_aux_only; Ilist rsyms_theory, rsyms_aux, rsyms_all; Ilist bad; input_symbols(FORMULAS, FALSE, &fsyms_theory, &rsyms_theory); input_symbols(FORMULAS, TRUE, &fsyms_aux, &rsyms_aux); fsyms_all = ilist_union(fsyms_theory, fsyms_aux); rsyms_all = ilist_union(rsyms_theory, rsyms_aux); fsyms_aux_only = ilist_subtract(fsyms_aux, fsyms_theory); declare_aux_symbols(fsyms_aux_only); /* Check for variables in rsyms. */ bad = variable_symbols(rsyms_all); if (bad) { Ilist g; String_buf sb = init_string_buf("The following symbols cannot be used as" " atomic formulas, because they are" " variables: "); for (g = bad; g; g = g->next) { sb_append(sb, sn_to_str(g->i)); if (g->next) sb_append(sb, ", "); } fatal_input_error(stdout, sb_to_malloc_string(sb), NULL); } /* Check if any symbol is used as both a relation and function symbol. */ bad = ilist_intersect(fsyms_all, rsyms_all); if (bad) { Ilist g; String_buf sb = init_string_buf("The following symbols/arities are used as" " both relation and function symbols: "); for (g = bad; g; g = g->next) { sb_append(sb, sn_to_str(g->i)); sb_append_char(sb, '/'); sb_append_int(sb, sn_to_arity(g->i)); if (g->next) sb_append(sb, ", "); } fatal_input_error(stdout, sb_to_malloc_string(sb), NULL); } /* Check if any symbol is used with multiple arities. */ bad = arity_check(fsyms_all, rsyms_all); if (bad) { Ilist g; String_buf sb = init_string_buf("The following symbols are used with" " multiple arities: "); for (g = bad; g; g = g->next) { sb_append(sb, sn_to_str(g->i)); sb_append_char(sb, '/'); sb_append_int(sb, sn_to_arity(g->i)); if (g->next) sb_append(sb, ", "); } fatal_input_error(stdout, sb_to_malloc_string(sb), NULL); } /* Tell the symbol package the functions and relations. (needed for ordering the symbols) */ declare_functions_and_relations(fsyms_all, rsyms_all); process_skolem_list(Skolem_list, fsyms_theory); zap_plist(Skolem_list); Skolem_list = NULL; process_lex_list(Lex_function_list, fsyms_all, FUNCTION_SYMBOL); process_lex_list(Lex_predicate_list, rsyms_all, PREDICATE_SYMBOL); zap_plist(Lex_function_list); zap_plist(Lex_predicate_list); Lex_function_list = NULL; Lex_predicate_list = NULL; /* p_syms(); printf("fsyms_theory: "); p_ilist(fsyms_theory); printf("fsyms_aux: "); p_ilist(fsyms_aux); printf("fsyms_all: "); p_ilist(fsyms_all); printf("fsyms_aux_only: "); p_ilist(fsyms_aux_only); printf("rsyms_theory: "); p_ilist(rsyms_theory); printf("rsyms_aux: "); p_ilist(rsyms_aux); printf("rsyms_all: "); p_ilist(rsyms_all); */ zap_ilist(fsyms_theory); zap_ilist(fsyms_aux); zap_ilist(fsyms_all); zap_ilist(fsyms_aux_only); zap_ilist(rsyms_theory); zap_ilist(rsyms_aux); zap_ilist(rsyms_all); } /* symbol_check_and_declare */ /************* * * read_from_file() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void read_from_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action) { int if_depth = 0; /* for conditional inclusion */ Term t = read_term(fin, fout); while (t != NULL) { if (is_term(t, "set", 1) || is_term(t, "clear", 1)) { /********************************************************** set, clear */ if (echo) fwrite_term_nl(fout, t); flag_handler(fout, t, echo, unknown_action); } else if (is_term(t, "assign", 2)) { /************************************************************** assign */ if (echo) fwrite_term_nl(fout, t); parm_handler(fout, t, echo, unknown_action); } else if (is_term(t, "assoc_comm", 1) || is_term(t, "commutative", 1)) { /************************************************************ AC, etc. */ Term f = ARG(t,0); if (!CONSTANT(f)) { fatal_input_error(fout, "Argument must be symbol only", t); } else { if (echo) fwrite_term_nl(fout, t); if (is_term(t, "assoc_comm", 1)) set_assoc_comm(sn_to_str(SYMNUM(f)), TRUE); else set_commutative(sn_to_str(SYMNUM(f)), TRUE); } } else if (is_term(t, "op", 3) || is_term(t, "op", 2)) { /****************************************************************** op */ /* e.g., op(300, infix, +). op(ordinary, *) */ process_op(t, echo, fout); } else if (is_term(t, "redeclare", 2)) { /*********************************************************** redeclare */ /* e.g., redeclare(~, negation). */ process_redeclare(t, echo, fout); } else if (is_term(t, "lex", 1) || is_term(t, "predicate_order", 1) || is_term(t, "function_order", 1) || is_term(t, "skolem", 1)) { /********************************************************* lex, skolem */ char *command = sn_to_str(SYMNUM(t)); Plist p = listterm_to_tlist(ARG(t,0)); if (p == NULL) { fatal_input_error(fout, "Function_order/predicate_order/skolem command" "must contain a list, e.g., [a,b,c]", t); } else { if (echo) fwrite_term_nl(fout, t); process_symbol_list(t, command, p); zap_plist(p); } } else if (is_term(t, "formulas", 1) || is_term(t, "clauses", 1) || is_term(t, "terms", 1) || is_term(t, "list", 1)) { /***************************************************** list of objects */ int type = (is_term(t, "formulas", 1) || is_term(t, "clauses", 1) ? FORMULAS : TERMS); char *name = term_symbol(ARG(t,0)); Plist objects = NULL; int echo_id = str_to_flag_id("echo_input"); BOOL echo_objects = (echo_id == -1 ? TRUE : flag(echo_id)); if (is_term(t, "clauses", 1)) { bell(stderr); fprintf(stderr, "\nWARNING: \"clauses(...)\" should be replaced with \"formulas(...)\".\n" "Please update your input files. Future versions will not accept \"clauses(...)\".\n\n"); } else if (is_term(t, "terms", 1)) { bell(stderr); fprintf(stderr, "\nWARNING: \"terms(...)\" should be replaced with \"list(...)\".\n" "Please update your input files. Future versions will not accept \"terms(...)\".\n\n"); } objects = read_term_list(fin, fout); if (type == FORMULAS) { Plist p; for (p = objects; p; p = p->next) { Term t = p->v; p->v = term_to_formula(t); zap_term(t); } } if (echo) { if (echo_objects) { if (type == FORMULAS) fwrite_formula_list(fout, objects, name); else fwrite_term_list(fout, objects, name); } else { fprintf(fout, "\n%% "); fwrite_term(fout, t); fprintf(fout, ". %% not echoed (%d %s)\n", plist_count(objects), type == FORMULAS ? "formulas" : "terms"); } } /* Find the correct list, and append the objects to it. */ { Readlist r = readlist_member(Input_lists, name, type); if (r == NULL) r = readlist_member_wild(Input_lists, type); if (r == NULL) { fatal_input_error(fout, "List name/type not recognized", t); } else { *(r->p) = plist_cat(*(r->p), objects); } } } /* list of formulas or terms */ else if (is_term(t, "if", 1)) { /***************************************************** if() ... end_if */ Term condition = ARG(t,0); if (echo) fwrite_term_nl(fout, t); if (condition_is_true(condition)) { if (echo) fprintf(fout, "%% Conditional input included.\n"); if_depth++; } else { /* skip to matching end_if */ int depth = 1; /* if-depth */ Term t2; do { t2 = read_term(fin, fout); if (!t2) fatal_input_error(fout, "Missing end_if (condition is false)", t); else if (is_term(t2, "if", 1)) depth++; else if (is_term(t2, "end_if", 0)) depth--; zap_term(t2); } while (depth > 0); if (echo) fprintf(fout, "%% Conditional input omitted.\nend_if.\n"); } } /* if() ... end_if. */ else if (is_term(t, "end_if", 0)) { /***************************************************** end_if (true case) */ if_depth--; if (echo) fwrite_term_nl(fout, t); if (if_depth < 0) fatal_input_error(fout, "Extra end_if", t); } else fatal_input_error(fout, "Unrecognized command or list", t); zap_term(t); t = read_term(fin, fout); } if (if_depth != 0) { fatal_input_error(fout, "Missing end_if (condition is true)", t); } } /* read_from_file */ /************* * * read_all_input() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void read_all_input(int argc, char **argv, FILE *fout, BOOL echo, int unknown_action) { int n = which_string_member("-f", argv, argc); if (n == -1) { read_from_file(stdin, fout, echo, unknown_action); } else { int i; for (i = n+1; i < argc; i++) { FILE *fin = fopen(argv[i], "r"); if (fin == NULL) { char s[100]; sprintf(s, "read_all_input, file %s not found", argv[i]); fatal_error(s); } if (echo) printf("\n%% Reading from file %s\n\n", argv[i]); read_from_file(fin, fout, echo, unknown_action); fclose(fin); } } process_standard_options(); symbol_check_and_declare(); } /* read_all_input */ /************* * * check_formula_attributes() * *************/ static void check_formula_attributes(Formula f) { if (subformula_contains_attributes(f)) { Term t = formula_to_term(f); fatal_input_error(stdout, "Subformulas cannot contain attributes", t); } else if (!clausal_formula(f) && attributes_contain_variables(f->attributes)) { Term t = formula_to_term(f); fatal_input_error(stdout, "Answer attributes on non-clausal formulas" " cannot contain variables", t); } } /* check_formula_attributes */ /************* * * process_input_formulas() * *************/ /* DOCUMENTATION Input is Plist of Topforms containing formulas. Result is a Plist of Topforms containing clauses. */ /* PUBLIC */ Plist process_input_formulas(Plist formulas, BOOL echo) { Plist new = NULL; /* collect Topforms (clauses) to be returned */ Plist p; for (p = formulas; p; p = p->next) { Topform tf = p->v; if (clausal_formula(tf->formula)) { /* just make it into a clause data structure and use the same Topform */ tf->literals = formula_to_literals(tf->formula); upward_clause_links(tf); zap_formula(tf->formula); tf->formula = NULL; tf->is_formula = FALSE; clause_set_variables(tf, MAX_VARS); new = plist_prepend(new, tf); } else { /* Clausify, collecting new Topforms to be returned. */ Formula f2; Plist clauses, p; assign_clause_id(tf); f2 = universal_closure(formula_copy(tf->formula)); clauses = clausify_formula(f2); for (p = clauses; p; p = p->next) { Topform c = p->v; c->attributes = copy_attributes(tf->attributes); c->justification = clausify_just(tf); new = plist_prepend(new, c); } append_label_attribute(tf, "non_clause"); if (echo) fwrite_clause(stdout, tf, CL_FORM_STD); /* After this point, tf will be accessible only from the ID table. */ } } zap_plist(formulas); /* shallow */ new = reverse_plist(new); return new; } /* process_input_formulas */ /************* * * process_demod_formulas() * *************/ /* DOCUMENTATION Input is Plist of Topforms containing formulas. Result is a Plist of Topforms containing clauses. */ /* PUBLIC */ Plist process_demod_formulas(Plist formulas, BOOL echo) { Plist new = NULL; /* collect Topforms (clauses) to be returned */ Plist p; for (p = formulas; p; p = p->next) { Topform tf = p->v; if (clausal_formula(tf->formula)) { /* just make it into a clause data structure and use the same Topform */ tf->literals = formula_to_literals(tf->formula); upward_clause_links(tf); zap_formula(tf->formula); tf->formula = NULL; tf->is_formula = FALSE; clause_set_variables(tf, MAX_VARS); new = plist_prepend(new, tf); } else if (tf->formula->type == IMP_FORM || tf->formula->type == IMPBY_FORM || tf->formula->type == IFF_FORM) { new = plist_prepend(new, tf); } else fatal_error("process_demod_formulas: bad demodulator"); } zap_plist(formulas); /* shallow */ new = reverse_plist(new); return new; } /* process_demod_formulas */ /************* * * process_goal_formulas() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist process_goal_formulas(Plist formulas, BOOL echo) { BOOL must_be_positive = (plist_count(formulas) > 1); Plist new = NULL; Plist p; for (p = formulas; p; p = p->next) { Topform tf = p->v; Formula f2; Plist clauses, q; f2 = universal_closure(formula_copy(tf->formula)); if (must_be_positive && !positive_formula(f2)) { Term t = formula_to_term(tf->formula); fatal_input_error(stdout, "If there are multiple goals, all must be " "positive", t); } f2 = negate(f2); clauses = clausify_formula(f2); assign_clause_id(tf); for (q = clauses; q; q = q->next) { Topform c = q->v; c->attributes = copy_attributes(tf->attributes); c->justification = deny_just(tf); new = plist_prepend(new, c); } append_label_attribute(tf, "non_clause"); append_label_attribute(tf, "goal"); if (echo) fwrite_clause(stdout, tf, CL_FORM_STD); /* After this point, tf will be accessible only from the ID table. */ } zap_plist(formulas); /* shallow */ new = reverse_plist(new); return new; } /* process_goal_formulas */ /************* * * read_commands() * *************/ /* DOCUMENTATION This is a legacy routine. */ /* PUBLIC */ Term read_commands(FILE *fin, FILE *fout, BOOL echo, int unknown_action) { Term t = read_term(fin, fout); BOOL go = (t != NULL); while (go) { BOOL already_echoed = FALSE; /************************************************************ set, clear */ if (is_term(t, "set", 1) || is_term(t, "clear", 1)) { if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } flag_handler(fout, t, echo, unknown_action); /* SPECIAL CASES: these need action right now! */ if (is_term(ARG(t,0), "prolog_style_variables", 0)) { if (is_term(t,"set",1)) set_variable_style(PROLOG_STYLE); else set_variable_style(STANDARD_STYLE); } } else if (is_term(t, "assign", 2)) { /************************************************************** assign */ if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } parm_handler(fout, t, echo, unknown_action); } else if (is_term(t, "assoc_comm", 1) || is_term(t, "commutative", 1)) { /************************************************************ AC, etc. */ Term f = ARG(t,0); if (!CONSTANT(f)) { fatal_input_error(fout, "Argument must be symbol only", t); } else { if (is_term(t, "assoc_comm", 1)) set_assoc_comm(sn_to_str(SYMNUM(f)), TRUE); else set_commutative(sn_to_str(SYMNUM(f)), TRUE); } } else if (is_term(t, "op", 3)) { /****************************************************************** op */ /* e.g., op(300, infix, +); */ process_op(t, echo, fout); } else if (is_term(t, "lex", 1)) { /***************************************************************** lex */ Plist p = listterm_to_tlist(ARG(t,0)); if (p == NULL) { fatal_input_error(fout, "Lex command must contain a proper list, " "e.g., [a,b,c]", t); } else { process_symbol_list(t, "lex", p); zap_plist(p); } } else { /******************************************************** unrecognized */ /* return this unknown term */ go = FALSE; } if (go) { if (echo && !already_echoed) fwrite_term_nl(fout, t); zap_term(t); t = read_term(fin, fout); go = (t != NULL); } } return t; } /* read_commands */ /************* * * embed_formulas_in_topforms() * *************/ /* DOCUMENTATION The formulas are not copied. Any attributes on the top of the formula are moved to the Topform. An ID is not assigned. Topforms get the justifiction "input". */ /* PUBLIC */ Plist embed_formulas_in_topforms(Plist formulas, BOOL assumption) { Plist p; for (p = formulas; p; p = p->next) { Formula f = p->v; Topform tf = get_topform(); tf->is_formula = TRUE; tf->formula = f; check_formula_attributes(f); tf->justification = (assumption ? input_just() : goal_just()); tf->attributes = f->attributes; f->attributes = NULL; p->v = tf; } return formulas; } /* embed_formulas_in_topforms */ LADR-2009-11A/ladr/temp250000644000175000017500000000240711024245316014000 0ustar mccunemccuneMIN = 2 def kolmogorov(string): # print "string=%s" % string total = 0 length = len(string) - 2 index = MIN # print "Will check from index %d to %d." % (index,length) # print "Length of string is %d." % length while index <= length: # index of where the search begins maxlook = (length - index) + 2 # don't check for occurences longer than head of string if maxlook > index: maxlook = index # print "Checking at index: %d." % index # print "Will check strings of length %d through %d." % (MIN,maxlook) flen = 0 # length of found redundancy # index of length of lookahead to check for window in range(MIN, maxlook+1): # note: range(2,5) is [2,3,4] tocheck = string[ index : index+window ] # note: "abcde"[1:3] is "bc" # print "Want to know if %s occurs in pos 0 until %d." % (tocheck,index) ind = string.find(tocheck) if ind < index: flen = window if flen == 0: index += 1 else: index += flen total += flen # print "total=%d, index=%d, length=%d, MIN=%d" % (total,index,length,MIN) # print "DONE."; # print "TOTAL REDUNDANCY: %d" % total return float(total) / (length-1) LADR-2009-11A/ladr/fpa.h0000644000175000017500000000524311151265364013667 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FPA_H #define TP_FPA_H #include "unify.h" #include "index.h" #include "fpalist.h" /* INTRODUCTION This package implements FPA/Path indexing for first-order terms. It is used to retrieive terms that are likely to unify (in various ways) with a query term. The answers are not guaranteed to unify, and the caller must call some kind of unification routine to check and to construct a substitution.

The unification types are FPA_UNIFY, FPA_INSTANCE, FPA_GENERALIZATION, FPA_VARIANT, and FPA_IDENTICAL. Performance is very good for FPA_INSTANCE, FPA_VARIANT, and FPA_IDENTICAL, fair for FPA_UNIFY, and poor for FPA_GENERALIZATION. (Use Discrimination indexing for FPA_GENERALIZATION, e.g., forward demodulation and forward subsumption.)

Associative-commutative (AC) function symbols are handled by simply ignoring all subterms of AC symbols (which can give bad performance). Commutative/symmetric (C) operations are handled. */ /* Public definitions */ /* #define FPA_DEBUG */ typedef struct fpa_index * Fpa_index; typedef struct fpa_state * Fpa_state; /* End of public definitions */ /* Public function prototypes from fpa.c */ void fprint_fpa_mem(FILE *fp, BOOL heading); void p_fpa_mem(); void fprint_path(FILE *fp, Ilist p); void p_path(Ilist p); void fprint_fpa_index(FILE *fp, Fpa_index idx); void p_fpa_index(Fpa_index idx); Fpa_index fpa_init_index(int depth); void fpa_update(Term t, Fpa_index idx, Indexop op); void fprint_fpa_state(FILE *fp, Fpa_state q, int depth); void p_fpa_state(Fpa_state q); void p_fpa_query(Term t, Querytype query_type, Fpa_index idx); Term fpa_next_answer(Fpa_state q); Term fpa_first_answer(Term t, Context c, Querytype query_type, Fpa_index idx, Fpa_state *ppos); void fpa_cancel(Fpa_state q); void zap_fpa_index(Fpa_index idx); BOOL fpa_empty(Fpa_index idx); void p_fpa_density(Fpa_index idx); unsigned mega_next_calls(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/strbuf.c0000644000175000017500000002335711074677505014437 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "strbuf.h" /* * private definitions and types */ struct string_buf { struct chunk *first; int size; }; #define CHUNK_SIZE 100 struct chunk { char s[CHUNK_SIZE]; struct chunk *next; }; typedef struct chunk *Chunk; /* * memory management */ #define PTRS_CHUNK PTRS(sizeof(struct chunk)) static unsigned Chunk_gets, Chunk_frees; #define PTRS_STRING_BUF PTRS(sizeof(struct string_buf)) static unsigned String_buf_gets, String_buf_frees; /************* * * Chunk get_chunk() * *************/ static Chunk get_chunk(void) { Chunk p = get_cmem(PTRS_CHUNK); Chunk_gets++; return(p); } /* get_chunk */ /************* * * free_chunk() * *************/ static void free_chunk(Chunk p) { free_mem(p, PTRS_CHUNK); Chunk_frees++; } /* free_chunk */ /************* * * String_buf get_string_buf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ String_buf get_string_buf(void) { String_buf p = get_cmem(PTRS_STRING_BUF); String_buf_gets++; return(p); } /* get_string_buf */ /************* * * free_string_buf() * *************/ static void free_string_buf(String_buf p) { free_mem(p, PTRS_STRING_BUF); String_buf_frees++; } /* free_string_buf */ /************* * * fprint_strbuf_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the strbuf package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_strbuf_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct chunk); fprintf(fp, "chunk (%4d) %11u%11u%11u%9.1f K\n", n, Chunk_gets, Chunk_frees, Chunk_gets - Chunk_frees, ((Chunk_gets - Chunk_frees) * n) / 1024.); n = sizeof(struct string_buf); fprintf(fp, "string_buf (%4d) %11u%11u%11u%9.1f K\n", n, String_buf_gets, String_buf_frees, String_buf_gets - String_buf_frees, ((String_buf_gets - String_buf_frees) * n) / 1024.); } /* fprint_strbuf_mem */ /************* * * p_strbuf_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the strbuf package. */ /* PUBLIC */ void p_strbuf_mem() { fprint_strbuf_mem(stdout, 1); } /* p_strbuf_mem */ /* * end of memory management */ /************* * * String_buf init_string_buf() * *************/ /* DOCUMENTATION This routine allocates and returns a String_buf, initialized to string s. Don't forget to call zap_string_buf(sb) when finished with it. Also see get_string_buf(). */ /* PUBLIC */ String_buf init_string_buf(char *s) { String_buf p = get_string_buf(); sb_append(p, s); return(p); } /* init_string_buf */ /************* * * fprint_sb() * *************/ /* DOCUMENTATION This routine prints String_buf sb to FILE *fp. */ /* PUBLIC */ void fprint_sb(FILE *fp, String_buf sb) { Chunk h = sb->first; int i = 0; while (i < sb->size) { char c = h->s[i % CHUNK_SIZE]; if (c != '\0') putc(c, fp); i++; if (i % CHUNK_SIZE == 0) h = h->next; } } /* fprint_sb */ /************* * * p_sb() * *************/ /* DOCUMENTATION This routine prints String_buf sb, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_sb() instead. */ /* PUBLIC */ void p_sb(String_buf sb) { fprint_sb(stdout, sb); printf("\n"); fflush(stdout); } /* p_sb */ /************* * * sb_append() * *************/ /* DOCUMENTATION This routine appends string s to String_buf sb. The NULL character that marks the end of s does not go into the String_buf. */ /* PUBLIC */ void sb_append(String_buf sb, char *s) { int i; int n = sb->size; Chunk last = sb->first; while (last != NULL && last->next != NULL) last = last->next; for (i = 0; s[i] != '\0'; i++) { if (n % CHUNK_SIZE == 0) { Chunk new = get_chunk(); if (last != NULL) last->next = new; else sb->first = new; last = new; } last->s[n % CHUNK_SIZE] = s[i]; n++; } sb->size = n; } /* sb_append */ /************* * * sb_append_char() * *************/ /* DOCUMENTATION This routine appends character c to String_buf sb. */ /* PUBLIC */ void sb_append_char(String_buf sb, char c) { /* In the first version of this routine, we simply built a string "c", and then called sb_append. This causes a problem, however, if we use this package for sequences of small integers. In particular, if we want to append the char 0, that won't work. */ int n = sb->size; Chunk last = sb->first; while (last != NULL && last->next != NULL) last = last->next; if (n % CHUNK_SIZE == 0) { Chunk new = get_chunk(); if (last != NULL) last->next = new; else sb->first = new; last = new; } last->s[n % CHUNK_SIZE] = c; n++; sb->size = n; } /* sb_append_char */ /************* * * sb_replace_char() * *************/ /* DOCUMENTATION This routine replaces a character in a String_buf. If the index i is out of range, nothing happens. */ /* PUBLIC */ void sb_replace_char(String_buf sb, int i, char c) { if (i < 0 || i >= sb->size) return; else { Chunk h = sb->first; int j; for (j = 0; j < i / CHUNK_SIZE; j++) h = h->next; h->s[i % CHUNK_SIZE] = c; } } /* sb_replace_char */ /************* * * sb_char() * *************/ /* DOCUMENTATION This routine returns the n-th character (counting from 0) of String_buf sb. If index n is out of range, the NULL character '\0' is returned. */ /* PUBLIC */ char sb_char(String_buf sb, int n) { if (n < 0 || n >= sb->size) return '\0'; else { Chunk h = sb->first; int i; for (i = 0; i < n / CHUNK_SIZE; i++) h = h->next; return h->s[n % CHUNK_SIZE]; } } /* sb_char */ /************* * * sb_cat_copy() * *************/ /* DOCUMENTATION This routine appends a copy of sb2 to sb1. String_buf sb2 is not changed. You can use sb_cat() instead if you won't be needing sb2. */ /* PUBLIC */ void sb_cat_copy(String_buf sb1, String_buf sb2) { /* Note that this is inefficient if there are many chunks in either sb. */ int i; char c; for (i = 0; (c = sb_char(sb2, i)); i++) sb_append_char(sb1, c); } /* sb_cat_copy */ /************* * * sb_cat() * *************/ /* DOCUMENTATION This routine appends a copy of sb2 to sb1, then deallocates sb2. Do not refer to sb2 after calling this rouine because it won't exist. You can use sb_cat_copy() instead if you need to save sb2. */ /* PUBLIC */ void sb_cat(String_buf sb1, String_buf sb2) { sb_cat_copy(sb1, sb2); zap_string_buf(sb2); } /* sb_cat */ /************* * * zap_string_buf() * *************/ /* DOCUMENTATION This routine deallocates a String_buf and frees all memory associated with it. */ /* PUBLIC */ void zap_string_buf(String_buf sb) { Chunk curr, prev; curr = sb->first; while (curr != NULL) { prev = curr; curr = curr->next; free_chunk(prev); } free_string_buf(sb); } /* zap_string_buf */ /************* * * sb_to_malloc_string() * *************/ /* DOCUMENTATION This routine returns a new, ordinary C string corresponding to the String_buf argument sb. WARNING: the new string, say s, is dynamically allocated (malloced), so don't forget to call free(s) when you are finished with the string. (This routine is not intended for printing String_bufs; use fprint_sb() instead.)

String_bufs do not have a NULL character marking the end; instead, they keep a count of the number of characters.

If the String_buf contains NULL characters, they do NOT mark the end of the string. Instead, they are simply ignored when constructing the ordinary string. */ /* PUBLIC */ char *sb_to_malloc_string(String_buf sb) { char *s = malloc(sb->size + 1); if (s == NULL) return NULL; else { int j = 0; /* index for new string */ int i; /* index for Str_buf */ for (i = 0; i < sb->size; i++) { char c = sb_char(sb, i); if (c != '\0') s[j++] = c; } s[j] = '\0'; return s; } } /* sb_to_malloc_string */ /************* * * sb_to_malloc_char_array() * *************/ /* DOCUMENTATION This routine is similar to sb_to_malloc_string(), except that null characters are copied to the new string. */ /* PUBLIC */ char *sb_to_malloc_char_array(String_buf sb) { char *s = malloc(sb->size + 1); if (s == NULL) return NULL; else { int i; for (i = 0; i < sb->size; i++) s[i] = sb_char(sb, i); s[i] = '\0'; return s; } } /* sb_to_malloc_char_array */ /************* * * sb_size() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int sb_size(String_buf sb) { return sb->size; } /* sb_size */ /************* * * sb_append_int() * *************/ /* DOCUMENTATION Convert an integer to a string and append the string to a String_buf. */ /* PUBLIC */ void sb_append_int(String_buf sb, int i) { char s[25]; sb_append(sb, int_to_str(i, s, 25)); } /* sb_append_int */ LADR-2009-11A/ladr/resolve.c0000644000175000017500000005426511140362255014576 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "resolve.h" #include "dollar.h" /* Private definitions and types */ static BOOL Ordered = FALSE; static BOOL Check_instances = FALSE; static int Ur_nucleus_limit = INT_MAX; /* limit num of clashable lits */ static BOOL Initial_nuclei = FALSE; /* nuclei must be input clauses */ static BOOL Production_mode = FALSE; static int Res_instance_prunes = 0; /* counter */ /************* * * resolution_options() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void resolution_options(BOOL ordered, BOOL check_instances, BOOL initial_nuclei, int ur_nucleus_limit, BOOL production_mode) { Ordered = ordered; Check_instances = check_instances; Initial_nuclei = initial_nuclei; Ur_nucleus_limit = (ur_nucleus_limit == -1 ? INT_MAX : ur_nucleus_limit); Production_mode = production_mode; Res_instance_prunes = 0; } /* resolution_options */ /************* * * res_instance_prunes() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int res_instance_prunes() { return Res_instance_prunes; } /* res_instance_prunes */ /************* * * unit_check() * *************/ static BOOL unit_check(Literals lit) { Topform c = lit->atom->container; return unit_clause(c->literals); } /* unit_check */ /************* * * pos_hyper_sat_test() * *************/ static BOOL pos_hyper_sat_test(Literals lit) { Topform c = lit->atom->container; if (positive_clause(c->literals)) return Ordered ? maximal_literal(c->literals, lit, FLAG_CHECK) : TRUE; else return FALSE; } /* pos_hyper_sat_test */ /************* * * neg_hyper_sat_test() * *************/ static BOOL neg_hyper_sat_test(Literals lit) { Topform c = lit->atom->container; if (negative_clause(c->literals)) return Ordered ? maximal_literal(c->literals, lit, FLAG_CHECK) : TRUE; else return FALSE; } /* neg_hyper_sat_test */ /************* * * hyper_sat_atom() * *************/ static void hyper_sat_atom(BOOL flipped, Literals slit, Term atom, int pos_or_neg, Lindex idx, void (*proc_proc) (Topform)) { BOOL positive = (pos_or_neg == POS_RES); Context sat_subst = get_context(); Context nuc_subst = get_context(); Term fnd_atom; Mindex_pos mate_pos; fnd_atom = mindex_retrieve_first(atom, positive ? idx->neg : idx->pos, UNIFY, sat_subst, nuc_subst, FALSE, &mate_pos); while (fnd_atom) { /* loop through found nuclei atoms */ /* it must be in a nucleus because of the index used above */ Topform nuc = fnd_atom->container; Literals nuc_lit = atom_to_literal(fnd_atom); Clash p = NULL; Clash first = NULL; Literals nlit; for (nlit = nuc->literals; nlit; nlit = nlit->next) { p = append_clash(p); if (first == NULL) first = p; p->nuc_lit = nlit; p->nuc_subst = nuc_subst; if (nlit == nuc_lit) { p->sat_lit = slit; p->sat_subst = sat_subst; p->clashable = TRUE; p->clashed = TRUE; p->flipped = flipped; } else { if (!Production_mode) p->clashable = positive ? !nlit->sign : nlit->sign; else p->clashable = (positive && !nlit->sign && !evaluable_predicate(SYMNUM(nlit->atom))); if (p->clashable) { p->mate_index = positive ? idx->pos : idx->neg; p->sat_subst = get_context(); } } } /* for each literal of nucleus */ clash(first, positive ? pos_hyper_sat_test : neg_hyper_sat_test, HYPER_RES_JUST, proc_proc); zap_clash(first); fnd_atom = mindex_retrieve_next(mate_pos); } /* for each found nucleus atom */ free_context(sat_subst); free_context(nuc_subst); } /* hyper_sat_atom */ /************* * * hyper_satellite() * *************/ static void hyper_satellite(Topform c, int pos_or_neg, Lindex idx, void (*proc_proc) (Topform)) { Literals slit; for (slit = c->literals; slit; slit = slit->next) { if (!Ordered || maximal_literal(c->literals, slit, FLAG_CHECK)) { hyper_sat_atom(FALSE, slit, slit->atom, pos_or_neg, idx, proc_proc); if (pos_eq(slit)) { Term flip = top_flip(slit->atom); hyper_sat_atom(TRUE, slit, flip, pos_or_neg, idx, proc_proc); zap_top_flip(flip); } } /* if sat is ok */ } /* for each literal of satellite */ } /* hyper_satellite */ /************* * * hyper_nucleus() * *************/ static void hyper_nucleus(Topform c, int pos_or_neg, Lindex idx, void (*proc_proc) (Topform)) { BOOL positive = (pos_or_neg == POS_RES); Clash p = NULL; Clash first = NULL; Literals lit; Context nuc_subst = get_context(); for (lit = c->literals; lit; lit = lit->next) { p = append_clash(p); if (first == NULL) first = p; if (!Production_mode) p->clashable = positive ? !lit->sign : lit->sign; else p->clashable = (positive && !lit->sign && !evaluable_predicate(SYMNUM(lit->atom))); p->nuc_lit = lit; p->nuc_subst = nuc_subst; if (p->clashable) { p->mate_index = positive ? idx->pos : idx->neg; p->sat_subst = get_context(); } } clash(first, positive ? pos_hyper_sat_test : neg_hyper_sat_test, HYPER_RES_JUST, proc_proc); free_context(nuc_subst); zap_clash(first); /* This also frees satellite contexts. */ } /* hyper_nucleus */ /************* * * hyper_resolution() * *************/ /* DOCUMENTATION Hyperresolution. */ /* PUBLIC */ void hyper_resolution(Topform c, int pos_or_neg, Lindex idx, void (*proc_proc) (Topform)) { if (pos_or_neg == POS_RES ? positive_clause(c->literals) : negative_clause(c->literals)) hyper_satellite(c, pos_or_neg, idx, proc_proc); else hyper_nucleus(c, pos_or_neg, idx, proc_proc); } /* hyper_resolution */ /************* * * target_check() * *************/ static BOOL target_check(Literals lit, int target_constraint) { if (target_constraint == ANY_RES) return TRUE; else if (target_constraint == POS_RES) return lit->sign; else if (target_constraint == NEG_RES) return !lit->sign; else { fatal_error("target_check, constraint out of range"); return FALSE; /* to please the compiler */ } } /* target_check */ /************* * * ur_sat_atom() * *************/ static void ur_sat_atom(BOOL flipped, Topform c, int target_constraint, Term sat_atom, Lindex idx, void (*proc_proc) (Topform)) { /* Assume C is a unit. */ Context sat_subst = get_context(); Context nuc_subst = get_context(); Term fnd_atom; Mindex_pos mate_pos; Literals slit = c->literals; fnd_atom = mindex_retrieve_first(sat_atom, (slit->sign?idx->neg:idx->pos), UNIFY, sat_subst, nuc_subst, FALSE, &mate_pos); while (fnd_atom) { Topform nuc = fnd_atom->container; int numlits = number_of_literals(nuc->literals); if (numlits > 1 && numlits <= Ur_nucleus_limit && (!Initial_nuclei || nuc->initial)) { Literals fnd_lit = atom_to_literal(fnd_atom); Literals target; for (target=nuc->literals; target; target=target->next) { if (target != fnd_lit && target_check(target, target_constraint)) { Clash p = NULL; Clash first = NULL; Literals nlit; for (nlit = nuc->literals; nlit; nlit = nlit->next) { p = append_clash(p); if (first == NULL) first = p; p->nuc_lit = nlit; p->nuc_subst = nuc_subst; if (nlit == fnd_lit) { p->sat_lit = slit; p->sat_subst = sat_subst; p->clashable = TRUE; p->clashed = TRUE; p->flipped = flipped; } else { p->clashable = (nlit != target); if (p->clashable) { p->mate_index = (nlit->sign ? idx->neg : idx->pos); p->sat_subst = get_context(); } } } /* for each literal of nucleus */ clash(first, unit_check, UR_RES_JUST, proc_proc); zap_clash(first); } } /* for each target */ } /* if we have a nuc */ fnd_atom = mindex_retrieve_next(mate_pos); } /* for each mate */ free_context(sat_subst); free_context(nuc_subst); } /* ur_sat_atom */ /************* * * ur_satellite() * *************/ static void ur_satellite(Topform c, int target_constraint, Lindex idx, void (*proc_proc) (Topform)) { Term atom = c->literals->atom; ur_sat_atom(FALSE, c, target_constraint, atom, idx, proc_proc); /* if equality, try with the flip */ if (eq_term(atom)) { Term flip = top_flip(atom); ur_sat_atom(TRUE, c, target_constraint, flip, idx, proc_proc); zap_top_flip(flip); } } /* ur_satellite */ /************* * * ur_nucleus() * *************/ static void ur_nucleus(Topform c, int target_constraint, Lindex idx, void (*proc_proc) (Topform)) { if (number_of_literals(c->literals) > Ur_nucleus_limit || (Initial_nuclei && !c->initial)) return; else { Literals target; for (target = c->literals; target; target = target->next) { if (target_check(target, target_constraint)) { Clash p = NULL; Clash first = NULL; Literals lit; Context nuc_subst = get_context(); for (lit = c->literals; lit; lit = lit->next) { p = append_clash(p); if (first == NULL) first = p; p->clashable = (lit != target); p->nuc_lit = lit; p->nuc_subst = nuc_subst; if (p->clashable) { p->mate_index = (lit->sign ? idx->neg : idx->pos); p->sat_subst = get_context(); } } clash(first, unit_check, UR_RES_JUST, proc_proc); free_context(nuc_subst); zap_clash(first); /* This also frees satellite contexts. */ } } } } /* ur_nucleus */ /************* * * ur_resolution() * *************/ /* DOCUMENTATION Unit-resulting resolution. */ /* PUBLIC */ void ur_resolution(Topform c, int target_constraint, Lindex idx, void (*proc_proc) (Topform)) { if (unit_clause(c->literals)) ur_satellite(c, target_constraint, idx, proc_proc); else ur_nucleus(c, target_constraint, idx, proc_proc); } /* ur_resolution */ /************* * * xx_res() * *************/ static void xx_res(Literals lit, void (*proc_proc) (Topform)) { Term alpha = ARG(lit->atom,0); Term beta = ARG(lit->atom,1); Context subst = get_context(); Trail tr = NULL; if (unify(alpha, subst, beta, subst, &tr)) { Topform parent = lit->atom->container; int n = literal_number(parent->literals, lit); Topform c = get_topform(); Literals l; c->justification = xxres_just(parent, n); for (l = parent->literals; l; l = l->next) { if (l != lit) c->literals = append_literal(c->literals, apply_lit(l, subst)); } undo_subst(tr); upward_clause_links(c); c->attributes = inheritable_att_instances(parent->attributes, subst); (*proc_proc)(c); } free_context(subst); } /* xx_res */ /************* * * binary_resolvent() - construct a binary resolvent * *************/ static void binary_resolvent(BOOL flipped, Literals l1, Context s1, Literals l2, Context s2, void (*proc_proc) (Topform)) { Topform r = get_topform(); Topform nuc = l1->atom->container; Topform sat = l2->atom->container; Ilist j = NULL; Literals l3; int i; int n = 0; /* Include literals in the nucleus. */ for (l3 = nuc->literals, i=1; l3; l3 = l3->next, i++) { if (l3 == l1) n = i; /* index of resolved literal */ else r->literals = append_literal(r->literals, apply_lit(l3, s1)); } j = ilist_append(j, nuc->id); j = ilist_append(j, n); /* Include literals in the satellite. */ for (l3 = sat->literals, i=1; l3; l3 = l3->next, i++) { if (l3 == l2) n = i; /* index of resolved literal */ else r->literals = append_literal(r->literals, apply_lit(l3, s2)); } j = ilist_append(j, sat->id); j = ilist_append(j, flipped ? -n : n); inherit_attributes(nuc, s1, sat, s2, r); r->justification = resolve_just(j, BINARY_RES_JUST); upward_clause_links(r); (*proc_proc)(r); } /* binary_resolvent */ /************* * * binary_parent_test() * * Is a literal eligible for binary resolution? * *************/ static BOOL binary_parent_test(Literals lit, int res_type, int check_type) { Topform c = lit->atom->container; if (res_type == POS_RES) { /* positive resolution (one parent positive) */ if (positive_clause(c->literals)) return !Ordered || maximal_literal(c->literals, lit, check_type); else if (lit->sign) return FALSE; /* cannot resolve on pos literal in nonpos clause */ else if (exists_selected_literal(c->literals)) return selected_literal(lit); else return !Ordered || maximal_signed_literal(c->literals, lit, check_type); /* max neg */ } else if (res_type == NEG_RES) { /* negative resolution (one parent neg) */ if (negative_clause(c->literals)) return !Ordered || maximal_literal(c->literals, lit, check_type); else if (!lit->sign) return FALSE; /* cannot resolve on neg literal in nonneg clause */ else /* selection ignored for negative resolution */ return !Ordered || maximal_signed_literal(c->literals, lit, check_type); /* max pos */ } else { /* ANY_RES (not necessarily positive or negative resolution) */ if (exists_selected_literal(c->literals)) { if (lit->sign) return FALSE; /* if any selected lits, cannot resolve on pos lit */ else return selected_literal(lit); } else /* no selected literals in clause */ return !Ordered || maximal_literal(c->literals, lit, check_type); } } /* binary_parent_test */ /************* * * instantiate_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform instantiate_clause(Topform c, Context subst) { Topform d = get_topform(); Literals lit; for (lit = c->literals; lit; lit = lit->next) d->literals = append_literal(d->literals, apply_lit(lit, subst)); for (lit = d->literals; lit; lit = lit->next) lit->atom->container = d; return d; } /* instantiate_clause */ /************* * * check_instance() * *************/ static BOOL check_instance(Literals lit, Context subst, int res_type) { Topform c = lit->atom->container; if (number_of_maximal_literals(c->literals, FLAG_CHECK) == 1 || variable_substitution(subst)) return TRUE; else { Literals a; BOOL ok; int n = literal_number(c->literals, lit); Topform d = instantiate_clause(c, subst); copy_selected_literal_marks(c->literals, d->literals); a = ith_literal(d->literals, n); /* Note that using binary_parent_test repeats several tests not having to do with maximality. These repeated steps are not expensive. */ ok = binary_parent_test(a, res_type, FULL_CHECK); zap_topform(d); if (!ok) Res_instance_prunes++; return ok; } } /* check_instance */ /************* * * check_instances() * *************/ static BOOL check_instances(Literals lit1, Context subst1, Literals lit2, Context subst2, int res_type) { if (!Check_instances) return TRUE; else return check_instance(lit1, subst1, res_type) && check_instance(lit2, subst2, res_type); } /* check_instances */ /************* * * bin_res_lit() * *************/ static void bin_res_lit(Topform giv, Literals lit, Term atom, int res_type, Lindex idx, void (*proc_proc) (Topform)) { BOOL flipped = (lit->atom != atom); Context nuc_subst = get_context(); Context sat_subst = get_context(); Term sat_atom; Mindex_pos mate_pos; sat_atom = mindex_retrieve_first(atom, lit->sign ? idx->neg : idx->pos, UNIFY, nuc_subst, sat_subst, FALSE, &mate_pos); while (sat_atom) { Literals slit = atom_to_literal(sat_atom); if (binary_parent_test(slit, res_type, FLAG_CHECK) && check_instances(lit, nuc_subst, slit, sat_subst, res_type)) binary_resolvent(flipped, lit, nuc_subst, slit, sat_subst, proc_proc); sat_atom = mindex_retrieve_next(mate_pos); } free_context(nuc_subst); free_context(sat_subst); } /* bin_res_lit */ /************* * * binary_resolution() * *************/ /* DOCUMENTATION Binary resolution. */ /* PUBLIC */ void binary_resolution(Topform c, int res_type, /* POS_RES, NEG_RES, ANY_RES */ Lindex idx, void (*proc_proc) (Topform)) { Literals lit; for (lit = c->literals; lit; lit = lit->next) { if (binary_parent_test(lit, res_type, FLAG_CHECK)) { bin_res_lit(c, lit, lit->atom, res_type, idx, proc_proc); /* If equality, try for resolution with the flip. */ if (eq_term(lit->atom)) { Term flip = top_flip(lit->atom); bin_res_lit(c, lit, flip, res_type, idx, proc_proc); zap_top_flip(flip); } /* Try for resolution with x=x. */ if (neg_eq(lit)) { xx_res(lit, proc_proc); } } } } /* binary_resolution */ /************* * * binary_factors() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void binary_factors(Topform c, void (*proc_proc) (Topform)) { Literals l1; int i = 1; Context subst = get_context(); for (l1 = c->literals; l1; l1 = l1->next, i++) { Literals l2; int j = i+1; for (l2 = l1->next; l2; l2 = l2->next, j++) { Trail tr = NULL; if (l1->sign == l2->sign && /* maximal_literal_check ??? */ unify(l1->atom,subst,l2->atom,subst,&tr)) { Topform f = get_topform(); Literals l3; f->justification = factor_just(c, i, j); for (l3 = c->literals; l3; l3 = l3->next) { if (l3 != l2) f->literals = append_literal(f->literals, apply_lit(l3, subst)); } undo_subst(tr); upward_clause_links(f); f->attributes = cat_att(f->attributes, inheritable_att_instances(c->attributes, subst)); (*proc_proc)(f); } } } free_context(subst); } /* binary_factors */ /************* * * merge_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void merge_literals(Topform c) { Literals l3; int n; BOOL null_literals = FALSE; for (l3 = c->literals, n = 1; l3; l3 = l3->next, n++) { Literals l2; for (l2 = c->literals; l2 != l3; l2 = l2->next) { if (l2->atom && l3->atom) { if (l3->sign == l2->sign && term_ident(l3->atom, l2->atom)) { zap_term(l3->atom); c->justification = append_just(c->justification, merge_just(n)); l3->atom = NULL; /* remove it below */ null_literals = TRUE; } } } } if (null_literals) c->literals = remove_null_literals(c->literals); } /* merge_literals */ /************* * * copy_inference() * *************/ /* DOCUMENTATION This makes a "copy" inference; that is, a copy of the clause in which the justification is "copy". All attributes are copied (not just the inheritible attributes). An ID is not assigned. */ /* PUBLIC */ Topform copy_inference(Topform c) { Topform new = copy_clause(c); /* Don't copy the justification; build a "copy" justification. */ new->justification = copy_just(c); #if 0 /* Copy all attributes. */ new->attributes = copy_attributes(c->attributes); #else /* Copy inheritable attributes only. */ new->attributes = inheritable_att_instances(c->attributes, NULL); #endif return new; } /* copy_inference */ /************* * * resolve2() * *************/ /* DOCUMENTATION Resolve, if possible, two clauses on the literals (specified by literals, counting from 1). Include justification, transfer inheritable attributes, but do not assign an ID. Renumbering of variables is optional.

if n2 < 0, then the literal is abs(n2), and it should be flipped. */ /* PUBLIC */ Topform resolve2(Topform c1, int n1, Topform c2, int n2, BOOL renumber_vars) { Topform res; Literals l1 = ith_literal(c1->literals, n1); Literals l2 = ith_literal(c2->literals, abs(n2)); Term a1 = l1->atom; Term a2 = l2->atom; Context s1 = get_context(); Context s2 = get_context(); Trail tr = NULL; Term a2x; if (n2 < 0) a2x = top_flip(a2); else a2x = a2; if (l1->sign != l2->sign && unify(a1, s1, a2x, s2, &tr)) { Literals lit; res = get_topform(); for (lit = c1->literals; lit; lit = lit->next) if (lit != l1) res->literals = append_literal(res->literals, apply_lit(lit, s1)); for (lit = c2->literals; lit; lit = lit->next) if (lit != l2) res->literals = append_literal(res->literals, apply_lit(lit, s2)); inherit_attributes(c1, s1, c2, s2, res); res->justification = binary_res_just(c1, n1, c2, n2); upward_clause_links(res); if (renumber_vars) renumber_variables(res, MAX_VARS); undo_subst(tr); } else res = NULL; if (n2 < 0) zap_top_flip(a2x); free_context(s1); free_context(s2); return res; } /* resolve2 */ /************* * * resolve3() * *************/ /* DOCUMENTATION Similar to resolve2(), but literals are given instead of integers. */ /* PUBLIC */ Topform resolve3(Topform c1, Literals l1, Topform c2, Literals l2, BOOL renumber_vars) { return resolve2(c1, literal_number(c1->literals, l1), c2, literal_number(c2->literals, l2), renumber_vars); } /* resolve3 */ /************* * * xx_resolve2() * *************/ /* DOCUMENTATION Resolve, if possible, a clause with x=x. Renumber vars, include justification, transfer inheritable attributes, but do not assign an ID. */ /* PUBLIC */ Topform xx_resolve2(Topform c, int n, BOOL renumber_vars) { Topform res; Literals l = ith_literal(c->literals, n); Context s = get_context(); Trail tr = NULL; if (neg_eq(l) && unify(ARG(l->atom,0), s, ARG(l->atom,1), s, &tr)) { Literals lit; res = get_topform(); for (lit = c->literals; lit; lit = lit->next) if (lit != l) res->literals = append_literal(res->literals, apply_lit(lit, s)); res->attributes = inheritable_att_instances(c->attributes, s); res->justification = xxres_just(c, n); upward_clause_links(res); if (renumber_vars) renumber_variables(res, MAX_VARS); undo_subst(tr); } else res = NULL; free_context(s); return res; } /* xx_resolve2 */ LADR-2009-11A/ladr/features.h0000644000175000017500000000224111151265364014732 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FEATURES_H #define TP_FEATURES_H #include "literals.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from features.c */ void init_features(Ilist fsyms, Ilist rsyms); Ilist features(Literals lits); int feature_length(void); BOOL features_less_or_equal(Ilist c, Ilist d); void p_features(Ilist f); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/topform.h0000644000175000017500000001036311151265364014606 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSE_H #define TP_CLAUSE_H #include "literals.h" #include "attrib.h" #include "formula.h" #include "maximal.h" /* INTRODUCTION A Topform can be used to store a formula or a clause. The field is_formula says which it is.

In earlier versions of LADR, this data structure was called Clause. When we decided to put non-clausal formulas in proofs, they needed to have IDs, attributes, and justifications, so we elevated the data structure to include non-clausal formulas and changed the name to Topform (top formula).

In many cases, when we say "clause", we mean a list of Literals. For example, most of the functions that tell the properties of clauses (positive_clause, number_of_literals, etc.) take a list of Literals, not a Topform.

If C had data structures with inheritance, this would be a good place to use it. */ /* Public definitions */ typedef struct topform * Topform; struct topform { /* for both clauses and formulas */ int id; struct clist_pos *containers; /* Clists that contain the Topform */ Attribute attributes; struct just *justification; double weight; char *compressed; /* if nonNULL, a compressed form */ Topform matching_hint; /* hint that matches clause, if any */ /* for clauses only */ Literals literals; /* NULL can mean the empty clause */ /* for formulas only */ Formula formula; int semantics; /* evaluation in interpretations */ /* The rest of the fields are flags. These could be bits. */ char is_formula; /* is this really a formula? */ char normal_vars; /* variables have been renumbered */ char used; /* used to infer a clause that was kept */ char official_id; /* Topform is in the ID table */ char initial; /* existed at the start of the search */ char neg_compressed; /* negative and compressed */ char subsumer; /* has this clause back subsumed anything? */ }; /* End of public definitions */ /* Public function prototypes from topform.c */ Topform get_topform(void); void fprint_topform_mem(FILE *fp, int heading); void p_topform_mem(); void zap_topform(Topform tf); void fprint_clause(FILE *fp, Topform c); void p_clause(Topform c); Topform term_to_clause(Term t); Topform term_to_topform(Term t, BOOL is_formula); Term topform_to_term(Topform tf); Term topform_to_term_without_attributes(Topform tf); void clause_set_variables(Topform c, int max_vars); void renumber_variables(Topform c, int max_vars); void term_renumber_variables(Term t, int max_vars); Plist renum_vars_map(Topform c); void upward_clause_links(Topform c); BOOL check_upward_clause_links(Topform c); Topform copy_clause(Topform c); Topform copy_clause_with_flags(Topform c); Topform copy_clause_with_flag(Topform c, int flag); void inherit_attributes(Topform par1, Context s1, Topform par2, Context s2, Topform child); void gather_symbols_in_topform(Topform c, I2list *rsyms, I2list *fsyms); void gather_symbols_in_topforms(Plist lst, I2list *rsyms, I2list *fsyms); Ilist fsym_set_in_topforms(Plist lst); Ilist rsym_set_in_topforms(Plist lst); BOOL min_depth(Literals lit); BOOL initial_clause(Topform c); BOOL negative_clause_possibly_compressed(Topform c); Term topform_properties(Topform c); void append_label_attribute(Topform tf, char *s); Ordertype cl_id_compare(Topform c1, Topform c2); Ordertype cl_wt_id_compare(Topform c1, Topform c2); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clausify.h0000644000175000017500000000234711151265364014742 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSIFY_H #define TP_CLAUSIFY_H #include "topform.h" #include "cnf.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from clausify.c */ Literals formula_to_literal(Formula f); Literals formula_to_literals(Formula f); Topform formula_to_clause(Formula f); Plist formula_to_clauses(Formula f); Plist clausify_formula(Formula f); Formula clause_to_formula(Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/termorder.c0000644000175000017500000004536611137702106015123 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "termorder.h" #include "multiset.h" /* Private definitions and types */ Order_method Ordering_method = LRPO_METHOD; /* see assign_order_method() */ /************* * * assign_order_method() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void assign_order_method(Order_method method) { Ordering_method = method; } /* assign_order_method */ /************* * * term_compare_basic(t1, t2) * *************/ /* DOCUMENTATION This routine compares two terms. variable < nonvariable; within type, the order is by VARNUM and lexigocgaphic by ASCII ordering. The range of return values is {SAME_AS, GREATER_THAN, LESS_THAN}. */ /* PUBLIC */ Ordertype term_compare_basic(Term t1, Term t2) { Ordertype rc; if (!VARIABLE(t1) && !VARIABLE(t2)) { char *s1 = sn_to_str(SYMNUM(t1)); char *s2 = sn_to_str(SYMNUM(t2)); int a1 = ARITY(t1); int a2 = ARITY(t2); if (str_ident(s1, s2)) { /* allow for different arities with same symbol */ int i; for (rc = SAME_AS, i = 0; rc == SAME_AS && i < a1 && i < a2; i++) rc = term_compare_basic(ARG(t1,i), ARG(t2,i)); if (rc == SAME_AS) rc = (a1 < a2 ? LESS_THAN : (a1 > a2 ? GREATER_THAN : SAME_AS)); } else { int r = strcmp(s1, s2); rc = (r < 0 ? LESS_THAN : (r > 0 ? GREATER_THAN : SAME_AS)); } } else if (VARIABLE(t1) && VARIABLE(t2)) { if (VARNUM(t1) == VARNUM(t2)) rc = SAME_AS; else rc = (VARNUM(t1) > VARNUM(t2) ? GREATER_THAN : LESS_THAN); } else if (VARIABLE(t1)) rc = LESS_THAN; else rc = GREATER_THAN; return rc; } /* term_compare_basic */ /************* * * int term_compare_ncv(t1, t2) * *************/ /* DOCUMENTATION This routine compares two terms. The ordering is total: CONSTANT < COMPLEX < VARIABLE; within type, the order is by VARNUM and lexigocgaphic by SYMNUM. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}. */ /* PUBLIC */ Ordertype term_compare_ncv(Term t1, Term t2) { Ordertype rc; if ((COMPLEX(t1) && COMPLEX(t2)) || (CONSTANT(t1) && CONSTANT(t2))) { if (SYMNUM(t1) == SYMNUM(t2)) { int i; for (rc = SAME_AS, i = 0; rc == SAME_AS && i < ARITY(t1); i++) rc = term_compare_ncv(ARG(t1,i), ARG(t2,i)); } else if (SYMNUM(t1) > SYMNUM(t2)) rc = GREATER_THAN; else rc = LESS_THAN; } else if (VARIABLE(t1) && VARIABLE(t2)) { if (VARNUM(t1) == VARNUM(t2)) rc = SAME_AS; else rc = (VARNUM(t1) > VARNUM(t2) ? GREATER_THAN : LESS_THAN); } /* Now we know they are different types. */ else if (VARIABLE(t1)) rc = GREATER_THAN; else if (VARIABLE(t2)) rc = LESS_THAN; else if (COMPLEX(t1)) rc = GREATER_THAN; else rc = LESS_THAN; /* CONSTANT(t1) && COMPLEX(t2) */ return rc; } /* term_compare_ncv */ /************* * * int term_compare_vcp(t1, t2) * *************/ /* DOCUMENTATION This routine compares two terms. The ordering is total: VARIABLE < CONSTANT < COMPLEX; within type, the order is by VARNUM and lexigocgaphic by SYMNUM. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}. */ /* PUBLIC */ Ordertype term_compare_vcp(Term t1, Term t2) { Ordertype rc; if ((COMPLEX(t1) && COMPLEX(t2)) || (CONSTANT(t1) && CONSTANT(t2))) { if (SYMNUM(t1) == SYMNUM(t2)) { int i; for (rc = SAME_AS, i = 0; rc == SAME_AS && i < ARITY(t1); i++) rc = term_compare_vcp(ARG(t1,i), ARG(t2,i)); } else if (SYMNUM(t1) > SYMNUM(t2)) rc = GREATER_THAN; else rc = LESS_THAN; } else if (VARIABLE(t1) && VARIABLE(t2)) { if (VARNUM(t1) == VARNUM(t2)) rc = SAME_AS; else rc = (VARNUM(t1) > VARNUM(t2) ? GREATER_THAN : LESS_THAN); } /* Now we know they are different types. */ else if (VARIABLE(t1)) rc = LESS_THAN; else if (VARIABLE(t2)) rc = GREATER_THAN; else if (COMPLEX(t1)) rc = GREATER_THAN; else rc = LESS_THAN; /* CONSTANT(t1) && COMPLEX(t2) */ return rc; } /* term_compare_vcp */ /************* * * term_compare_vr(t1, t2) * *************/ /* DOCUMENTATION This routine compares two terms. variable < nonvariable; within type, the order is by VARNUM and lexigocgaphic by symbol precedence. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}. */ /* PUBLIC */ Ordertype term_compare_vr(Term t1, Term t2) { Ordertype rc; if (!VARIABLE(t1) && !VARIABLE(t2)) { if (SYMNUM(t1) == SYMNUM(t2)) { int i; for (rc = SAME_AS, i = 0; rc == SAME_AS && i < ARITY(t1); i++) rc = term_compare_vr(ARG(t1,i), ARG(t2,i)); } else rc = sym_precedence(SYMNUM(t1), SYMNUM(t2)); } else if (VARIABLE(t1) && VARIABLE(t2)) { if (VARNUM(t1) == VARNUM(t2)) rc = SAME_AS; else rc = (VARNUM(t1) > VARNUM(t2) ? GREATER_THAN : LESS_THAN); } else if (VARIABLE(t1)) rc = LESS_THAN; else rc = GREATER_THAN; return rc; } /* term_compare_vr */ /************* * * flatterm_compare_vr(t1, t2) * *************/ /* DOCUMENTATION This routine compares two flatterms. variable < nonvariable; within type, the order is by VARNUM and lexigocgaphic by symbol precedence. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}. */ /* PUBLIC */ Ordertype flatterm_compare_vr(Flatterm a, Flatterm b) { Ordertype rc; if (!VARIABLE(a) && !VARIABLE(b)) { if (SYMNUM(a) == SYMNUM(b)) { int i; Flatterm ai = a->next; Flatterm bi = b->next; for (rc = SAME_AS, i = 0; rc == SAME_AS && i < ARITY(a); i++) { rc = flatterm_compare_vr(ai, bi); ai = ai->end->next; bi = bi->end->next; } } else rc = sym_precedence(SYMNUM(a), SYMNUM(b)); } else if (VARIABLE(a) && VARIABLE(b)) { if (VARNUM(a) == VARNUM(b)) rc = SAME_AS; else rc = (VARNUM(a) > VARNUM(b) ? GREATER_THAN : LESS_THAN); } else if (VARIABLE(a)) rc = LESS_THAN; else rc = GREATER_THAN; return rc; } /* flatterm_compare_vr */ /************* * * int lrpo_multiset(t1, t2) -- Is t1 > t2 in the lrpo multiset ordering? * *************/ /* DOCUMENTATION This routine */ /* PUBLIC */ BOOL lrpo_multiset(Term t1, Term t2, BOOL lex_order_vars) { return greater_multiset(ARGS(t1), ARITY(t1), ARGS(t2), ARITY(t2), lrpo, lex_order_vars); } /* lrpo_multiset */ /************* * * lrpo_lex(s, t) -- Is s > t ? * * s and t have same symbol and the symbol has lr status. * *************/ static BOOL lrpo_lex(Term s, Term t, BOOL lex_order_vars) { int i; int arity = ARITY(s); /* First skip over any identical arguments. */ for (i = 0; i < arity && term_ident(ARG(s,i),ARG(t,i)); i++); if (i == arity) return FALSE; /* s and t identical */ else if (lrpo(ARG(s,i), ARG(t,i), lex_order_vars)) { /* return (s > each remaining arg of t) */ BOOL ok; for (ok = TRUE, i++; ok && i < arity; i++) ok = lrpo(s, ARG(t,i), lex_order_vars); return ok; } else { /* return (there is a remaining arg of s s.t. arg >= t) */ BOOL ok; for (ok = FALSE, i++; !ok && i < arity; i++) ok = (term_ident(ARG(s,i), t) || lrpo(ARG(s,i), t, lex_order_vars)); return ok; } } /* lrpo_lex */ /************* * * lrpo() * *************/ /* DOCUMENTATION This routine checks if Term s > Term t in the Lexicographic Recursive Path Ordering (LRPO), also known as Recursive Path Ordering with Status (RPOS).

Function symbols can have either multiset or left-to-right status (see symbols.c). If all symbols are multiset, this reduces to the Recursive Path Ordering (RPO). If all symbols are left-to-right, this reduces to Lexicographic Path Ordering (LPO). */ /* PUBLIC */ BOOL lrpo(Term s, Term t, BOOL lex_order_vars) { if (VARIABLE(s)) { if (lex_order_vars) return VARIABLE(t) && VARNUM(s) > VARNUM(t); else return FALSE; } else if (VARIABLE(t)) { if (lex_order_vars) return TRUE; else return occurs_in(t, s); /* s > var iff s properly contains that var */ } else if (SYMNUM(s) == SYMNUM(t) && sn_to_lrpo_status(SYMNUM(s)) == LRPO_LR_STATUS) /* both have the same "left-to-right" symbol. */ return lrpo_lex(s, t, lex_order_vars); else { Ordertype p = sym_precedence(SYMNUM(s), SYMNUM(t)); if (p == SAME_AS) return lrpo_multiset(s, t, lex_order_vars); else if (p == GREATER_THAN) { /* return (s > each arg of t) */ int i; BOOL ok; for (ok = TRUE, i = 0; ok && i < ARITY(t); i++) ok = lrpo(s, ARG(t,i), lex_order_vars); return ok; } else { /* LESS_THAN or NOT_COMPARABLE */ /* return (there is an arg of s s.t. arg >= t) */ int i; BOOL ok; for (ok = FALSE, i = 0; !ok && i < ARITY(s); i++) ok = term_ident(ARG(s,i), t) || lrpo(ARG(s,i), t, lex_order_vars); return ok; } } } /* lrpo */ /************* * * init_kbo_weights() * *************/ /* DOCUMENTATION Plist should be a list of terms, e.g., a=3, g=0. Symbols are written as constants; arity is deduced from the symbol table. */ /* PUBLIC */ void init_kbo_weights(Plist weights) { Plist p; for (p = weights; p; p = p->next) { Term t = p->v; if (!is_eq_symbol(SYMNUM(t))) fatal_error("init_kbo_weights, not equality"); else { Term a = ARG(t,0); Term b = ARG(t,1); if (!CONSTANT(a)) fatal_error("init_kbo_weights, symbol not constant"); else { int wt = natural_constant_term(b); if (wt == -1) fatal_error("init_kbo_weights, weight not natural"); else { char *str = sn_to_str(SYMNUM(a)); int symnum = function_or_relation_sn(str); if (symnum == -1) { char mess[200]; sprintf(mess, "init_kbo_weights, symbol %s not found", str); fatal_error(mess); } set_kb_weight(symnum, wt); } } } } } /* init_kbo_weights */ /************* * * kbo_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int kbo_weight(Term t) { if (VARIABLE(t)) return 1; else { int wt = sn_to_kb_wt(SYMNUM(t)); int i; for (i = 0; i < ARITY(t); i++) wt += kbo_weight(ARG(t,i)); return wt; } } /* kbo_weight */ /************* * * kbo() * *************/ /* DOCUMENTATION Is alpha kbo-greater-than beta? */ /* PUBLIC */ BOOL kbo(Term alpha, Term beta, BOOL lex_order_vars) { if (VARIABLE(alpha)) { if (lex_order_vars) return VARIABLE(beta) && VARNUM(alpha) > VARNUM(beta); else return FALSE; } else if (VARIABLE(beta)) { if (lex_order_vars) return TRUE; else return occurs_in(beta, alpha); } else if (ARITY(alpha) == 1 && ARITY(beta) == 1 && SYMNUM(alpha) == SYMNUM(beta)) return kbo(ARG(alpha, 0), ARG(beta, 0), lex_order_vars); else if (!variables_multisubset(beta, alpha)) return FALSE; else { int wa = kbo_weight(alpha); int wb = kbo_weight(beta); /* printf("kbo_weight=%d: ", wa); p_term(alpha); */ /* printf("kbo_weight=%d: ", wb); p_term(beta); */ if (wa > wb) return TRUE; else if (wa < wb) return FALSE; else if (!variables_multisubset(alpha, beta)) return FALSE; /* if weights same, multisets of variables must be same */ else if (sym_precedence(SYMNUM(alpha), SYMNUM(beta)) == GREATER_THAN) return TRUE; else if (SYMNUM(alpha) != SYMNUM(beta)) return FALSE; else { /* Call KBO on first arguments that differ. */ int i = 0; while (i < ARITY(alpha) && term_ident(ARG(alpha,i),ARG(beta,i))) i++; if (i == ARITY(alpha)) return FALSE; else return kbo(ARG(alpha,i), ARG(beta,i), lex_order_vars); } } } /* kbo */ /************* * * term_greater() * *************/ /* DOCUMENTATION Is alpha > beta in the current term ordering? (LPR, RPO, KBO) */ /* PUBLIC */ BOOL term_greater(Term alpha, Term beta, BOOL lex_order_vars) { if (Ordering_method == KBO_METHOD) return kbo(alpha, beta, lex_order_vars); else return lrpo(alpha, beta, lex_order_vars); /* LPO, RPO, LRPO */ } /* term_greater */ /************* * * term_order() * *************/ /* DOCUMENTATION Compare two terms with the current term ordering (LPR, RPO, KBO) Return GREATER_THAN, LESS_THAN, SAME_AS, or NOT_COMPARABLE. */ /* PUBLIC */ Ordertype term_order(Term alpha, Term beta) { if (term_greater(alpha, beta, FALSE)) return GREATER_THAN; else if (term_greater(beta, alpha, FALSE)) return LESS_THAN; else if (term_ident(beta, alpha)) return SAME_AS; else return NOT_COMPARABLE; } /* term_order */ /************* * * flat_kbo_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int flat_kbo_weight(Flatterm f) { if (VARIABLE(f)) return 1; else { int wt = sn_to_kb_wt(SYMNUM(f)); int i; Flatterm fi = f->next; for (i = 0; i < ARITY(f); i++) { wt += flat_kbo_weight(fi); fi = fi->end->next; } return wt; } } /* flat_kbo_weight */ /************* * * flat_kbo() * *************/ static BOOL flat_kbo(Flatterm alpha, Flatterm beta, BOOL lex_order_vars) { if (VARIABLE(alpha)) { if (lex_order_vars) return VARIABLE(beta) && VARNUM(alpha) > VARNUM(beta); else return FALSE; } else if (VARIABLE(beta)) { if (lex_order_vars) return TRUE; else return flat_occurs_in(beta, alpha); } else if (ARITY(alpha) == 1 && ARITY(beta) == 1 && SYMNUM(alpha) == SYMNUM(beta)) return flat_kbo(alpha->next, beta->next, lex_order_vars); else if (!flat_variables_multisubset(beta, alpha)) return FALSE; else { int wa = flat_kbo_weight(alpha); int wb = flat_kbo_weight(beta); /* printf("kbo_weight=%d: ", wa); p_term(alpha); */ /* printf("kbo_weight=%d: ", wb); p_term(beta); */ if (wa > wb) return TRUE; else if (wa < wb) return FALSE; else if (!flat_variables_multisubset(alpha, beta)) return FALSE; /* multisets of variables must be the same */ else if (sym_precedence(SYMNUM(alpha), SYMNUM(beta)) == GREATER_THAN) return TRUE; else if (SYMNUM(alpha) != SYMNUM(beta)) return FALSE; else { Flatterm ai = alpha->next; Flatterm bi = beta->next; int i = 0; while (i < ARITY(alpha) && flatterm_ident(ai,bi)) { ai = ai->end->next; bi = bi->end->next; i++; } if (i == ARITY(alpha)) return FALSE; else return flat_kbo(ai, bi, lex_order_vars); } } } /* flat_kbo */ /************* * * flat_lrpo_multiset() * *************/ static BOOL flat_lrpo_multiset(Flatterm s, Flatterm t) { printf("ready to abort\n"); p_syms(); p_flatterm(s); p_flatterm(t); printf("lex vals: %d %d\n", sn_to_lex_val(SYMNUM(s)), sn_to_lex_val(SYMNUM(s))); fatal_error("flat_lrpo_multiset not implemented"); return FALSE; } /* flat_lrpo_multiset */ /************* * * flat_lrpo_lex() * *************/ static BOOL flat_lrpo_lex(Flatterm s, Flatterm t, BOOL lex_order_vars) { int arity = ARITY(s); /* First skip over any identical arguments. */ Flatterm si = s->next; Flatterm ti = t->next; int i = 0; while (i < arity && flatterm_ident(si, ti)) { si = si->end->next; ti = ti->end->next; i++; } if (i == arity) return FALSE; /* s and t identical */ else if (flat_lrpo(si, ti, lex_order_vars)) { /* return (s > each remaining arg of t) */ BOOL ok = TRUE; i++; ti = ti->end->next; while (ok && i < arity) { ok = flat_lrpo(s, ti, lex_order_vars); ti = ti->end->next; i++; } return ok; } else { /* return (there is a remaining arg of s s.t. arg >= t) */ BOOL ok = FALSE; si = si->end->next; i++; while (!ok && i < arity) { ok = (flatterm_ident(si, t) || flat_lrpo(si, t, lex_order_vars)); si = si->end->next; i++; } return ok; } } /* flat_lrpo_lex */ /************* * * flat_lrpo() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL flat_lrpo(Flatterm s, Flatterm t, BOOL lex_order_vars) { if (VARIABLE(s)) { if (lex_order_vars) return VARIABLE(t) && VARNUM(s) > VARNUM(t); else return FALSE; } else if (VARIABLE(t)) { if (lex_order_vars) return TRUE; else return flat_occurs_in(t, s); } else if (SYMNUM(s) == SYMNUM(t) && sn_to_lrpo_status(SYMNUM(s)) == LRPO_LR_STATUS) /* both have the same "left-to-right" symbol. */ return flat_lrpo_lex(s, t, lex_order_vars); else { Ordertype p = sym_precedence(SYMNUM(s), SYMNUM(t)); if (p == SAME_AS) return flat_lrpo_multiset(s, t); else if (p == GREATER_THAN) { /* return (s > each arg of t) */ int i = 0; BOOL ok = TRUE; Flatterm ti = t->next; while (ok && i < ARITY(t)) { ok = flat_lrpo(s, ti, lex_order_vars); ti = ti->end->next; i++; } return ok; } else { /* LESS_THEN or NOT_COMPARABLE */ /* return (there is an arg of s s.t. arg >= t) */ int i = 0; BOOL ok = FALSE; Flatterm si = s->next; while (!ok && i < ARITY(s)) { ok = flatterm_ident(si, t) || flat_lrpo(si, t, lex_order_vars); si = si->end->next; i++; } return ok; } } } /* flat_lrpo */ /************* * * flat_greater() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL flat_greater(Flatterm alpha, Flatterm beta, BOOL lex_order_vars) { if (Ordering_method == RPO_METHOD || Ordering_method == LRPO_METHOD) { /* haven't done the flat versions of the multiset operations */ Term t1 = flatterm_to_term(alpha); Term t2 = flatterm_to_term(beta); BOOL result = term_greater(t1, t2, lex_order_vars); /* LPO, RPO, KBO */ zap_term(t1); zap_term(t2); return result; } else if (Ordering_method == LPO_METHOD) return flat_lrpo(alpha, beta, lex_order_vars); else if (Ordering_method == KBO_METHOD) return flat_kbo(alpha, beta, lex_order_vars); else { fatal_error("flat_greater: unknown Ordering_method"); return FALSE; } } /* flat_greater */ /************* * * greater_multiset_current_ordering() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL greater_multiset_current_ordering(Term t1, Term t2) { return greater_multiset(ARGS(t1), ARITY(t1), ARGS(t2), ARITY(t2), Ordering_method == KBO_METHOD ? kbo : lrpo, FALSE); } /* greater_multiset_current_ordering */ LADR-2009-11A/ladr/parse.c0000644000175000017500000012515511157754035014237 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "parse.h" /* Private definitions and types */ #define COMMENT_CHAR '%' static char Cons_char = ':'; static char Quote_char = '\"'; static int Quantifier_precedence = 0; /* see declare_quantifier_precedence */ static BOOL Parenthesize = FALSE; static BOOL Check_for_illegal_symbols = TRUE; static BOOL Simple_parse = FALSE; /* Token types */ typedef enum {TOK_UNKNOWN, /* probably a garbage binary char */ TOK_ORDINARY, /* see ordinary_char() */ TOK_SPECIAL, /* see special_char() */ TOK_STRING, /* see quote_char() */ TOK_COMMENT, /* see comment_char() */ TOK_PUNC /* see punctutation_char() */ } Toktype; /* Return codes from read_buf() */ typedef enum {READ_BUF_OK,READ_BUF_EOF, READ_BUF_ERROR,READ_BUF_QUOTE_ERROR} Read_rc; /* A list of tokens */ typedef struct token * Token; struct token { Toktype type; char c; /* for punctuation and unknown tokens */ String_buf sb; /* for other tokens */ int buf_pos; /* position of this token in buffer */ Token next; }; /* A list of terms with some other data. */ typedef struct pterm * Pterm; struct pterm { Term t; BOOL parenthesized; /* prevents "a b" being parsed as a(b) */ Pterm prev, next; }; /* Token position */ typedef struct tok_pos *Tok_pos; struct tok_pos { Token tok; char *error_message; int start_error, end_error; }; /* Private variables */ static BOOL Translate_neg_equalities = FALSE; static Plist Multiple_char_special_syms = NULL; /* * memory management */ #define PTRS_TOKEN PTRS(sizeof(struct token)) static unsigned Token_gets, Token_frees; #define PTRS_PTERM PTRS(sizeof(struct pterm)) static unsigned Pterm_gets, Pterm_frees; /************* * * Token get_token() * *************/ static Token get_token(void) { Token p = get_cmem(PTRS_TOKEN); Token_gets++; return(p); } /* get_token */ /************* * * free_token() * *************/ static void free_token(Token p) { free_mem(p, PTRS_TOKEN); Token_frees++; } /* free_token */ /************* * * Pterm get_pterm() * *************/ static Pterm get_pterm(void) { Pterm p = get_cmem(PTRS_PTERM); Pterm_gets++; return(p); } /* get_pterm */ /************* * * free_pterm() * *************/ static void free_pterm(Pterm p) { free_mem(p, PTRS_PTERM); Pterm_frees++; } /* free_pterm */ /************* * * fprint_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the parse package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_parse_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct token); fprintf(fp, "token (%4d) %11u%11u%11u%9.1f K\n", n, Token_gets, Token_frees, Token_gets - Token_frees, ((Token_gets - Token_frees) * n) / 1024.); n = sizeof(struct pterm); fprintf(fp, "pterm (%4d) %11u%11u%11u%9.1f K\n", n, Pterm_gets, Pterm_frees, Pterm_gets - Pterm_frees, ((Pterm_gets - Pterm_frees) * n) / 1024.); } /* fprint_parse_mem */ /************* * * p_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the parse package. */ /* PUBLIC */ void p_parse_mem(void) { fprint_parse_mem(stdout, TRUE); } /* p_parse_mem */ /* * end of memory management */ /************* * * p_tokens() * *************/ #if 0 static void p_tokens(Token t) { Token p; for (p = t; p; p = p->next) { if (p->sb == NULL) printf("%c", p->c); else fprint_sb(stdout, p->sb); printf(" "); } printf("\n\n"); } /* p_tokens */ #endif /************* * * translate_neg_equalities() * *************/ /* DOCUMENTATION This routine sets or clears the flag which tells the parser to automatically translate alpha!=beta to ~(alpha=beta). This happens in read_term(), which is called by read_clause(), read_formula(), and read_term_list(). */ /* PUBLIC */ void translate_neg_equalities(BOOL flag) { Translate_neg_equalities = flag; } /* translate_neg_equalities */ /************* * * translate_neg_eq() * *************/ static Term translate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = translate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), neq_sym(), 2)) { Term eq_term = get_rigid_term(eq_sym(), 2); Term not_term = get_rigid_term(not_sym(), 1); ARG(eq_term,0) = ARG(t, 0); ARG(eq_term,1) = ARG(t, 1); ARG(not_term,0) = eq_term; free_term(t); t = not_term; } } return t; } /* translate_neg_eq */ /************* * * untranslate_neg_eq() * *************/ static Term untranslate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = untranslate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), not_sym(), 1) && is_symbol(SYMNUM(ARG(t,0)), eq_sym(), 2)) { Term neq_term = get_rigid_term(neq_sym(), 2); ARG(neq_term,0) = ARG(ARG(t,0), 0); ARG(neq_term,1) = ARG(ARG(t,0), 1); free_term(ARG(t,0)); free_term(t); t = neq_term; } } return t; } /* untranslate_neg_eq */ /************* * * free_pterm_list() * *************/ static void free_pterm_list(Pterm p) { Pterm p1; while (p != NULL) { if (p->t != NULL) zap_term(p->t); p1 = p; p = p->next; free_pterm(p1); } } /* free_pterm_list */ /************* * * free_token_list() * *************/ static void free_token_list(Token p) { Token p1; while (p != NULL) { p1 = p; p = p->next; if (p1->sb != NULL) zap_string_buf(p1->sb); free_token(p1); } } /* free_token_list */ /************* * * end_char() * *************/ static BOOL end_char(char c) { return (c == '.'); } /* end_char */ /************* * * comment_char() * *************/ static BOOL comment_char(char c) { return (c == COMMENT_CHAR); } /* comment_char */ /************* * * quote_char() * *************/ static BOOL quote_char(char c) { return (c == Quote_char); } /* quote_char */ /************* * * punctuation_char() * *************/ static BOOL punctuation_char(char c) { return (c == ',' || c == Cons_char || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '.'); } /* punctuation_char */ /************* * * ordinary_char() * *************/ static BOOL ordinary_char(char c) { return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$'); } /* ordinary_char */ /************* * * special_char(c) * *************/ static BOOL special_char(char c) { /* This allows us to have special chars in the list below. */ if (quote_char(c) || end_char(c) || comment_char(c) || punctuation_char(c)) return 0; else return (c == '+' || c == '-' || c == '*' || c == '/' || c == '\\' || c == '^' || c == '<' || c == '>' || c == '=' || c == '`' || c == '~' || c == '?' || c == '@' || c == '&' || c == '|' || c == ':' || c == '!' || c == '#' || c == '%' || c == '\'' || c == '\"' || c == '.' || c == ';' ); } /* special_char */ /************* * * white_char() * *************/ static BOOL white_char(char c) { return (c == ' ' || c == '\t' || /* tab */ c == '\n' || /* newline */ c == '\v' || /* vertical tab */ c == '\r' || /* carriage return */ c == '\f'); /* form feed */ } /* white_char */ /************* * * all_whitespace() * *************/ static BOOL all_whitespace(String_buf sb) { int i = 0; BOOL ok = TRUE; int n = sb_size(sb); while (ok && i < n) { char c = sb_char(sb, i); if (white_char(c)) i++; else ok = FALSE; } return ok; } /* all_whitespace */ /************* * * finish_comment() * * Return the last character read: * * EOF file ended before comment ended * \n end of line-comment * COMMENT_CHAR end of block-comment * *************/ static int finish_comment(FILE *fp) { int c; if (((c = getc(fp)) == 'B') && ((c = getc(fp)) == 'E') && ((c = getc(fp)) == 'G') && ((c = getc(fp)) == 'I') && ((c = getc(fp)) == 'N')) { /* We have a block comment. Read up to 'END%' */ while (TRUE) { while (c != 'E' && c != EOF) c = getc(fp); if (c == EOF) return EOF; else if (((c = getc(fp)) == 'N') && ((c = getc(fp)) == 'D') && ((c = getc(fp)) == COMMENT_CHAR)) return COMMENT_CHAR; else if (c == EOF) return EOF; } } else { /* We have a line comment. */ while (c != '\n' && c != EOF) c = getc(fp); } return c; } /* finish_comment */ /************* * * read_buf() * * Read characters into buffer until one of the following: * 1. END_CHAR is reached (which goes into the buffer) * (except if in quoted string or comment). * 2. EOF is reached (everything still goes into buffer). * * Return: * READ_BUF_OK * READ_BUF_EOF possible white space or comment, then EOF * READ_BUF_ERROR non-white space, noncomment then EOF * READ_BUF_QUOTE_ERROR no end to quoted string (EOF) * *************/ static int read_buf(FILE *fp, String_buf sb) { int c; /* character read */ BOOL end, eof, eof_q; /* stop conditions */ end = eof = eof_q = FALSE; while (!end && !eof && !eof_q) { c = getc(fp); if (c == EOF) eof = TRUE; else if (comment_char(c)) { c = finish_comment(fp); if (c == EOF) eof = TRUE; } else { sb_append_char(sb, c); if (end_char(c)) end = TRUE; else if (quote_char(c)) { /* quoted string */ int qc = c; c = getc(fp); while (c != qc && c != EOF) { sb_append_char(sb, c); c = getc(fp); } if (c == EOF) eof_q = TRUE; else sb_append_char(sb, c); } } } if (end) return READ_BUF_OK; else if (eof_q) return READ_BUF_QUOTE_ERROR; else { /* eof -- make sure that the only things in the buffer are whitespace */ if (all_whitespace(sb)) return READ_BUF_EOF; else return READ_BUF_ERROR; } } /* read_buf */ /************* * * max_special_symbol() * * token is maximal sequence that is a known special symbol * *************/ static String_buf max_special_symbol(String_buf sb, int *ip) { String_buf tok_sb; int m = longest_string_in_plist(Multiple_char_special_syms); char *work = malloc(m+1); int n = 0; int i = *ip; BOOL ok = FALSE; /* Get the longest possible token. */ char c = sb_char(sb,i++); while (special_char(c) && n < m) { work[n++] = c; c = sb_char(sb,i++); } i--; work[n] = '\0'; /* Keep chopping one from the end until a known special symbol is found. If none is known, the token is a single character. */ while (!ok && n > 1) { /* printf("checking symbol :%s:\n", work); fflush(stdout); */ ok = (position_of_string_in_plist(work,Multiple_char_special_syms) != -1); if (!ok) { n--; work[n] = '\0'; i--; } } tok_sb = init_string_buf(work); free(work); *ip = i; return tok_sb; } /* max_special_symbol */ /************* * * tokenize() * * Break up a string into a sequence of tokens, including * punctuation tokens such as parentheses and commas. * *************/ static Token tokenize(String_buf sb) { int i = 0; char c = sb_char(sb, i); Token first, last, tok; first = last = NULL; while (!end_char(c) && c != '\0') { tok = get_token(); /* delete if not needed, i.e., white space */ tok->buf_pos = i; /* Make sure that each case, when finished, sets c to the next char. */ if (white_char(c)) { do { c = sb_char(sb, ++i); } while (white_char(c)); free_token(tok); tok = NULL; } else if (punctuation_char(c)) { tok->type = TOK_PUNC; tok->c = c; c = sb_char(sb, ++i); } else if (ordinary_char(c)) { tok->type = TOK_ORDINARY; tok->sb = get_string_buf(); while (ordinary_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (special_char(c)) { tok->type = TOK_SPECIAL; if (Simple_parse) { /* token is maximal sequence of special chars */ tok->sb = get_string_buf(); while (special_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else { /* token is maximal sequence that is a known special symbol */ tok->sb = max_special_symbol(sb, &i); c = sb_char(sb, i); } } else if (quote_char(c)) { char qc = c; tok->type = TOK_STRING; tok->sb = get_string_buf(); sb_append_char(tok->sb, c); do { c = sb_char(sb, ++i); sb_append_char(tok->sb, c); } while (c != qc && c != '\0'); if (c == qc) c = sb_char(sb, ++i); } else { tok->type = TOK_UNKNOWN; tok->c = c; c = sb_char(sb, ++i); } if (tok != NULL) { if (first == NULL) first = tok; else last->next = tok; last = tok; } } /* while */ return first; } /* tokenize */ /************* * * comma_terms() * *************/ static int comma_terms(Term t) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) return 1; else return comma_terms(ARG(t,0)) + comma_terms(ARG(t,1)); } /* comma_terms */ /************* * * transfer_comma_term() * *************/ static void transfer_comma_term(Term t, Term dest, int *p) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { ARG(dest,*p) = copy_term(t); (*p)++; } else { transfer_comma_term(ARG(t,0), dest, p); transfer_comma_term(ARG(t,1), dest, p); } } /* transfer_comma_term */ /************* * * quantifier() * *************/ static BOOL quantifier(Term t) { return (is_symbol(SYMNUM(t), all_sym(), 0) || is_symbol(SYMNUM(t), exists_sym(), 0)); } /* quantifier */ /************* * * ordinary_constant_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ordinary_constant_string(char *s) { while (ordinary_char(*s)) s++; return *s == '\0'; } /* ordinary_constant_string */ /************* * * ordinary_constant() * *************/ static BOOL ordinary_constant(Term t) { if (ARITY(t) != 0) return FALSE; else return ordinary_constant_string(sn_to_str(SYMNUM(t))); } /* ordinary_constant */ /************* * * quant_prefix() * *************/ static BOOL quant_prefix(Pterm start, Pterm end) { return quantifier(start->t) && start->next != end && ordinary_constant(start->next->t); } /* quant_prefix */ /************* * * terms_to_term() * * This routine takes a sequence of terms/symbols, and attempts * to construct a term with precedence <= m. * * On success, the resulting term is an entirely new copy. * *************/ static Term terms_to_term(Pterm start, Pterm end, int m) { if (start == end) { if (is_term(start->t, ",", 0)) return NULL; /* don't allow commas as constants */ else if (ARITY(start->t) == 0 && special_parse_type(sn_to_str(SYMNUM(start->t))) == 1 && m < 998) /* Don't allow prefix or postfix as constants. This prevents expressions that would otherwise be ambiguous, like -v(a) and -v&(a->b), where - is prefix and v is infix. An exception: allow them as members of comma-list, e.g., f(-), [-], f(a,_), [a,-]. This allows lex terms, e.g., lex([-,a,b,f,*]). */ return NULL; else return copy_term(start->t); } else { int rc, prec; Parsetype type; char *str; /* Try for quantified formula; return if successful. */ if (Quantifier_precedence <= m && quant_prefix(start, end)) { Term t1 = terms_to_term(start->next->next, end, Quantifier_precedence); if (t1 != NULL) { Term t = get_rigid_term(quant_sym(), 3); ARG(t,0) = copy_term(start->t); ARG(t,1) = copy_term(start->next->t); ARG(t,2) = t1; return t; } } /* Try for prefix op; return if successful. */ if (ARITY(start->t) == 0) { str = sn_to_str(SYMNUM(start->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == PREFIX_PAREN || type == PREFIX)) { int p = (type == PREFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start->next, end, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); ARG(t,0) = t1; return t; } } } /* Try for postfix op; return if successful. */ if (ARITY(end->t) == 0) { str = sn_to_str(SYMNUM(end->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == POSTFIX_PAREN || type == POSTFIX)) { int p = (type == POSTFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start, end->prev, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); ARG(t,0) = t1; return t; } } } /* Try for an application, e.g., f(a,b); return if successful. */ if (start->next == end && ARITY(start->t) == 0 && !is_term(start->t, ",", 0) && end->parenthesized) { int num_args = comma_terms(end->t); /* number of args for application */ int argnum = 0; Term t = get_rigid_term(sn_to_str(SYMNUM(start->t)), num_args); transfer_comma_term(end->t, t, &argnum); return t; } /* Try for infix op; return if successful. */ if (start->next != end) { /* Try each possible infix op, until success or exhausted. */ Pterm op; int backward = 0; /* If we parse a long left-associated expression left-to-right, * it ends up trying all the different associations before finding * the correct one. Therefore, as a heuristic, if the second * symbol is INFIX_LEFT, then we try to parse backward. This * doesn't always work efficiently, for example, with & right * and + left, a&...&a -> a+...+a (symmetric shape) is slow both * forward and backward. To speed things up, the user can include * parentheses, i.e., (a&...&a) -> (a+...+a). */ if (ARITY(start->next->t) == 0) { str = sn_to_str(SYMNUM(start->next->t)); rc = binary_parse_type(str, &prec, &type); backward = (rc && type == INFIX_LEFT); } op = (backward ? end->prev : start->next); while (backward ? op != start : op != end) { if (ARITY(op->t) == 0) { str = sn_to_str(SYMNUM(op->t)); rc = binary_parse_type(str, &prec, &type); /* If "v" is infix, prevent "(v)" from being infix. */ if (rc && prec <= m && !op->parenthesized) { Term t1, t2; int p1 = (type == INFIX || type == INFIX_RIGHT ? prec-1 : prec); int p2 = (type == INFIX || type == INFIX_LEFT ? prec-1 : prec); t1 = terms_to_term(start, op->prev, p1); if (t1 != NULL) { t2 = terms_to_term(op->next, end, p2); if (t2 == NULL) zap_term(t1); else { Term t = get_rigid_term(str, 2); ARG(t,0) = t1; ARG(t,1) = t2; return t; } } } } /* arity 0 */ op = (backward ? op->prev : op->next); } /* while (binary attempts) */ } /* nothing works */ return NULL; } /* start != end */ } /* terms_to_term */ /************* * * next_token() * * This routine is called when it's time to move to the next token. * The current token (including any sb) is deleted. Don't call this * routine if an error is found; instead, set the error message and * return NULL (from whereever you are). * *************/ static void next_token(Tok_pos p) { Token tok = p->tok; p->tok = p->tok->next; if (tok->sb != NULL) zap_string_buf(tok->sb); free_token(tok); } /* next_token */ /* reference for mutual recursion */ static Term toks_to_term(Tok_pos p); /************* * * toks_to_set() * *************/ static Term toks_to_set(Tok_pos p) { p->error_message = "Set parsing is not available (see end of marked string)"; p->start_error = 0; p->end_error = p->tok->buf_pos; return NULL; } /* toks_to_set */ /************* * * make_a_list() * * Prepend, to tail, copies of comma-elements in t. * *************/ static Term make_a_list(Term t, Term tail) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { return listterm_cons(copy_term(t), tail); } else { Term l = make_a_list(ARG(t,1), tail); return make_a_list(ARG(t,0), l); } } /* make_a_list */ /************* * * toks_to_list() * * On entry, current token is [. * On successful exit, current token should be ]. * *************/ static Term toks_to_list(Tok_pos p) { /* Assume current token is "[". */ int start_pos = p->tok->buf_pos; next_token(p); if (p->tok == NULL) { p->error_message = "Extra open bracket \'[\'"; p->start_error = start_pos; p->end_error = -1; return NULL; } else if (p->tok->c == ']') { return get_nil_term(); } else { Term cterm = toks_to_term(p); /* a comma-term */ if (cterm == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || (p->tok->c != ']' && p->tok->c != Cons_char)) { p->error_message = "Character \']\' or \':\' expected in list"; p->start_error = start_pos; p->end_error = p->tok->buf_pos; zap_term(cterm); return NULL; } else if (p->tok->type == TOK_PUNC && p->tok->c == Cons_char) { Term tail; next_token(p); tail = toks_to_term(p); if (tail == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || p->tok->c != ']') { p->error_message = "Character \']\' expected in list"; p->start_error = start_pos; p->end_error = p->tok->buf_pos; zap_term(cterm); zap_term(tail); return NULL; } else { Term list = make_a_list(cterm, tail); zap_term(cterm); return list; } } else { /* current token is ']' */ Term list = make_a_list(cterm, get_nil_term()); zap_term(cterm); return list; } } } /* toks_to_list */ /************* * * toks_to_terms() * *************/ static Pterm toks_to_terms(Tok_pos p) { Term t; BOOL done = FALSE; BOOL error = FALSE; BOOL parenthesized; Pterm first = NULL; Pterm last = NULL; Pterm new; int start_pos; while (!done && !error) { parenthesized = FALSE; t = NULL; start_pos = p->tok->buf_pos; if (p->tok->type == TOK_ORDINARY || p->tok->type == TOK_SPECIAL || p->tok->type == TOK_STRING ) { char *str = sb_to_malloc_string(p->tok->sb); t = get_rigid_term(str, 0); free(str); } else if (p->tok->type == TOK_PUNC && p->tok->c == ',') { /* Special case: comma is both punctuation and operator. */ t = get_rigid_term(",", 0); } else if (p->tok->type == TOK_PUNC) { if (p->tok->c == '(') { next_token(p); if (p->tok == NULL) { p->error_message = "Extra open parenthesis"; p->start_error = start_pos; p->end_error = -1; error = TRUE; } else { t = toks_to_term(p); if (t == NULL) error = TRUE; else if (p->tok == NULL || p->tok->c != ')') { p->error_message = "Closing parenthesis expected"; p->start_error = start_pos; p->end_error = (p->tok ? p->tok->buf_pos : -1); zap_term(t); t = NULL; error = TRUE; } else parenthesized = TRUE; } } else if (p->tok->c == '[') { t = toks_to_list(p); error = (t == NULL); } else if (p->tok->c == '{') { t = toks_to_set(p); error = (t == NULL); } else { /* bad punctuation */ p->error_message = "Unexpected character (see end of marked string)"; p->start_error = 0; /* mark whole string */ p->end_error = p->tok->buf_pos; error = TRUE; } } else if (p->tok->type == TOK_COMMENT) { ; /* do nothing */ } else if (p->tok->type == TOK_UNKNOWN) { p->error_message = "Unexpected character (see end of marked string)"; p->start_error = 0; /* mark whole string */ p->end_error = p->tok->buf_pos; error = TRUE; } if (t != NULL) { /* Add a node to the terms list. */ new = get_pterm(); new->prev = last; if (first == NULL) first = new; else last->next = new; new->t = t; new->parenthesized = parenthesized; last = new; } if (!error) { /* */ next_token(p); if (p->tok == NULL) done = TRUE; else if(p->tok->type == TOK_PUNC && (p->tok->c == ')' || p->tok->c == ']' || p->tok->c == '}' || p->tok->c == Cons_char)) done = TRUE; } } /* while */ if (error) { free_pterm_list(first); return NULL; } else return first; } /* toks_to_terms */ /************* * * toks_to_term() * *************/ static Term toks_to_term(Tok_pos p) { Term t; int start_pos = p->tok->buf_pos; Pterm terms = toks_to_terms(p); if (terms == NULL) t = NULL; else { Pterm end; for (end = terms; end->next != NULL; end = end->next); t = terms_to_term(terms, end, 1000); free_pterm_list(terms); if (t == NULL) { p->error_message = "A term cannot be constructed from the marked string"; p->start_error = start_pos; p->end_error = (p->tok ? p->tok->buf_pos-1 : -1); } } return t; } /* toks_to_term */ /************* * * fprint_parse_error() * * This routine prints an error message, pointing to a * substring of a String_buf. * * (There is a similar routine that points to a whole term.) * *************/ static void fprint_parse_error(FILE *fp, char *msg, String_buf sb, int start_pos, int end_pos) { int i; int n = sb_size(sb); if (end_pos == -1) end_pos = n-1; fprintf(fp, "%%%%ERROR: %s:\n\n", msg); for (i = 0; i < start_pos; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, "%%%%START ERROR%%%%"); for (i = start_pos; i <= end_pos; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, "%%%%END ERROR%%%%"); for (i = end_pos+1; i < n; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, "\n"); } /* fprint_parse_error */ /************* * * sread_term() * *************/ /* DOCUMENTATION This routine reads a term (from String_buf *sb). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term sread_term(String_buf sb, FILE *fout) { Token tokens; Term t; struct tok_pos tp; tokens = tokenize(sb); if (tokens == NULL) { fprint_parse_error(fout, "Empty term (too many periods?)", sb, 0, sb_size(sb)-1); free_token_list(tokens); fatal_error("sread_term, empty term (too many periods?)"); } tp.tok = tokens; tp.error_message = ""; tp.start_error = 0; tp.end_error = 0; /* index of last char (not like python) */ t = toks_to_term(&tp); if (t == NULL) { fprint_parse_error(fout, tp.error_message, sb, tp.start_error, tp.end_error); free_token_list(tp.tok); fatal_error("sread_term error"); } else if (tp.tok != NULL) { fprint_parse_error(fout, "Unexpected character (extra closing parenthesis?)", sb, 0, tp.tok->buf_pos); free_token_list(tp.tok); fatal_error("sread_term error"); } return t; } /* sread_term */ /************* * * read_term() * *************/ /* DOCUMENTATION This routine reads a term (from FILE *fin). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term read_term(FILE *fin, FILE *fout) { Read_rc rc; String_buf sb = get_string_buf(); rc = read_buf(fin, sb); if (rc == READ_BUF_EOF) { zap_string_buf(sb); return NULL; } else if (rc != READ_BUF_OK) { char *msg; switch (rc) { case READ_BUF_ERROR: msg = "Unexpected end of input (missing period?)"; break; case READ_BUF_QUOTE_ERROR: msg = "Quoted string has no end"; break; default: msg = "Error reading term"; break; } fprint_parse_error(fout, msg, sb, 0, sb_size(sb)); zap_string_buf(sb); fatal_error("read_term error"); return NULL; /* to please the complier */ } else { Term t = sread_term(sb, fout); zap_string_buf(sb); if (Translate_neg_equalities) t = translate_neg_eq(t); return t; } } /* read_term */ /************* * * parse_term_from_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term parse_term_from_string(char *s) { String_buf sb = init_string_buf(s); Term t = sread_term(sb, stdout); zap_string_buf(sb); return t; } /* parse_term_from_string */ /************* * * arrange_term() * *************/ static void arrange_term(String_buf sb, Term t, int par_prec) { if (t == NULL) sb_append(sb, "arrange_term gets NULL term"); else if (VARIABLE(t)) { char str[100]; symbol_for_variable(str, VARNUM(t)); sb_append(sb, str); } /* variable */ else if (CONSTANT(t)) { if (nil_term(t)) sb_append(sb, "[]"); else sb_append(sb, sn_to_str(SYMNUM(t))); } /* constant */ else if (is_term(t, quant_sym(), 3)) { /* This may insert more parentheses than necessary, to avoid confusing formulas like "all x p | q". That formula means "(all x p) | q", and we insert those parentheses. Also, we print "(all x all y p)" instead of "(all x (all y p))", by handling a sequence of quantifier iteratively instead of recursively. */ Term q = t; sb_append(sb, "("); do { arrange_term(sb, ARG(q,0), 1000); /* quantifier */ sb_append(sb, " "); arrange_term(sb, ARG(q,1), 1000); /* variable */ sb_append(sb, " "); q = ARG(q,2); } while (is_term(q, quant_sym(), 3)); arrange_term(sb, q, Quantifier_precedence); sb_append(sb, ")"); } /* quantified */ else if (cons_term(t)) { Term t1 = t; sb_append(sb, "["); while (cons_term(t1)) { arrange_term(sb, ARG(t1,0), 1000); t1 = ARG(t1,1); if (cons_term(t1)) sb_append(sb, ","); } if (!nil_term(t1)) { sb_append(sb, ":"); arrange_term(sb, t1, 1000); } sb_append(sb, "]"); } /* cons_term */ else { Parsetype type; int op_prec; if (ARITY(t) == 2 && binary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = (type == INFIX || type == INFIX_RIGHT ? op_prec-1 : op_prec); int p2 = (type == INFIX || type == INFIX_LEFT ? op_prec-1 : op_prec); if (op_prec > par_prec || Parenthesize) sb_append(sb, "("); arrange_term(sb, ARG(t,0), p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, ARG(t,1), p2); if (op_prec > par_prec || Parenthesize) sb_append(sb, ")"); } /* binary infix */ else if (ARITY(t) == 1 && unary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = ((type == PREFIX_PAREN || type == POSTFIX_PAREN) ? op_prec-1 : op_prec); if (op_prec > par_prec || Parenthesize) sb_append(sb, "("); if (type == PREFIX_PAREN || type == PREFIX) { sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, ARG(t,0), p1); } /* prefix */ else { arrange_term(sb, ARG(t,0), p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); } /* postfix */ if (op_prec > par_prec || Parenthesize) sb_append(sb, ")"); } /* unary prefix or postfix */ else { /* ordinary application */ int i; sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, "("); for (i = 0; i < ARITY(t); i++) { arrange_term(sb, ARG(t,i), 1000); if (i < ARITY(t)-1) sb_append(sb, ","); } sb_append(sb, ")"); } /* ordinary application */ } } /* arrange_term */ /************* * * sb_remove_some_space() * *************/ static void sb_remove_some_space(String_buf sb, int begin, int end) { int i; BOOL in_quote = FALSE; for (i = begin; i < end-1; i++) { char c = sb_char(sb, i); if (quote_char(c)) in_quote = !in_quote; else if (!in_quote && sb_char(sb, i) == ' ') { if (sb_char(sb, i-1) == '-') { if (!special_char(sb_char(sb, i-2))) sb_replace_char(sb, i, '\0'); } else if (sb_char(sb, i+1) == '\'') { if (!special_char(sb_char(sb, i+2))) sb_replace_char(sb, i, '\0'); } } } } /* sb_remove_some_space */ /************* * * sb_write_term() * *************/ /* DOCUMENTATION This routine prints a term to a String_buf in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void sb_write_term(String_buf sb, Term t) { int begin = sb_size(sb) + 1; int end; if (Translate_neg_equalities) { Term temp_term = untranslate_neg_eq(copy_term(t)); arrange_term(sb, temp_term, 1000); zap_term(temp_term); } else arrange_term(sb, t, 1000); end = sb_size(sb)+1; sb_remove_some_space(sb, begin, end); } /* sb_write_term */ /************* * * fwrite_term() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term(FILE *fp, Term t) { String_buf sb = get_string_buf(); sb_write_term(sb, t); fprint_sb(fp, sb); zap_string_buf(sb); } /* fwrite_term */ /************* * * fwrite_term_nl() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. Also printed is ".\n".

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term_nl(FILE *fp, Term t) { fwrite_term(fp, t); fprintf(fp, ".\n"); } /* fwrite_term_nl */ /************* * * process_quoted_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *process_quoted_symbol(char *str) { if (quote_char(*str)) { int sn; char *str2 = new_str_copy(str); str2[strlen(str2)-1] = '\0'; str2 = str2+1; /* str2 is nwo quote-free. */ sn = str_to_sn(str2, 0); /* Inserts a copy into the symbol table. */ /* Free what was returned from new_str_copy above. */ free(str2-1); /* Get the quote-free string out of the symbol table. */ str2 = sn_to_str(sn); return str2; } else return str; } /* process_quoted_symbol */ /************* * * remember_multiple_char_special_syms() * *************/ static void remember_multiple_char_special_syms(char *str) { /* If string is multiple-char-special, add it to a global list (which is used for parsing). */ if (special_char(*str) && strlen(str) > 1 && !string_member_plist(str, Multiple_char_special_syms)) { Multiple_char_special_syms = plist_prepend(Multiple_char_special_syms, str); } } /* remember_multiple_char_special_syms */ /************* * * forget_multiple_char_special_syms() * *************/ static void forget_multiple_char_special_syms(char *str) { /* If string is multiple-char-special, add it to a global list (which is used for parsing). */ if (special_char(*str) && strlen(str) > 1 && string_member_plist(str, Multiple_char_special_syms)) { Multiple_char_special_syms = plist_remove_string(Multiple_char_special_syms, str); } } /* forget_multiple_char_special_syms */ /************* * * look_for_illegal_symbols() * *************/ static void look_for_illegal_symbols(char *str) { if (strlen(str) > 1 && string_of_repeated('-', str)) { printf("bad string: %s\n", str); fatal_error("operations that are strings of repeated \"-\" are not allowed"); } else if (strlen(str) > 1 && string_of_repeated('\'', str)) fatal_error("operations that are strings of repeated \"\'\" are not allowed"); } /* look_for_illegal_symbols */ /************* * * declare_parse_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_parse_type(char *str, int precedence, Parsetype type) { char *str2 = process_quoted_symbol(str); /* if quoted, remove quotes */ if (Check_for_illegal_symbols) look_for_illegal_symbols(str2); set_parse_type(str2, precedence, type); if (type == NOTHING_SPECIAL) forget_multiple_char_special_syms(str2); else remember_multiple_char_special_syms(str2); } /* declare_parse_type */ /************* * * declare_quantifier_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_quantifier_precedence(int prec) { Quantifier_precedence = prec; } /* declare_quantifier_precedence */ /************* * * declare_standard_parse_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_standard_parse_types(void) { declare_parse_type(",", 999, INFIX_RIGHT); /* essential */ declare_parse_type(attrib_sym(), 810, INFIX_RIGHT); declare_parse_type(iff_sym(), 800, INFIX); declare_parse_type(imp_sym(), 800, INFIX); declare_parse_type(impby_sym(),800, INFIX); declare_parse_type(or_sym(), 790, INFIX_RIGHT); declare_parse_type("||", 790, INFIX_RIGHT); /* special-purpose */ declare_parse_type(and_sym(), 780, INFIX_RIGHT); declare_parse_type("&&", 780, INFIX_RIGHT); /* special-purpose */ declare_quantifier_precedence(750); /* special case for quantifiers */ declare_parse_type(eq_sym(), 700, INFIX); declare_parse_type(neq_sym(), 700, INFIX); declare_parse_type("==", 700, INFIX); declare_parse_type("!==", 700, INFIX); declare_parse_type("<", 700, INFIX); declare_parse_type("<=", 700, INFIX); declare_parse_type(">", 700, INFIX); declare_parse_type(">=", 700, INFIX); declare_parse_type("@<", 700, INFIX); declare_parse_type("@<=", 700, INFIX); declare_parse_type("@>", 700, INFIX); declare_parse_type("@>=", 700, INFIX); declare_parse_type("+", 500, INFIX); declare_parse_type("*", 500, INFIX); declare_parse_type("@", 500, INFIX); declare_parse_type("/", 500, INFIX); declare_parse_type("\\", 500, INFIX); declare_parse_type("^", 500, INFIX); declare_parse_type("v", 500, INFIX); declare_parse_type(not_sym(), 350, PREFIX); declare_parse_type("\'", 300, POSTFIX); /* Other things */ set_cons_char(':'); /* List cons, as in [x:y] */ } /* declare_standard_parse_types */ /************* * * redeclare_symbol_and_copy_parsetype() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL redeclare_symbol_and_copy_parsetype(char *operation, char *str, BOOL echo, FILE *fout) { char *new_str = process_quoted_symbol(str); /* if quoted, remove quotes */ if (symbol_in_use(new_str)) return FALSE; else { Parsetype type; int prec; char *old_str = get_operation_symbol(operation); set_operation_symbol(operation, new_str); remember_multiple_char_special_syms(new_str); /* for subsequent parsing */ if (unary_parse_type(old_str, &prec, &type) || binary_parse_type(old_str, &prec, &type)) { set_parse_type(new_str, prec, type); if (echo) { fprintf(fout, " %% op(%d, %s, %s). %% copying parse/print properties" " from %s to %s\n", prec, parse_type_to_str(type), new_str, old_str, new_str); } } return TRUE; /* success */ } } /* redeclare_symbol_and_copy_parsetype */ /************* * * skip_to_nl() * *************/ /* DOCUMENTATION Read characters up to the first newline (or EOF). */ /* PUBLIC */ void skip_to_nl(FILE *fp) { int c = fgetc(fp); while (c != EOF && c != '\n') c = fgetc(fp); } /* skip_to_nl */ /************* * * split_string() * *************/ /* DOCUMENTATION This splits a string of symbols, separated by whitespace, into a list of strings. A Plist of (malloced) strings is returned. */ /* PUBLIC */ Plist split_string(char *onlys) { Plist p = NULL; char *work = malloc(strlen(onlys)+1); int len = strlen(onlys); int i = 0; while (i < len) { while (i < len && white_char(onlys[i])) i++; if (i < len) { int j = 0; while (i < len && !white_char(onlys[i])) work[j++] = onlys[i++]; work[j] = '\0'; p = plist_append(p, new_str_copy(work)); } } free(work); return p; } /* split_string */ /************* * * set_cons_char() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_cons_char(char c) { Cons_char = c; } /* set_cons_char */ /************* * * get_cons_char() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char get_cons_char(void) { return Cons_char; } /* set_cons_char */ /************* * * set_quote_char() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_quote_char(char c) { Quote_char = c; } /* set_quote_char */ /************* * * get_quote_char() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char get_quote_char(void) { return Quote_char; } /* set_quote_char */ /************* * * parenthesize() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void parenthesize(BOOL setting) { Parenthesize = setting; } /* parenthesize */ /************* * * check_for_illegal_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void check_for_illegal_symbols(BOOL setting) { Check_for_illegal_symbols = setting; } /* check_for_illegal_symbols */ /************* * * simple_parse() * *************/ /* DOCUMENTATION Do not try to parse "op command" symbols. */ /* PUBLIC */ void simple_parse(BOOL setting) { Simple_parse = setting; } /* simple_parse */ LADR-2009-11A/ladr/clausify.c0000644000175000017500000001311311136170730014721 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clausify.h" /* Private definitions and types */ /************* * * formula_to_literal() * *************/ /* DOCUMENTATION This routine takes a Formula f and returns a Literals representation. If the formula is not an ATOM_FORM or the negation of an ATOM_FORM, NULL is returned.

The returned literal is an entirely new copy, and the given formula is not changed. */ /* PUBLIC */ Literals formula_to_literal(Formula f) { if (f->type == NOT_FORM && f->kids[0]->type == ATOM_FORM) return new_literal(FALSE, copy_term(f->kids[0]->atom)); else if (f->type == ATOM_FORM) return new_literal(TRUE, copy_term(f->atom)); else return NULL; } /* formula_to_literal */ /************* * * formula_to_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals formula_to_literals(Formula f) { Literals lits = NULL; if (f->type == ATOM_FORM || f->type == NOT_FORM) lits = append_literal(lits, formula_to_literal(f)); else if (f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) lits = append_literal(lits,formula_to_literal(f->kids[i])); } else { fatal_error("formula_to_literals, formula not ATOM, NOT, or OR"); } return lits; } /* formula_to_literals */ /************* * * formula_to_clause() * *************/ /* DOCUMENTATION This routine takes a Formula f and returns a Topform representation. If f is not an atom, literal, or disjunction of literals, the returned clause will be NULL or not well formed.

The returned clause is an entirely new copy, and the given formula is not changed. */ /* PUBLIC */ Topform formula_to_clause(Formula f) { Topform c = get_topform(); c->literals = formula_to_literals(f); upward_clause_links(c); return c; } /* formula_to_clause */ /************* * * formula_to_clauses() * *************/ /* DOCUMENTATION This routine takes a Formula f and returns a Plist of clauses representation. If f is not an atom, literal, or disjunction of literals, or a conjunction of those things, the clauses in the returned list may be NULL or not well formed.

The returned clauses are entirely new copies, and the given formula is not changed. */ /* PUBLIC */ Plist formula_to_clauses(Formula f) { Plist lst = NULL; if (f->type == AND_FORM) { int i; for (i = 0; i < f->arity; i++) lst = plist_append(lst, formula_to_clause(f->kids[i])); } else if (f->type == OR_FORM || f->type == NOT_FORM || f->type == ATOM_FORM) lst = plist_append(lst, formula_to_clause(f)); return lst; } /* formula_to_clauses */ /************* * * clausify_formula() * *************/ /* DOCUMENTATION This routine translates a Formula f into a Plist of clauses. The translation includes Skolemization, so the result should be unsatisfiable iff f is unsatisfiable. The variables in each clause are renumbered. If there are more than MAX_VARS variables in a clause, a fatal error occurs.

Formula f is not changed. */ /* PUBLIC */ Plist clausify_formula(Formula f) { Formula g; Plist clauses, p; g = clausify_prepare(formula_copy(f)); clauses = formula_to_clauses(g); for (p = clauses; p; p = p->next) { Topform c = p->v; renumber_variables(c, MAX_VARS); } zap_formula(g); return clauses; } /* clausify_formula */ /************* * * vars_to_names() * *************/ static Term vars_to_names(Term t) { if (VARIABLE(t)) { Term a; char *s1 = malloc(25); char *s2 = malloc(25); Variable_style v = variable_style(); s2 = int_to_str(VARNUM(t), s2, 25); switch (v) { case INTEGER_STYLE: s1 = strcpy(s1, ""); break; case STANDARD_STYLE: s1 = strcpy(s1, "var_"); break; case PROLOG_STYLE: s1 = strcpy(s1, "VAR_"); break; } s1 = strcat(s1, s2); a = get_rigid_term(s1, 0); free_term(t); free(s1); free(s2); return a; } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = vars_to_names(ARG(t,i)); return t; } } /* vars_to_names */ /************* * * literal_to_formula() * *************/ static Formula literal_to_formula(Literals lit) { Formula a = formula_get(0, ATOM_FORM); a->atom = vars_to_names(copy_term(lit->atom)); if (lit->sign) return a; else { Formula n = formula_get(1, NOT_FORM); n->kids[0] = a; return n; } } /* literal_to_formula */ /************* * * clause_to_formula() * *************/ /* DOCUMENTATION Return an entirely new formula. */ /* PUBLIC */ Formula clause_to_formula(Topform c) { if (c->literals == NULL) { Formula f = formula_get(0, ATOM_FORM); f->atom = get_rigid_term(false_sym(), 0); return f; } else { Literals lit; int i; Formula f = formula_get(number_of_literals(c->literals), OR_FORM); for (lit = c->literals, i = 0; lit; lit = lit->next, i++) { f->kids[i] = literal_to_formula(lit); } return f; } } /* clause_to_formula */ LADR-2009-11A/ladr/term.h0000644000175000017500000001701211151265363014064 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TERM_H #define TP_TERM_H #include "symbols.h" /* INTRODUCTION The Term data structure is designed mainly to represent first-order untyped terms. It is generally used for atoms as well, because the indexing and unification methods don't care whether an object is a term or an atom.

No term structure sharing is supported at this level of abstraction. (Higher-level packagers can build terms with shared structure if they wish.) Because we envision applications with tens of millions of terms, small size for the individual nodes is important. So we have some overloaded fields, and macros are provided to get some of the information from from term nodes.

There are three types of term, and the Boolean macros VARIABLE(t), CONSTANT(t), and COMPLEX(t) should be used to find out what type a term is. If you have a CONSTANT or COMPLEX term t, you can get its symbol id with SYMNUM(t) (from which you can get other information about the symbol such as the print string and any special properties). If you have a variable t, you can get its index with VARNUM(t), which is a signed integral type in the range [0..MAX_VAR]. Warning: MAX_VAR is a big number---a higher-level unification package will typically have a much smaller MAX_VARS defined for array sizes, because it does array indexing with VARNUM(t).

The macro ARITY(t) gets the arity of a term (constants and variables have arity 0), and ARG(t,i) gets the i-th argument (counting from 0) of a term. When using ARG(t,i), make sure that i is in range [0..ARITY(t)-1], because ARG does not check.

Here is an example of recursing through a term.

int symbol_count(Term t)
{
  int count = 0;
  int i;
  for (i = 0; i < ARITY(t); i++)
    count += symbol_count(ARG(t,i));
  return count+1;
}
*/ /* Public definitions */ #define MAX_VARS 100 /* max number of (distinct) variables per term */ #define MAX_VNUM 5000 /* maximum variable ID, for array of vars */ #define MAX_VAR INT_MAX /* max var ID that fits in sym field of term */ #define MAX_SYM INT_MAX /* max ID of any rigid symbol */ #define MAX_ARITY UCHAR_MAX /* max arity of any term (don't make this big) */ #define FLAGS_TYPE unsigned char /* for private_flags field of Term */ typedef struct term * Term; /* Term is a pointer to a term struct */ struct term { int private_symbol; /* const/func/pred/var symbol ID */ unsigned char arity; /* number of auguments */ FLAGS_TYPE private_flags; /* for marking terms in various ways */ Term *args; /* array (size arity) of pointers to args */ void *container; /* containing object */ union { unsigned id; /* unique ID, probably for FPA indexing */ void *vp; /* auxiliary pointer */ } u; }; /* to check type of term */ #define VARIABLE(t) ((t)->private_symbol >= 0) #define CONSTANT(t) ((t)->private_symbol < 0 && (t)->arity == 0) #define COMPLEX(t) ((t)->private_symbol < 0 && (t)->arity > 0) /* to get symbol ID from a CONSTANT or COMPLEX term */ #define SYMNUM(t) (-((t)->private_symbol)) /* to get the variable number of a VARIABLE term */ #define VARNUM(t) ((t)->private_symbol) /* to get the arity of a term (VARIABLE terms have arity 0) */ #define ARITY(t) ((t)->arity) /* to get the i-th argument of a term (make sure i is in [0..arity-1]) */ #define ARG(t,i) ((t)->args[i]) /* to get the array of arguments */ #define ARGS(t) ((t)->args) /* End of public definitions */ /* Public function prototypes from term.c */ void free_term(Term p); void fprint_term_mem(FILE *fp, BOOL heading); void p_term_mem(void); Term get_variable_term(int var_num); Term get_rigid_term_like(Term t); Term get_rigid_term(char *sym, int arity); Term get_rigid_term_dangerously(int symnum, int arity); void zap_term(Term t); BOOL term_ident(Term t1, Term t2); Term copy_term(Term t); BOOL ground_term(Term t); int biggest_variable(Term t); int term_depth(Term t); int symbol_count(Term t); BOOL occurs_in(Term t1, Term t2); void fprint_term(FILE *fp, Term t); void sprint_term(String_buf sb, Term t); char *term_to_string(Term t); void p_term(Term t); BOOL all_args_vars(Term t); Term build_binary_term(int sn, Term a1, Term a2); Term build_binary_term_safe(char *str, Term a1, Term a2); Term build_unary_term(int sn, Term a); Term build_unary_term_safe(char *str, Term a); Term subst_term(Term t, Term target, Term replacement); Term subst_var_term(Term t, int symnum, int varnum); int greatest_variable(Term t); int greatest_symnum_in_term(Term t); void upward_term_links(Term t, void *p); BOOL check_upward_term_links(Term t, void *p); int occurrences(Term t, Term target); void term_set_variables(Term t, int max_vars); Term nat_to_term(int n); Term int_to_term(int i); Term bool_to_term(BOOL val); Term double_to_term(double d); int natural_constant_term(Term t); int arg_position(Term parent, Term child); BOOL is_term(Term t, char *str, int arity); BOOL is_constant(Term t, char *str); char *term_symbol(Term t); BOOL term_to_int(Term t, int *result); BOOL term_to_double(Term t, double *result); BOOL term_to_number(Term t, double *result); BOOL true_term(Term t); BOOL false_term(Term t); BOOL term_to_bool(Term t, BOOL *result); I2list symbols_in_term(Term t, I2list g); Ilist fsym_set_in_term(Term t); Term renum_vars_recurse(Term t, int vmap[], int max_vars); Term set_vars_recurse(Term t, char *vnames[], int max_vars); I2list multiset_of_vars(Term t, I2list vars); I2list multiset_vars(Term t); Plist set_of_vars(Term t, Plist vars); Plist set_of_variables(Term t); int number_of_vars_in_term(Term t); Ilist set_of_ivars(Term t, Ilist ivars); Ilist set_of_ivariables(Term t); BOOL variables_subset(Term t1, Term t2); BOOL variables_multisubset(Term a, Term b); Term term_at_pos(Term t, Ilist pos); Ilist position_of_subterm(Term t, Term subterm); int symbol_occurrences(Term t, int symnum); BOOL args_distinct_vars(Term t); unsigned hash_term(Term t); BOOL skolem_term(Term t); BOOL contains_skolem_term(Term t); BOOL contains_skolem_function(Term t); Term term0(char *sym); Term term1(char *sym, Term arg); Term term2(char *sym, Term arg1, Term arg2); BOOL symbol_in_term(int symnum, Term t); BOOL same_structure(Term a, Term b); Plist copy_plist_of_terms(Plist terms); void zap_plist_of_terms(Plist lst); BOOL eq_term(Term a); Plist plist_of_subterms(Term t); BOOL tlist_member(Term t, Plist lst); int position_of_term_in_tlist(Term t, Plist lst); BOOL tlist_subset(Plist a, Plist b); BOOL tlist_set(Plist a); Plist free_vars_term(Term t, Plist vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/tptp_trans.h0000644000175000017500000000274111151265364015317 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TPTP_TRANS_H #define TP_TPTP_TRANS_H #include "ioutil.h" #include "clausify.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from tptp_trans.c */ void declare_tptp_input_types(void); void declare_tptp_output_types(void); Formula tptp_input_to_ladr_formula(Term t); Plist ladr_list_to_tptp_list(Plist in, char *name, char *type); Ilist syms_in_form(Term t, BOOL clausal); I2list map_for_bad_tptp_syms(Ilist syms, BOOL quote_bad_syms); I2list map_for_bad_ladr_syms(Ilist syms, BOOL quote_bad_syms); Term replace_bad_syms_term(Term t, I2list map); Term replace_bad_tptp_syms_form(Term t, BOOL clausal, I2list map); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/xproofs.c0000644000175000017500000003705411010671370014611 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "xproofs.h" #include "demod.h" /* #define DEBUG_EXPAND */ /* Private definitions and types */ /************* * * check_parents_and_uplinks_in_proof() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void check_parents_and_uplinks_in_proof(Plist proof) { Ilist seen = NULL; Plist p; for (p = proof; p; p = p->next) { Topform c = p->v; Ilist parents = get_parents(c->justification, FALSE); if (!check_upward_clause_links(c)) { printf("bad uplinks: "); fprint_clause(stdout, c); fatal_error("check_parents_and_uplinks_in_proof, bad uplinks"); } if (!ilist_subset(parents, seen)) { printf("seen: "); p_ilist(seen); printf("parents: "); p_ilist(parents); fatal_error("check_parents_and_uplinks_in_proof, parents not seen"); } seen = ilist_prepend(seen, c->id); zap_ilist(parents); } zap_ilist(seen); } /* check_parents_and_uplinks_in_proof */ /************* * * xx_res2() * *************/ static Topform xx_res2(Topform c, int n) { Literals lit = ith_literal(c->literals, n); if (lit == NULL || lit->sign == TRUE || !eq_term(lit->atom)) return NULL; else { Context subst = get_context(); Trail tr = NULL; Topform res; if (unify(ARG(lit->atom,0), subst, ARG(lit->atom,1), subst, &tr)) { Literals l2; res = get_topform(); for (l2 = c->literals; l2; l2 = l2->next) if (l2 != lit) res->literals = append_literal(res->literals, apply_lit(l2, subst)); res->attributes = cat_att(res->attributes, inheritable_att_instances(c->attributes, subst)); res->justification = xxres_just(c, n); upward_clause_links(res); renumber_variables(res, MAX_VARS); undo_subst(tr); } else { res = NULL; } free_context(subst); return res; } } /* xx_res2 */ /************* * * xx_simp2() * *************/ static void xx_simp2(Topform c, int n) { Literals lit = ith_literal(c->literals, n); Term a = lit->atom; if ((!lit->sign && eq_term(a) && term_ident(ARG(a,0), ARG(a,1))) || eq_removable_literal(c, lit)) { zap_term(lit->atom); lit->atom = NULL; c->literals = remove_null_literals(c->literals); c->justification = append_just(c->justification, xx_just(n)); } else { printf("\nERROR, literal %d in clause cannot be removed: ", n); fprint_clause(stdout, c); fatal_error("xx_simp2, bad literal"); } } /* xx_simp2 */ /************* * * factor() * *************/ static Topform factor(Topform c, int n1, int n2) { Topform fac; Literals l1 = ith_literal(c->literals, n1); Literals l2 = ith_literal(c->literals, n2); Context subst = get_context(); Trail tr = NULL; if (l1->sign == l2->sign && unify(l1->atom, subst, l2->atom, subst, &tr)) { Literals lit; fac = get_topform(); for (lit = c->literals; lit; lit = lit->next) if (lit != l2) fac->literals = append_literal(fac->literals, apply_lit(lit, subst)); fac->attributes = cat_att(fac->attributes, inheritable_att_instances(c->attributes, subst)); fac->justification = factor_just(c, n1, n2); upward_clause_links(fac); renumber_variables(fac, MAX_VARS); undo_subst(tr); } else fac = NULL; free_context(subst); return fac; } /* factor */ /************* * * merge1() * *************/ static void merge1(Topform c, int n) { Literals target = ith_literal(c->literals, n); Literals prev = ith_literal(c->literals, n-1); Literals lit = c->literals; BOOL go = TRUE; while (go) { if (lit->sign == target->sign && term_ident(lit->atom, target->atom)) go = FALSE; else lit = lit->next; } if (lit == target) fatal_error("merge1, literal does not merge"); prev->next = target->next; zap_literal(target); c->justification = append_just(c->justification, merge_just(n)); } /* merge1 */ /************* * * proof_id_to_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform proof_id_to_clause(Plist proof, int id) { Plist p = proof; while (p && ((Topform) p->v)->id != id) p = p->next; if (p == NULL) return NULL; else return p->v; } /* proof_id_to_clause */ /************* * * greatest_id_in_proof() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int greatest_id_in_proof(Plist proof) { if (proof == NULL) return INT_MIN; else { int x = greatest_id_in_proof(proof->next); Topform c = proof->v; return (c->id > x ? c->id : x); } } /* greatest_id_in_proof */ /************* * * expand_proof() * *************/ /* DOCUMENTATION Given a proof, return a more detailed proof, entirely new, leaving the given proof unchanged. Also returned is an I3list mapping new IDs to pairs . The n compnent identifies the sub-steps arising from the expansions, e.g., 66 -> <23,4> means that step 66 in the new proof corresponds to the 4th substep in expanding step 23 of the old proof. Clauses in the new proof that match clauses in the old proof retain the IDs from the old proof, and there is no entry in the map for them. */ /* PUBLIC */ Plist expand_proof(Plist proof, I3list *pmap) { Plist new_proof = NULL; /* build it backward, reverse at end */ I3list map = NULL; /* map new IDs to for intermediate steps */ int old_id, old_id_n; /* for mapping new steps to old */ int next_id; Plist p; /* Start numbering the new proof where the old one ends. */ next_id = greatest_id_in_proof(proof) + 1; for (p = proof; p; p = p->next) { Topform c = p->v; /* the clause we're expanding */ Topform current = NULL; /* by substeps, this becomes identical to c */ Just j; j = c->justification; old_id = c->id; old_id_n = 0; /* this counts substeps of the expansion */ #ifdef DEBUG_EXPAND printf("\nexpanding: "); fprint_clause(stdout, c); #endif if (j->next == NULL && j->type != HYPER_RES_JUST && j->type != UR_RES_JUST) { /* No expansion is necessary for this step. We take a shortcut by just copying the clause. */ current = copy_clause_ija(c); new_proof = plist_prepend(new_proof, current); /* The next 2 steps get undone below. They are performed here so that the state is consistent with the cases in which some expansion occurs. */ map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; } else { /* To adjust literal numbers when literals disappear. */ int merges = 0; int unit_deletes = 0; int xx_simplify = 0; /* primary inference */ if (j->type == COPY_JUST || j->type == BACK_DEMOD_JUST || j->type == PROPOSITIONAL_JUST || j->type == BACK_UNIT_DEL_JUST) { /* Note that we get "current" directly from the new proof. This prevents an unnecessary "copy" inference. This assumes there is some secondary justification. */ current = proof_id_to_clause(new_proof, j->u.id); } else if (j->type == HYPER_RES_JUST || j->type == UR_RES_JUST || j->type == BINARY_RES_JUST) { /* c ncn ncn ncn ... (length is 3m+1) */ Ilist p = j->u.lst; Topform c1 = proof_id_to_clause(proof, p->i); int j = 0; /* literals resolved; subtract from nucleus position */ p = p->next; while (p != NULL) { Topform resolvent; int n1 = p->i - j; /* literal number in c1 */ int sat_id = p->next->i; if (sat_id == 0) resolvent = xx_resolve2(c1, n1, TRUE); else { Topform c2 = proof_id_to_clause(proof, sat_id); int n2 = p->next->next->i; resolvent = resolve2(c1, n1, c2, n2, TRUE); if (resolvent == NULL) { printf("Lit %d: ",n1); fprint_clause(stdout, c1); printf("Lit %d: ",n2); fprint_clause(stdout, c2); fatal_error("expand_step, clauses don't resolve"); } } map = alist2_insert(map, next_id, old_id, old_id_n++); resolvent->id = next_id++; new_proof = plist_prepend(new_proof, resolvent); c1 = resolvent; j++; p = p->next->next->next; } current = c1; } else if (j->type == PARA_JUST) { Topform from = proof_id_to_clause(proof, j->u.para->from_id); Topform into = proof_id_to_clause(proof, j->u.para->into_id); Ilist from_pos = j->u.para->from_pos; Ilist into_pos = j->u.para->into_pos; current = para_pos(from, from_pos, into, into_pos); /* does just. */ map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; new_proof = plist_prepend(new_proof, current); } else if (j->type == FACTOR_JUST) { Ilist p = j->u.lst; Topform parent = proof_id_to_clause(proof, p->i); int lit1 = p->next->i; int lit2 = p->next->next->i; current = factor(parent, lit1, lit2); map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; new_proof = plist_prepend(new_proof, current); } else if (j->type == XXRES_JUST) { Ilist p = j->u.lst; Topform parent = proof_id_to_clause(proof, p->i); int lit = p->next->i; current = xx_res2(parent, lit); map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; new_proof = plist_prepend(new_proof, current); } else if (j->type == NEW_SYMBOL_JUST) { Topform parent = proof_id_to_clause(proof, j->u.id); /* Assume EQ unit with right side constant. */ int sn = SYMNUM(ARG(c->literals->atom,1)); current = new_constant(parent, sn); map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; new_proof = plist_prepend(new_proof, current); } else { printf("expand_step, unknown primary justification\n"); new_proof = plist_prepend(new_proof, copy_clause_ija(c)); } #ifdef DEBUG_EXPAND printf("primary: "); fprint_clause(stdout, current); #endif /* secondary inferences */ for (j = j->next; j; j = j->next) { if (j->type == DEMOD_JUST) { /* list of triples: */ I3list p; for (p = j->u.demod; p; p = p->next) { Topform demod = proof_id_to_clause(proof, p->i); int position = p->j; int direction = p->k; Ilist from_pos, into_pos; Topform work = copy_clause(current); map = alist2_insert(map, next_id, old_id, old_id_n++); work->id = next_id++; particular_demod(work, demod, position, direction, &from_pos, &into_pos); work->justification = para_just(PARA_JUST, demod, from_pos, current, into_pos); current = work; new_proof = plist_prepend(new_proof, current); #ifdef DEBUG_EXPAND printf("demod: "); fprint_clause(stdout, current); #endif } } else if (j->type == FLIP_JUST) { Term atom; int n = j->u.id; Topform work = copy_inference(current); current = work; map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; atom = ith_literal(current->literals, n)->atom; if (!eq_term(atom)) fatal_error("expand_step, cannot flip nonequality"); flip_eq(atom, n); /* updates justification */ new_proof = plist_prepend(new_proof, current); #ifdef DEBUG_EXPAND printf("flip: "); fprint_clause(stdout, current); #endif } else if (j->type == MERGE_JUST) { int n = j->u.id - merges; Topform work = copy_inference(current); current = work; map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; merge1(current, n); /* updates justification */ new_proof = plist_prepend(new_proof, current); #ifdef DEBUG_EXPAND printf("merge: "); fprint_clause(stdout, current); #endif merges++; } else if (j->type == UNIT_DEL_JUST) { Ilist p = j->u.lst; int n = p->i - unit_deletes; Topform unit = proof_id_to_clause(proof, p->next->i); Topform work = resolve2(unit, 1,current, n, TRUE); if (work == NULL) { printf("Lit %d: ",n); fprint_clause(stdout, current); printf("Lit %d: ",1); fprint_clause(stdout, unit); fatal_error("expand_step, clauses don't unit_del"); } current = work; map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; new_proof = plist_prepend(new_proof, current); unit_deletes++; #ifdef DEBUG_EXPAND printf("unit_del: "); fprint_clause(stdout, current); #endif } else if (j->type == XX_JUST) { int n = j->u.id - xx_simplify; Topform work = copy_inference(current); current = work; map = alist2_insert(map, next_id, old_id, old_id_n++); current->id = next_id++; xx_simp2(current,n); new_proof = plist_prepend(new_proof, current); xx_simplify++; #ifdef DEBUG_EXPAND printf("xx_simplify: "); fprint_clause(stdout, current); #endif } else { printf("expand_step, unknown secondary justification\n"); new_proof = plist_prepend(new_proof, current); } } renumber_variables(current, MAX_VARS); #ifdef DEBUG_EXPAND printf("secondary: "); fprint_clause(stdout, current); #endif } /* Okay. Now current should be identical to c. */ if (current == c) fatal_error("expand_proof, current == c"); else if (!clause_ident(current->literals, c->literals)) { fprint_clause(stdout, c); fprint_clause(stdout, current); fatal_error("expand step, result is not identical"); } else { /* Now we undo the numbering of the last substep (including the cases in which no expansion is done). This is so that the clauses in the expanded proof that match the clauses in the original proof have the same IDs. That is, only the clauses introduced by expansion (e.g., intermedediate demodulants) get new IDs. */ current->id = c->id; next_id--; map = alist2_remove(map, next_id); #ifdef DEBUG_EXPAND printf("end: "); fprint_clause(stdout, current); #endif } /* expand */ } /* process proof step c */ *pmap = map; /* make available to caller */ new_proof = reverse_plist(new_proof); check_parents_and_uplinks_in_proof(new_proof); return new_proof; } /* expand_proof */ /************* * * renumber_proof() * *************/ /* DOCUMENTATION We assume that every clause occurs after its parents. */ /* PUBLIC */ void renumber_proof(Plist proof, int start) { I2list map = NULL; /* map old IDs to new IDs */ int n = start; /* for numbering the steps */ Plist p; for (p = proof; p; p = p->next) { Topform c = p->v; int old_id = c->id; c->id = n++; map_just(c->justification, map); map = alist_insert(map, old_id, c->id); } zap_i2list(map); check_parents_and_uplinks_in_proof(proof); } /* renumber_proof */ /************* * * copy_and_renumber_proof() * *************/ /* DOCUMENTATION We assume that every clause occurs after its parents. */ /* PUBLIC */ Plist copy_and_renumber_proof(Plist proof, int start) { Plist workproof = copy_clauses_ija(proof); renumber_proof(workproof, start); return workproof; } /* copy_and_renumber_proof */ /************* * * proof_to_xproof() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist proof_to_xproof(Plist proof) { I3list map; Plist xproof = expand_proof(proof, &map); return xproof; } /* proof_to_xproof */ LADR-2009-11A/ladr/nonport.c0000644000175000017500000000422110637466322014613 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "nonport.h" #include /* Private definitions and types */ #ifdef PRIMITIVE_ENVIRONMENT /* This means that we don't have some UNIXy things */ #else # include # include #endif /************* * * username() * *************/ /* DOCUMENTATION Return the name of the user who started the current job. */ /* PUBLIC */ char *username(void) { #ifdef PRIMITIVE_ENVIRONMENT return("an unknown user"); #else struct passwd *p; p = getpwuid(getuid()); return(p ? p->pw_name : "???"); #endif } /* username */ /************* * * hostname() * *************/ /* DOCUMENTATION Return the hostname of the computer on which the current job is running. */ /* PUBLIC */ char *hostname(void) { #ifdef PRIMITIVE_ENVIRONMENT return("an unknown computer"); #else static char host[64]; if (gethostname(host, 64) != 0) strcpy(host, "???"); return(host); #endif } /* hostname */ /************* * * my_process_id() * *************/ /* DOCUMENTATION Return the process ID of the current process. */ /* PUBLIC */ int my_process_id(void) { #ifdef PRIMITIVE_ENVIRONMENT return 0; #else return getpid(); #endif } /* my_process_id */ /************* * * get_bits() * *************/ /* DOCUMENTATION If (64-bit long and pointer) return 64, else return 32. */ /* PUBLIC */ int get_bits(void) { return sizeof(long) == 8 && sizeof(void *) == 8 ? 64 : 32; } /* get_bits */ LADR-2009-11A/ladr/fatal.h0000644000175000017500000000223711151265363014207 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FATAL_H #define TP_FATAL_H #include "header.h" /* INTRODUCTION This package is just a few utilities for handling fatal errors. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from fatal.c */ void bell(FILE *fp); int get_fatal_exit_code(); void set_fatal_exit_code(int exit_code); void fatal_error(char *message); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clauses.c~0000644000175000017500000001372410745462134014756 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clauses.h" /* Private definitions and types */ /* * memory management */ /************* * * clause_member_plist() * *************/ /* DOCUMENTATION Is a clause a member of a Plist? A deep identity check is done (clause_ident). */ /* PUBLIC */ Topform clause_member_plist(Plist p, Topform c) { while (p) { Topform d = p->v; if (clause_ident(c->literals, d->literals)) return p->v; p = p->next; } return NULL; } /* clause_member_plist */ /************* * * intersect_clauses() * *************/ /* DOCUMENTATION Intersect 2 Plists of clauses. The order of the result is determined by the order of the first list. A deep identity check is done (clause_ident). */ /* PUBLIC */ Plist intersect_clauses(Plist a, Plist b) { if (a == NULL) return NULL; else { Plist c = intersect_clauses(a->next, b); if (clause_member_plist(b, a->v)) return plist_prepend(c, a->v); else return c; } } /* intersect_clauses */ /************* * * max_clause_weight() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the weight of the heaviest clause. The weight field of the clause is used. */ /* PUBLIC */ int max_clause_weight(Plist p) { if (p == NULL) return INT_MIN; else { int max_rest = max_clause_weight(p->next); Topform c = p->v; return IMAX(c->weight,max_rest); } } /* max_clause_weight */ /************* * * max_clause_symbol_count() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the symbol_count of a clause with most symbols. */ /* PUBLIC */ int max_clause_symbol_count(Plist p) { if (p == NULL) return INT_MIN; else { int max_rest = max_clause_symbol_count(p->next); Topform c = p->v; return IMAX(clause_symbol_count(c->literals), max_rest); } } /* max_clause_symbol_count */ /************* * * nonneg_clauses() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the subset of nonnegative clauses. */ /* PUBLIC */ Plist nonneg_clauses(Plist clauses) { Plist nonneg = NULL; Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; if (!negative_clause(c->literals)) nonneg = plist_append(nonneg, c); } return nonneg; } /* nonneg_clauses */ /************* * * all_clauses_horn() * *************/ /* DOCUMENTATION Is every clause in the Plist a Horn clause? */ /* PUBLIC */ BOOL all_clauses_horn(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!horn_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_horn */ /************* * * all_clauses_unit() * *************/ /* DOCUMENTATION Is every clause in the Plist a unit clause? */ /* PUBLIC */ BOOL all_clauses_unit(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!unit_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_unit */ /************* * * all_clauses_positive() * *************/ /* DOCUMENTATION Is every clause in the Plist a unit clause? */ /* PUBLIC */ BOOL all_clauses_positive(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!positive_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_positive */ /************* * * neg_nonunit_clauses() * *************/ /* DOCUMENTATION How many negative nonunits are in a Plist of clauses? */ /* PUBLIC */ int neg_nonunit_clauses(Plist l) { int n = 0; Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (negative_clause(c->literals) && number_of_literals(c->literals) > 1) n++; } return n; } /* neg_nonunit_clauses */ /************* * * negative_clauses() * *************/ /* DOCUMENTATION How many negative clauses are in a Plist of clauses? */ /* PUBLIC */ int negative_clauses(Plist l) { int n = 0; Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (negative_clause(c->literals)) n++; } return n; } /* negative_clauses */ /************* * * most_literals() * *************/ /* DOCUMENTATION Given a Plist of clauses, what is the maximum number of literals in a clause. */ /* PUBLIC */ int most_literals(Plist clauses) { int max = -1; Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; int n = number_of_literals(c->literals); max = IMAX(max,n); } return max; } /* most_literals */ /************* * * pos_equality_in_clauses() * *************/ /* DOCUMENTATION Does the Plist contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL pos_equality_in_clauses(Plist clauses) { if (clauses == NULL) return FALSE; else { Topform c = clauses->v; if (contains_pos_eq(c->literals)) return TRUE; else return pos_equality_in_clauses(clauses->next); } } /* pos_equality_in_clauses */ /************* * * equality_in_clauses() * *************/ /* DOCUMENTATION Does the Plist contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL equality_in_clauses(Plist clauses) { if (clauses == NULL) return FALSE; else { Topform c = clauses->v; if (contains_eq(c->literals)) return TRUE; else return equality_in_clauses(clauses->next); } } /* equality_in_clauses */ LADR-2009-11A/ladr/work0000644000175000017500000007761710445336711013673 0ustar mccunemccune#include "parse.h" /* TO DO * 1. term_to_terms should not have to call binary_parse_type and * sn_to_str when backtracking. Store that info in pterm. * 2. less use of strbuf? * 3. DONE. Keep allowing applications without parens? NO * 4. think about check_arity. * 5. reduce some term copying? * 6. less space on output? * 7. more parens on output? * 8. another symbol type for single-character tokens? (comma, single quote) */ /* Private definitions and types */ /* Token types */ typedef enum {TOK_UNKNOWN, /* probably a garbage binary char */ TOK_NAME, /* see name_char() */ TOK_SYMBOL, /* see symbol_char() */ TOK_STRING, /* see quote_char() */ TOK_COMMENT, /* see comment_char() */ TOK_PUNC /* see punctutation_char() */ } Toktype; /* Return codes from read_buf() */ typedef enum {READ_BUF_OK,READ_BUF_EOF, READ_BUF_ERROR,READ_BUF_QUOTE_ERROR} Read_rc; /* A list of tokens */ typedef struct token * Token; struct token { Toktype type; char c; /* for punctuation & unknown tokens */ String_buf sb; /* for other tokens */ int buf_pos; /* position of this token in buffer */ Token next; }; /* A list of terms with some other data. */ typedef struct pterm * Pterm; struct pterm { Term t; int possible_application; /* avoids "a b" being parsed as a(b) */ Pterm prev, next; }; /* Token position */ typedef struct tok_pos *Tok_pos; struct tok_pos { Token tok; char *error_message; }; /* Private variables */ static BOOL Translate_neg_equalities = FALSE; /* * memory management */ #define PTRS_TOKEN PTRS(sizeof(struct token)) static unsigned Token_gets, Token_frees; #define PTRS_PTERM PTRS(sizeof(struct pterm)) static unsigned Pterm_gets, Pterm_frees; /************* * * Token get_token() * *************/ static Token get_token(void) { Token p = get_cmem(PTRS_TOKEN); Token_gets++; return(p); } /* get_token */ /************* * * free_token() * *************/ static void free_token(Token p) { free_mem(p, PTRS_TOKEN); Token_frees++; } /* free_token */ /************* * * Pterm get_pterm() * *************/ static Pterm get_pterm(void) { Pterm p = get_cmem(PTRS_PTERM); Pterm_gets++; return(p); } /* get_pterm */ /************* * * free_pterm() * *************/ static void free_pterm(Pterm p) { free_mem(p, PTRS_PTERM); Pterm_frees++; } /* free_pterm */ /************* * * fprint_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the parse package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_parse_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct token); fprintf(fp, "token (%4d) %11u%11u%11u%9.1f K\n", n, Token_gets, Token_frees, Token_gets - Token_frees, ((Token_gets - Token_frees) * n) / 1024.); n = sizeof(struct pterm); fprintf(fp, "pterm (%4d) %11u%11u%11u%9.1f K\n", n, Pterm_gets, Pterm_frees, Pterm_gets - Pterm_frees, ((Pterm_gets - Pterm_frees) * n) / 1024.); } /* fprint_parse_mem */ /************* * * p_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the parse package. */ /* PUBLIC */ void p_parse_mem() { fprint_parse_mem(stdout, TRUE); } /* p_parse_mem */ /* * end of memory management */ /************* * * translate_neg_equalities() * *************/ /* DOCUMENTATION This routine sets or clears the flag which tells the parser to automatically translate alpha!=beta to ~(alpha=beta). This happens in read_term(), which is called by read_clause(), read_formula(), and read_term_list(). */ /* PUBLIC */ void translate_neg_equalities(BOOL flag) { Translate_neg_equalities = flag; } /* translate_neg_equalities */ /************* * * translate_neg_eq() * *************/ static Term translate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = translate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), NEQ_SYM, 2)) { Term eq_term = get_rigid_term(EQ_SYM, 2); Term not_term = get_rigid_term(NOT_SYM, 1); ARG(eq_term,0) = ARG(t, 0); ARG(eq_term,1) = ARG(t, 1); ARG(not_term,0) = eq_term; free_term(t); t = not_term; } } return t; } /* translate_neg_eq */ /************* * * untranslate_neg_eq() * *************/ static Term untranslate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = untranslate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), NOT_SYM, 1) && is_symbol(SYMNUM(ARG(t,0)), EQ_SYM, 2)) { Term neq_term = get_rigid_term(NEQ_SYM, 2); ARG(neq_term,0) = ARG(ARG(t,0), 0); ARG(neq_term,1) = ARG(ARG(t,0), 1); free_term(ARG(t,0)); free_term(t); t = neq_term; } } return t; } /* untranslate_neg_eq */ /************* * * free_pterm_list() * *************/ static void free_pterm_list(Pterm p) { Pterm p1; while (p != NULL) { if (p->t != NULL) zap_term(p->t); p1 = p; p = p->next; free_pterm(p1); } } /* free_pterm_list */ /************* * * free_token_list() * *************/ static void free_token_list(Token p) { Token p1; while (p != NULL) { p1 = p; p = p->next; if (p1->sb != NULL) zap_string_buf(p1->sb); free_token(p1); } } /* free_token_list */ /************* * * end_char() * *************/ static BOOL end_char(char c) { return (c == '.'); } /* end_char */ /************* * * comment_char() * *************/ static BOOL comment_char(char c) { return (c == '%'); } /* comment_char */ /************* * * quote_char() * *************/ static BOOL quote_char(char c) { return (c == '\"'); } /* quote_char */ /************* * * punctuation_char() * *************/ static BOOL punctuation_char(char c) { return (c == ',' || c == ':' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '.'); } /* punctuation_char */ /************* * * name_char() * *************/ static BOOL name_char(char c) { return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$'); } /* name_char */ /************* * * symbol_char(c) * *************/ static BOOL symbol_char(char c) { /* This allows us to have special chars in the list below. */ if (quote_char(c) || end_char(c) || comment_char(c)) return 0; else return (c == '+' || c == '-' || c == '*' || c == '/' || c == '\\' || c == '^' || c == '<' || c == '>' || c == '=' || c == '`' || c == '~' || c == '?' || c == '@' || c == '&' || c == '|' || c == '!' || c == '#' || c == '%' || c == '\'' || c == '\"' || c == '.' || c == ';' ); } /* symbol_char */ /************* * * white_char() * *************/ static BOOL white_char(char c) { return (c == ' ' || c == '\t' || /* tab */ c == '\n' || /* newline */ c == '\v' || /* vertical tab */ c == '\r' || /* carriage return */ c == '\f'); /* form feed */ } /* white_char */ /************* * * white_or_comment() * *************/ static BOOL white_or_comment(String_buf sb) { int i = 0; BOOL ok = TRUE; int n = sb_size(sb); while (ok && i < n) { char c = sb_char(sb, i); if (white_char(c)) i++; else if (comment_char(c)) { /* skip over comment */ i++; while (i < n && sb_char(sb, i) != '\n') i++; if (i < n) i++; } else ok = FALSE; } return ok; } /* white_or_comment */ /************* * * read_buf() * * Read characters into buffer until one of the following: * 1. END_CHAR is reached (which goes into the buffer) * (except if in quoted string or comment). * 2. EOF is reached (everything still goes into buffer). * * Return: * READ_BUF_OK * READ_BUF_EOF possible white space or comment, then EOF * READ_BUF_ERROR non-white space, noncomment then EOF * READ_BUF_QUOTE_ERROR no end to quoted string (EOF) * *************/ static int read_buf(FILE *fp, String_buf sb) { int c; /* character read */ BOOL end, eof, eof_q; /* stop conditions */ end = eof = eof_q = FALSE; while (!end && !eof && !eof_q) { c = getc(fp); if (c == EOF) eof = TRUE; else if (comment_char(c)) { char s[6]; int i = 0; c = getc(fp); while (c != '\n' && c != EOF) { if (i < 6) s[i++] = c; c = getc(fp); } if ( if (c == EOF) eof = TRUE; } else { sb_append_char(sb, c); if (end_char(c)) end = TRUE; else if (quote_char(c)) { /* quoted string */ int qc = c; c = getc(fp); while (c != qc && c != EOF) { sb_append_char(sb, c); c = getc(fp); } if (c == EOF) eof_q = TRUE; else sb_append_char(sb, c); } } } if (end) return READ_BUF_OK; else if (eof_q) return READ_BUF_QUOTE_ERROR; else { /* eof -- make sure that the only things in the buffer are white space and comments. */ if (white_or_comment(sb)) return READ_BUF_EOF; else return READ_BUF_ERROR; } } /* read_buf */ /************* * * tokenize() * * Break up a string into a sequence of tokens. * *************/ static Token tokenize(String_buf sb) { int i = 0; char c = sb_char(sb, i); Token first, last, tok; first = last = NULL; while (!end_char(c) && c != '\0') { tok = get_token(); /* delete if not needed, i.e., white space */ tok->buf_pos = i; /* Make sure that each case, when finished, sets c to the next char. */ if (white_char(c)) { do { c = sb_char(sb, ++i); } while (white_char(c)); free_token(tok); tok = NULL; } else if (punctuation_char(c)) { tok->type = TOK_PUNC; tok->c = c; c = sb_char(sb, ++i); } else if (name_char(c)) { tok->type = TOK_NAME; tok->sb = get_string_buf(); while (name_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (symbol_char(c)) { tok->type = TOK_SYMBOL; tok->sb = get_string_buf(); while (symbol_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (comment_char(c)) { tok->type = TOK_COMMENT; tok->sb = get_string_buf(); while (c != '\n' && c != '\0') { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (quote_char(c)) { char qc = c; tok->type = TOK_STRING; tok->sb = get_string_buf(); sb_append_char(tok->sb, c); do { c = sb_char(sb, ++i); sb_append_char(tok->sb, c); } while (c != qc && c != '\0'); if (c == qc) c = sb_char(sb, ++i); } else { tok->type = TOK_UNKNOWN; tok->c = c; c = sb_char(sb, ++i); } if (tok != NULL) { if (first == NULL) first = tok; else last->next = tok; last = tok; } } /* while */ return first; } /* tokenize */ /************* * * comma_terms() * *************/ static int comma_terms(Term t) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) return 1; else return comma_terms(ARG(t,0)) + comma_terms(ARG(t,1)); } /* comma_terms */ /************* * * transfer_comma_term() * *************/ static void transfer_comma_term(Term t, Term dest, int *p) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { ARG(dest,*p) = copy_term(t); (*p)++; } else { transfer_comma_term(ARG(t,0), dest, p); transfer_comma_term(ARG(t,1), dest, p); } } /* transfer_comma_term */ /************* * * quantifier() * *************/ static BOOL quantifier(Term t) { return (is_symbol(SYMNUM(t), ALL_SYM, 0) || is_symbol(SYMNUM(t), EXISTS_SYM, 0)); } /* quantifier */ /* reference for mutual recursion */ static Term terms_to_term(Pterm start, Pterm end, int m); /************* * * terms_to_quant_term() * * Try to build a quantified term from a sequence of terms. * A quantified term is like this $quantified([all,x,all,y,exists,z,term]). * Why the "$quantified"? Because we wish * to recognize it as a special term for printing and transformations. * Note that, different from previous versions, each variable needs * its own quantifier. * *************/ static Term terms_to_quant_term(Pterm start, Pterm end) { Pterm curr = start; int vars_ok = 1; while (curr != NULL && quantifier(curr->t) && vars_ok) { curr = curr->next; if (curr != NULL && ARITY(curr->t) == 0) curr = curr->next; else vars_ok = 0; } if (vars_ok && curr != NULL) { Term formula = terms_to_term(curr, end, 1000); if (formula == NULL) return NULL; else { /* We have a good quantifier prefix and formula. * Build and return the quantified term. */ Pterm p; Term q = get_rigid_term(QUANT_SYM, 1); Term t = get_nil_term(); /* build list from the back */ t = listterm_cons(formula, t); for (p = curr->prev; p != NULL; p = p->prev) { t = listterm_cons(copy_term(p->t), t); } ARG(q,0) = t; return q; } } else return NULL; } /* terms_to_quant_term */ /************* * * terms_to_term() * * This routine takes a sequence of terms/symbols, and attempts * to construct a term with precedence <= m. * * On success, the resulting term is an entirely new copy. * *************/ static Term terms_to_term(Pterm start, Pterm end, int m) { if (start == end) { if (is_symbol(SYMNUM(start->t), ",", 0)) return NULL; /* don't allow commas as constants */ else return copy_term(start->t); } else { int rc, prec; Parsetype type; char *str; /* Try for prefix op; return if successful. */ if (ARITY(start->t) == 0) { str = sn_to_str(SYMNUM(start->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == PREFIX_PAREN || type == PREFIX)) { int p = (type == PREFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start->next, end, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); ARG(t,0) = t1; return t; } } } /* Try for postfix op; return if successful. */ if (ARITY(end->t) == 0) { str = sn_to_str(SYMNUM(end->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == POSTFIX_PAREN || type == POSTFIX)) { int p = (type == POSTFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start, end->prev, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); ARG(t,0) = t1; return t; } } } /* Try for an application; return if successful. */ if (start->next == end && end->possible_application && ARITY(start->t) == 0 && !is_symbol(SYMNUM(start->t), ",", 0)) { int args = comma_terms(end->t); /* number of args for application */ int special_arity = special_parse_type(sn_to_str(SYMNUM(start->t))); /* Fail if it's a special op with the wrong number of args. This addresses problem terms like p(~ v => (a & b)) which are ambiguous without this check. (~ prefix, v infix) */ if (special_arity == -1 || special_arity == args) { int argnum = 0; Term t = get_rigid_term(sn_to_str(SYMNUM(start->t)), args); transfer_comma_term(end->t, t, &argnum); return t; } } /* Try for quantified formula; return if successful. * Allow this only if we are not in a recursive call. */ if (start->next != end && m == 1000) { if (quantifier(start->t)) { Term t = terms_to_quant_term(start, end); if (t != NULL) return t; } } /* Try for infix op; return if successful. */ if (start->next != end) { /* Try each possible infix op, until success or exhausted. */ Pterm op; int backward = 0; /* If we parse a long left-associated expression left-to-right, * it ends up trying all the different associations before finding * the correct one. Therefore, as a heuristic, if the second * symbol is INFIX_LEFT, then we try to parse backward. This * doesn't always work well, for example, with & right and + left, * a&...&a -> a+...+a (symmetric shape) is slow both forward * and backward. To speed things up, the user can include * parentheses, i.e., (a&...&a) -> (a+...+a). */ if (ARITY(start->next->t) == 0) { str = sn_to_str(SYMNUM(start->next->t)); rc = binary_parse_type(str, &prec, &type); backward = (rc && type == INFIX_LEFT); } op = (backward ? end->prev : start->next); while (backward ? op != start : op != end) { if (ARITY(op->t) == 0) { str = sn_to_str(SYMNUM(op->t)); rc = binary_parse_type(str, &prec, &type); if (rc && prec <= m) { Term t1, t2; int p1 = (type == INFIX || type == INFIX_RIGHT ? prec-1 : prec); int p2 = (type == INFIX || type == INFIX_LEFT ? prec-1 : prec); t1 = terms_to_term(start, op->prev, p1); if (t1 != NULL) { t2 = terms_to_term(op->next, end, p2); if (t2 == NULL) zap_term(t1); else { Term t = get_rigid_term(str, 2); ARG(t,0) = t1; ARG(t,1) = t2; return t; } } } } /* arity 0 */ op = (backward ? op->prev : op->next); } /* while (binary attempts) */ } /* nothing works */ return NULL; } /* start != end */ } /* terms_to_term */ /************* * * next_token() * * This routine is called when it's time to move to the next token. * The current token (including any sb) is deleted. Don't call this * routine if an error is found; instead, set the error message ane * return NULL (from whereever you are). * *************/ static void next_token(Tok_pos p) { Token tok = p->tok; p->tok = p->tok->next; if (tok->sb != NULL) zap_string_buf(tok->sb); free_token(tok); } /* next_token */ /* reference for mutual recursion */ static Term toks_to_term(Tok_pos p); /************* * * toks_to_set() * *************/ static Term toks_to_set(Tok_pos p) { p->error_message = "set parsing not done"; return NULL; } /* toks_to_set */ /************* * * make_a_list() * * Prepend, to tail, copies of comma-elements in t. * *************/ static Term make_a_list(Term t, Term tail) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { return listterm_cons(copy_term(t), tail); } else { Term l = make_a_list(ARG(t,1), tail); return make_a_list(ARG(t,0), l); } } /* make_a_list */ /************* * * toks_to_list() * * On entry, current token is [. * On successful exit, current token should be ]. * *************/ static Term toks_to_list(Tok_pos p) { /* Assume current token is "[". */ next_token(p); if (p->tok != NULL && p->tok->c == ']') { return get_nil_term(); } else { Term cterm = toks_to_term(p); /* a comma-term */ if (cterm == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || (p->tok->c != ']' && p->tok->c != ':')) { p->error_message = "\']\' or \':\' expected in list"; zap_term(cterm); return NULL; } else if (p->tok->type == TOK_PUNC && p->tok->c == ':') { Term tail; next_token(p); tail = toks_to_term(p); if (tail == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || p->tok->c != ']') { p->error_message = "\']\' expected in list"; zap_term(cterm); zap_term(tail); return NULL; } else { Term list = make_a_list(cterm, tail); zap_term(cterm); return list; } } else { /* current token is ']' */ Term list = make_a_list(cterm, get_nil_term()); zap_term(cterm); return list; } } } /* toks_to_list */ /************* * * toks_to_terms() * *************/ static Pterm toks_to_terms(Tok_pos p) { Term t; int done = 0; int error = 0; int possible_application; int comma_constant; Pterm first = NULL; Pterm last = NULL; Pterm new; while (!done && !error) { possible_application = 0; comma_constant = 0; t = NULL; if (p->tok->type == TOK_NAME || p->tok->type == TOK_SYMBOL || p->tok->type == TOK_STRING ) { char *str = sb_to_malloc_string(p->tok->sb); t = get_rigid_term(str, 0); free(str); } else if (p->tok->type == TOK_PUNC && p->tok->c == ',') { /* Special case: comma is both punctuation and operator. */ t = get_rigid_term(",", 0); comma_constant = 1; } else if (p->tok->type == TOK_PUNC) { if (p->tok->c == '(') { next_token(p); t = toks_to_term(p); if (t == NULL) error = 1; else if (p->tok == NULL || p->tok->c != ')') { p->error_message = "closing parenthesis expected"; zap_term(t); t = NULL; error = 1; } else possible_application = 1; } else if (p->tok->c == '[') { t = toks_to_list(p); error = (t == NULL); } else if (p->tok->c == '{') { t = toks_to_set(p); error = (t == NULL); } else { /* bad punctuation */ p->error_message = "bad punctuation character"; error = 1; } } else if (p->tok->type == TOK_COMMENT) { ; /* do nothing */ } else if (p->tok->type == TOK_UNKNOWN) { p->error_message = "bad character"; error = 1; } if (t != NULL) { /* Add a node to the terms list. */ new = get_pterm(); new->prev = last; if (first == NULL) first = new; else last->next = new; new->t = t; new->possible_application = possible_application; last = new; } if (!error) { /* */ next_token(p); if (p->tok == NULL) done = 1; else if(p->tok->type == TOK_PUNC && (p->tok->c == ')' || p->tok->c == ']' || p->tok->c == '}' || p->tok->c == ':')) done = 1; } } /* while */ if (error) { free_pterm_list(first); return NULL; } else return first; } /* toks_to_terms */ /************* * * toks_to_term() * *************/ static Term toks_to_term(Tok_pos p) { Term t; Pterm terms; terms = toks_to_terms(p); if (terms == NULL) t = NULL; else { Pterm end; for (end = terms; end->next != NULL; end = end->next); t = terms_to_term(terms, end, 1000); free_pterm_list(terms); if (t == NULL) { p->error_message = "terms/ops could not be combined into a term"; } } return t; } /* toks_to_term */ /************* * * fprint_parse_error() * *************/ static void fprint_parse_error(FILE *fp, char *msg, String_buf sb, int position) { int i; int n = sb_size(sb); fprintf(fp, "Error parsing input string, %s:\n", msg); for (i = 0; i < position; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, " **HERE** "); for (i = position; i < n; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, "\n"); } /* fprint_parse_error */ /************* * * sread_term() * *************/ /* DOCUMENTATION This routine reads a term (from String_buf *sb). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term sread_term(String_buf sb, FILE *fout) { Token tokens; Term t; struct tok_pos tp; tokens = tokenize(sb); if (tokens == NULL) fatal_error("sread_term, empty term (too many periods?)"); tp.tok = tokens; tp.error_message = ""; t = toks_to_term(&tp); if (t == NULL || tp.tok != NULL) { int pos; if (t != NULL) tp.error_message = "characters after complete term"; pos = (tp.tok != NULL ? tp.tok->buf_pos : sb_size(sb)-1); fprint_parse_error(fout, tp.error_message, sb, pos); free_token_list(tp.tok); fatal_error("sread_term error"); } return t; } /* sread_term */ /************* * * read_term() * *************/ /* DOCUMENTATION This routine reads a term (from FILE *fin). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term read_term(FILE *fin, FILE *fout) { Read_rc rc; String_buf sb = get_string_buf(); rc = read_buf(fin, sb); if (rc == READ_BUF_EOF) { zap_string_buf(sb); return NULL; } else if (rc != READ_BUF_OK) { char *msg; switch (rc) { case READ_BUF_ERROR: msg = "EOF found while reading term (missing period?)"; break; case READ_BUF_QUOTE_ERROR: msg = "EOF found while reading quoted string"; break; default: msg = "error reading characters from file"; break; } fprint_parse_error(fout, msg, sb, sb_size(sb)); zap_string_buf(sb); fatal_error("read_term error"); return NULL; /* to please the complier */ } else { Term t = sread_term(sb, fout); zap_string_buf(sb); if (Translate_neg_equalities) t = translate_neg_eq(t); return t; } } /* read_term */ /************* * * parse_term_from_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term parse_term_from_string(char *s) { String_buf sb = init_string_buf(s); Term t = sread_term(sb, stdout); zap_string_buf(sb); return t; } /* parse_term_from_string */ /************* * * quantified_term() * *************/ static BOOL quantified_term(Term t) { return (COMPLEX(t) && is_symbol(SYMNUM(t), QUANT_SYM, 1) && listterm_length(ARG(t,0)) >= 3); } /* quantified_term */ /************* * * arrange_term() * *************/ static void arrange_term(String_buf sb, Term t, int par_prec) { if (t == NULL) sb_append(sb, "arrange_term gets NULL term"); else if (VARIABLE(t)) { char str[100]; if (variable_style() == INTEGER_STYLE) sprintf(str, "%d", VARNUM(t)); else if (variable_style() == PROLOG_STYLE) { /* A,B,C,D,E,F,V6,V7,V8,... */ if (VARNUM(t) < 6) sprintf(str, "%c", 'A' + VARNUM(t)); else sprintf(str, "V%d", VARNUM(t)); } else { /* x,y,z,u,v,w,v6,v7,v8,... */ if (VARNUM(t) < 3) sprintf(str, "%c", 'x' + VARNUM(t)); else if (VARNUM(t) < 6) sprintf(str, "%c", 'r' + VARNUM(t)); else sprintf(str, "v%d", VARNUM(t)); } sb_append(sb, str); } /* variable */ else if (CONSTANT(t)) { if (nil_term(t)) sb_append(sb, "[]"); else sb_append(sb, sn_to_str(SYMNUM(t))); } /* constant */ else if (quantified_term(t)) { Term t1 = ARG(t,0); sb_append(sb, "("); while (cons_term(ARG(t1,1))) { arrange_term(sb, ARG(t1,0), 1000); sb_append(sb, " "); t1 = ARG(t1,1); } sb_append(sb, "("); arrange_term(sb, ARG(t1,0), 1000); sb_append(sb, ")"); sb_append(sb, ")"); } /* quantified */ else if (cons_term(t)) { Term t1 = t; sb_append(sb, "["); while (cons_term(t1)) { arrange_term(sb, ARG(t1,0), 1000); t1 = ARG(t1,1); if (cons_term(t1)) sb_append(sb, ","); } if (!nil_term(t1)) { sb_append(sb, ":"); arrange_term(sb, t1, 1000); } sb_append(sb, "]"); } /* cons_term */ else { Parsetype type; int op_prec; if (ARITY(t) == 2 && binary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = (type == INFIX || type == INFIX_RIGHT ? op_prec-1 : op_prec); int p2 = (type == INFIX || type == INFIX_LEFT ? op_prec-1 : op_prec); if (op_prec > par_prec) sb_append(sb, "("); arrange_term(sb, ARG(t,0), p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, ARG(t,1), p2); if (op_prec > par_prec) sb_append(sb, ")"); } /* binary infix */ else if (ARITY(t) == 1 && unary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = (type == PREFIX_PAREN || type == POSTFIX_PAREN ? op_prec-1 : op_prec); if (op_prec > par_prec) sb_append(sb, "("); if (type == PREFIX_PAREN || type == PREFIX) { sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, ARG(t,0), p1); } /* prefix */ else { arrange_term(sb, ARG(t,0), p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); } /* postfix */ if (op_prec > par_prec) sb_append(sb, ")"); } /* unary prefix or postfix */ else { /* ordinary application */ int i; sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, "("); for (i = 0; i < ARITY(t); i++) { arrange_term(sb, ARG(t,i), 1000); if (i < ARITY(t)-1) sb_append(sb, ","); } sb_append(sb, ")"); } /* ordinary application */ } } /* arrange_term */ /************* * * sb_write_term() * *************/ /* DOCUMENTATION This routine prints a term to a String_buf in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void sb_write_term(String_buf sb, Term t) { if (Translate_neg_equalities) { Term temp_term = untranslate_neg_eq(copy_term(t)); arrange_term(sb, temp_term, 1000); zap_term(temp_term); } else arrange_term(sb, t, 1000); } /* sb_write_term */ /************* * * fwrite_term() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term(FILE *fp, Term t) { String_buf sb = get_string_buf(); sb_write_term(sb, t); fprint_sb(fp, sb); zap_string_buf(sb); } /* fwrite_term */ /************* * * fwrite_term_nl() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. Also printed is ".\n".

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term_nl(FILE *fp, Term t) { fwrite_term(fp, t); fprintf(fp, ".\n"); } /* fwrite_term_nl */ /************* * * declare_standard_parse_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_standard_parse_types(void) { set_parse_type(",", 999, INFIX_RIGHT); /* essential */ set_parse_type(ATTRIB_SYM, 810, INFIX_RIGHT); set_parse_type(IFF_SYM, 800, INFIX); set_parse_type(IMP_SYM, 800, INFIX); set_parse_type(IMPBY_SYM, 800, INFIX); set_parse_type(OR_SYM, 790, INFIX_RIGHT); set_parse_type(AND_SYM, 780, INFIX_RIGHT); set_parse_type(EQ_SYM, 700, INFIX); set_parse_type(NEQ_SYM, 700, INFIX); set_parse_type("==", 700, INFIX); set_parse_type("<", 700, INFIX); set_parse_type("<=", 700, INFIX); set_parse_type(">", 700, INFIX); set_parse_type(">=", 700, INFIX); set_parse_type("+", 500, INFIX); set_parse_type("*", 500, INFIX); set_parse_type("@", 500, INFIX); set_parse_type("/", 500, INFIX); set_parse_type("\\", 500, INFIX); set_parse_type("^", 500, INFIX); set_parse_type("v", 500, INFIX); set_parse_type(NOT_SYM, 400, PREFIX); set_parse_type("\'", 300, POSTFIX); } /* declare_standard_parse_types */ /************* * * skip_to_nl() * *************/ /* DOCUMENTATION Read characters up to the first newline (or EOF). */ /* PUBLIC */ void skip_to_nl(FILE *fp) { int c = fgetc(fp); while (c != EOF && c != '\n') c = fgetc(fp); } /* skip_to_nl */ LADR-2009-11A/ladr/TAGS0000644000175000017500000022125411151265425013431 0ustar mccunemccune ac_redun.c,440 static Ilist C_symbols 21,778 static Ilist A1_symbols 22,833 static Ilist A2_symbols 23,905 static Ilist AC_symbols 24,977 BOOL same_top(39,1200 int commutativity(59,1569 int associativity(91,2262 int c_associativity(132,3207 int associativity3(179,4198 int associativity4(231,5386 Ordertype can_compare(272,6474 Term canon(293,6928 BOOL cac_redundant_atom(342,7960 BOOL cac_tautology(387,9107 BOOL cac_redundancy(425,10067 accanon.c,142 void flatten(36,1030 void right_associate(69,1748 void ac_canonical2(121,2627 void ac_canonical(180,4499 int check_ac_canonical(234,5902 attrib.c,1700 struct attribute attribute25,875 #define MAX_ATTRIBUTE_NAMES 37,1170 } Attribute_names[43,1482 static int Next_attribute_name 45,1523 #define PTRS_ATTRIBUTE 51,1589 static unsigned Attribute_gets,52,1643 static unsigned Attribute_gets, Attribute_frees;52,1643 Attribute get_attribute(61,1769 void free_attribute(75,1968 void fprint_attrib_mem(94,2362 void p_attrib_mem(120,2992 Attribute_type attribute_type(136,3176 char *attribute_name(148,3351 int register_attribute(166,3693 void declare_term_attribute_inheritable(195,4526 BOOL inheritable(209,4840 Attribute set_int_attribute(228,5206 int get_int_attribute(261,5911 BOOL exists_attribute(287,6465 Attribute set_term_attribute(312,6950 void replace_term_attribute(346,7713 void replace_int_attribute(378,8531 Term get_term_attribute(410,9327 Term get_term_attributes(441,10052 Attribute set_string_attribute(477,10858 char *get_string_attribute(512,11717 BOOL string_attribute_member(542,12414 void zap_attributes(567,12990 Attribute delete_attributes(589,13421 Attribute cat_att(619,14026 Term build_attr_term(644,14497 Term attributes_to_term(689,15504 Attribute cat_attributes(709,15928 int attribute_name_to_id(732,16387 Attribute term_to_attributes(762,17061 Attribute inheritable_att_instances(814,18323 Attribute copy_attributes(840,18889 void instantiate_inheritable_attributes(869,19513 void renumber_vars_attributes(892,20006 void set_vars_attributes(913,20429 Plist vars_in_attributes(935,20868 int label_att(959,21280 BOOL attributes_contain_variables(982,21725 Attribute copy_int_attribute(1009,22234 Attribute copy_string_attribute(1030,22613 Attribute copy_term_attribute(1051,22993 avltree.c,964 struct avl_node avl_node24,832 static BOOL Debug 31,1046 #define PTRS_AVL_NODE 37,1103 static unsigned Avl_node_gets,38,1155 static unsigned Avl_node_gets, Avl_node_frees;38,1155 Avl_node get_avl_node(47,1277 void free_avl_node(61,1468 void fprint_avltree_mem(80,1859 void p_avltree_mem(106,2486 int avl_height(126,2753 int avl_size(142,2972 void set_height_and_size(154,3126 BOOL balance_ok(167,3383 Avl_node rotate_left(179,3563 Avl_node rotate_right(198,3893 Avl_node avl_fix(217,4220 Avl_node avl_insert(262,5260 Avl_node remove_and_return_largest(295,6105 Avl_node remove_and_return_smallest(315,6512 Avl_node avl_delete(342,7133 Avl_node avl_lookup(383,8118 void *avl_find(414,8891 void *avl_smallest(432,9226 void *avl_largest(453,9575 int avl_place(476,10045 double avl_position(510,10853 void *avl_nth_item(529,11236 void *avl_item_at_position(556,11890 void avl_zap(580,12406 void avl_check(604,12878 void p_avl(646,14150 backdemod.c,234 void index_term_back_demod(30,890 void index_clause_back_demod(51,1303 BOOL rewritable_term(70,1684 BOOL rewritable_clause(99,2257 Plist back_demod_linear(129,2996 BOOL lex_rewritable(149,3404 Plist back_demod_indexed(177,4113 banner.c,57 void print_separator(40,1020 void print_banner(66,1615 basic.c,453 static BOOL Basic_paramodulation 64,2487 static int Nonbasic_flag 65,2561 void init_basic_paramod(77,2744 void set_basic_paramod(95,3090 BOOL basic_paramod(111,3311 void mark_term_nonbasic(126,3491 void mark_all_nonbasic(143,3781 BOOL nonbasic_term(165,4200 BOOL basic_term(181,4448 int nonbasic_flag(196,4627 Term apply_basic(213,4932 Term apply_basic_substitute(258,6220 void clear_all_nonbasic_marks(287,6842 void p_term_basic(308,7218 btm.c,1920 typedef struct ac_match_pos * Ac_match_pos;Ac_match_pos23,810 typedef struct ac_match_free_vars_pos * Ac_match_free_vars_pos;Ac_match_free_vars_pos24,854 struct btm_state btm_state26,919 struct ac_match_pos ac_match_pos47,1586 struct ac_match_free_vars_pos ac_match_free_vars_pos70,2776 #define POP 81,3224 #define BACKTRACK 82,3244 #define GO 83,3264 #define SUCCESS 84,3284 #define FAILURE 85,3304 #define BIND_BT(BIND_BT89,3378 #define PTRS_AC_MATCH_POS 101,3681 static unsigned Ac_match_pos_gets,102,3741 static unsigned Ac_match_pos_gets, Ac_match_pos_frees;102,3741 #define PTRS_AC_MATCH_FREE_VARS_POS 104,3797 static unsigned Ac_match_free_vars_pos_gets,105,3877 static unsigned Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees;105,3877 #define PTRS_BTM_STATE 107,3953 static unsigned Btm_state_gets,108,4007 static unsigned Btm_state_gets, Btm_state_frees;108,4007 Ac_match_pos get_ac_match_pos(117,4139 void free_ac_match_pos(131,4359 Ac_match_free_vars_pos get_ac_match_free_vars_pos(144,4588 void free_ac_match_free_vars_pos(158,4878 Btm_state get_btm_state(171,5131 void free_btm_state(187,5375 void fprint_btm_mem(206,5763 void p_btm_mem(244,7007 void flatten_mult(265,7447 int macbv_rec(302,8180 int match_ac_bound_vars(340,9232 void set_up_free_vars(382,10517 void unbind_free_var(442,11941 int free_var_match(477,12690 Term build_partial_term(591,15486 void clear_partial_term(621,16054 #define GO_FUNCTORS 637,16348 #define GO_BOUND_VARS 638,16372 #define GO_FREE_VARS 639,16396 #define SUCCESS 640,16420 #define FAILURE 641,16444 int match_ac(661,16973 void match_ac_cancel(860,22259 Btm_state match_bt_backup(888,22838 Btm_state match_bt_guts(932,23563 int match_commute(1081,26575 void p_acm(1134,27766 void p_btm_state(1177,28734 Btm_state match_bt_first(1234,30497 Btm_state match_bt_next(1259,30987 void match_bt_cancel(1294,31787 btu.c,1356 #define MAX_ACU_ARGS 23,810 typedef struct ac_position * Ac_position;Ac_position25,836 struct ac_position ac_position27,879 struct btu_state btu_state45,1792 #define GO 67,2411 #define SUCCESS 68,2431 #define EXHAUSTED 69,2451 #define FAILURE 70,2471 #define POP 71,2491 #define BACKTRACK 72,2511 #define BIND_BT(BIND_BT76,2598 #define PTRS_BTU_STATE 88,2836 static unsigned Btu_state_gets,89,2890 static unsigned Btu_state_gets, Btu_state_frees;89,2890 #define PTRS_AC_POSITION 91,2940 static unsigned Ac_position_gets,92,2998 static unsigned Ac_position_gets, Ac_position_frees;92,2998 Btu_state get_btu_state(101,3128 void free_btu_state(116,3345 Ac_position get_ac_position(129,3537 void free_ac_position(143,3750 void fprint_btu_mem(162,4148 void p_btu_mem(194,5020 void p_binding(210,5195 void flatten_deref(244,6222 int compare_ncv_context(287,7062 void sort_ac(345,8378 void elim_con_context(382,9030 void ac_mult_context(411,9681 void ac_prepare(466,10784 void set_up_basis_terms(514,12013 int unify_ac(560,13210 void unify_ac_cancel(897,22343 void p_ac_position(956,23602 Btu_state unify_bt_backup(986,24303 int unify_commute(1040,25430 Btu_state unify_bt_first(1152,28803 Btu_state unify_bt_next(1175,29320 void unify_bt_cancel(1208,30123 Btu_state unify_bt_guts(1246,30927 void p_bt_tree(1434,34834 clash.c,438 #define PTRS_CLASH 27,841 static unsigned Clash_gets,28,887 static unsigned Clash_gets, Clash_frees;28,887 Clash get_clash(37,997 void free_clash(51,1168 void fprint_clash_mem(70,1540 void p_clash_mem(96,2138 Clash append_clash(116,2451 void zap_clash(136,2773 Literals atom_to_literal(158,3124 Literals apply_lit(179,3547 int lit_position(191,3732 Topform resolve(212,4064 void clash_recurse(272,5622 void clash(356,8078 clause_eval.c,1430 enum { CL_EVAL_AND,39,1420 CL_EVAL_OR,40,1440 CL_EVAL_NOT,41,1459 CL_EVAL_ALL,42,1479 CL_EVAL_LESS,44,1500 CL_EVAL_LESS_EQUAL,45,1521 CL_EVAL_GREATER,46,1548 CL_EVAL_GREATER_EQUAL,47,1572 CL_EVAL_EQUAL,48,1602 CL_EVAL_POSITIVE,50,1625 CL_EVAL_NEGATIVE,51,1650 CL_EVAL_MIXED,52,1675 CL_EVAL_HINT,54,1698 CL_EVAL_TRUE,56,1720 CL_EVAL_FALSE,57,1741 CL_EVAL_HAS_EQUALITY,59,1764 CL_EVAL_HORN,60,1793 CL_EVAL_DEFINITE,61,1814 CL_EVAL_UNIT,62,1839 CL_EVAL_INITIAL,64,1861 CL_EVAL_RESOLVENT,65,1885 CL_EVAL_UR_RESOLVENT,66,1911 CL_EVAL_HYPER_RESOLVENT,67,1940 CL_EVAL_FACTOR,68,1972 CL_EVAL_PARAMODULANT,69,1995 CL_EVAL_BACK_DEMODULANT,70,2024 CL_EVAL_SUBSUMER,71,2056 CL_EVAL_WEIGHT,73,2082 CL_EVAL_VARIABLES,74,2105 CL_EVAL_DEPTH,75,2131 CL_EVAL_LITERALS,76,2153 CL_EVAL_LEVEL77,2178 struct clause_eval clause_eval82,2300 #define PTRS_EVAL_RULE 94,2608 static unsigned Clause_eval_gets,95,2682 static unsigned Clause_eval_gets, Clause_eval_frees;95,2682 Clause_eval get_clause_eval(104,2816 void free_clause_eval(118,3027 void zap_clause_eval_rule(138,3280 Clause_eval compile_clause_eval_rule(160,3685 BOOL eval_clause_in_rule(284,7091 BOOL rule_contains_semantics(384,9884 clause_misc.c,317 Clist clist_copy(39,1033 Clist copy_clauses_to_clist(64,1527 Clist move_clauses_to_clist(90,2067 Plist input_clauses(115,2549 void delete_clause(145,3153 void delete_clist(169,3732 Topform copy_clause_ija(199,4222 Plist copy_clauses_ija(220,4687 void delete_clauses(244,5109 void make_clause_basic(264,5419 clauseid.c,421 #define CLAUSE_ID_TAB_SIZE 23,815 static Plist Topform_id_tab[25,850 static unsigned Topform_id_count 26,903 int next_clause_id(35,1010 int clause_ids_assigned(51,1236 void assign_clause_id(70,1642 void unassign_clause_id(97,2232 Topform find_clause_by_id(135,3043 void fprint_clause_id_tab(161,3524 void p_clause_id_tab(184,3955 Plist insert_clause_into_plist(204,4377 BOOL clause_plist_member(239,5183 clauses.c,437 Topform clause_member_plist(38,1022 Plist intersect_clauses(62,1485 int max_clause_weight(87,1954 int max_clause_symbol_count(110,2355 Plist nonneg_clauses(132,2776 BOOL all_clauses_horn(155,3173 BOOL all_clauses_unit(177,3512 BOOL all_clauses_positive(199,3855 int neg_nonunit_clauses(221,4219 int negative_clauses(244,4615 int most_literals(268,4988 BOOL pos_equality_in_clauses(291,5389 BOOL equality_in_clauses(315,5835 clausify.c,280 Literals formula_to_literal(39,1157 Literals formula_to_literals(59,1553 Topform formula_to_clause(91,2367 Plist formula_to_clauses(117,2962 Plist clausify_formula(147,3746 Term vars_to_names(170,4123 Formula literal_to_formula(207,4852 Formula clause_to_formula(231,5263 clist.c,1622 #define PTRS_CLIST_POS 27,841 static unsigned Clist_pos_gets,28,895 static unsigned Clist_pos_gets, Clist_pos_frees;28,895 #define PTRS_CLIST 30,945 static unsigned Clist_gets,31,991 static unsigned Clist_gets, Clist_frees;31,991 Clist_pos get_clist_pos(40,1109 void free_clist_pos(54,1308 Clist get_clist(67,1488 void free_clist(81,1659 void fprint_clist_mem(100,2031 void p_clist_mem(132,2871 Clist clist_init(155,3359 void name_clist(178,3714 void clist_free(201,4068 void clist_append(223,4378 void clist_prepend(255,4847 void clist_insert_before(287,5333 void clist_insert_after(319,5861 void clist_remove(353,6518 void clist_remove_all_clauses(397,7384 int clist_remove_all(415,7735 int clist_member(436,8061 void fprint_clist(461,8549 void p_clist(486,8968 void clist_zap(504,9279 void clist_check(532,9736 void clist_append_all(570,10469 BOOL clist_empty(589,10852 int clist_length(604,11025 int max_wt_in_clist(620,11248 BOOL horn_clist(641,11587 BOOL unit_clist(661,11901 BOOL equality_in_clist(681,12244 BOOL neg_nonunit_in_clist(701,12592 Plist clauses_in_clist(722,13005 void clist_swap(746,13489 void clist_move_clauses(772,14011 Plist move_clist_to_plist(791,14285 Plist copy_clist_to_plist_shallow(814,14637 Clist plist_to_clist(833,14955 void clist_reverse(854,15260 Clist_pos pos_in_clist(879,15637 void clist_append_plist(896,15894 Plist prepend_clist_to_plist(914,16159 int clist_number_of_weight(936,16490 Ordertype compare_clause_ids(958,16827 void sort_clist_by_id(978,17126 Plist neg_clauses_in_clist(1008,17641 void fprint_clause_clist(1031,18092 clock.c,937 struct clock clock23,812 static BOOL Clocks_enabled 30,1081 static unsigned Clock_starts 31,1146 static unsigned Wall_start;33,1203 #define CPU_TIME(CPU_TIME42,1527 #define CPU_TIME(CPU_TIME45,1674 #define PTRS_CLOCK 52,1761 static unsigned Clock_gets,53,1807 static unsigned Clock_gets, Clock_frees;53,1807 Clock get_clock(62,1917 void free_clock(79,2115 Clock clock_init(107,2663 void clock_start(127,2968 void clock_stop(151,3396 unsigned clock_milliseconds(179,3912 double clock_seconds(207,4372 BOOL clock_running(234,4808 void clock_reset(251,5106 void fprint_clock(270,5325 char * get_date(287,5644 unsigned user_time(305,5933 double user_seconds(329,6331 unsigned system_time(356,6877 double system_seconds(383,7425 unsigned absolute_wallclock(405,7739 void init_wallclock(422,8004 unsigned wallclock(439,8293 void disable_clocks(454,8474 void enable_clocks(469,8646 BOOL clocks_enabled(484,8816 cnf.c,1177 static jmp_buf Jump_env;41,1433 static unsigned Fid_call_limit 43,1491 static unsigned Fid_calls 44,1534 Formula share_formula(53,1632 Formula consolidate_formula(90,2386 BOOL formula_ident_share(115,2931 Formula formula_copy_share(152,3804 BOOL complementary_share(180,4399 BOOL contains_complements_share(197,4738 BOOL prop_member_share(216,5099 BOOL prop_subset_share(232,5423 BOOL prop_subsume_share(250,5741 Formula remove_subsumed_share(274,6226 Formula bbt(316,7052 Formula balanced_binary(338,7474 Formula disjoin_flatten_simplify(360,7885 Formula simplify_and_share(407,9049 Formula distribute_top(436,9582 Formula distribute(473,10375 Formula cnf(502,10907 Formula dnf(535,11490 Formula skolem(547,11617 Formula skolemize(621,13568 Ilist unique_qvars(634,13719 Formula unique_quantified_vars(679,14878 void mark_free_vars_formula(697,15195 Formula remove_uni_quant(717,15650 Formula remove_universal_quantifiers(751,16407 Formula clausify_prepare(781,17249 Formula ms_free_vars(811,17860 Formula miniscope(871,19356 typedef void (*sighandler_t)sighandler_t932,20765 Formula miniscope_formula(938,20835 int cnf_max_clauses(990,22135 complex.c,399 #define IMAX(IMAX24,936 double complexity1(51,1570 double complexity2(111,2721 double complexity3(152,3498 Term complex4_devar(185,4140 Term complex4_revar(207,4566 void complex4_compare(229,4954 BOOL complex4_p2(249,5423 void complex4_p1(271,5813 double complex4(302,6749 void term_to_ints(335,7465 double term_complexity(358,7801 double clause_complexity(390,8370 int main(401,8659 compress.c,192 Term uncompress_term(33,910 void compress_term_recurse(55,1319 char *compress_term(78,1696 void compress_clause(103,2153 void uncompress_clause(132,2862 void uncompress_clauses(162,3508 definitions.c,379 BOOL is_definition(37,940 Term subst_terms(78,1936 void subst_free_vars(112,2782 Formula subst_atomic_formula(135,3358 Formula strip_quantifiers(174,4541 BOOL definition_applies(188,4735 Formula expand_with_definition(210,5158 Topform first_definition(236,5869 void process_definitions(260,6261 void expand_with_definitions(303,7215 void separate_definitions(344,8150 demod.c,397 static int Demod_attempts 26,866 static int Demod_rewrites 27,897 int demodulator_type(40,1100 void idx_demodulator(90,2289 int demod_attempts(117,2927 int demod_rewrites(133,3167 Term demod(147,3324 Term contract_bt(207,4875 Term demod_bt(242,5761 Term demodulate(288,6961 Term demod1_recurse(312,7536 void demod1(372,8902 Term part_recurse(403,9616 void particular_demod(468,11105 di_tree.c,869 static int Nonunit_fsub_tests;23,814 static int Nonunit_bsub_tests;24,845 static unsigned Sub_calls 26,877 static unsigned Sub_calls_overflows 27,908 #define BUMP_SUB_CALLS 28,949 int nonunit_fsub_tests(40,1133 int nonunit_bsub_tests(55,1324 #define PTRS_DI_TREE 64,1442 static unsigned Di_tree_gets,65,1492 static unsigned Di_tree_gets, Di_tree_frees;65,1492 Di_tree get_di_tree(77,1637 void free_di_tree(94,1849 void fprint_di_tree_mem(113,2235 void p_di_tree_mem(139,2855 Di_tree init_di_tree(160,3152 void di_tree_insert(175,3322 BOOL di_tree_delete(215,4094 void zap_di_tree(256,4984 void p_di_tree(281,5358 BOOL subsume_di_literals(311,5899 BOOL subsumes_di(343,6538 Topform di_tree_forward(359,6817 Topform forward_feature_subsume(395,7566 void di_tree_back(412,7903 Plist back_feature_subsume(448,8685 unsigned mega_sub_calls(469,9075 dioph.c,641 int gcd(28,860 int lcm(44,1095 int less_vec(57,1316 int var_check_1(79,1794 int var_check_2(105,2379 int add_solution(131,2924 int a_in_bounds(158,3623 int b_in_bounds(199,4664 int dio(242,5899 #define ADD_TO_SUM(ADD_TO_SUM359,8409 #define SUBTRACT_FROM_SUM(SUBTRACT_FROM_SUM362,8507 int next_combo_a(391,9547 int next_combo_b(451,10916 #define DOWN 514,12188 #define OVER 515,12206 #define BACKUP 516,12224 #define SUCCESS 517,12242 #define FAILURE 518,12260 int next_combo_c(527,12463 int superset_degree(615,14638 int next_combo_ss(661,16079 void p_ac_basis(722,17305 int all_combos(745,17807 int main(790,18715 discrim.c,598 #define PTRS_DISCRIM 27,843 static unsigned Discrim_gets,28,893 static unsigned Discrim_gets, Discrim_frees;28,893 #define PTRS_DISCRIM_POS 30,939 static unsigned Discrim_pos_gets,31,997 static unsigned Discrim_pos_gets, Discrim_pos_frees;31,997 Discrim get_discrim(43,1150 void free_discrim(60,1362 Discrim_pos get_discrim_pos(77,1605 void free_discrim_pos(94,1867 void fprint_discrim_mem(113,2273 void p_discrim_mem(145,3149 Discrim discrim_init(166,3480 void discrim_dealloc(182,3717 void zap_discrim_tree(198,3950 void destroy_discrim_tree(235,4636 BOOL discrim_empty(252,4937 discrimb.c,913 typedef struct flat2 * Flat2;Flat227,844 struct flat2 flat229,875 #define GO 38,1079 #define BACKTRACK 39,1099 #define SUCCESS 40,1119 #define FAILURE 41,1139 #define PTRS_FLAT2 47,1189 static unsigned Flat2_gets,48,1235 static unsigned Flat2_gets, Flat2_frees;48,1235 Flat2 get_flat2(57,1345 void free_flat2(71,1516 void fprint_discrimb_mem(90,1894 void p_discrimb_mem(116,2504 void print_discrim_bind_tree(132,2724 void fprint_discrim_bind_index(176,3623 void p_discrim_bind_index(192,3913 Discrim discrim_bind_insert_rec(207,4231 void discrim_bind_insert(279,5800 Discrim discrim_bind_end(313,6725 void discrim_bind_delete(364,7795 void discrim_bind_update(447,9650 Flat2 check_flat2(462,9927 void p_flat2(489,10403 Plist discrim_bind_retrieve_leaf(512,10803 void *discrim_bind_retrieve_first(681,14446 void *discrim_bind_retrieve_next(721,15400 void discrim_bind_cancel(758,16255 discrimw.c,1022 typedef struct flat * Flat;Flat23,815 struct flat flat25,844 #define GO 38,1324 #define BACKTRACK 39,1344 #define SUCCESS 40,1364 #define FAILURE 41,1384 #define PTRS_FLAT 47,1434 static unsigned Flat_gets,48,1478 static unsigned Flat_gets, Flat_frees;48,1478 Flat get_flat(57,1584 void free_flat(85,1982 void fprint_discrimw_mem(104,2355 void p_discrimw_mem(130,2958 Flat check_flat(146,3145 void p_flat(173,3612 void flip_flat(193,3918 int num_ac_args(230,4647 int num_ac_nv_args(246,4937 void print_discrim_wild_tree(262,5259 void fprint_discrim_wild_index(313,6394 void p_discrim_wild_index(329,6685 Discrim discrim_wild_insert_ac(341,6876 Discrim discrim_wild_insert_rec(390,7938 void discrim_wild_insert(459,9393 Discrim discrim_wild_end(493,10311 void discrim_wild_delete(568,11780 void discrim_wild_update(650,13625 Plist discrim_wild_retrieve_leaf(665,13937 void *discrim_wild_retrieve_first(895,19451 void *discrim_wild_retrieve_next(932,20234 void discrim_wild_cancel(968,20980 dollar.c,1127 struct rule rule26,963 SUM_OP=35,1067 SUM_OP=1, PROD_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP, MAX_OP,35,1067 SUM_OP=1, PROD_OP, DIV_OP, MOD_OP, MIN_OP, MAX_OP, ABS_OP,35,1067 NEG_OP,36,1128 LT_OP,37,1138 LT_OP, LE_OP,37,1138 LT_OP, LE_OP, GT_OP,37,1138 LT_OP, LE_OP, GT_OP, GE_OP,37,1138 LLT_OP,38,1201 LLT_OP, LLE_OP,38,1201 LLT_OP, LLE_OP, LGT_OP,38,1201 LLT_OP, LLE_OP, LGT_OP, LGE_OP,38,1201 AND_OP,39,1261 AND_OP, OR_OP,39,1261 AND2_OP,40,1278 AND2_OP, OR2_OP,40,1278 IF_OP,41,1297 ID_OP,42,1306 ID_OP, NID_OP,42,1306 VAR_OP,43,1381 VAR_OP, CONST_OP,43,1381 VAR_OP, CONST_OP, GROUND_OP}43,1381 static int Symbols_size;45,1414 static int *Op_codes;46,1439 static struct rule **Rules;47,1461 static int Local_evals;48,1489 void init_dollar_eval(64,1639 BOOL evaluable_predicate(167,4724 Term dollar_eval(189,5046 Term rewrite_top(364,8968 Term rewrite(419,10202 void rewrite_with_eval(510,11971 fastparse.c,354 static int Arity[23,816 static int Symnum[24,883 static int Pos;26,951 #define MAX_LINE 28,1003 void fast_set_symbol(48,1442 void fast_set_defaults(79,2054 Term fast_parse(105,2556 Term fast_read_term(169,4110 void fast_fwrite_term(201,4733 void fast_fwrite_term_nl(245,5761 Topform fast_read_clause(271,6328 void fast_fwrite_clause(305,7065 fatal.c,146 static int Fatal_exit_code 23,812 void bell(36,971 int get_fatal_exit_code(53,1223 void set_fatal_exit_code(70,1517 void fatal_error(88,1880 features.c,384 static Ilist Feature_symbols;23,815 static int Work_size;30,1078 static int *Pos_occurrences;31,1139 static int *Neg_occurrences;32,1168 static int *Pos_maxdepth;33,1197 static int *Neg_maxdepth;34,1223 void init_features(46,1343 void fill_in_arrays(66,1852 Ilist features(114,2905 int feature_length(161,3850 BOOL features_less_or_equal(185,4281 void p_features(204,4544 flatdemod.c,528 static int Fdemod_attempts 23,816 static int Fdemod_rewrites 24,848 Flatterm fapply_demod(45,1284 enum { GO,75,1854 enum { GO, BACKTRACK 75,1854 void maybe_unbind(85,1964 #define MAYBE_UNBIND(MAYBE_UNBIND94,2152 Plist discrim_flat_retrieve_leaf(100,2309 void *discrim_flat_retrieve_first(187,3981 void *discrim_flat_retrieve_next(217,4536 void discrim_flat_cancel(250,5155 Flatterm fdemod(272,5561 Term fdemodulate(387,8548 int fdemod_attempts(426,9492 int fdemod_rewrites(442,9721 void fdemod_clause(462,10083 flatterm.c,646 #define PTRS_FLATTERM 27,844 static unsigned Flatterm_gets,28,896 static unsigned Flatterm_gets, Flatterm_frees;28,896 Flatterm get_flatterm(40,1045 void free_flatterm(63,1450 void fprint_flatterm_mem(82,1843 void p_flatterm_mem(108,2474 BOOL flatterm_ident(127,2691 void zap_flatterm(146,3031 Flatterm term_to_flatterm(166,3302 Term flatterm_to_term(204,3921 Flatterm copy_flatterm(230,4367 void print_flatterm(264,4906 int flatterm_symbol_count(300,5563 void p_flatterm(326,5941 BOOL flat_occurs_in(342,6123 I2list flat_multiset_vars(361,6434 BOOL flat_variables_multisubset(381,6778 int flatterm_count_without_vars(401,7167 formula.c,2323 #define PTRS_FORMULA 27,843 static unsigned Formula_gets,28,893 static unsigned Formula_gets, Formula_frees;28,893 static unsigned Arg_mem;30,939 Formula get_formula(39,1081 void free_formula(59,1367 void fprint_formula_mem(82,1891 void p_formula_mem(111,2630 unsigned formula_megs(131,2917 Formula formula_get(151,3208 void zap_formula(170,3576 BOOL logic_term(200,4042 void gather_symbols_in_term(220,4455 void gather_symbols_in_formula_term(248,5073 void gather_symbols_in_formula(277,5701 void gather_symbols_in_formulas(305,6386 Ilist function_symbols_in_formula(322,6699 Ilist relation_symbols_in_formula(344,7080 BOOL relation_symbol_in_formula(366,7460 Formula term_to_formula(386,7870 Term formula_to_term(459,9600 void fprint_formula(533,11467 void p_formula(602,13310 unsigned hash_formula(621,13611 BOOL formula_ident(652,14307 Formula formula_copy(682,14976 BOOL dual_type(708,15395 Formula dual(730,15755 Formula and(750,16001 Formula or(768,16221 Formula imp(786,16439 Formula impby(804,16662 Formula not(819,16862 Formula negate(836,17057 BOOL quant_form(851,17241 Formula flatten_top(866,17466 Formula formula_flatten(922,18562 Formula nnf2(949,19247 Formula nnf(1069,22166 Formula make_conjunction(1085,22381 Formula make_disjunction(1107,22721 void formula_canon_eq(1130,23122 int formula_size(1161,23679 int greatest_qvar(1189,24231 int greatest_symnum_in_formula(1222,24937 void subst_free_var(1256,25698 Formula elim_rebind(1277,26210 Formula eliminate_rebinding(1332,27677 Plist free_vars(1345,27850 BOOL closed_formula(1374,28407 Formula get_quant_form(1392,28686 Formula uni_close(1407,28935 Formula universal_closure(1430,29364 BOOL free_var(1445,29616 BOOL free_variable(1472,30064 Formula formulas_to_conjunction(1495,30575 Formula formulas_to_disjunction(1522,31168 Plist copy_plist_of_formulas(1544,31530 BOOL literal_formula(1567,31927 BOOL clausal_formula(1587,32226 void formula_set_vars_recurse(1608,32559 void formula_set_variables(1639,33407 BOOL positive_formula(1697,34792 BOOL formula_contains_attributes(1726,35312 BOOL subformula_contains_attributes(1752,35792 Ilist constants_in_formula(1775,36170 BOOL relation_in_formula(1792,36426 void rename_all_bound_vars(1815,36815 void rename_these_bound_vars(1843,37364 fpa.c,2247 static unsigned Fpa_id_count 23,810 static unsigned Next_calls 25,845 static unsigned Next_calls_overflows 26,877 #define BUMP_NEXT_CALLS 27,919 typedef struct fpa_trie * Fpa_trie;Fpa_trie29,1005 struct fpa_trie fpa_trie31,1042 struct fpa_index fpa_index40,1180 struct fpa_state fpa_state46,1261 struct path path61,1661 enum { LEAF,66,1708 enum { LEAF, UNION,66,1708 enum { LEAF, UNION, INTERSECT 66,1708 #define PTRS_FPA_TRIE 77,1963 static unsigned Fpa_trie_gets,78,2015 static unsigned Fpa_trie_gets, Fpa_trie_frees;78,2015 #define PTRS_FPA_STATE 80,2063 static unsigned Fpa_state_gets,81,2117 static unsigned Fpa_state_gets, Fpa_state_frees;81,2117 #define PTRS_FPA_INDEX 83,2167 static unsigned Fpa_index_gets,84,2221 static unsigned Fpa_index_gets, Fpa_index_frees;84,2221 Fpa_trie get_fpa_trie(93,2345 void free_fpa_trie(108,2554 Fpa_state get_fpa_state(121,2737 void free_fpa_state(135,2936 Fpa_index get_fpa_index(148,3124 void free_fpa_index(163,3340 void fprint_fpa_mem(182,3728 void p_fpa_mem(220,4823 void fprint_path(240,5096 void p_path(271,5602 void fprint_fpa_trie(284,5785 void fprint_fpa_index(326,6666 void p_fpa_index(345,7117 Fpa_trie fpa_trie_member_insert(360,7486 Fpa_trie fpa_trie_member(400,8533 void fpa_trie_possible_delete(430,9371 void path_insert(457,9995 void path_delete(479,10475 Ilist path_push(506,11060 void path_restore(529,11490 void fpa_paths(548,11912 Fpa_index fpa_init_index(591,12904 void fpa_update(616,13461 Fpa_state query_leaf_full(645,14164 Fpa_state query_leaf(663,14497 Fpa_state query_intersect(690,14941 Fpa_state query_union(707,15219 Fpa_state query_special(729,15561 void zap_fpa_state(779,16950 Fpa_state union_commuted(798,17226 BOOL var_in_context(846,18193 BOOL all_args_vars_in_context(859,18379 Fpa_state build_query(878,18691 void fprint_fpa_state(961,21085 void p_fpa_state(1007,22033 void p_fpa_query(1023,22283 Term next_term(1063,23565 Term fpa_next_answer(1180,26140 Term fpa_first_answer(1206,26777 void fpa_cancel(1229,27278 void zap_fpa_trie(1241,27415 void zap_fpa_index(1273,27873 BOOL fpa_empty(1290,28131 void fpa_density(1302,28304 void p_fpa_density(1325,28682 unsigned mega_next_calls(1340,28864 fpalist.c,985 #define F_INITIAL_SIZE 48,1970 #define F_MAX_SIZE 49,2050 #define PTRS_FPA_CHUNK 55,2135 static unsigned Fpa_chunk_gets,56,2189 static unsigned Fpa_chunk_gets, Fpa_chunk_frees;56,2189 #define PTRS_FPA_LIST 58,2239 static unsigned Fpa_list_gets,59,2291 static unsigned Fpa_list_gets, Fpa_list_frees;59,2291 static unsigned Chunk_mem;61,2339 Fpa_chunk get_fpa_chunk(70,2493 void free_fpa_chunk(87,2748 Fpa_list get_fpa_list(105,3012 void free_fpa_list(120,3233 void fprint_fpalist_mem(139,3624 void p_fpalist_mem(173,4613 #define FLAST(FLAST184,4799 #define FFIRST(FFIRST185,4838 Fpa_chunk double_chunksize(194,4953 Fpa_chunk flist_insert(232,5850 void fpalist_insert(314,7782 Fpa_chunk consolidate(344,8542 Fpa_chunk flist_delete(367,8977 void fpalist_delete(413,9894 struct fposition first_fpos(433,10232 struct fposition next_fpos(448,10440 void zap_fpa_chunks(474,10917 void zap_fpalist(492,11143 BOOL fpalist_empty(508,11338 void p_fpa_list(523,11519 glist.c,3091 #define PTRS_ILIST 25,804 static unsigned Ilist_gets,26,850 static unsigned Ilist_gets, Ilist_frees;26,850 #define PTRS_PLIST 28,892 static unsigned Plist_gets,29,938 static unsigned Plist_gets, Plist_frees;29,938 #define PTRS_I2LIST 31,980 static unsigned I2list_gets,32,1028 static unsigned I2list_gets, I2list_frees;32,1028 #define PTRS_I3LIST 34,1072 static unsigned I3list_gets,35,1120 static unsigned I3list_gets, I3list_frees;35,1120 Ilist get_ilist(47,1259 void free_ilist(65,1474 Plist get_plist(81,1661 void free_plist(99,1876 I2list get_i2list(115,2065 void free_i2list(133,2287 I3list get_i3list(149,2481 void free_i3list(167,2703 void fprint_glist_mem(186,3080 void p_glist_mem(224,4113 Plist plist_cat(251,4747 Plist plist_cat2(282,5266 Plist plist_pop(299,5589 int plist_count(318,5830 Plist rev_app_plist(332,6009 Plist reverse_plist(361,6506 Plist copy_plist(377,6752 void zap_plist(408,7226 Plist plist_append(432,7563 Plist plist_prepend(458,7987 BOOL plist_member(477,8269 Plist plist_subtract(500,8630 BOOL plist_subset(523,8978 Plist plist_remove(544,9317 Plist plist_remove_string(572,9760 Plist sort_plist(599,10177 Plist plist_remove_last(624,10653 int position_of_string_in_plist(649,11055 BOOL string_member_plist(674,11454 int longest_string_in_plist(690,11714 void *ith_in_plist(711,12022 void *plist_last(731,12298 Ilist ilist_cat(759,12990 Ilist ilist_cat2(788,13481 Ilist ilist_pop(810,13878 int ilist_count(829,14119 Ilist rev_app_ilist(843,14298 Ilist reverse_ilist(872,14795 Ilist copy_ilist(888,15041 void zap_ilist(918,15461 Ilist ilist_append(942,15799 Ilist ilist_prepend(968,16222 Ilist ilist_last(986,16442 BOOL ilist_member(1009,16859 Ilist ilist_subtract(1032,17218 Ilist ilist_removeall(1058,17629 Ilist ilist_intersect(1086,18078 Ilist ilist_union(1114,18550 Ilist ilist_set(1137,19085 Ilist ilist_rem_dups(1163,19488 BOOL ilist_is_set(1190,19851 BOOL ilist_subset(1210,20128 void fprint_ilist(1232,20497 void p_ilist(1255,20899 Ilist ilist_copy(1272,21092 Ilist ilist_remove_last(1294,21386 int ilist_occurrences(1319,21769 Ilist ilist_insert_up(1337,22034 int position_in_ilist(1362,22431 void zap_i2list(1392,23069 I2list i2list_append(1416,23415 I2list i2list_prepend(1443,23879 I2list i2list_removeall(1465,24190 I2list i2list_member(1490,24565 void p_i2list(1512,24930 int i2list_count(1534,25272 BOOL i3list_member(1556,25786 I3list i3list_append(1578,26196 I3list i3list_prepend(1606,26684 void zap_i3list(1627,26995 I3list rev_app_i3list(1646,27243 I3list reverse_i3list(1675,27751 I3list copy_i3list(1691,28005 int i3list_count(1723,28469 I2list alist_insert(1750,29242 int assoc(1766,29456 I3list alist2_insert(1793,30040 int assoc2a(1809,30265 int assoc2b(1831,30591 I3list alist2_remove(1852,30904 BOOL i2list_multimember(1889,31720 BOOL i2list_multisubset(1909,32029 I2list multiset_add_n(1930,32385 I2list multiset_add(1955,32761 I2list multiset_union(1973,33095 Ilist multiset_to_set(1992,33369 int multiset_occurrences(2014,33674 hash.c,644 struct hashtab hashtab23,811 struct hashnode hashnode28,868 #define PTRS_HASHTAB 37,952 static unsigned Hashtab_gets,38,1002 static unsigned Hashtab_gets, Hashtab_frees;38,1002 #define PTRS_HASHNODE 40,1048 static unsigned Hashnode_gets,41,1100 static unsigned Hashnode_gets, Hashnode_frees;41,1100 Hashtab get_hashtab(50,1220 void free_hashtab(64,1405 Hashnode get_hashnode(77,1581 void free_hashnode(91,1773 void fprint_hash_mem(110,2158 void p_hash_mem(142,3001 Hashtab hash_init(161,3256 void hash_insert(180,3502 void *hash_lookup(199,3796 void hash_delete(220,4134 void hash_destroy(255,4798 void hash_info(280,5152 hints.c,647 static Lindex Hints_idx 23,812 static Clist Redundant_hints 24,876 static Mindex Back_demod_idx;25,946 static int Bsub_wt_attr;26,1026 static BOOL Back_demod_hints;27,1051 static BOOL Collect_labels;28,1081 static int Hint_id_count 36,1258 static int Active_hints_count 37,1288 static int Redundant_hints_count 38,1323 void init_hints(50,1452 void done_with_hints(76,2040 int redundant_hints(99,2474 Topform find_equivalent_hint(111,2641 Topform find_matching_hint(139,3373 void index_hint(168,4042 void unindex_hint(208,5136 void adjust_weight_with_hints(232,5571 void keep_hint_matcher(300,7373 void back_demod_hints(316,7586 ibuffer.c,317 Ibuffer ibuf_init(39,1002 void ibuf_free(60,1356 void ibuf_write(77,1562 void ibuf_write_block(106,2183 void ibuf_rewind(124,2447 int ibuf_read(141,2725 int ibuf_xread(165,3175 int ibuf_length(185,3499 int *ibuf_buffer(200,3675 #define ISIZE 211,3811 Ibuffer fd_read_to_ibuf(217,3864 void p_ibuf(254,4562 int_code.c,374 void put_ilist_to_ibuf(30,885 Ilist get_ilist_from_ibuf(45,1158 void put_i3list_to_ibuf(63,1473 I3list get_i3list_from_ibuf(81,1814 void put_term_to_ibuf(103,2226 Term get_term_from_ibuf(123,2563 void put_just_to_ibuf(150,3118 Just get_just_from_ibuf(208,4462 void put_clause_to_ibuf(277,6069 Topform get_clause_from_ibuf(312,6775 void check_ibuf_clause(348,7493 interp.c,2821 struct interp interp28,878 #define ISWAP(ISWAP50,1726 #define I2(I254,1828 #define I3(I355,1868 #define UNDEFINED 57,1927 #define FUNCTION 58,1947 #define RELATION 59,1967 #define MAX_VARS_EVAL 61,1988 static long unsigned Iso_checks 65,2033 static long unsigned Iso_perms 66,2070 #define PTRS_INTERP 72,2136 static unsigned Interp_gets,73,2184 static unsigned Interp_gets, Interp_frees;73,2184 Interp get_interp(82,2298 void free_interp(96,2476 void fprint_interp_mem(115,2855 void p_interp_mem(141,3464 int *trivial_permutation(157,3653 int int_power(179,4009 Interp compile_interp(219,4800 void transpose_binary(355,8547 void zap_interp(394,9407 void fprint_interp_tex(436,10153 void compute_args(535,12726 void fprint_interp_xml(558,13122 void fprint_interp_standard(669,16515 void fprint_interp_standard2(727,17968 static void portable_indent(785,19409 void portable_recurse(800,19634 void fprint_interp_portable(834,20417 void p_interp(891,21744 void fprint_interp_cooked(908,22019 void fprint_interp_tabular(979,23652 void fprint_interp_raw(1065,25522 int eval_term_ground(1120,26821 BOOL eval_literals_ground(1169,27986 BOOL all_recurse(1195,28581 BOOL eval_literals(1238,29798 int all_recurse2(1263,30229 int eval_literals_true_instances(1295,31009 int eval_literals_false_instances(1322,31558 int eval_fterm_ground(1340,32021 BOOL eval_form(1390,33153 BOOL eval_formula(1483,35753 Term interp_remove_constants_recurse(1524,36471 void interp_remove_constants(1552,37072 Term interp_remove_others_recurse(1568,37362 void interp_remove_others(1596,38002 Interp copy_interp(1612,38304 Interp permute_interp(1697,40420 BOOL ident_interp_perm(1765,42087 Interp normal_interp(1846,44462 BOOL iso_interp_recurse(1890,45364 BOOL isomorphic_interps(1931,46353 int interp_size(1969,47049 Term interp_comments(1985,47257 int *interp_table(2001,47488 long unsigned iso_checks(2022,47898 long unsigned iso_perms(2038,48128 BOOL evaluable_term(2053,48294 BOOL evaluable_atom(2084,48896 BOOL evaluable_literals(2115,49511 BOOL evaluable_formula(2134,49818 BOOL evaluable_topform(2157,50192 void update_interp_with_constant(2175,50497 BOOL eval_topform(2201,51060 Ordertype compare_interp(2221,51416 BOOL ident_interp(2254,52054 Ordertype compare_ints(2260,52165 void invert_perm(2271,52339 void copy_perm(2279,52462 Ordertype compare_permed_interps(2301,52814 void canon_recurse(2376,54556 Interp canon_interp(2426,55803 void assign_discriminator_counts(2460,56579 BOOL same_discriminator_counts(2484,57099 void update_profile(2503,57518 void create_profile(2538,58246 void p_interp_profile(2573,59022 Interp normal3_interp(2625,60257 BOOL same_profiles(2695,61897 long unsigned perms_required(2715,62230 long unsigned factorial(2750,62758 ioutil.c,1118 void fwrite_formula(39,1187 Topform read_clause(66,1781 Topform parse_clause_from_string(89,2167 BOOL end_of_list_clause(108,2509 Clist read_clause_clist(139,3248 Plist read_clause_list(168,3865 void sb_write_clause_jmap(185,4223 void sb_write_clause(245,5407 void sb_xml_write_clause_jmap(262,5747 void sb_tagged_write_clause_jmap(328,7779 void fwrite_clause_jmap(372,8576 void fwrite_clause(405,9332 void f_clause(421,9601 void fwrite_clause_clist(444,9974 void fwrite_demod_clist(470,10547 void fwrite_clause_list(510,11400 void f_clauses(535,11865 Formula read_formula(554,12238 BOOL end_of_list_formula(576,12553 Plist read_formula_list(605,13137 void fwrite_formula_list(639,13751 void zap_formula_list(665,14232 BOOL end_of_list_term(687,14559 BOOL end_of_commands_term(708,14905 Plist read_term_list(735,15512 void fwrite_term_list(769,16107 Term term_reader(801,16807 void term_writer(823,17271 Topform clause_reader(847,17767 void clause_writer(863,18187 Topform term_to_topform2(882,18466 Topform read_clause_or_formula(912,19033 Plist read_clause_or_formula_list(934,19379 ivy.c,790 #define DICT_SIZE 23,810 static char *Dict[27,895 char *dict_lookup(40,1177 void ivy_term_trans(57,1422 void ivy_clause_trans(78,1779 void sb_ivy_write_term(93,2012 void sb_ivy_write_pair(118,2462 void sb_ivy_write_pairs(136,2784 void sb_ivy_write_position(155,3113 void sb_ivy_write_lit(174,3445 void sb_ivy_write_literals(192,3766 void sb_ivy_write_just(217,4228 void sb_ivy_write_clause_jmap(275,5687 Topform instantiate_inference(299,6422 Topform renumber_inference(316,6902 Ilist ivy_lit_position(339,7358 Ilist ivy_para_position(368,8198 Plist paramod2_instances(396,8920 Topform flip_inference(481,11512 Plist resolve2_instances(524,12674 Plist factor2_instances(621,15016 Plist copy_proof_and_rename_symbols_for_ivy(682,16548 Plist expand_proof_ivy(704,16948 just.c,2701 #define PTRS_JUST 27,840 static unsigned Just_gets,28,884 static unsigned Just_gets, Just_frees;28,884 #define PTRS_PARAJUST 30,924 static unsigned Parajust_gets,31,976 static unsigned Parajust_gets, Parajust_frees;31,976 #define PTRS_INSTANCEJUST 33,1024 static unsigned Instancejust_gets,34,1084 static unsigned Instancejust_gets, Instancejust_frees;34,1084 #define PTRS_IVYJUST 36,1140 static unsigned Ivyjust_gets,37,1190 static unsigned Ivyjust_gets, Ivyjust_frees;37,1190 Just get_just(49,1329 void free_just(63,1493 Parajust get_parajust(79,1681 void free_parajust(93,1873 Instancejust get_instancejust(109,2089 void free_instancejust(123,2309 Ivyjust get_ivyjust(136,2508 void free_ivyjust(150,2692 void fprint_just_mem(169,3072 void p_just_mem(213,4385 Just ivy_just(232,4584 Just input_just(260,5122 Just goal_just(279,5399 Just deny_just(298,5672 Just clausify_just(318,5979 Just expand_def_just(338,6306 Just copy_just(358,6686 Just propositional_just(378,7011 Just new_symbol_just(398,7376 Just back_demod_just(418,7719 Just back_unit_deletion_just(438,8078 Just binary_res_just(460,8541 Just binary_res_just_by_id(484,9082 Just factor_just(508,9609 Just xxres_just(528,10030 Just resolve_just(549,10454 Just demod_just(568,10749 Just para_just(588,11095 Just instance_just(616,11650 Just para_just_rev_copy(640,12131 Just unit_del_just(660,12557 Just flip_just(680,12966 Just xx_just(700,13286 Just merge_just(721,13641 Just eval_just(741,13959 Just append_just(760,14220 Just copy_justification(781,14502 char *jstring(859,16592 int jstring_to_jtype(907,18115 char itoc(974,19897 int ctoi(993,20130 int jmap1(1015,20486 char *jmap2(1039,20998 void sb_append_id(1065,21403 void sb_write_res_just(1081,21733 void sb_write_position(1120,22565 void sb_write_ids(1142,22947 void sb_write_just(1164,23346 void sb_xml_write_just(1324,27317 void p_just(1371,28377 void zap_parajust(1387,28617 void zap_instancejust(1401,28813 void zap_ivyjust(1414,29000 void zap_just(1433,29300 Ilist get_parents(1491,30600 Topform first_negative_parent(1586,33386 Plist get_clanc(1607,33826 Plist get_clause_ancestors(1643,34667 int proof_length(1659,34894 int map_id(1671,35037 void map_just(1688,35301 int just_count(1780,37903 void mark_parents_as_used(1797,38119 I2list cl_level(1815,38451 int clause_level(1849,39245 int lit_string_to_int(1864,39488 Ilist args_to_ilist(1882,39739 Just term_to_just(1914,40333 BOOL primary_just_type(2078,43902 BOOL has_input_just(2094,44174 BOOL has_copy_just(2110,44409 BOOL has_copy_flip_just(2126,44670 void sb_tagged_write_res_just(2148,45325 void sb_tagged_write_just(2183,46015 lindex.c,409 #define PTRS_LINDEX 27,842 static unsigned Lindex_gets,28,890 static unsigned Lindex_gets, Lindex_frees;28,890 Lindex get_lindex(37,1004 void free_lindex(51,1182 void fprint_lindex_mem(70,1561 void p_lindex_mem(96,2170 Lindex lindex_init(126,2904 void lindex_destroy(149,3447 void lindex_update(167,3737 void lindex_update_first(189,4181 BOOL lindex_empty(212,4636 BOOL lindex_backtrack(229,4949 listterm.c,413 #define CONS_SYM 23,815 #define NIL_SYM 24,841 Term get_nil_term(37,998 Term listterm_cons(54,1249 BOOL cons_term(74,1584 BOOL nil_term(91,1856 BOOL proper_listterm(109,2165 Term listterm_append(137,2839 int listterm_length(158,3208 Term listterm_i(179,3547 BOOL listterm_member(200,3896 Plist listterm_to_tlist(224,4321 void listterm_zap(249,4709 Term rev2(266,4914 Term listterm_reverse(286,5279 literals.c,1875 #define PTRS_LITERALS 27,844 static unsigned Literals_gets,28,896 static unsigned Literals_gets, Literals_frees;28,896 Literals get_literals(40,1045 void free_literals(57,1264 void fprint_literals_mem(76,1655 void p_literals_mem(102,2284 void zap_literal(122,2527 void zap_literals(139,2754 Literals new_literal(159,3063 Literals copy_literal(177,3308 Literals append_literal(193,3572 Literals term_to_literals(213,3864 Term literal_to_term(248,4584 Term literals_to_term(270,4892 Term lits_to_term(297,5513 void free_lits_to_term(327,6046 int positive_literals(349,6449 int negative_literals(370,6832 BOOL positive_clause(391,7217 BOOL any_clause(407,7485 BOOL negative_clause(423,7719 BOOL mixed_clause(440,8008 int number_of_literals(457,8298 BOOL unit_clause(476,8604 BOOL horn_clause(492,8861 BOOL definite_clause(508,9129 int greatest_variable_in_clause(525,9443 Plist vars_in_clause(547,9888 Ilist varnums_in_clause(566,10233 int number_of_variables(590,10686 BOOL ground_clause(608,10947 Literals copy_literals(626,11272 Literals copy_literals_with_flags(652,11785 Literals copy_literals_with_flag(678,12334 int literal_number(704,12938 int atom_number(729,13444 Literals ith_literal(753,13853 BOOL true_clause(775,14233 BOOL complementary_scan(792,14506 BOOL tautology(815,15004 int symbol_occurrences_in_clause(839,15441 Literals remove_null_literals(859,15797 Literals first_literal_of_sign(885,16191 Ilist constants_in_clause(906,16590 BOOL clause_ident(927,16968 int clause_symbol_count(952,17478 int clause_depth(972,17872 BOOL pos_eq(995,18305 BOOL neg_eq(1012,18588 BOOL pos_eq_unit(1029,18899 BOOL neg_eq_unit(1047,19191 BOOL contains_pos_eq(1066,19539 BOOL contains_eq(1089,19959 BOOL only_eq(1111,20321 int literals_depth(1133,20707 Term term_at_position(1154,21010 Ilist pos_predicates(1175,21354 maximal.c,539 int Maximal_flag 23,814 int Maximal_signed_flag 24,886 int Selected_flag 25,961 void init_maximal(37,1118 BOOL greater_literals(53,1434 BOOL max_lit_test(83,2124 BOOL max_signed_lit_test(110,2672 void mark_maximal_literals(134,3148 BOOL maximal_literal(164,3873 BOOL maximal_signed_literal(184,4301 int number_of_maximal_literals(203,4706 void mark_selected_literal(224,5045 void mark_selected_literals(239,5265 BOOL selected_literal(270,5924 BOOL exists_selected_literal(285,6138 void copy_selected_literal_marks(304,6448 memory.c,816 #define MALLOC_MEGS 21,776 #define DEFAULT_MAX_MEGS 22,847 #define MAX_MEM_LISTS 23,912 static void ** M[25,985 static BOOL Max_megs_check 27,1019 static int Max_megs 28,1054 static int Malloc_calls 31,1206 static unsigned Bytes_palloced 33,1280 static void *Block 35,1317 static void *Block_pos 36,1397 static unsigned Mem_calls 38,1464 static unsigned Mem_calls_overflows 39,1495 #define BUMP_MEM_CALLS 41,1537 void *palloc(50,1728 void *get_cmem(96,2788 void *get_mem(134,3421 void free_mem(166,4013 int mlist_length(190,4401 void memory_report(207,4598 int megs_malloced(233,5277 void set_max_megs(251,5617 void set_max_megs_proc(268,5900 int bytes_palloced(285,6189 void *tp_alloc(302,6468 unsigned mega_mem_calls(321,6786 void disable_max_megs(338,7026 void enable_max_megs(353,7204 mindex.c,948 struct mindex_pos mindex_pos23,813 #define PTRS_MINDEX 53,1371 static unsigned Mindex_gets,54,1419 static unsigned Mindex_gets, Mindex_frees;54,1419 #define PTRS_MINDEX_POS 56,1463 static unsigned Mindex_pos_gets,57,1519 static unsigned Mindex_pos_gets, Mindex_pos_frees;57,1519 Mindex get_mindex(66,1641 void free_mindex(82,1862 Mindex_pos get_mindex_pos(95,2037 void free_mindex_pos(110,2265 void fprint_mindex_mem(129,2664 void p_mindex_mem(161,3522 Mindex mindex_init(204,4833 BOOL mindex_empty(234,5560 void mindex_free(263,6056 void mindex_destroy(295,6675 void linear_insert(324,7230 void linear_delete(343,7538 void linear_update(375,8158 void mindex_update(398,8628 Term mindex_retrieve_first(465,10746 Term next_candidate(510,11865 Term retrieve_next_backtrack(565,13185 Term mindex_retrieve_next(643,15321 void mindex_retrieve_cancel(733,17311 void fprint_linear_index(765,18162 void fprint_mindex(787,18560 multiset.c,98 int num_occurrences(30,883 Plist set_of_more_occurrences(48,1211 BOOL greater_multiset(83,2083 nonport.c,98 char *username(42,1117 char *hostname(64,1471 int my_process_id(87,1826 int get_bits(107,2093 options.c,2570 typedef enum { FLAGT,28,892 typedef enum { FLAGT, PARMT,28,892 typedef enum { FLAGT, PARMT, FLOATPARMT,28,892 typedef enum { FLAGT, PARMT, FLOATPARMT, STRINGPARMT 28,892 typedef enum { FLAGT, PARMT, FLOATPARMT, STRINGPARMT } Opttype;Opttype28,892 typedef struct optdep * Optdep;Optdep29,956 struct optdep optdep31,989 struct flag flag42,1544 struct parm parm49,1671 struct floatparm floatparm57,1858 struct stringparm stringparm65,2063 static struct flag Flags[74,2414 static struct parm Parms[75,2451 static struct floatparm Floatparms[76,2488 static struct stringparm Stringparms[77,2540 static int Next_flag 79,2596 static int Next_parm 80,2622 static int Next_floatparm 81,2648 static int Next_stringparm 82,2679 static int Option_updates 84,2712 static BOOL Ignore_dependencies 86,2774 #define PTRS_OPTDEP 92,2845 static unsigned Optdep_gets,93,2893 static unsigned Optdep_gets, Optdep_frees;93,2893 Optdep get_optdep(102,3007 void free_optdep(117,3191 void fprint_options_mem(137,3579 void p_options_mem(163,4192 void enable_option_dependencies(182,4418 void disable_option_dependencies(197,4633 BOOL option_dependencies_state(212,4847 int init_flag(232,5286 int init_parm(269,6140 int init_floatparm(304,6932 int init_stringparm(343,7903 void fprint_options(380,8848 void p_options(433,10186 int flag(451,10449 int parm(468,10715 BOOL at_parm_limit(484,10918 BOOL over_parm_limit(504,11245 double floatparm(525,11646 BOOL stringparm(542,11938 char *stringparm1(559,12207 void update_flag(576,12495 void set_flag(654,14482 void clear_flag(672,14825 void assign_parm(691,15219 void assign_floatparm(753,16903 void assign_stringparm(788,18079 int str_to_flag_id(827,19037 int str_to_parm_id(848,19417 int str_to_floatparm_id(869,19802 int str_to_stringparm_id(890,20214 char *flag_id_to_str(910,20562 char *parm_id_to_str(928,20873 char *floatparm_id_to_str(946,21199 char *stringparm_id_to_str(964,21553 Optdep append_dep(978,21803 void flag_flag_dependency(1001,22217 void flag_flag_dep_default(1024,22759 void flag_parm_dependency(1047,23298 void flag_floatparm_dependency(1070,23840 void flag_parm_dep_default(1093,24394 void flag_floatparm_dep_default(1116,24941 void parm_flag_dependency(1139,25497 void parm_parm_dependency(1160,25974 void flag_stringparm_dependency(1183,26530 void flag_stringparm_dep_default(1206,27104 int option_updates(1227,27582 int flag_default(1242,27751 int parm_default(1257,27935 int floatparm_default(1272,28124 char *stringparm1_default(1287,28340 order.c,116 void merge_sort_recurse(49,1403 void merge_sort(110,2752 Ordertype compare_vecs(129,3112 void copy_vec(151,3428 paramod.c,839 static BOOL Ordered_inference 23,814 static BOOL Positive_inference 24,854 static BOOL Para_from_vars 25,895 static BOOL Para_into_vars 26,931 static BOOL Para_from_small 27,968 static BOOL Check_instances 28,1006 static int Para_instance_prunes 30,1077 static int Basic_prunes 31,1132 void paramodulation_options(44,1291 int para_instance_prunes(73,1977 int basic_paramodulation_prunes(89,2248 BOOL basic_check(101,2413 Literals apply_lit_para(118,2656 Term apply_substitute_para(134,2960 Topform paramodulate(156,3402 BOOL para_from_right(200,4715 BOOL from_parent_test(221,5098 BOOL into_parent_test(245,5699 BOOL check_instance(287,6779 BOOL check_instances(319,7529 void para_into(341,7989 void para_into_lit(391,9296 void para_from_into(442,10931 Topform para_pos(479,11980 Topform para_pos2(529,13395 parautil.c,719 int Oriented_flag 23,815 int Renamable_flip_flag 24,893 void init_paramod(36,1064 void mark_renamable_flip(55,1452 BOOL renamable_flip_eq(74,1898 BOOL renamable_flip_eq_test(95,2333 void mark_oriented_eq(126,2933 BOOL oriented_eq(145,3347 BOOL same_term_structure(168,3792 void flip_eq(194,4304 void orient_equalities(218,4878 BOOL eq_tautology(295,7028 Term top_flip(320,7539 void zap_top_flip(343,7906 Literals literal_flip(358,8065 void zap_literal_flip(377,8355 Topform clause_with_new_constant(390,8537 Topform new_constant(422,9495 Topform fold_denial(453,10163 BOOL equational_def_2(486,10939 int equational_def(504,11256 Ordertype unfold_order(530,11691 Topform build_reflex_eq(555,12146 parse.c,3210 #define COMMENT_CHAR 23,812 static char Cons_char 25,838 static char Quote_char 26,867 static int Quantifier_precedence 27,898 static BOOL Parenthesize 29,978 static BOOL Check_for_illegal_symbols 30,1012 typedef enum {TOK_UNKNOWN,34,1078 TOK_ORDINARY,35,1143 TOK_SPECIAL,36,1190 TOK_STRING,37,1236 TOK_COMMENT,38,1280 TOK_PUNC 39,1326 } Toktype;Toktype40,1377 typedef enum {READ_BUF_OK,44,1425 typedef enum {READ_BUF_OK,READ_BUF_EOF,44,1425 READ_BUF_ERROR,45,1465 READ_BUF_ERROR,READ_BUF_QUOTE_ERROR}45,1465 READ_BUF_ERROR,READ_BUF_QUOTE_ERROR} Read_rc;Read_rc45,1465 typedef struct token * Token;Token49,1543 struct token token51,1574 typedef struct pterm * Pterm;Pterm61,1848 struct pterm pterm63,1879 typedef struct tok_pos *Tok_pos;Tok_pos71,2017 struct tok_pos tok_pos73,2051 static BOOL Translate_neg_equalities 81,2163 static Plist Multiple_char_special_syms 82,2211 #define PTRS_TOKEN 88,2290 static unsigned Token_gets,89,2336 static unsigned Token_gets, Token_frees;89,2336 #define PTRS_PTERM 91,2378 static unsigned Pterm_gets,92,2424 static unsigned Pterm_gets, Pterm_frees;92,2424 Token get_token(101,2534 void free_token(115,2705 Pterm get_pterm(128,2865 void free_pterm(142,3036 void fprint_parse_mem(161,3408 void p_parse_mem(193,4220 void p_tokens(210,4405 void translate_neg_equalities(238,4950 Term translate_neg_eq(250,5132 Term untranslate_neg_eq(276,5697 void free_pterm_list(302,6270 void free_token_list(321,6527 BOOL end_char(340,6788 BOOL comment_char(352,6920 BOOL quote_char(364,7067 BOOL punctuation_char(376,7214 BOOL ordinary_char(394,7496 BOOL special_char(410,7749 BOOL white_char(448,8430 BOOL all_whitespace(465,8733 int finish_comment(494,9236 int read_buf(545,10478 String_buf max_special_symbol(605,11583 Token tokenize(653,12639 int comma_terms(737,14469 void transfer_comma_term(752,14722 BOOL quantifier(771,15075 BOOL ordinary_constant_string(787,15320 BOOL ordinary_constant(801,15524 BOOL quant_prefix(816,15755 Term terms_to_term(836,16173 void next_token(985,20811 Term toks_to_set(1005,21119 Term make_a_list(1022,21443 Term toks_to_list(1043,21856 Pterm toks_to_terms(1107,23377 Term toks_to_term(1226,26058 void fprint_parse_error(1259,26820 Term sread_term(1296,27820 Term read_term(1347,29180 Term parse_term_from_string(1395,30120 void arrange_term(1410,30364 void sb_remove_some_space(1528,33570 void sb_write_term(1564,34452 void fwrite_term(1594,35155 void fwrite_term_nl(1617,35633 char *process_quoted_symbol(1633,35843 void remember_multiple_char_special_syms(1661,36447 void forget_multiple_char_special_syms(1681,36944 void look_for_illegal_symbols(1701,37433 void declare_parse_type(1721,37933 void declare_quantifier_precedence(1744,38457 void declare_standard_parse_types(1759,38684 BOOL redeclare_symbol_and_copy_parsetype(1815,40550 void skip_to_nl(1852,41549 Plist split_string(1872,41888 void set_cons_char(1902,42418 char get_cons_char(1917,42581 void set_quote_char(1932,42746 char get_quote_char(1947,42913 void parenthesize(1962,43079 void check_for_illegal_symbols(1977,43267 pindex.c,636 struct pair_index pair_index23,813 #define INT_LARGE 35,1259 #define IN_RANGE(IN_RANGE36,1332 #define PTRS_PAIR_INDEX 42,1430 static unsigned Pair_index_gets,43,1486 static unsigned Pair_index_gets, Pair_index_frees;43,1486 Pair_index get_pair_index(52,1616 void free_pair_index(68,1870 void fprint_pindex_mem(87,2269 void p_pindex_mem(113,2906 Pair_index init_pair_index(137,3368 void zap_pair_index(180,4129 int pairs_exhausted(210,4697 void init_pair(224,4894 void insert_pair_index(265,5757 void delete_pair_index(304,6619 void retrieve_pair(401,8657 void p_pair_index(514,11412 int pair_already_used(558,12222 random.c,224 Term random_term(45,1344 Term random_nonvariable_term(112,2549 Term random_complex_term(136,3110 Ilist random_path(161,3687 void random_permutation(194,4356 Topform random_clause(238,5072 Term random_op_term(265,5604 resolve.c,1076 static BOOL Ordered 24,834 static BOOL Check_instances 25,875 static int Ur_nucleus_limit 27,917 static BOOL Initial_nuclei 28,995 static BOOL Production_mode 29,1075 static int Res_instance_prunes 31,1117 void resolution_options(45,1271 int res_instance_prunes(70,1772 BOOL unit_check(82,1923 BOOL pos_hyper_sat_test(95,2118 BOOL neg_hyper_sat_test(111,2430 void hyper_sat_atom(127,2738 void hyper_satellite(191,4489 void hyper_nucleus(214,5115 void hyper_resolution(258,6158 BOOL target_check(276,6562 void ur_sat_atom(297,7005 void ur_satellite(364,8858 void ur_nucleus(385,9332 void ur_resolution(430,10391 void xx_res(446,10724 void binary_resolvent(479,11566 BOOL binary_parent_test(529,12788 Topform instantiate_clause(576,14334 BOOL check_instance(594,14738 BOOL check_instances(628,15574 void bin_res_lit(647,15930 void binary_resolution(681,16847 void binary_factors(716,17626 void merge_literals(759,18566 Topform copy_inference(795,19439 Topform resolve2(827,20231 Topform resolve3(883,21518 Topform xx_resolve2(903,21972 std_options.c,252 static int Prolog_style_variables 25,831 static int Ignore_option_dependencies 26,898 static int Clocks 27,967 void init_standard_options(39,1136 void process_standard_options(58,1559 int clocks_id(86,2038 int prolog_style_variables_id(101,2202 strbuf.c,953 struct string_buf string_buf25,817 #define CHUNK_SIZE 30,876 struct chunk chunk32,900 typedef struct chunk *Chunk;Chunk37,963 #define PTRS_CHUNK 43,1022 static unsigned Chunk_gets,44,1068 static unsigned Chunk_gets, Chunk_frees;44,1068 #define PTRS_STRING_BUF 46,1110 static unsigned String_buf_gets,47,1166 static unsigned String_buf_gets, String_buf_frees;47,1166 Chunk get_chunk(56,1286 void free_chunk(70,1457 String_buf get_string_buf(86,1654 void free_string_buf(100,1860 void fprint_strbuf_mem(119,2259 void p_strbuf_mem(151,3110 String_buf init_string_buf(173,3495 void fprint_sb(191,3762 void p_sb(218,4235 void sb_append(238,4549 void sb_append_char(273,5138 void sb_replace_char(312,6005 char sb_char(337,6493 void sb_cat_copy(363,6960 void sb_cat(386,7480 void zap_string_buf(404,7764 char *sb_to_malloc_string(438,8673 char *sb_to_malloc_char_array(469,9262 int sb_size(494,9618 void sb_append_int(510,9847 string.c,468 static char *Float_format 23,813 BOOL str_ident(36,1027 char *new_str_copy(53,1325 BOOL string_member(71,1585 int which_string_member(92,1983 BOOL initial_substring(112,2308 BOOL substring(131,2563 void reverse_chars(153,2935 int natural_string(171,3220 int char_occurrences(192,3479 char *escape_char(215,3849 BOOL str_to_int(243,4396 char *int_to_str(266,4802 BOOL str_to_double(286,5142 char *double_to_str(316,5653 BOOL string_of_repeated(349,6145 subsume.c,574 static int Nonunit_subsumption_tests 23,814 int nonunit_subsumption_tests(35,966 BOOL subsume_literals(53,1367 BOOL subsume_bt_literals(87,2046 BOOL subsumes(133,2991 BOOL subsumes_bt(158,3532 Topform forward_subsume(185,4008 Plist back_subsume(238,5526 Topform back_subsume_one(294,7039 void atom_conflict(343,8206 void unit_conflict_by_index(388,9345 Topform try_unit_conflict(413,9942 void unit_delete(445,10778 Plist back_unit_del_by_index(519,12836 void simplify_literals(566,13936 BOOL eq_removable_literal(604,14823 void simplify_literals2(646,15920 symbols.c,5368 struct symbol symbol23,813 #define SYM_TAB_SIZE 42,1707 static Plist By_id[44,1736 static Plist By_sym[45,1804 static unsigned Symbol_count;47,1874 static char *True_sym 51,1944 static char *False_sym 52,1977 static char *And_sym 53,2010 static char *Or_sym 54,2042 static char *Not_sym 55,2074 static char *Iff_sym 56,2106 static char *Imp_sym 57,2140 static char *Impby_sym 58,2173 static char *All_sym 59,2206 static char *Exists_sym 60,2240 static char *Quant_sym 61,2277 static char *Attrib_sym 65,2359 static char *Eq_sym 66,2434 static char *Neq_sym 67,2504 char *true_sym(79,2670 char *false_sym(94,2820 char *and_sym(109,2967 char *or_sym(124,3107 char *not_sym(139,3245 char *iff_sym(154,3386 char *imp_sym(169,3527 char *impby_sym(184,3670 char *all_sym(199,3817 char *exists_sym(214,3961 char *quant_sym(229,4118 char *attrib_sym(244,4273 char *eq_sym(259,4422 char *neq_sym(274,4560 void set_operation_symbol(289,4714 char *get_operation_symbol(335,6043 BOOL symbol_in_use(382,7339 Symbol get_symbol(427,8477 int new_symnum(457,9065 unsigned hash_sym(470,9212 unsigned hash_id(488,9464 Symbol lookup_by_id(500,9607 Symbol lookup_by_sym(518,9879 int str_to_sn(544,10557 void fprint_syms(580,11386 void p_syms(609,12018 void fprint_sym(626,12269 void sprint_sym(643,12568 void p_sym(660,12851 BOOL str_exists(678,13168 int greatest_symnum(705,13684 char *sn_to_str(725,14205 BOOL is_symbol(747,14552 int sn_to_arity(767,14966 int sn_to_occurrences(787,15289 void set_unfold_symbol(807,15626 BOOL is_unfold_symbol(823,15842 void declare_aux_symbols(839,16059 char *parse_type_to_str(862,16573 void clear_parse_type_for_all_symbols(887,17104 void clear_parse_type(910,17488 void check_diff_type_same_prec(932,17865 void set_parse_type(979,19088 BOOL binary_parse_type(1023,20238 BOOL unary_parse_type(1048,20824 int special_parse_type(1073,21340 static int Assoc_comm_symbols 1089,21815 static int Comm_symbols 1090,21873 void set_assoc_comm(1108,22278 void set_commutative(1135,22822 BOOL assoc_comm_symbols(1161,23274 BOOL comm_symbols(1178,23537 BOOL is_assoc_comm(1199,24000 BOOL is_commutative(1221,24518 static int Eq_symnum 1231,24896 static int Or_symnum 1232,24922 static int Not_symnum 1233,24948 BOOL is_eq_symbol(1248,25234 int not_symnum(1267,25529 int or_symnum(1285,25782 void declare_base_symbols(1302,26006 static Variable_style Var_style 1315,26405 void set_variable_style(1328,26616 Variable_style variable_style(1344,26855 BOOL variable_name(1362,27200 void symbol_for_variable(1387,27814 Ilist variable_symbols(1424,28651 Ilist remove_variable_symbols(1448,29133 void set_symbol_type(1471,29682 Symbol_type get_symbol_type(1489,29974 BOOL function_symbol(1507,30255 BOOL relation_symbol(1522,30464 BOOL function_or_relation_symbol(1537,30686 void declare_functions_and_relations(1553,30981 int function_or_relation_sn(1576,31540 Ilist all_function_symbols(1601,31983 Ilist all_relation_symbols(1626,32397 void set_lrpo_status(1655,33045 void all_symbols_lrpo_status(1673,33373 Lrpo_status sn_to_lrpo_status(1698,33908 static BOOL Zero_wt_kb 1708,34288 void set_kb_weight(1720,34455 BOOL zero_wt_kb(1750,35093 int sn_to_kb_wt(1766,35329 void print_kbo_weights(1785,35579 static char *Skolem_constant_prefix 1801,36121 static char *Skolem_function_prefix 1802,36164 static int Next_skolem_constant 1803,36207 static int Next_skolem_function 1804,36279 static BOOL Skolem_check 1805,36351 void set_skolem(1818,36591 void skolem_check(1835,36818 BOOL skolem_ok(1847,36957 int next_skolem_symbol(1876,37565 Ilist skolem_symbols(1910,38221 BOOL is_skolem(1935,38599 void skolem_reset(1952,38858 void decommission_skolem_symbols(1970,39178 void set_skolem_symbols(1995,39590 static Ilist Preliminary_prec_func 2010,40092 static Ilist Preliminary_prec_pred 2011,40135 void set_lex_val(2025,40387 int sn_to_lex_val(2047,40891 Ordertype sym_precedence(2066,41309 Ilist syms_with_lex_val(2099,41911 BOOL exists_preliminary_precedence(2124,42311 Ordertype preliminary_lex_compare(2150,42998 Ordertype lex_compare_base(2189,43968 Ordertype lex_compare_arity_0123(2278,46207 Ordertype lex_compare_arity_0213(2299,46616 void lex_order(2337,47653 Ilist insert_by_lex_val(2370,48473 Ilist sort_by_lex_val(2396,48902 Ilist remove_syms_without_lex_val(2412,49147 Ilist current_fsym_precedence(2438,49598 Ilist current_rsym_precedence(2456,49899 Ilist not_in_preliminary_precedence(2474,50206 void print_fsym_precedence(2500,50789 void print_rsym_precedence(2523,51210 int min_lex_val(2546,51623 int max_lex_val(2566,51921 void assign_greatest_precedence(2589,52261 BOOL has_greatest_precedence(2604,52489 void lex_insert_after_initial_constants(2619,52729 Ilist skolem_insert(2650,53369 void add_skolems_to_preliminary_precedence(2676,53990 static unsigned Mark_for_new_symbols 2695,54752 int fresh_symbol(2711,55152 int gen_new_symbol(2738,55564 void mark_for_new_symbols(2769,56107 I2list new_symbols_since_mark(2784,56336 void add_new_symbols(2806,56707 void new_constant_properties(2833,57314 Ilist collect_multiples(2855,57751 Ilist arity_check(2888,58425 int symbol_with_string(2905,58718 void process_skolem_list(2925,59051 void process_lex_list(2950,59593 Ilist symnums_of_arity(2992,60712 term.c,2866 static Term Shared_variables[59,2360 #define PTRS_TERM 65,2430 static unsigned Term_gets,66,2474 static unsigned Term_gets, Term_frees;66,2474 static unsigned Arg_mem;68,2514 Term get_term(77,2655 void free_term(114,3487 void fprint_term_mem(135,3937 void p_term_mem(165,4627 Term get_variable_term(187,4957 Term get_rigid_term_like(219,5707 Term get_rigid_term(240,6162 Term get_rigid_term_dangerously(274,7100 void zap_term(295,7514 BOOL term_ident(319,8002 Term copy_term(347,8545 BOOL ground_term(373,9027 int biggest_variable(398,9454 int term_depth(423,9882 int symbol_count(450,10328 BOOL occurs_in(475,10893 void fprint_term(499,11283 void sprint_term(535,11939 char *term_to_string(573,12641 void p_term(596,13110 BOOL all_args_vars(615,13409 Term build_binary_term(642,13867 Term build_binary_term_safe(665,14354 Term build_unary_term(683,14730 Term build_unary_term_safe(704,15159 Term subst_term(721,15501 Term subst_var_term(748,16050 int greatest_variable(775,16576 int greatest_symnum_in_term(802,17086 void upward_term_links(829,17592 BOOL check_upward_term_links(851,18011 int occurrences(877,18501 Term trm_set_vars_recurse(899,18882 void term_set_variables(945,19996 Term nat_to_term(978,20634 Term int_to_term(998,20964 Term bool_to_term(1020,21308 Term double_to_term(1038,21642 int natural_constant_term(1057,21999 int arg_position(1078,22377 BOOL is_term(1099,22694 BOOL is_constant(1115,22935 char *term_symbol(1132,23223 BOOL term_to_int(1153,23647 BOOL term_to_double(1186,24258 BOOL term_to_number(1207,24666 BOOL true_term(1230,24990 BOOL false_term(1245,25161 BOOL term_to_bool(1263,25461 I2list symbols_in_term(1289,25893 Ilist fsym_set_in_term(1310,26218 Term renum_vars_recurse(1335,26816 Term set_vars_recurse(1373,27707 I2list multiset_of_vars(1409,28397 I2list multiset_vars(1431,28748 Plist set_of_vars(1447,28955 Plist set_of_variables(1474,29395 int number_of_vars_in_term(1490,29631 Ilist set_of_ivars(1509,29907 Ilist set_of_ivariables(1536,30404 BOOL variables_subset(1551,30594 BOOL variables_multisubset(1571,30945 Term term_at_pos(1603,31527 Ilist pos_of_subterm(1622,31811 Ilist position_of_subterm(1653,32563 int symbol_occurrences(1674,32923 BOOL args_distinct_vars(1699,33383 unsigned hash_term(1750,34178 BOOL skolem_term(1773,34502 BOOL contains_skolem_term(1788,34682 BOOL contains_skolem_function(1813,35067 Term term0(1839,35480 Term term1(1855,35692 Term term2(1873,35949 BOOL symbol_in_term(1891,36190 BOOL same_structure(1917,36623 Plist copy_plist_of_terms(1942,37049 void zap_plist_of_terms(1966,37448 BOOL eq_term(1989,37848 Plist plist_of_subterms(2004,38032 BOOL tlist_member(2025,38416 int position_of_term_in_tlist(2045,38717 BOOL tlist_subset(2065,39018 BOOL tlist_set(2083,39271 Plist free_vars_term(2104,39673 termflag.c,410 #define TERM_BITS 25,842 #define SET_BIT(SET_BIT27,893 #define CLEAR_BIT(CLEAR_BIT28,949 static int bits_in_use[31,1058 int claim_term_flag(47,1414 void release_term_flag(73,1862 void term_flag_set(99,2602 void term_flag_clear(119,3045 BOOL term_flag(139,3489 int term_flags(162,3944 Term copy_term_with_flags(180,4242 Term copy_term_with_flag(209,4822 void term_flag_clear_recursively(236,5289 termorder.c,697 Order_method Ordering_method 24,838 void assign_order_method(36,1014 Ordertype term_compare_basic(55,1421 Ordertype term_compare_ncv(107,2712 Ordertype term_compare_vcp(155,3913 Ordertype term_compare_vr(203,5088 Ordertype flatterm_compare_vr(246,6030 BOOL lrpo_multiset(291,6920 BOOL lrpo_lex(306,7244 BOOL lrpo(354,8491 void init_kbo_weights(413,9891 int kbo_weight(454,10743 BOOL kbo(478,11082 BOOL term_greater(536,12612 Ordertype term_order(556,13071 int flat_kbo_weight(578,13455 BOOL flat_kbo(601,13814 BOOL flat_lrpo_multiset(659,15326 BOOL flat_lrpo_lex(677,15699 BOOL flat_lrpo(731,16764 BOOL flat_greater(796,18114 BOOL greater_multiset_current_ordering(828,18956 test.c,57 #define N 22,795 void compute_args(24,808 main(35,987 tlist.c,140 void zap_tlist(35,1035 Plist tlist_remove(56,1346 Plist tlist_union(87,1890 Ilist constants_in_term(114,2345 Plist tlist_copy(142,2788 top_input.c,1344 typedef struct readlist * Readlist;Readlist29,933 struct readlist readlist31,970 static Readlist Input_lists 39,1179 static Plist Lex_function_list 41,1216 static Plist Lex_predicate_list 42,1255 static Plist Skolem_list 43,1295 static char *Program_name 45,1372 #define PTRS_READLIST 51,1434 static unsigned Readlist_gets,52,1486 static unsigned Readlist_gets, Readlist_frees;52,1486 Readlist get_readlist(61,1608 void free_readlist(76,1806 void fprint_top_input_mem(96,2208 void p_top_input_mem(122,2844 void init_standard_ladr(142,3117 void fatal_input_error(161,3449 void set_program_name(186,3927 BOOL condition_is_true(198,4083 void process_op2(210,4246 void process_op(249,5317 void process_redeclare(298,6408 void execute_unknown_action(333,7283 void flag_handler(361,7923 void parm_handler(390,8658 void process_symbol_list(440,9806 Readlist readlist_member(468,10675 Readlist readlist_member_wild(485,10995 void accept_list(513,11772 void input_symbols(538,12219 void symbol_check_and_declare(582,13457 void read_from_file(697,16616 void read_all_input(880,22079 void check_formula_attributes(913,22828 Plist process_input_formulas(939,23499 Plist process_demod_formulas(992,25007 Plist process_goal_formulas(1032,26043 Term read_commands(1081,27281 Plist embed_formulas_in_topforms(1175,29840 topform.c,1249 #define PTRS_TOPFORM 27,843 static unsigned Topform_gets,28,893 static unsigned Topform_gets, Topform_frees;28,893 Topform get_topform(40,1038 void free_topform(54,1223 void fprint_topform_mem(73,1608 void p_topform_mem(99,2226 void zap_topform(124,2712 void fprint_clause(143,3010 void p_clause(184,3756 Topform term_to_clause(206,4271 Topform term_to_topform(233,4712 Term topform_to_term(269,5528 Term topform_to_term_without_attributes(304,6331 void clause_set_variables(338,7176 void renumber_variables(405,8912 void term_renumber_variables(453,10002 Plist renum_vars_map(482,10453 void upward_clause_links(526,11387 BOOL check_upward_clause_links(545,11754 Topform copy_clause(568,12208 Topform copy_clause_with_flags(589,12614 Topform copy_clause_with_flag(610,13056 void inherit_attributes(634,13587 void gather_symbols_in_topform(653,14047 void gather_symbols_in_topforms(674,14485 Ilist fsym_set_in_topforms(691,14791 Ilist rsym_set_in_topforms(713,15154 BOOL min_depth(736,15582 BOOL initial_clause(760,16026 BOOL negative_clause_possibly_compressed(777,16322 Term topform_properties(797,16764 void append_label_attribute(848,18000 Ordertype cl_id_compare(863,18250 Ordertype cl_wt_id_compare(883,18545 tptp_trans.c,562 void declare_tptp_input_types(152,4779 void declare_tptp_output_types(198,5945 Term tptp2_to_ladr_term(250,7493 Term tptp3_to_ladr_term(301,8629 Formula tptp_input_to_ladr_formula(418,11841 void rename_vars_to_upper(459,12889 Term ladr_term_to_tptp_term(482,13388 Plist ladr_list_to_tptp_list(564,15539 Ilist syms_in_form(613,16793 BOOL good_tptp_sym(667,18225 BOOL good_ladr_sym(697,18731 I2list map_for_bad_tptp_syms(712,18909 I2list map_for_bad_ladr_syms(752,19771 Term replace_bad_syms_term(793,20657 Term replace_bad_tptp_syms_form(824,21289 unify.c,1146 struct trail trail28,1016 #define BIND_TR(BIND_TR36,1258 #define MAX_MULTIPLIERS 41,1456 static BOOL Multipliers[45,1510 int next_available_multiplier(54,1669 #define PTRS_CONTEXT 70,2011 static unsigned Context_gets,71,2061 static unsigned Context_gets, Context_frees;71,2061 #define PTRS_TRAIL 73,2107 static unsigned Trail_gets,74,2153 static unsigned Trail_gets, Trail_frees;74,2153 Context get_context(86,2294 void free_context(104,2553 Trail get_trail(120,2853 void free_trail(134,3044 void fprint_unify_mem(153,3416 void p_unify_mem(185,4242 BOOL unify(241,5800 BOOL variant(333,7872 BOOL occur_check(370,8651 BOOL match(419,10170 Term apply(477,11462 Term apply_substitute(516,12530 Term apply_substitute2(546,13300 Term apply_demod(585,14289 void undo_subst(613,14835 void undo_subst_2(646,15760 void fprint_context(669,16166 void p_context(712,17023 void fprint_trail(728,17281 void p_trail(751,17676 BOOL match_weight(767,17874 Ilist vars_in_trail(824,19130 Plist context_to_pairs(842,19386 BOOL empty_substitution(873,19923 BOOL variable_substitution(893,20202 BOOL subst_changes_term(919,20673 weight.c,987 static Plist Rules;26,874 static double Constant_weight;28,895 static double Sk_constant_weight;29,926 static double Not_weight;30,960 static double Or_weight;31,986 static double Prop_atom_weight;32,1011 static double Variable_weight;33,1043 static double Nest_penalty;34,1074 static double Depth_penalty;35,1102 static double Var_penalty;36,1131 static double Complexity;37,1158 static BOOL Not_rules;38,1184 static BOOL Or_rules;39,1239 static int Eq_sn;43,1319 static int Weight_sn;44,1357 static int Sum_sn;46,1402 static int Prod_sn;47,1450 static int Neg_sn;48,1498 static int Div_sn;49,1546 static int Max_sn;50,1594 static int Min_sn;51,1642 static int Depth_sn;52,1690 static int Vars_sn;53,1725 static int Call_sn;54,1759 static int Avar_sn;55,1793 BOOL weight_beta_check(64,1912 BOOL weight_rule_check(100,2720 void init_weight(125,3224 int apply_depth(193,4832 double weight_calc(217,5280 double weight(301,7546 double clause_weight(358,8787 weight2.c,186 #define IMAX(IMAX39,1413 int char_array_ident(52,1612 int char_array_find(69,1954 double complexity_1(88,2316 double test1(141,3647 double call_weight(166,4182 int main(179,4426 xproofs.c,350 void check_parents_and_uplinks_in_proof(36,975 Topform xx_res2(65,1751 void xx_simp2(108,2678 Topform factor(134,3290 void merge1(171,4145 Topform proof_id_to_clause(201,4773 int greatest_id_in_proof(222,5088 Plist expand_proof(251,5910 void renumber_proof(539,14887 Plist copy_and_renumber_proof(568,15492 Plist proof_to_xproof(585,15778 LADR-2009-11A/ladr/ivy.c0000644000175000017500000005577110746415034013736 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "ivy.h" /* Private definitions and types */ #define DICT_SIZE 6 /* The following maps symbols that are unacceptable to IVY. */ static char *Dict[DICT_SIZE][2] = {{"0", "zero_for_ivy"}, {"1", "one_for_ivy"}, {"'", "quote_for_ivy"}, {"\\", "backslash_for_ivy"}, {"@", "at_for_ivy"}, {"^", "meet_for_ivy"}}; /************* * * dict_lookup() * *************/ static char *dict_lookup(char *key) { int i; for (i = 0; i < DICT_SIZE; i++) { if (str_ident(Dict[i][0], key)) return Dict[i][1]; } return NULL; } /* dict_lookup */ /************* * * ivy_term_trans() * *************/ static void ivy_term_trans(Term t) { if (VARIABLE(t)) return; else { int i; char *s = dict_lookup(sn_to_str(SYMNUM(t))); if (s) t->private_symbol = -str_to_sn(s, ARITY(t)); for (i = 0; i < ARITY(t); i++) ivy_term_trans(ARG(t,i)); } } /* ivy_term_trans */ /************* * * ivy_clause_trans() * *************/ static void ivy_clause_trans(Topform c) { Literals lit; for (lit = c->literals; lit; lit = lit->next) { ivy_term_trans(lit->atom); } } /* ivy_clause_trans */ /************* * * sb_ivy_write_term() * *************/ static void sb_ivy_write_term(String_buf sb, Term t) { if (VARIABLE(t)) { sb_append(sb, "v"); sb_append_int(sb, VARNUM(t)); } else { int i; sb_append(sb, "("); sb_append(sb, sn_to_str(SYMNUM(t))); for (i = 0; i < ARITY(t); i++) { sb_append(sb, " "); sb_ivy_write_term(sb, ARG(t,i)); } sb_append(sb, ")"); } } /* sb_ivy_write_term */ /************* * * sb_ivy_write_pair() * *************/ static void sb_ivy_write_pair(String_buf sb, Term pair) { Term v = ARG(pair,0); Term t = ARG(pair,1); sb_append(sb, "("); sb_ivy_write_term(sb, v); sb_append(sb, " . "); sb_ivy_write_term(sb, t); sb_append(sb, ")"); } /* sb_ivy_write_pair */ /************* * * sb_ivy_write_pairs() * *************/ static void sb_ivy_write_pairs(String_buf sb, Plist pairs) { Plist p; sb_append(sb, "("); for (p = pairs; p; p = p->next) { sb_ivy_write_pair(sb, p->v); if (p->next) sb_append(sb, " "); } sb_append(sb, ")"); } /* sb_ivy_write_pairs */ /************* * * sb_ivy_write_position() * *************/ static void sb_ivy_write_position(String_buf sb, Ilist position) { Ilist p; sb_append(sb, "("); for (p = position; p; p = p->next) { sb_append_int(sb, p->i); if (p->next) sb_append(sb, " "); } sb_append(sb, ")"); } /* sb_ivy_write_position */ /************* * * sb_ivy_write_lit() * *************/ static void sb_ivy_write_lit(String_buf sb, Literals lit) { if (lit->sign == FALSE) { sb_append(sb, "(not "); sb_ivy_write_term(sb, lit->atom); sb_append(sb, ")"); } else sb_ivy_write_term(sb, lit->atom); } /* sb_ivy_write_lit */ /************* * * sb_ivy_write_literals() * *************/ static void sb_ivy_write_literals(String_buf sb, Literals lits) { if (lits == NULL) sb_append(sb, "false"); else if (lits->next == NULL) sb_ivy_write_lit(sb, lits); else { sb_append(sb, "(or "); sb_ivy_write_lit(sb, lits); sb_append(sb, " "); sb_ivy_write_literals(sb, lits->next); sb_append(sb, ")"); } } /* sb_ivy_write_literals */ /************* * * sb_ivy_write_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_ivy_write_just(String_buf sb, Ivyjust j, I3list map) { if (j->type == INPUT_JUST) { sb_append(sb, "(input)"); } else if (j->type == PROPOSITIONAL_JUST) { sb_append(sb, "(propositional "); sb_append_id(sb, j->parent1, map); sb_append(sb, ")"); } else if (j->type == NEW_SYMBOL_JUST) { sb_append(sb, "(new_symbol "); sb_append_id(sb, j->parent1, map); sb_append(sb, ")"); } else if (j->type == FLIP_JUST) { sb_append(sb, "(flip "); sb_append_id(sb, j->parent1, map); sb_append(sb, " "); sb_ivy_write_position(sb, j->pos1); sb_append(sb, ")"); } else if (j->type == INSTANCE_JUST) { sb_append(sb, "(instantiate "); sb_append_id(sb, j->parent1, map); sb_append(sb, " "); sb_ivy_write_pairs(sb, j->pairs); sb_append(sb, ")"); } else if (j->type == BINARY_RES_JUST || j->type == PARA_JUST) { if (j->type == BINARY_RES_JUST) sb_append(sb, "(resolve "); else sb_append(sb, "(paramod "); sb_append_id(sb, j->parent1, map); sb_append(sb, " "); sb_ivy_write_position(sb, j->pos1); sb_append(sb, " "); sb_append_id(sb, j->parent2, map); sb_append(sb, " "); sb_ivy_write_position(sb, j->pos2); sb_append(sb, ")"); } else fatal_error("sb_ivy_write_just, bad ivy justification"); } /* sb_ivy_write_just */ /************* * * sb_ivy_write_clause_jmap() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_ivy_write_clause_jmap(String_buf sb, Topform c, I3list map) { if (c->justification->type != IVY_JUST) { printf("not ivy just: "); fprint_clause(stdout, c); fatal_error("sb_ivy_write_clause_jmap, not IVY_JUST"); } sb_append(sb, "("); /* start */ sb_append_id(sb, c->id, map); /* ID */ sb_append(sb, " "); sb_ivy_write_just(sb, c->justification->u.ivy, map); /* justification */ sb_append(sb, " "); sb_ivy_write_literals(sb, c->literals); /* literals */ sb_append(sb, " NIL)\n"); /* end */ } /* sb_ivy_write_clause_jmap */ /************* * * instantiate_inference() * *************/ static Topform instantiate_inference(Topform c, Context subst) { Topform d = instantiate_clause(c, subst); Plist pairs = context_to_pairs(varnums_in_clause(c->literals), subst); d->justification = ivy_just(INSTANCE_JUST, c->id, NULL, 0, NULL, pairs); inherit_attributes(c, subst, NULL, NULL, d); upward_clause_links(d); return d; } /* instantiate_inference */ /************* * * renumber_inference() - return NULL if renumbering does nothing * *************/ static Topform renumber_inference(Topform c) { Plist pairs; Topform child = copy_clause(c); pairs = renum_vars_map(child); if (pairs == NULL) { zap_topform(child); return NULL; } else { child->justification = ivy_just(INSTANCE_JUST, c->id, NULL, 0, NULL, pairs); child->attributes = copy_attributes(c->attributes); return child; } } /* renumber_inference */ /************* * * ivy_lit_position() * *************/ static Ilist ivy_lit_position(int n, int number_of_lits) { /* Build an Ivy-style position for a literal. Ivy clauses are binary trees of ORs. Ivy accepts any association, but the ones we are using are always right associated. To build the position, we have to know if the designated literal is the last, e.g., Designated If last If not last 1 () (1) 2 (2) (2 1) 3 (2 2) (2 2 1) 4 (2 2 2) (2 2 2 1) */ int i; Ilist pos = NULL; if (n != number_of_lits) pos = ilist_prepend(pos, 1); for (i = 1; i < n; i++) pos = ilist_prepend(pos, 2); return pos; } /* ivy_lit_position */ /************* * * ivy_para_position() * *************/ static Ilist ivy_para_position(Ilist pos1, BOOL sign, int number_of_lits) { /* Given a LADR-style position for a term within a clause, build an Ivy-style position for a term within a clause. See ivy_lit_position. */ Ilist pos2 = ivy_lit_position(pos1->i, number_of_lits); if (!sign) /* Ivy position considers sign, LADR's doesn't. */ pos2 = ilist_append(pos2, 1); pos2 = ilist_cat(pos2, copy_ilist(pos1->next)); return pos2; } /* ivy_para_position */ /************* * * paramod2_instances() * *************/ /* DOCUMENTATION Paramodulate, if possible, two clauses at the positions given. Renumber vars, include justification, transfer inheritable attributes, assign an ID.

*/ static Plist paramod2_instances(Topform from, Ilist from_pos, Topform into, Ilist into_pos, int *next_id) { Context subst_from = get_context(); Context subst_into = get_context(); Trail tr = NULL; Plist steps = NULL; /* build sequence of inferences (backward) */ BOOL demod_like; Literals from_lit = ith_literal(from->literals, from_pos->i); Literals into_lit = ith_literal(into->literals, into_pos->i); BOOL left_to_right = from_pos->next->i == 1; Term alpha = ARG(from_lit->atom, left_to_right ? 0 : 1); Term beta = ARG(from_lit->atom, left_to_right ? 1 : 0); Term into_term = term_at_pos(into_lit->atom, into_pos->next); if (into_term == NULL) fatal_error("paramod2_instances, term does not exist"); demod_like = unit_clause(from->literals) && variables_subset(beta, alpha) && match(alpha, subst_from, into_term, &tr); if (demod_like || unify(alpha, subst_from, into_term, subst_into, &tr)) { Topform from_instance, into_instance, para, para_renum; if (ground_clause(from->literals)) from_instance = from; else { from_instance = instantiate_inference(from, subst_from); from_instance->id = (*next_id)++; steps = plist_prepend(steps, from_instance); } if (demod_like || ground_clause(into->literals)) into_instance = into; else { into_instance = instantiate_inference(into, subst_into); into_instance->id = (*next_id)++; steps = plist_prepend(steps, into_instance); } undo_subst(tr); /* Positions in instances are same as positions in originals. */ from_lit = ith_literal(from_instance->literals, from_pos->i); into_lit = ith_literal(into_instance->literals, into_pos->i); para = paramodulate(from_lit, left_to_right ? 0 : 1, NULL, into_instance, into_pos, NULL); para->justification = ivy_just(PARA_JUST, from_instance->id, ivy_para_position(from_pos, TRUE, /* sign of literal */ number_of_literals(from_instance->literals)), into_instance->id, ivy_para_position(into_pos, into_lit->sign, number_of_literals(into_instance->literals)), NULL); para->id = (*next_id)++; steps = plist_prepend(steps, para); para_renum = renumber_inference(para); if (para_renum) { para_renum->id = (*next_id)++; steps = plist_prepend(steps, para_renum); } } else steps = NULL; free_context(subst_from); free_context(subst_into); return steps; } /* paramod2_instances */ /************* * * flip_inference() * *************/ static Topform flip_inference(Topform c, int n) { Topform child = copy_clause(c); Literals lit = ith_literal(child->literals, n); Term atom = lit->atom; Term t; if (!eq_term(atom)) fatal_error("flip_inference, literal not equality"); t = ARG(atom, 0); ARG(atom, 0) = ARG(atom, 1); ARG(atom, 1) = t; child->justification = ivy_just(FLIP_JUST, c->id, ivy_lit_position(n, number_of_literals(c->literals)), 0, NULL, NULL); child->attributes = copy_attributes(c->attributes); return child; } /* flip_inference */ /************* * * resolve2_instances() * *************/ /* DOCUMENTATION Resolve, if possible, two clauses on the literals (specified by literals, counting from 1). Renumber vars, include justification, transfer inheritable attributes, assign an ID.

The inference is done as a sequence of 2 -- 4 steps. (1,2) the parents are instantiated, (3) then resolution occurs on identical literals, (4) then the variables in the resolvent are renumbered. If any of the instantiation steps is vacuous, it is skipped.

if n2 < 0, then the literal is abs(n2), and it should be flipped. */ static Plist resolve2_instances(Topform c1, int n1, Topform c2, int n2, int *next_id) { Literals l1 = ith_literal(c1->literals, n1); Literals l2 = ith_literal(c2->literals, abs(n2)); Term a1 = l1->atom; Term a2 = l2->atom; Context s1 = get_context(); Context s2 = get_context(); Trail tr = NULL; Term a2x; Plist steps = NULL; if (n2 < 0) a2x = top_flip(a2); /* temporary flipped equality */ else a2x = a2; if (l1->sign != l2->sign && unify(a1, s1, a2x, s2, &tr)) { Literals l1i, l2i, lit; Topform res, res_renum, c1i, c2i; /* instantiate parents if not ground */ if (ground_clause(c1->literals)) c1i = c1; else { c1i = instantiate_inference(c1, s1); c1i->id = (*next_id)++; steps = plist_prepend(steps, c1i); } if (ground_clause(c2->literals)) c2i = c2; else { c2i = instantiate_inference(c2, s2); c2i->id = (*next_id)++; steps = plist_prepend(steps, c2i); } if (n2 < 0) { c2i = flip_inference(c2i, abs(n2)); c2i->id = (*next_id)++; steps = plist_prepend(steps, c2i); } undo_subst(tr); l1i = ith_literal(c1i->literals, n1); l2i = ith_literal(c2i->literals, abs(n2)); /* construct the resolvent */ res = get_topform(); for (lit = c1i->literals; lit; lit = lit->next) if (lit != l1i) res->literals = append_literal(res->literals, copy_literal(lit)); for (lit = c2i->literals; lit; lit = lit->next) if (lit != l2i) res->literals = append_literal(res->literals, copy_literal(lit)); inherit_attributes(c1i, NULL, c2i, NULL, res); upward_clause_links(res); res->justification = ivy_just(BINARY_RES_JUST, c1i->id, ivy_lit_position(n1,number_of_literals(c1i->literals)), c2i->id, ivy_lit_position(abs(n2), number_of_literals(c2i->literals)), NULL); res->id = (*next_id)++; steps = plist_prepend(steps, res); res_renum = renumber_inference(res); if (res_renum) { res_renum->id = (*next_id)++; steps = plist_prepend(steps, res_renum); } } else steps = NULL; if (n2 < 0) zap_top_flip(a2x); free_context(s1); free_context(s2); return steps; } /* resolve2_instances */ /************* * * factor2_instances() * *************/ static Plist factor2_instances(Topform c, int n1, int n2, int *next_id) { Literals l1 = ith_literal(c->literals, n1); Literals l2 = ith_literal(c->literals, n2); Term a1 = l1->atom; Term a2 = l2->atom; Context subst = get_context(); Trail tr = NULL; Plist steps = NULL; if (l1->sign == l2->sign && unify(a1, subst, a2, subst, &tr)) { Literals l1i, l2i, lit; Topform factor, factor_renum, c_instance; c_instance = instantiate_inference(c, subst); c_instance->id = (*next_id)++; steps = plist_prepend(steps, c_instance); undo_subst(tr); l1i = ith_literal(c_instance->literals, n1); l2i = ith_literal(c_instance->literals, n2); /* construct the factor */ factor = get_topform(); for (lit = c_instance->literals; lit; lit = lit->next) if (lit != l2i) factor->literals = append_literal(factor->literals, copy_literal(lit)); inherit_attributes(c_instance, NULL, NULL, NULL, factor); upward_clause_links(factor); factor->justification = ivy_just(PROPOSITIONAL_JUST, c_instance->id, NULL, 0, NULL, NULL); factor->id = (*next_id)++; steps = plist_prepend(steps, factor); factor_renum = renumber_inference(factor); if (factor_renum) { factor_renum->id = (*next_id)++; steps = plist_prepend(steps, factor_renum); } } else steps = NULL; free_context(subst); return steps; } /* factor2_instances */ /************* * * copy_proof_and_rename_symbols_for_ivy() * *************/ static Plist copy_proof_and_rename_symbols_for_ivy(Plist proof) { Plist new = NULL; Plist p; for (p = proof; p; p = p->next) { Topform c = copy_clause_ija(p->v); ivy_clause_trans(c); new = plist_prepend(new, c); } return reverse_plist(new); } /* copy_proof_and_rename_symbols_for_ivy */ /************* * * expand_proof_ivy() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist expand_proof_ivy(Plist proof) { Plist work_proof = copy_proof_and_rename_symbols_for_ivy(proof); Plist new_proof = NULL; /* build it backward, reverse at end */ int next_id; Plist p; BOOL need_reflexivity_of_eq = FALSE; Ilist to_be_removed = NULL; /* clauses to be removed from proof */ Plist final_proof = NULL; /* Build clause x=x, id=0, justification input; delete later if not used. */ Topform xx = build_reflex_eq(); xx->id = 0; xx->justification = ivy_just(INPUT_JUST, 0, NULL, 0, NULL, NULL); new_proof = plist_prepend(new_proof, xx); /* Start numbering the new proof where the old one ends. */ next_id = greatest_id_in_proof(work_proof) + 1; for (p = work_proof; p; p = p->next) { Topform c = p->v; Just j = c->justification; Topform new_c = NULL; if (j->type == BINARY_RES_JUST || j->type == XXRES_JUST) { Ilist p = j->u.lst; int id1 = p->i; int lit1 = p->next->i; int id2 = j->type == XXRES_JUST ? 0 : p->next->next->i; int lit2 = j->type == XXRES_JUST ? 1 : p->next->next->next->i; Topform c1 = proof_id_to_clause(new_proof, id1); Topform c2 = proof_id_to_clause(new_proof, id2); Plist new_steps = resolve2_instances(c1, lit1, c2, lit2, &next_id); new_c = new_steps->v; /* Give the new clause the ID of the old, so that subsequent steps in the old proof make sense. */ new_c->id = c->id; next_id--; new_proof = plist_cat(new_steps, new_proof); if (j->type == XXRES_JUST) need_reflexivity_of_eq = TRUE; } else if (j->type == PARA_JUST) { Parajust p = j->u.para; Topform from = proof_id_to_clause(new_proof, p->from_id); Topform into = proof_id_to_clause(new_proof, p->into_id); Plist new_steps = paramod2_instances(from, p->from_pos, into, p->into_pos, &next_id); new_c = new_steps->v; /* Give the new clause the ID of the old, so that subsequent steps in the old proof make sense. */ new_c->id = c->id; next_id--; new_proof = plist_cat(new_steps, new_proof); } else if (j->type == FACTOR_JUST) { Ilist p = j->u.lst; int id = p->i; int lit1 = p->next->i; int lit2 = p->next->next->i; Topform parent = proof_id_to_clause(new_proof, id); Plist new_steps = factor2_instances(parent, lit1, lit2, &next_id); new_c = new_steps->v; /* Give the new clause the ID of the old, so that subsequent steps in the old proof make sense. */ new_c->id = c->id; next_id--; new_proof = plist_cat(new_steps, new_proof); } else if (j->type == COPY_JUST && j->next && j->next->type == FLIP_JUST) { int flip_lit = j->next->u.id; Topform parent = proof_id_to_clause(new_proof, j->u.id); Topform child = flip_inference(parent, flip_lit); Topform child_renum; child->id = next_id++; new_proof = plist_prepend(new_proof, child); child_renum = renumber_inference(child); if (child_renum) { new_proof = plist_prepend(new_proof, child_renum); child_renum->id = next_id++; new_c = child_renum; } else new_c = child; new_c->id = c->id; next_id--; } else if (j->type == COPY_JUST && j->next && j->next->type == XX_JUST) { int id1 = j->u.id; int lit1 = j->next->u.id; int id2 = 0; /* special clause x = x */ int lit2 = 1; /* special clause x = x */ Topform c1 = proof_id_to_clause(new_proof, id1); Topform c2 = proof_id_to_clause(new_proof, id2); Plist new_steps = resolve2_instances(c1, lit1, c2, lit2, &next_id); new_c = new_steps->v; /* Give the new clause the ID of the old, so that subsequent steps in the old proof make sense. */ new_c->id = c->id; next_id--; new_proof = plist_cat(new_steps, new_proof); need_reflexivity_of_eq = TRUE; } else if (j->type == COPY_JUST && (j->next == NULL || j->next->type == MERGE_JUST)) { int parent_id = j->u.id; new_c = copy_clause(c); new_c->justification = ivy_just(PROPOSITIONAL_JUST, parent_id, NULL, 0, NULL, NULL); new_c->id = c->id; new_proof = plist_prepend(new_proof, new_c); } else if (j->type == INPUT_JUST || j->type == CLAUSIFY_JUST || j->type == EXPAND_DEF_JUST || j->type == GOAL_JUST || j->type == DENY_JUST) { new_c = copy_clause(c); new_c->id = c->id; new_c->attributes = copy_attributes(c->attributes); new_c->justification = ivy_just(INPUT_JUST, 0, NULL, 0, NULL, NULL); new_proof = plist_prepend(new_proof, new_c); if (j->type == CLAUSIFY_JUST || j->type == EXPAND_DEF_JUST || j->type == DENY_JUST) { /* Parents of these must be removed from the proof, because IVY expects ordinary clauses only. */ Ilist parents = get_parents(j, TRUE); to_be_removed = ilist_cat(to_be_removed, parents); } } else if (j->type == NEW_SYMBOL_JUST) { int parent_id = j->u.id; new_c = copy_clause(c); new_c->justification = ivy_just(NEW_SYMBOL_JUST, parent_id, NULL, 0, NULL, NULL); new_c->id = c->id; new_proof = plist_prepend(new_proof, new_c); fprintf(stdout, "\n;; WARNING: IVY proof contains unaccepted NEW_SYMBOL justification.\n\n"); fprintf(stderr, "\n;; WARNING: IVY proof contains unaccepted NEW_SYMBOL justification.\n\n"); } else { new_c = copy_clause_ija(c); new_proof = plist_prepend(new_proof, new_c); } if (!subsumes(c, new_c) || !subsumes(new_c, c)) { printf("old clause: "); fprint_clause(stdout, c); printf("new clause: "); fprint_clause(stdout, new_c); fatal_error("expand_proof_ivy, clauses not equivalent"); } } /* process proof step c */ delete_clauses(work_proof); /* The following does 2 things: remove clauses and reverse proof. */ final_proof = NULL; for (p = new_proof; p; p = p->next) { Topform c = p->v; if (!ilist_member(to_be_removed, c->id)) final_proof = plist_prepend(final_proof, c); } zap_plist(new_proof); /* shallow */ zap_ilist(to_be_removed); if (!need_reflexivity_of_eq) { /* We didn't use x=x, so delete it from the proof (it is first). */ Plist p = final_proof; final_proof = final_proof->next; zap_topform(p->v); free_plist(p); } check_parents_and_uplinks_in_proof(final_proof); return final_proof; } /* expand_proof_ivy */ LADR-2009-11A/ladr/sed.symbols0000644000175000017500000000051210637466000015125 0ustar mccunemccunes/TRUE_SYM/true_sym()/g s/FALSE_SYM/false_sym()/g s/AND_SYM/and_sym()/g s/OR_SYM/or_sym()/g s/NOT_SYM/not_sym()/g s/IFF_SYM/iff_sym()/g s/IMP_SYM/imp_sym()/g s/IMPBY_SYM/impby_sym()/g s/ALL_SYM/all_sym()/g s/EXISTS_SYM/exists_sym()/g s/QUANT_SYM/quant_sym()/g s/ATTRIB_SYM/attrib_sym()/g s/EQ_SYM/eq_sym()/g s/NEQ_SYM/neq_sym()/g LADR-2009-11A/ladr/paramod.h0000644000175000017500000000363611151265364014550 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_PARAMOD_H #define TP_PARAMOD_H #include "resolve.h" #include "basic.h" /* INTRODUCTION This package has a paramodulation inference rule. */ /* Public definitions */ /* where to paramodulate into */ typedef enum { PARA_ALL, PARA_ALL_EXCEPT_TOP, PARA_TOP_ONLY } Para_loc; /* End of public definitions */ /* Public function prototypes from paramod.c */ void paramodulation_options(BOOL ordered_inference, BOOL check_instances, BOOL positive_inference, BOOL basic_paramodulation, BOOL para_from_vars, BOOL para_into_vars, BOOL para_from_small); int para_instance_prunes(); int basic_paramodulation_prunes(void); Topform paramodulate(Literals from_lit, int from_side, Context from_subst, Topform into_clause, Ilist into_pos, Context into_subst); void para_from_into(Topform from, Context cf, Topform into, Context ci, BOOL check_top, void (*proc_proc) (Topform)); Topform para_pos(Topform from_clause, Ilist from_pos, Topform into_clause, Ilist into_pos); Topform para_pos2(Topform from, Ilist from_pos, Topform into, Ilist into_pos); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/lindex.h0000644000175000017500000000466011151265364014406 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_LINDEX_H #define TP_LINDEX_H #include "mindex.h" #include "maximal.h" #include "topform.h" /* INTRODUCTION This is a simple package that can be used when you need a pair of indexes (Mindexes), one for positive literals, and one for negative literals. The name Lindex means "literal index".

When you allocate the Lindex (lindex_init()), you specify the parameters as you would for two separate Mindexes. When you insert into or delete from the Lindex, you give a clause, and each literal of the clause is indexed: positive literals go into the positive component of the Lindex, and negative literals go into the negative component.

There are no retrieval operations in this package. Instead, use the retrieval operations from the Mindex package on the appropriate member (positive or negative) of the pair.

See the package "mindex" for information on the initialization parameters and retrieval operations. */ /* Public definitions */ typedef struct lindex * Lindex; struct lindex { Mindex pos; /* index for positive literals */ Mindex neg; /* index for negative literals */ Lindex next; /* for avail list */ }; /* End of public definitions */ /* Public function prototypes from lindex.c */ void fprint_lindex_mem(FILE *fp, BOOL heading); void p_lindex_mem(); Lindex lindex_init(Mindextype pos_mtype, Uniftype pos_utype, int pos_fpa_depth, Mindextype neg_mtype, Uniftype neg_utype, int neg_fpa_depth); void lindex_destroy(Lindex ldx); void lindex_update(Lindex ldx, Topform c, Indexop op); void lindex_update_first(Lindex ldx, Topform c, Indexop op); BOOL lindex_empty(Lindex idx); BOOL lindex_backtrack(Lindex idx); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/just.c0000644000175000017500000014060511150605557014104 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "just.h" /* Private definitions and types */ /* * memory management */ #define PTRS_JUST PTRS(sizeof(struct just)) static unsigned Just_gets, Just_frees; #define PTRS_PARAJUST PTRS(sizeof(struct parajust)) static unsigned Parajust_gets, Parajust_frees; #define PTRS_INSTANCEJUST PTRS(sizeof(struct instancejust)) static unsigned Instancejust_gets, Instancejust_frees; #define PTRS_IVYJUST PTRS(sizeof(struct ivyjust)) static unsigned Ivyjust_gets, Ivyjust_frees; /************* * * Just get_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just get_just(void) { Just p = get_cmem(PTRS_JUST); Just_gets++; return(p); } /* get_just */ /************* * * free_just() * *************/ static void free_just(Just p) { free_mem(p, PTRS_JUST); Just_frees++; } /* free_just */ /************* * * Parajust get_parajust() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Parajust get_parajust(void) { Parajust p = get_cmem(PTRS_PARAJUST); Parajust_gets++; return(p); } /* get_parajust */ /************* * * free_parajust() * *************/ static void free_parajust(Parajust p) { free_mem(p, PTRS_PARAJUST); Parajust_frees++; } /* free_parajust */ /************* * * Instancejust get_instancejust() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Instancejust get_instancejust(void) { Instancejust p = get_cmem(PTRS_INSTANCEJUST); Instancejust_gets++; return(p); } /* get_instancejust */ /************* * * free_instancejust() * *************/ static void free_instancejust(Instancejust p) { free_mem(p, PTRS_INSTANCEJUST); Instancejust_frees++; } /* free_instancejust */ /************* * * Ivyjust get_ivyjust() * *************/ static Ivyjust get_ivyjust(void) { Ivyjust p = get_mem(PTRS_IVYJUST); Ivyjust_gets++; return(p); } /* get_ivyjust */ /************* * * free_ivyjust() * *************/ static void free_ivyjust(Ivyjust p) { free_mem(p, PTRS_IVYJUST); Ivyjust_frees++; } /* free_ivyjust */ /************* * * fprint_just_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the just package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_just_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct just); fprintf(fp, "just (%4d) %11u%11u%11u%9.1f K\n", n, Just_gets, Just_frees, Just_gets - Just_frees, ((Just_gets - Just_frees) * n) / 1024.); n = sizeof(struct parajust); fprintf(fp, "parajust (%4d) %11u%11u%11u%9.1f K\n", n, Parajust_gets, Parajust_frees, Parajust_gets - Parajust_frees, ((Parajust_gets - Parajust_frees) * n) / 1024.); n = sizeof(struct instancejust); fprintf(fp, "instancejust (%4d) %11u%11u%11u%9.1f K\n", n, Instancejust_gets, Instancejust_frees, Instancejust_gets - Instancejust_frees, ((Instancejust_gets - Instancejust_frees) * n) / 1024.); n = sizeof(struct ivyjust); fprintf(fp, "ivyjust (%4d) %11u%11u%11u%9.1f K\n", n, Ivyjust_gets, Ivyjust_frees, Ivyjust_gets - Ivyjust_frees, ((Ivyjust_gets - Ivyjust_frees) * n) / 1024.); } /* fprint_just_mem */ /************* * * p_just_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the just package. */ /* PUBLIC */ void p_just_mem() { fprint_just_mem(stdout, TRUE); } /* p_just_mem */ /* * end of memory management */ /************* * * ivy_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just ivy_just(Just_type type, int parent1, Ilist pos1, int parent2, Ilist pos2, Plist pairs) { Just j = get_just(); j->type = IVY_JUST; j->u.ivy = get_ivyjust(); j->u.ivy->type = type; j->u.ivy->parent1 = parent1; j->u.ivy->parent2 = parent2; j->u.ivy->pos1 = pos1; j->u.ivy->pos2 = pos2; j->u.ivy->pairs = pairs; return j; } /* ivy_just */ /************* * * input_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for input. */ /* PUBLIC */ Just input_just(void) { /* (INPUT_JUST) */ Just j = get_just(); j->type = INPUT_JUST; return j; } /* input_just */ /************* * * goal_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for goal. */ /* PUBLIC */ Just goal_just(void) { /* (GOAL_JUST) */ Just j = get_just(); j->type = GOAL_JUST; return j; } /* goal_just */ /************* * * deny_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for deny. */ /* PUBLIC */ Just deny_just(Topform tf) { /* (DENY_JUST) */ Just j = get_just(); j->type = DENY_JUST; j->u.id = tf->id; return j; } /* deny_just */ /************* * * clausify_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for clausify. */ /* PUBLIC */ Just clausify_just(Topform tf) { /* (CLAUSIFY_JUST) */ Just j = get_just(); j->type = CLAUSIFY_JUST; j->u.id = tf->id; return j; } /* clausify_just */ /************* * * expand_def_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for expand_def. */ /* PUBLIC */ Just expand_def_just(Topform tf, Topform def) { /* (expand_def_JUST) */ Just j = get_just(); j->type = EXPAND_DEF_JUST; j->u.lst = ilist_append(ilist_append(NULL, tf->id), def->id); return j; } /* expand_def_just */ /************* * * copy_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for copy. */ /* PUBLIC */ Just copy_just(Topform c) { /* (COPY_JUST parent_id) */ Just j = get_just(); j->type = COPY_JUST; j->u.id = c->id; return j; } /* copy_just */ /************* * * propositional_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for propositional. */ /* PUBLIC */ Just propositional_just(Topform c) { /* (PROPOSITIONAL_JUST parent_id) */ Just j = get_just(); j->type = PROPOSITIONAL_JUST; j->u.id = c->id; return j; } /* propositional_just */ /************* * * new_symbol_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for new_symbol inference. */ /* PUBLIC */ Just new_symbol_just(Topform c) { /* (NEW_SYMBOL_JUST parent_id) */ Just j = get_just(); j->type = NEW_SYMBOL_JUST; j->u.id = c->id; return j; } /* new_symbol_just */ /************* * * back_demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_demod. */ /* PUBLIC */ Just back_demod_just(Topform c) { /* (BACK_DEMOD_JUST parent_id) */ Just j = get_just(); j->type = BACK_DEMOD_JUST; j->u.id = c->id; return j; } /* back_demod_just */ /************* * * back_unit_deletion_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_unit_deletion. */ /* PUBLIC */ Just back_unit_deletion_just(Topform c) { /* (BACK_UNIT_DEL_JUST parent_id) */ Just j = get_just(); j->type = BACK_UNIT_DEL_JUST; j->u.id = c->id; return j; } /* back_unit_deletion_just */ /************* * * binary_res_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for binary resolution. (Binary res justifications may also be constructed in resolve(), along with hyper and UR.) */ /* PUBLIC */ Just binary_res_just(Topform c1, int n1, Topform c2, int n2) { /* (BINARY_RES_JUST (id1 lit1 id2 lit2) */ Just j = get_just(); j->type = BINARY_RES_JUST; j->u.lst = ilist_append( ilist_append( ilist_append( ilist_append(NULL,c1->id),n1),c2->id),n2); return j; } /* binary_res_just */ /************* * * binary_res_just_by_id() * *************/ /* DOCUMENTATION Similar to binary_res_just, except that IDs are given instead of clauses. */ /* PUBLIC */ Just binary_res_just_by_id(int c1, int n1, int c2, int n2) { /* (BINARY_RES_JUST (id1 lit1 id2 lit2) */ Just j = get_just(); j->type = BINARY_RES_JUST; j->u.lst = ilist_append( ilist_append( ilist_append( ilist_append(NULL,c1),n1),c2),n2); return j; } /* binary_res_just_by_id */ /************* * * factor_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just factor_just(Topform c, int lit1, int lit2) { /* (FACTOR_JUST (clause_id lit1 lit2)) */ Just j = get_just(); j->type = FACTOR_JUST; j->u.lst = ilist_append(ilist_append(ilist_append(NULL,c->id),lit1),lit2); return j; } /* factor_just */ /************* * * xxres_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for resolution with x=x. */ /* PUBLIC */ Just xxres_just(Topform c, int lit) { /* (XXRES_JUST (clause_id lit)) */ Just j = get_just(); j->type = XXRES_JUST; j->u.lst = ilist_append(ilist_append(NULL,c->id),lit); return j; } /* xxres_just */ /************* * * resolve_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for resolution rules. This handles binary, hyper, ur, and maybe others. */ /* PUBLIC */ Just resolve_just(Ilist g, Just_type type) { Just j = get_just(); j->type = type; j->u.lst = g; return j; } /* resolve_just */ /************* * * demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for a demodulation. */ /* PUBLIC */ Just demod_just(I3list steps) { Just j = get_just(); j->type = DEMOD_JUST; j->u.demod = steps; return j; } /* demod_just */ /************* * * para_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are not copied. */ /* PUBLIC */ Just para_just(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec) { Just j = get_just(); j->type = rule; j->u.para = get_parajust(); j->u.para->from_id = from->id; j->u.para->into_id = into->id; j->u.para->from_pos = from_vec; j->u.para->into_pos = into_vec; return j; } /* para_just */ /************* * * instance_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for an instance inference. The list of pairs is not copied. */ /* PUBLIC */ Just instance_just(Topform parent, Plist pairs) { Just j = get_just(); j->type = INSTANCE_JUST; j->u.instance = get_instancejust(); j->u.instance->parent_id = parent->id; j->u.instance->pairs = pairs; return j; } /* instance_just */ /************* * * para_just_rev_copy() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are copied and reversed. */ /* PUBLIC */ Just para_just_rev_copy(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec) { return para_just(rule, from, reverse_ilist(copy_ilist(from_vec)), into, reverse_ilist(copy_ilist(into_vec))); } /* para_just_rev_copy */ /************* * * unit_del_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just unit_del_just(Topform deleter, int literal_num) { /* UNIT_DEL (literal-num clause-id) */ Just j = get_just(); j->type = UNIT_DEL_JUST; j->u.lst = ilist_append(ilist_append(NULL, literal_num), deleter->id); return j; } /* cd_just */ /************* * * flip_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for equality flipping. */ /* PUBLIC */ Just flip_just(int n) { Just j = get_just(); j->type = FLIP_JUST; j->u.id = n; return j; } /* flip_just */ /************* * * xx_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the XX rule, which removes literals that are instances of x!=x. */ /* PUBLIC */ Just xx_just(int n) { Just j = get_just(); j->type = XX_JUST; j->u.id = n; return j; } /* xx_just */ /************* * * merge_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the merging a literal. The n-th literal has been removed because it is identical to another literal. */ /* PUBLIC */ Just merge_just(int n) { Just j = get_just(); j->type = MERGE_JUST; j->u.id = n; return j; } /* merge_just */ /************* * * eval_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for an eval rewrite. The argument is the number of rewrites. */ /* PUBLIC */ Just eval_just(int n) { Just j = get_just(); j->type = EVAL_JUST; j->u.id = n; return j; } /* eval_just */ /************* * * append_just() * *************/ /* DOCUMENTATION This appends two justifications. No copying occurs. */ /* PUBLIC */ Just append_just(Just j1, Just j2) { if (j1 == NULL) return j2; else { j1->next = append_just(j1->next, j2); return j1; } } /* append_just */ /************* * * copy_justification() * *************/ /* DOCUMENTATION Copy a justification. */ /* PUBLIC */ Just copy_justification(Just j) { if (j == NULL) return NULL; else { Just j2 = get_just(); j2->type = j->type; j2->next = copy_justification(j->next); switch (j->type) { case INPUT_JUST: case GOAL_JUST: break; case DENY_JUST: case CLAUSIFY_JUST: case COPY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case EVAL_JUST: j2->u.id = j->u.id; break; case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: j2->u.lst = copy_ilist(j->u.lst); break; case DEMOD_JUST: j2->u.demod = copy_i3list(j->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: j2->u.para = get_parajust(); j2->u.para->from_id = j->u.para->from_id; j2->u.para->into_id = j->u.para->into_id; j2->u.para->from_pos = copy_ilist(j->u.para->from_pos); j2->u.para->into_pos = copy_ilist(j->u.para->into_pos); break; case INSTANCE_JUST: j2->u.instance = get_instancejust(); j2->u.instance->parent_id = j->u.instance->parent_id; j2->u.instance->pairs = copy_plist_of_terms(j->u.instance->pairs); break; case IVY_JUST: j2->u.ivy = get_ivyjust(); j2->u.ivy->type = j->u.ivy->type; j2->u.ivy->parent1 = j->u.ivy->parent1; j2->u.ivy->parent2 = j->u.ivy->parent2; j2->u.ivy->pos1 = copy_ilist(j->u.ivy->pos1); j2->u.ivy->pos2 = copy_ilist(j->u.ivy->pos2); j2->u.ivy->pairs = copy_plist_of_terms(j->u.ivy->pairs); break; default: fatal_error("copy_justification: unknown type"); } return j2; } } /* copy_justification */ /************* * * jstring() - strings for printing justifications * *************/ /* DOCUMENTATION What is the string, e.g., "resolve" associated with a justification node? */ /* PUBLIC */ char *jstring(Just j) { switch (j->type) { /* primary justifications */ case INPUT_JUST: return "assumption"; case GOAL_JUST: return "goal"; case DENY_JUST: return "deny"; case CLAUSIFY_JUST: return "clausify"; case COPY_JUST: return "copy"; case PROPOSITIONAL_JUST: return "propositional"; case NEW_SYMBOL_JUST: return "new_symbol"; case BACK_DEMOD_JUST: return "back_rewrite"; case BACK_UNIT_DEL_JUST: return "back_unit_del"; case EXPAND_DEF_JUST: return "expand_def"; case BINARY_RES_JUST: return "resolve"; case HYPER_RES_JUST: return "hyper"; case UR_RES_JUST: return "ur"; case FACTOR_JUST: return "factor"; case XXRES_JUST: return "xx_res"; case PARA_JUST: return "para"; case PARA_FX_JUST: return "para_fx"; case PARA_IX_JUST: return "para_ix"; case PARA_FX_IX_JUST: return "para_fx_ix"; case INSTANCE_JUST: return "instantiate"; case IVY_JUST: return "ivy"; /* secondary justifications */ case FLIP_JUST: return "flip"; case XX_JUST: return "xx"; case MERGE_JUST: return "merge"; case EVAL_JUST: return "eval"; case DEMOD_JUST: return "rewrite"; case UNIT_DEL_JUST: return "unit_del"; case UNKNOWN_JUST: return "unknown"; } return "unknown"; } /* jstring */ /************* * * jstring_to_jtype() - strings for printing justifications * *************/ static int jstring_to_jtype(char *s) { if (str_ident(s, "assumption")) return INPUT_JUST; else if (str_ident(s, "goal")) return GOAL_JUST; else if (str_ident(s, "deny")) return DENY_JUST; else if (str_ident(s, "clausify")) return CLAUSIFY_JUST; else if (str_ident(s, "copy")) return COPY_JUST; else if (str_ident(s, "propositional")) return PROPOSITIONAL_JUST; else if (str_ident(s, "new_symbol")) return NEW_SYMBOL_JUST; else if (str_ident(s, "back_rewrite")) return BACK_DEMOD_JUST; else if (str_ident(s, "back_unit_del")) return BACK_UNIT_DEL_JUST; else if (str_ident(s, "expand_def")) return EXPAND_DEF_JUST; else if (str_ident(s, "resolve")) return BINARY_RES_JUST; else if (str_ident(s, "hyper")) return HYPER_RES_JUST; else if (str_ident(s, "ur")) return UR_RES_JUST; else if (str_ident(s, "factor")) return FACTOR_JUST; else if (str_ident(s, "xx_res")) return XXRES_JUST; else if (str_ident(s, "para")) return PARA_JUST; else if (str_ident(s, "para_fx")) return PARA_FX_JUST; else if (str_ident(s, "para_ix")) return PARA_IX_JUST; else if (str_ident(s, "instantiate")) return INSTANCE_JUST; else if (str_ident(s, "para_fx_ix")) return PARA_FX_IX_JUST; else if (str_ident(s, "flip")) return FLIP_JUST; else if (str_ident(s, "xx")) return XX_JUST; else if (str_ident(s, "merge")) return MERGE_JUST; else if (str_ident(s, "eval")) return EVAL_JUST; else if (str_ident(s, "rewrite")) return DEMOD_JUST; else if (str_ident(s, "unit_del")) return UNIT_DEL_JUST; else if (str_ident(s, "ivy")) return IVY_JUST; else return UNKNOWN_JUST; } /* jstring_to_jtype */ /************* * * itoc() * *************/ static char itoc(int i) { if (i <= 0) return '?'; else if (i <= 26) return 'a' + i - 1; else if (i <= 52) return 'A' + i - 27; else return '?'; } /* itoc */ /************* * * ctoi() * *************/ static int ctoi(char c) { if (c >= 'a' && c <= 'z') return c - 'a' + 1; else if (c >= 'A' && c <= 'Z') return c - 'A' + 27; else return INT_MIN; } /* ctoi */ /************* * * jmap1() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns the first. If i is not in the map, i is returned. */ /* PUBLIC */ int jmap1(I3list map, int i) { int id = assoc2a(map, i); return (id == INT_MIN ? i : id); } /* jmap1 */ /************* * * jmap2() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns a string representation of the second. If i is not in the map, or if the int value of is INT_MIN, "" is returned. Starting with 0, the strings are "A" - "Z", "A26", "A27", ... . The argument *a must point to available space for the result. The result is returned. */ /* PUBLIC */ char *jmap2(I3list map, int i, char *a) { int n = assoc2b(map, i); if (n == INT_MIN) a[0] = '\0'; else if (n >= 0 && n <= 25) { /* "A" -- "Z" */ a[0] = 'A' + n; a[1] = '\0'; } else { /* "A26", ... */ a[0] = 'A'; sprintf(a+1, "%d", n); } return a; } /* jmap2 */ /************* * * sb_append_id() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_append_id(String_buf sb, int id, I3list map) { char s[21]; sb_append_int(sb, jmap1(map, id)); sb_append(sb, jmap2(map, id, s)); } /* sb_append_id */ /************* * * sb_write_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void sb_write_res_just(String_buf sb, Just g, I3list map) { Ilist q; Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); for (q = p->next; q != NULL; q = q->next->next->next) { int nuc_lit = q->i; int sat_id = q->next->i; int sat_lit = q->next->next->i; sb_append(sb, ","); sb_append_char(sb, itoc(nuc_lit)); if (sat_id == 0) sb_append(sb, ",xx"); else { sb_append(sb, ","); sb_append_id(sb, sat_id, map); sb_append(sb, ","); if (sat_lit > 0) sb_append_char(sb, itoc(sat_lit)); else { sb_append_char(sb, itoc(-sat_lit)); sb_append(sb, "(flip)"); } } } sb_append(sb, ")"); } /* sb_write_res_just */ /************* * * sb_write_position() - like this (a,2,1,3) * *************/ static void sb_write_position(String_buf sb, Ilist p) { Ilist q; sb_append(sb, "("); sb_append_char(sb, itoc(p->i)); for (q = p->next; q != NULL; q = q->next) { sb_append(sb, ","); sb_append_int(sb, q->i); } sb_append(sb, ")"); } /* sb_write_position */ /************* * * sb_write_ids() - separated by space * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_write_ids(String_buf sb, Ilist p, I3list map) { Ilist q; for (q = p; q; q = q->next) { sb_append_id(sb, q->i, map); if (q->next) sb_append(sb, " "); } } /* sb_write_ids */ /************* * * sb_write_just() * *************/ /* DOCUMENTATION This routine writes (to a String_buf) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void sb_write_just(String_buf sb, Just just, I3list map) { Just g = just; sb_append(sb, "["); while (g != NULL) { Just_type rule = g->type; if (rule == INPUT_JUST || rule == GOAL_JUST) sb_append(sb, jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { sb_write_res_just(sb, g, map); } else if (rule == DEMOD_JUST) { I3list p; sb_append(sb, jstring(g)); sb_append(sb, "(["); for (p = g->u.demod; p; p = p->next) { sb_append_int(sb, p->i); if (p->j > 0) { sb_append(sb, "("); sb_append_int(sb, p->j); if (p->k == 2) sb_append(sb, ",R"); sb_append(sb, ")"); } sb_append(sb, p->next ? "," : ""); } sb_append(sb, "])"); } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; int n = p->i; int id = p->next->i; sb_append(sb, jstring(g)); sb_append(sb, "("); if (n < 0) { sb_append_char(sb, itoc(-n)); sb_append(sb, "(flip),"); } else { sb_append_char(sb, itoc(n)); sb_append(sb, ","); } sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->next->i)); sb_append(sb, ")"); } else if (rule == XXRES_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ")"); } else if (rule == EXPAND_DEF_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_id(sb, p->next->i, map); sb_append(sb, ")"); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == NEW_SYMBOL_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_char(sb, itoc(id)); sb_append(sb, ")"); } else if (rule == EVAL_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_int(sb, id); sb_append(sb, ")"); } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->from_id, map); sb_write_position(sb, p->from_pos); sb_append(sb, ","); sb_append_id(sb, p->into_id, map); sb_write_position(sb, p->into_pos); sb_append(sb, ")"); } else if (rule == INSTANCE_JUST) { Plist p; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_int(sb, g->u.instance->parent_id); sb_append(sb, ",["); for (p = g->u.instance->pairs; p; p = p->next) { sb_write_term(sb, p->v); if (p->next) sb_append(sb, ","); } sb_append(sb, "])"); } else if (rule == IVY_JUST) { sb_append(sb, jstring(g)); } else { printf("\nunknown rule: %d\n", rule); fatal_error("sb_write_just: unknown rule"); } g = g->next; if (g) sb_append(sb, ","); } sb_append(sb, "]."); } /* sb_write_just */ /************* * * sb_xml_write_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_xml_write_just(String_buf sb, Just just, I3list map) { Just g; /* Put the standard form into an attribute. */ String_buf sb_standard = get_string_buf(); sb_write_just(sb_standard, just, map); sb_append(sb, " \n"); /* Put an abbreviated form (rule, parents) into an XML elements. */ for (g = just; g; g = g->next) { Ilist parents = get_parents(g, FALSE); /* for this node only */ if (g == just) sb_append(sb, " \n"); /* close the \n"); } /* sb_xml_write_just */ /************* * * p_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_just(Just j) { String_buf sb = get_string_buf(); sb_write_just(sb, j, NULL); sb_append(sb, "\n"); fprint_sb(stdout, sb); zap_string_buf(sb); } /* p_just */ /************* * * zap_parajust() * *************/ static void zap_parajust(Parajust p) { zap_ilist(p->from_pos); zap_ilist(p->into_pos); free_parajust(p); } /* zap_parajust */ /************* * * zap_instancejust() * *************/ static void zap_instancejust(Instancejust p) { zap_plist_of_terms(p->pairs); free_instancejust(p); } /* zap_instancejust */ /************* * * zap_ivyjust() * *************/ static void zap_ivyjust(Ivyjust p) { zap_ilist(p->pos1); zap_ilist(p->pos2); zap_plist_of_terms(p->pairs); free_ivyjust(p); } /* zap_ivyjust */ /************* * * zap_just() * *************/ /* DOCUMENTATION This routine frees a justification list, including any sublists. */ /* PUBLIC */ void zap_just(Just just) { if (just != NULL) { zap_just(just->next); switch (just->type) { case INPUT_JUST: case GOAL_JUST: case DENY_JUST: case CLAUSIFY_JUST: case COPY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case EVAL_JUST: break; /* nothing to do */ case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: zap_ilist(just->u.lst); break; case DEMOD_JUST: zap_i3list(just->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: zap_parajust(just->u.para); break; case INSTANCE_JUST: zap_instancejust(just->u.instance); break; case IVY_JUST: zap_ivyjust(just->u.ivy); break; default: fatal_error("zap_just: unknown type"); } free_just(just); } } /* zap_just */ /************* * * get_parents() * *************/ /* DOCUMENTATION This routine returns an Ilist of parent IDs. If (all), get parents from the whole justification; otherwise get parents from the first node only. */ /* PUBLIC */ Ilist get_parents(Just just, BOOL all) { Ilist parents = NULL; Just g = just; while (g) { Just_type rule = g->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid nuclit sat1id sat1lit nuclit2 sat2id sat2lit ...)] */ Ilist p = g->u.lst; int nuc_id = p->i; parents = ilist_prepend(parents, nuc_id); p = p->next; while (p != NULL) { int sat_id = p->next->i; if (sat_id == 0) ; /* resolution with x=x */ else parents = ilist_prepend(parents, sat_id); p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; parents = ilist_prepend(parents, p->from_id); parents = ilist_prepend(parents, p->into_id); } else if (rule == INSTANCE_JUST) { parents = ilist_prepend(parents, g->u.instance->parent_id); } else if (rule == EXPAND_DEF_JUST) { parents = ilist_prepend(parents, g->u.lst->i); parents = ilist_prepend(parents, g->u.lst->next->i); } else if (rule == FACTOR_JUST || rule == XXRES_JUST) { int parent_id = g->u.lst->i; parents = ilist_prepend(parents, parent_id); } else if (rule == UNIT_DEL_JUST) { int parent_id = g->u.lst->next->i; parents = ilist_prepend(parents, parent_id); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST || rule == NEW_SYMBOL_JUST || rule == BACK_UNIT_DEL_JUST) { int parent_id = g->u.id; parents = ilist_prepend(parents, parent_id); } else if (rule == DEMOD_JUST) { I3list p; /* list of triples: (i=ID, j=position, k=direction) */ for (p = g->u.demod; p; p = p->next) parents = ilist_prepend(parents, p->i); } else if (rule == IVY_JUST) { if (g->u.ivy->type == FLIP_JUST || g->u.ivy->type == BINARY_RES_JUST || g->u.ivy->type == PARA_JUST || g->u.ivy->type == INSTANCE_JUST || g->u.ivy->type == PROPOSITIONAL_JUST) parents = ilist_prepend(parents, g->u.ivy->parent1); if (g->u.ivy->type == BINARY_RES_JUST || g->u.ivy->type == PARA_JUST) parents = ilist_prepend(parents, g->u.ivy->parent2); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == EVAL_JUST || rule == GOAL_JUST || rule == INPUT_JUST) ; /* do nothing */ else fatal_error("get_parents, unknown rule."); g = (all ? g->next : NULL); } return reverse_ilist(parents); } /* get_parents */ /************* * * first_negative_parent() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform first_negative_parent(Topform c) { Ilist parents = get_parents(c->justification, TRUE); Ilist p; Topform first_neg = NULL; for (p = parents; p && first_neg == NULL; p = p->next) { Topform c = find_clause_by_id(p->i); if (negative_clause_possibly_compressed(c)) first_neg = c; } zap_ilist(p); return first_neg; } /* first_negative_parent */ /************* * * get_clanc() * *************/ static Plist get_clanc(int id, Plist anc) { Topform c = find_clause_by_id(id); if (c == NULL) { printf("get_clanc, clause with id=%d not found.\n", id); fatal_error("get_clanc, clause not found."); } if (!plist_member(anc, c)) { Ilist parents, p; anc = insert_clause_into_plist(anc, c, TRUE); parents = get_parents(c->justification, TRUE); for (p = parents; p; p = p->next) { anc = get_clanc(p->i, anc); } zap_ilist(parents); } return anc; } /* get_clanc */ /************* * * get_clause_ancestors() * *************/ /* DOCUMENTATION This routine returns the Plist of clauses that are ancestors of Topform c, including clause c. The result is sorted (increasing) by ID. If any of the ancestors are compressed, they are uncompressed (in place) and left uncompressed. */ /* PUBLIC */ Plist get_clause_ancestors(Topform c) { Plist ancestors = get_clanc(c->id, NULL); return ancestors; } /* get_clause_ancestors */ /************* * * proof_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int proof_length(Plist proof) { return plist_count(proof); } /* proof_length */ /************* * * map_id() * *************/ static int map_id(I2list a, int arg) { int val = assoc(a, arg); return val == INT_MIN ? arg : val; } /* map_id */ /************* * * map_just() * *************/ /* DOCUMENTATION Update the clause IDs in a justification according to the map. */ /* PUBLIC */ void map_just(Just just, I2list map) { Just j; for (j = just; j; j = j->next) { Just_type rule = j->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid n sat1id n n sat2id n ...)] */ Ilist p = j->u.lst; p->i = map_id(map, p->i); /* nucleus */ p = p->next; while (p != NULL) { int sat_id = p->next->i; if (sat_id == 0) ; /* resolution with x=x */ else p->next->i = map_id(map, p->next->i); /* satellite */ p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = j->u.para; p->from_id = map_id(map, p->from_id); p->into_id = map_id(map, p->into_id); } else if (rule == INSTANCE_JUST) { Instancejust p = j->u.instance; p->parent_id = map_id(map, p->parent_id); } else if (rule == EXPAND_DEF_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); p->next->i = map_id(map, p->next->i); } else if (rule == FACTOR_JUST || rule == XXRES_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); } else if (rule == UNIT_DEL_JUST) { Ilist p = j->u.lst; p->next->i = map_id(map, p->next->i); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST || rule == NEW_SYMBOL_JUST || rule == BACK_UNIT_DEL_JUST) { j->u.id = map_id(map, j->u.id); } else if (rule == DEMOD_JUST) { I3list p; /* list of triples: */ for (p = j->u.demod; p; p = p->next) p->i = map_id(map, p->i); } else if (rule == IVY_JUST) { if (j->u.ivy->type == FLIP_JUST || j->u.ivy->type == BINARY_RES_JUST || j->u.ivy->type == PARA_JUST || j->u.ivy->type == INSTANCE_JUST || j->u.ivy->type == PROPOSITIONAL_JUST) j->u.ivy->parent1 = map_id(map, j->u.ivy->parent1); if (j->u.ivy->type == BINARY_RES_JUST || j->u.ivy->type == PARA_JUST) j->u.ivy->parent2 = map_id(map, j->u.ivy->parent2); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == EVAL_JUST || rule == GOAL_JUST || rule == INPUT_JUST) ; /* do nothing */ else fatal_error("get_clanc, unknown rule."); } } /* map_just */ /************* * * just_count() * *************/ /* DOCUMENTATION Return the number of justification elements in a justtification. */ /* PUBLIC */ int just_count(Just j) { if (j == 0) return 0; else return 1 + just_count(j->next); } /* just_count */ /************* * * mark_parents_as_used() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_parents_as_used(Topform c) { Ilist parents = get_parents(c->justification, TRUE); Ilist p; for (p = parents; p; p = p->next) { Topform parent = find_clause_by_id(p->i); parent->used = TRUE; } zap_ilist(parents); } /* mark_parents_as_used */ /************* * * cl_level() * *************/ static I2list cl_level(Topform c, I2list others) { int level = assoc(others, c->id); if (level != INT_MIN) return others; else { Ilist parents = get_parents(c->justification, TRUE); Ilist p; int max = -1; for (p = parents; p; p = p->next) { Topform parent = find_clause_by_id(p->i); int parent_level; others = cl_level(parent, others); parent_level = assoc(others, parent->id); max = IMAX(max, parent_level); } others = alist_insert(others, c->id, max+1); return others; } } /* cl_level */ /************* * * clause_level() * *************/ /* DOCUMENTATION Return the level of a clause. Input clauses have level=0, and a derived clause has level 1 more than the max of the levels of its parents. */ /* PUBLIC */ int clause_level(Topform c) { I2list ancestors = cl_level(c, NULL); int level = assoc(ancestors, c->id); zap_i2list(ancestors); return level; } /* clause_level */ /************* * * lit_string_to_int() * *************/ static int lit_string_to_int(char *s) { int i; if (str_to_int(s, &i)) return i; else if (strlen(s) > 1) return INT_MIN; else return ctoi(s[0]); } /* lit_string_to_int */ /************* * * args_to_ilist() * *************/ static Ilist args_to_ilist(Term t) { Ilist p = NULL; int i; for (i = 0; i < ARITY(t); i++) { Term a = ARG(t,i); char *s = sn_to_str(SYMNUM(a)); int x = lit_string_to_int(s); if (x > 0) { if (ARITY(a) == 1 && is_constant(ARG(a,0), "flip")) p = ilist_append(p, -x); else p = ilist_append(p, x); } else if (str_ident(s, "xx")) p = ilist_append(ilist_append(p, 0), 0); else fatal_error("args_to_ilist, bad arg"); } return p; } /* args_to_ilist */ /************* * * term_to_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just term_to_just(Term lst) { if (nil_term(lst)) return NULL; else { Term t = ARG(lst,0); Just j = get_just(); j->next = term_to_just(ARG(lst,1)); /* do the tail */ j->type = jstring_to_jtype(sn_to_str(SYMNUM(t))); switch (j->type) { /* primary and secondary are mixed */ case INPUT_JUST: case GOAL_JUST: return j; case COPY_JUST: case DENY_JUST: case CLAUSIFY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: { int id; if (term_to_int(ARG(t,0), &id)) j->u.id = id; else fatal_error("term_to_just, bad just id"); return j; } case FLIP_JUST: /* secondary */ case XX_JUST: /* secondary */ case EVAL_JUST: /* secondary */ case MERGE_JUST: /* secondary */ { j->u.id = lit_string_to_int(sn_to_str(SYMNUM(ARG(t,0)))); return j; } case DEMOD_JUST: /* secondary, rewrite([id(pos,side), ... ]) */ { I3list p = NULL; Term lst = ARG(t,0); if (!proper_listterm(lst)) fatal_error("term_to_just: rewrites must be proper list"); while(cons_term(lst)) { Term a = ARG(lst,0); int i, j; int k = 0; char *s = sn_to_str(SYMNUM(a)); if (ARITY(a) == 2 && str_to_int(s,&i) & term_to_int(ARG(a,0),&j)) { if (is_constant(ARG(a,1), "L")) k = 1; else if (is_constant(ARG(a,1), "R")) k = 2; else fatal_error("term_to_just: bad justification term (demod 1)"); p = i3list_append(p, i, j, k); } else if (ARITY(a) == 1 && str_to_int(s,&i) & term_to_int(ARG(a,0),&j)) { p = i3list_append(p, i, j, 1); } else if (ARITY(a) == 0 && str_to_int(s,&i)) { p = i3list_append(p, i, 0, 1); } else fatal_error("term_to_just: bad justification term (demod 2)"); lst = ARG(lst,1); } j->u.demod = p; return j; } case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case FACTOR_JUST: case XXRES_JUST: case UNIT_DEL_JUST: /* secondary */ j->u.lst = args_to_ilist(t); return j; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: { int id; Term from = ARG(t,0); Term into = ARG(t,1); Parajust p = get_parajust(); j->u.para = p; if (str_to_int(sn_to_str(SYMNUM(from)), &id)) p->from_id = id; else fatal_error("term_to_just, bad from_id"); p->from_pos = args_to_ilist(from); if (str_to_int(sn_to_str(SYMNUM(into)), &id)) p->into_id = id; else fatal_error("term_to_just, bad into_id"); p->into_pos = args_to_ilist(into); return j; } case INSTANCE_JUST: { int id; Term parent = ARG(t,0); Term pairs = ARG(t,1); Instancejust ij = get_instancejust(); j->u.instance = ij; if (str_to_int(sn_to_str(SYMNUM(parent)), &id)) ij->parent_id = id; else fatal_error("term_to_just, bad parent_id"); ij->pairs = NULL; while (cons_term(pairs)) { ij->pairs = plist_append(ij->pairs, copy_term(ARG(pairs,0))); pairs = ARG(pairs,1); } return j; } case IVY_JUST: fatal_error("term_to_just, IVY_JUST not handled"); return NULL; case UNKNOWN_JUST: default: printf("unknown: %d, %s\n", j->type, jstring(j)); fatal_error("term_to_just, unknown justification"); return NULL; } } } /* term_to_just */ /************* * * primary_just_type() * *************/ /* DOCUMENTATION Does a clause have justtification "input"? */ /* PUBLIC */ BOOL primary_just_type(Topform c, Just_type t) { return c->justification && c->justification->type == t; } /* primary_just_type */ /************* * * has_input_just() * *************/ /* DOCUMENTATION Does a clause have justtification "input"? */ /* PUBLIC */ BOOL has_input_just(Topform c) { return primary_just_type(c, INPUT_JUST); } /* has_input_just */ /************* * * has_copy_just() * *************/ /* DOCUMENTATION Does a clause have justification "copy"? */ /* PUBLIC */ BOOL has_copy_just(Topform c) { return primary_just_type(c, COPY_JUST); } /* has_copy_just */ /************* * * has_copy_flip_just() * *************/ /* DOCUMENTATION Does a clause have justification "copy, flip", and nothing else? */ /* PUBLIC */ BOOL has_copy_flip_just(Topform c) { return (c->justification && c->justification->type == COPY_JUST && c->justification->next && c->justification->next->type == FLIP_JUST && c->justification->next->next == NULL); } /* has_copy_flip_just */ /* ************************************************************************ BV(2007-aug-20): new functions to support tagged proofs (prooftrans) ***********************************************************************/ /************* * * sb_tagged_write_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void sb_tagged_write_res_just(String_buf sb, Just g, I3list map) { Ilist q; Ilist p = g->u.lst; #if 1 /* BV(2007-jul-10) */ sb_append(sb, jstring(g)); sb_append(sb, "\np "); sb_append_id(sb, p->i, map); for (q = p->next; q != NULL; q = q->next->next->next) { int sat_id = q->next->i; sb_append(sb, "\np "); if (sat_id == 0) sb_append(sb, ",xx"); else sb_append_id(sb, sat_id, map); } return; #endif } /* sb_tagged_write_res_just */ /************* * * sb_tagged_write_just() * *************/ /* DOCUMENTATION This routine writes (to a String_buf) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void sb_tagged_write_just(String_buf sb, Just just, I3list map) { Just g = just; /* sb_append(sb, "["); */ while (g != NULL) { Just_type rule = g->type; sb_append(sb, "i "); if (rule == INPUT_JUST || rule == GOAL_JUST) sb_append(sb, jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { sb_tagged_write_res_just(sb, g, map); } else if (rule == DEMOD_JUST) { I3list p; sb_append(sb, jstring(g)); for (p = g->u.demod; p; p = p->next) { sb_append(sb, "\np "); sb_append_int(sb, p->i); } } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; int n = p->i; int id = p->next->i; sb_append(sb, jstring(g)); sb_append(sb, "("); if (n < 0) { sb_append_char(sb, itoc(-n)); sb_append(sb, "(flip),"); } else { sb_append_char(sb, itoc(n)); sb_append(sb, ","); } sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->next->i)); sb_append(sb, ")"); } else if (rule == XXRES_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ")"); } else if (rule == EXPAND_DEF_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_id(sb, p->next->i, map); sb_append(sb, ")"); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == NEW_SYMBOL_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "\np "); sb_append_id(sb, id, map); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == EVAL_JUST || rule == MERGE_JUST) { /* int id = g->u.id; */ #if 1 /* BV(2007-jul-10) */ sb_append(sb, "(flip)"); /* break; */ #endif } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; #if 1 /* BV(2007-jul-10) */ sb_append(sb, "para"); sb_append(sb, "\np "); sb_append_id(sb, p->from_id, map); sb_append(sb, "\np "); sb_append_id(sb, p->into_id, map); /* break; */ #endif } else if (rule == INSTANCE_JUST) { Plist p; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_int(sb, g->u.instance->parent_id); sb_append(sb, ",["); for (p = g->u.instance->pairs; p; p = p->next) { sb_write_term(sb, p->v); if (p->next) sb_append(sb, ","); } sb_append(sb, "])"); } else if (rule == IVY_JUST) { sb_append(sb, jstring(g)); } else { printf("\nunknown rule: %d\n", rule); fatal_error("sb_write_just: unknown rule"); } g = g->next; /* if (g) */ /* sb_append(sb, ","); */ sb_append(sb, "\n"); } /* sb_append(sb, "]."); */ } /* sb_tagged_write_just */ LADR-2009-11A/ladr/subsume.c0000644000175000017500000004166011136261230014571 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "subsume.h" /* Private definitions and types */ static int Nonunit_subsumption_tests = 0; /************* * * nonunit_subsumption_tests(void) * *************/ /* DOCUMENTATION */ /* PUBLIC */ int nonunit_subsumption_tests(void) { return Nonunit_subsumption_tests; } /* nonunit_subsumption_tests */ /************* * * subsume_literals() * * This is a recursive routine that tries to map a list of literals * into a clause d. If successful, the trail is updated; if failure, * the trail is unchanged. * * This version uses ordinary unification. * *************/ static BOOL subsume_literals(Literals clit, Context subst, Topform d, Trail *trp) { BOOL subsumed = FALSE; Literals dlit; if (clit == NULL) return TRUE; else { for (dlit = d->literals; !subsumed && dlit != NULL; dlit = dlit->next) { if (clit->sign == dlit->sign) { Trail mark = *trp; if (match(clit->atom, subst, dlit->atom, trp)) { if (subsume_literals(clit->next, subst, d, trp)) subsumed = TRUE; else { undo_subst_2(*trp, mark); *trp = mark; } } } } return subsumed; } } /* subsume_literals */ /************* * * subsume_bt_literals() * * This version uses backtrack unification. * *************/ static BOOL subsume_bt_literals(Literals clit, Context subst, Topform d, Plist *gp) { if (clit == NULL) return TRUE; else { BOOL subsumed = FALSE; Literals dlit; *gp = plist_prepend(*gp, NULL); for (dlit=d->literals; !subsumed && dlit!=NULL; dlit=dlit->next) { if (clit->sign == dlit->sign) { Btm_state bt = match_bt_first(clit->atom, subst, dlit->atom, FALSE); while (bt != NULL && !subsumed) { (*gp)->v = bt; if (subsume_bt_literals(clit->next, subst, d, gp)) subsumed = TRUE; else { bt = match_bt_next(bt); } } } } if (subsumed) return TRUE; else { *gp = plist_pop(*gp); return FALSE; } } } /* Subsume_bt_literals */ /************* * * subsumes() * *************/ /* DOCUMENTATION This routine checks if Topform c subsumes Topform d. Ordinary unification is used; in particular, symmetry of equality is not built in.

*/ /* PUBLIC */ BOOL subsumes(Topform c, Topform d) { Context subst = get_context(); Trail tr = NULL; BOOL subsumed = subsume_literals(c->literals, subst, d, &tr); if (subsumed) undo_subst(tr); free_context(subst); Nonunit_subsumption_tests++; return subsumed; } /* subsumes */ /************* * * subsumes_bt() * *************/ /* DOCUMENTATION This routine checks if Topform c subsumes Topform d. Backtrack unification is used; in particular, AC and commutative/symmetric matching are applied where appropriate. */ /* PUBLIC */ BOOL subsumes_bt(Topform c, Topform d) { Context subst = get_context(); Plist g = NULL; int rc = subsume_bt_literals(c->literals, subst, d, &g); if (rc) { /* Cancel the list (stack) of btm_states */ while (g != NULL) { Btm_state bt = g->v; match_bt_cancel(bt); g = plist_pop(g); } } free_context(subst); return rc; } /* subsumes_bt */ /************* * * forward_subsume() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform forward_subsume(Topform d, Lindex idx) { Literals dlit; Topform subsumer = NULL; Context subst = get_context(); int nd = number_of_literals(d->literals); /* We have to consider all literals of d, because when d is subsumed by c, not all literals of d have to match with a literal in c. c is indexed on the first literal only. */ for (dlit=d->literals; dlit!=NULL && subsumer==NULL; dlit=dlit->next) { Mindex mdx = dlit->sign ? idx->pos : idx->neg; Mindex_pos pos; Term catom = mindex_retrieve_first(dlit->atom, mdx, GENERALIZATION, NULL, subst, FALSE, &pos); BOOL backtrack = lindex_backtrack(idx); while (catom != NULL && subsumer == NULL) { Topform c = catom->container; if (atom_number(c->literals, catom) == 1) { int nc = number_of_literals(c->literals); /* If c is a unit then we already know it subsumes d; otherwise, * do a full subsumption check on the clauses. (We don't let * a clause subsume a shorter one, because that would cause * factors to be deleted.) */ if (nc == 1 || (nc <= nd && (backtrack ? subsumes_bt(c,d) : subsumes(c,d)))) { subsumer = c; mindex_retrieve_cancel(pos); } } if (subsumer == NULL) catom = mindex_retrieve_next(pos); } } free_context(subst); return subsumer; } /* forward_subsume */ /************* * * back_subsume() * *************/ /* DOCUMENTATION Look in the index and return the list of clauses subsumed by c. */ /* PUBLIC */ Plist back_subsume(Topform c, Lindex idx) { int nc = number_of_literals(c->literals); if (nc == 0) return NULL; else { Plist subsumees = NULL; Context subst = get_context(); Literals clit = c->literals; /* We only have to consider the first literal of c, because when c subsumes a clause d, all literals of c have to map into d. All literals of d are indexed. */ Mindex mdx = clit->sign ? idx->pos : idx->neg; Mindex_pos pos; Term datom = mindex_retrieve_first(clit->atom, mdx, INSTANCE, subst, NULL, FALSE, &pos); BOOL backtrack = lindex_backtrack(idx); while (datom != NULL) { Topform d = datom->container; if (d != c) { /* in case c is already in idx */ int nd = number_of_literals(d->literals); /* If c is a unit the we already know it subsumes d; otherwise, * do a full subsumption check on the clauses. (We don't let * a clause subsume a shorter one.) */ if (nc == 1 || (nc <= nd && (backtrack ? subsumes_bt(c, d) : subsumes(c, d)))) subsumees = insert_clause_into_plist(subsumees, d, FALSE); } datom = mindex_retrieve_next(pos); } free_context(subst); return subsumees; } } /* back_subsume */ /************* * * back_subsume_one() * *************/ /* DOCUMENTATION Look in the index for a clause subsumed by c. The first one found is returned. (It is not necessarily the first of the subsumees that was inserted into the index.) */ /* PUBLIC */ Topform back_subsume_one(Topform c, Lindex idx) { int nc = number_of_literals(c->literals); if (nc == 0) return NULL; else { Context subst = get_context(); Literals clit = c->literals; Mindex mdx = clit->sign ? idx->pos : idx->neg; Mindex_pos pos; Term datom = mindex_retrieve_first(clit->atom, mdx, INSTANCE, subst, NULL, FALSE, &pos); BOOL backtrack = lindex_backtrack(idx); BOOL found = FALSE; Topform d = NULL; while (datom != NULL && !found) { d = datom->container; if (d != c) { /* in case c is already in idx */ int nd = number_of_literals(d->literals); /* If c is a unit the we already know it subsumes d; otherwise, * do a full subsumption check on the clauses. (We don't let * a clause subsume a shorter one.) */ if (nc == 1 || (nc <= nd && (backtrack ? subsumes_bt(c, d) : subsumes(c, d)))) { found = TRUE; mindex_retrieve_cancel(pos); } else datom = mindex_retrieve_next(pos); } } free_context(subst); return found ? d : NULL; } } /* back_subsume_one */ /************* * * atom_conflict() * *************/ static void atom_conflict(BOOL flipped, Topform c, BOOL sign, Term a, Lindex idx, void (*empty_proc) (Topform)) { int n = 0; Context subst1 = get_context(); Context subst2 = get_context(); Mindex mdx = sign ? idx->neg : idx->pos; Mindex_pos pos; Term b = mindex_retrieve_first(a, mdx, UNIFY, subst1, subst2, FALSE, &pos); while (b) { Topform d = b->container; if (number_of_literals(d->literals) == 1) { Topform conflictor = d; Topform empty = get_topform(); if (c->id == 0) assign_clause_id(c); /* so that justification makes sense */ c->used = TRUE; /* so it won't be discarded */ empty->justification = binary_res_just(c, 1, conflictor, flipped ? -1 : 1); inherit_attributes(c, subst1, conflictor, subst2, empty); n++; (*empty_proc)(empty); b = mindex_retrieve_next(pos); } else b = mindex_retrieve_next(pos); } free_context(subst1); free_context(subst2); } /* atom_conflict */ /************* * * unit_conflict_by_index() * *************/ /* DOCUMENTATION Look in idx for unit conflicts */ /* PUBLIC */ void unit_conflict_by_index(Topform c, Lindex idx, void (*empty_proc) (Topform)) { if (number_of_literals(c->literals) == 1) { Literals lit = c->literals; Term atom = lit->atom; atom_conflict(FALSE, c, lit->sign, atom, idx, empty_proc); /* maybe try the flip */ if (eq_term(atom) && !renamable_flip_eq(atom)) { Term flip = top_flip(atom); atom_conflict(TRUE, c, lit->sign, flip, idx, empty_proc); zap_top_flip(flip); } } } /* unit_conflict_by_index */ /************* * * try_unit_conflict() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform try_unit_conflict(Topform a, Topform b) { Context c1 = get_context(); Context c2 = get_context(); Trail tr = NULL; Topform empty = NULL; if (unit_clause(a->literals) && unit_clause(b->literals) && a->literals->sign != b->literals->sign && unify(a->literals->atom, c1, b->literals->atom, c2, &tr)) { empty = get_topform(); empty->justification = binary_res_just(a, 1, b, 1); inherit_attributes(a, c1, b, c2, empty); undo_subst(tr); } free_context(c1); free_context(c2); return empty; } /* try_unit_conflict */ /************* * * unit_delete() * *************/ /* DOCUMENTATION Given a clause and a literal index, remove the literals that can be removed by "unit deletion" with units in the index. Update the clause's justification for each removed literal. */ /* PUBLIC */ void unit_delete(Topform c, Lindex idx) { Context subst = get_context(); Literals l; int i; BOOL null_literals = FALSE; for (l = c->literals, i = 1; l; l = l->next, i++) { Mindex mdx = l->sign ? idx->neg : idx->pos; Mindex_pos pos; Term datom = mindex_retrieve_first(l->atom, mdx, GENERALIZATION, NULL, subst, FALSE, &pos); BOOL ok = FALSE; while (datom && !ok) { Topform d = datom->container; if (unit_clause(d->literals)) { ok = TRUE; c->justification = append_just(c->justification, unit_del_just(d, i)); c->attributes = cat_att(c->attributes, inheritable_att_instances(d->attributes, subst)); mindex_retrieve_cancel(pos); zap_term(l->atom); l->atom = NULL; /* remove it below */ null_literals = TRUE; } } /* If still there and equality, try flipping it. */ if (l->atom && eq_term(l->atom)) { Term flip = top_flip(l->atom); Term datom = mindex_retrieve_first(flip, mdx, GENERALIZATION, NULL, subst, FALSE, &pos); BOOL ok = FALSE; while (datom && !ok) { Topform d = datom->container; if (unit_clause(d->literals)) { ok = TRUE; mindex_retrieve_cancel(pos); c->justification = append_just(c->justification, unit_del_just(d, -i)); c->attributes = cat_att(c->attributes, inheritable_att_instances(d->attributes, subst)); zap_term(l->atom); l->atom = NULL; /* remove it below */ null_literals = TRUE; } } zap_top_flip(flip); } /* eq_atom */ } /* foreach literal */ if (null_literals) { c->literals = remove_null_literals(c->literals); c->normal_vars = FALSE; /* removing literals can make vars non-normal */ } free_context(subst); } /* unit_delete */ /************* * * back_unit_del_by_index() * *************/ /* DOCUMENTATION Given a unit clause and a literal index, return the Plist of clauses containing literals that are instances of the negation of the unit clause.

Such clauses can be "back unit deleted". */ /* PUBLIC */ Plist back_unit_del_by_index(Topform unit, Lindex idx) { Plist nonunits = NULL; Context subst = get_context(); Literals clit = unit->literals; Mindex mdx = clit->sign ? idx->neg : idx->pos; Mindex_pos pos; Term datom = mindex_retrieve_first(clit->atom, mdx, INSTANCE, subst, NULL, FALSE, &pos); while (datom != NULL) { Topform d = datom->container; nonunits = insert_clause_into_plist(nonunits, d, FALSE); datom = mindex_retrieve_next(pos); } /* If equality, do the same with the flip. */ if (eq_term(clit->atom)) { Term flip = top_flip(clit->atom); Term datom = mindex_retrieve_first(flip, mdx, INSTANCE, subst, NULL, FALSE, &pos); while (datom != NULL) { Topform d = datom->container; nonunits = insert_clause_into_plist(nonunits, d, FALSE); datom = mindex_retrieve_next(pos); } zap_top_flip(flip); } free_context(subst); return nonunits; } /* back_unit_del_by_index */ /************* * * simplify_literals() * *************/ /* DOCUMENTATION Remove any literals t!=t. */ /* PUBLIC */ void simplify_literals(Topform c) { Literals l; int i; BOOL null_literals = FALSE; for (l = c->literals, i = 1; l; l = l->next, i++) { Term a = l->atom; BOOL sign = l->sign; if ((!sign && eq_term(a) && term_ident(ARG(a,0), ARG(a,1))) || (!sign && true_term(a)) || (sign && false_term(a))) { c->justification = append_just(c->justification, xx_just(i)); zap_term(l->atom); l->atom = NULL; null_literals = TRUE; } } if (null_literals) c->literals = remove_null_literals(c->literals); } /* simplify_literals */ /************* * * eq_removable_literal() * *************/ /* DOCUMENTATION Can a literal in a clause be removed by resolution with x=x without instantiating any other literal in the clause?

If so, instantiate any inheritable (e.g., answer) attributes with the corresponding substitution. */ /* PUBLIC */ BOOL eq_removable_literal(Topform c, Literals lit) { if (lit->sign || !eq_term(lit->atom)) return FALSE; else { Term alpha = ARG(lit->atom, 0); Term beta = ARG(lit->atom, 1); Context subst = get_context(); Trail tr = NULL; BOOL ok = unify(alpha, subst, beta, subst, &tr); if (ok) { /* Check if substitution instantiates any other literal. */ /* Note that other literals may have atom==NULL. */ Literals l; for (l = c->literals; l && ok; l = l->next) { if (l != lit && l->atom != NULL) if (subst_changes_term(l->atom, subst)) ok = FALSE; } if (ok) instantiate_inheritable_attributes(c->attributes, subst); undo_subst(tr); } free_context(subst); return ok; } } /* eq_removable_literal */ /************* * * simplify_literals2() * *************/ /* DOCUMENTATION 1. If there are any literals t=t, the clause becomes true_sym(). 2. Remove any literals t!=t. 3. If there are any literals s!=t, where unify(s,t), without instantiating any other literals, remove the literal. */ /* PUBLIC */ void simplify_literals2(Topform c) { Literals l; int i; BOOL null_literals = FALSE; BOOL tautological = FALSE; if (!c->normal_vars) renumber_variables(c, MAX_VARS); for (l = c->literals, i = 1; l && !tautological; l = l->next, i++) { Term a = l->atom; BOOL sign = l->sign; if ((!sign && eq_term(a) && term_ident(ARG(a,0), ARG(a,1))) || /* (!sign && true_term(a)) || */ /* (sign && false_term(a)) || */ eq_removable_literal(c, l)) { /* literal is FALSE, so remove it */ c->justification = append_just(c->justification, xx_just(i)); zap_term(l->atom); l->atom = NULL; null_literals = TRUE; } else if ((!sign && true_term(a)) || (sign && false_term(a))) { zap_term(l->atom); l->atom = NULL; null_literals = TRUE; } else if ((sign && eq_term(a) && term_ident(ARG(a,0), ARG(a,1))) || (sign && true_term(a)) || (!sign && false_term(a))) tautological = TRUE; } if (null_literals) { c->literals = remove_null_literals(c->literals); c->normal_vars = 0; renumber_variables(c, MAX_VARS); } if (tautological || tautology(c->literals)) { zap_literals(c->literals); c->literals = new_literal(TRUE, get_rigid_term(true_sym(), 0)); c->literals->atom->container = c; /* justification not necessary because clause will disappear??? */ } } /* simplify_literals2 */ LADR-2009-11A/ladr/options.c0000644000175000017500000006743411075032770014617 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "options.h" #include /* for variable argument lists */ /* Private definitions and types */ /* Dependencies. */ typedef enum { FLAGT, PARMT, FLOATPARMT, STRINGPARMT } Opttype; typedef struct optdep * Optdep; struct optdep { /* these get attached to flags/parms that have dependents */ BOOL flag_trigger; /* whether set or clear triggers action */ Opttype type; /* type of dependent option */ int id; /* id of dependent option */ int val; /* value for dependent flag or parm */ double dval; /* value for dependent floatparm */ char *sval; /* value for dependent stringparm */ BOOL multiply; /* means val is multiplier instead of fixed value */ Optdep next; /* next dependent */ }; struct flag { /* Flags are boolean valued options */ char *name; BOOL val; BOOL default_val; Optdep dependencies; }; struct parm { /* Parms are integer valued options */ char *name; int val; int default_val; int min, max; /* minimum and maximum permissible values */ Optdep dependencies; }; struct floatparm { /* FloatParms are double-valued options */ char *name; double val; double default_val; double min, max; /* minimum and maximum permissible values */ Optdep dependencies; }; struct stringparm { /* Stringparms are string valued options */ char *name; char *val; /* current valuse: index into array of strings */ char *default_val; /* current valuse: index into array of strings */ int n; /* number of possible values */ char **range; /* array of possible values */ /* Optdep dependencies; */ }; static struct flag Flags[MAX_FLAGS]; static struct parm Parms[MAX_PARMS]; static struct floatparm Floatparms[MAX_FLOATPARMS]; static struct stringparm Stringparms[MAX_STRINGPARMS]; static int Next_flag = 0; static int Next_parm = 0; static int Next_floatparm = 0; static int Next_stringparm = 0; static int Option_updates = 0; /* Flag, Parm, Stringparm */ static BOOL Ignore_dependencies = FALSE; /* * memory management */ #define PTRS_OPTDEP PTRS(sizeof(struct optdep)) static unsigned Optdep_gets, Optdep_frees; /************* * * Optdep get_optdep() * *************/ static Optdep get_optdep(void) { Optdep p = get_cmem(PTRS_OPTDEP); Optdep_gets++; return(p); } /* get_optdep */ /************* * * free_optdep() * *************/ #if 0 static void free_optdep(Optdep p) { free_mem(p, PTRS_OPTDEP); Optdep_frees++; } /* free_optdep */ #endif /************* * * fprint_options_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the options package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_options_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct optdep); fprintf(fp, "optdep (%4d) %11u%11u%11u%9.1f K\n", n, Optdep_gets, Optdep_frees, Optdep_gets - Optdep_frees, ((Optdep_gets - Optdep_frees) * n) / 1024.); } /* fprint_options_mem */ /************* * * p_options_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the options package. */ /* PUBLIC */ void p_options_mem() { fprint_options_mem(stdout, TRUE); } /* p_options_mem */ /* * end of memory management */ /************* * * enable_option_dependencies() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void enable_option_dependencies(void) { Ignore_dependencies = FALSE; } /* enable_option_dependencies */ /************* * * disable_option_dependencies() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void disable_option_dependencies(void) { Ignore_dependencies = TRUE; } /* disable_option_dependencies */ /************* * * option_dependencies_state() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL option_dependencies_state(void) { return !Ignore_dependencies; } /* option_dependencies_state */ /************* * * init_flag() * *************/ /* DOCUMENTATION Initialize a flag (boolean-valued option). You give it a name and a default value, and an integer id is returned. Flags are typically changed by user commands which are parsed by read_commands(). The value of a flag is checked with flag(ID). */ /* PUBLIC */ int init_flag(char *name, BOOL default_value) { int id = -1; if (Next_flag == MAX_FLAGS) fatal_error("init_flag, too many flags"); else if (FALSE && str_to_flag_id(name) != -1) { char s[100]; sprintf(s, "init_flag, flag %s already exists", name); fatal_error(s); } else { id = Next_flag++; Flags[id].name = name; Flags[id].val = default_value; Flags[id].default_val = default_value; Flags[id].dependencies = NULL; } return id; } /* init_flag */ /************* * * init_parm() * *************/ /* DOCUMENTATION Initialize a parm (integer-valued option). You give it a name, a default value, and min and max values. An integer id is returned. Parms are typically changed by user commands which are parsed by read_commands(). The value of a parm is checked with parm(ID). */ /* PUBLIC */ int init_parm(char *name, int default_value, int min_value, int max_value) { int id = -1; if (Next_parm == MAX_PARMS) fatal_error("init_parm: too many parms"); else { id = Next_parm++; Parms[id].name = name; Parms[id].val = default_value; Parms[id].default_val = default_value; Parms[id].min = min_value; Parms[id].max = max_value; } return id; } /* init_parm */ /************* * * init_floatparm() * *************/ /* DOCUMENTATION Initialize a floatparmparm (double-valued option). You give it a name, a default value, and min and max values. An integer id is returned. Parms are typically changed by user commands which are parsed by read_commands(). The value of a parm is checked with floatparm(ID). */ /* PUBLIC */ int init_floatparm(char *name, double default_value, double min_value, double max_value) { int id = -1; if (Next_floatparm == MAX_FLOATPARMS) fatal_error("init_floatparm: too many parms"); else { id = Next_floatparm++; Floatparms[id].name = name; Floatparms[id].val = default_value; Floatparms[id].default_val = default_value; Floatparms[id].min = min_value; Floatparms[id].max = max_value; } return id; } /* init_floatparm */ /************* * * init_stringparm() * *************/ /* DOCUMENTATION Initialize a stringparm (string-valued option). You give it a name, a number n of possible values, and n strings which are the possible values. An integer id is returned The first string given is the default value.

Stringparms are typically changed by user commands which are parsed by read_commands(). The value of a stringparm is checked with the Boolean routine stringparm(ID, string). */ /* PUBLIC */ int init_stringparm(char *name, int n, ...) { int id = -1; if (Next_stringparm == MAX_STRINGPARMS) fatal_error("init_stringparm: too many stringparms"); else { int i; va_list parameters; id = Next_stringparm++; va_start(parameters, n); Stringparms[id].range = malloc(n * sizeof(char *)); for (i = 0; i < n; i++) Stringparms[id].range[i] = va_arg(parameters, char *); va_end(parameters); Stringparms[id].name = name; Stringparms[id].n = n; /* number of values */ Stringparms[id].val = Stringparms[id].range[0]; /* first is default */ Stringparms[id].default_val = Stringparms[id].range[0]; /* first is default */ } return id; } /* init_stringparm */ /************* * * fprint_options(fp) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the current values of all of the the options (flags, parms, and stringparms). */ /* PUBLIC */ void fprint_options(FILE *fp) { int i, j; fprintf(fp, "\n--------------- options ---------------\n"); j = 0; for (i = 0; i < Next_flag; i++) { /* print flags */ fprintf(fp, "%s", Flags[i].val ? "set(" : "clear("); fprintf(fp, "%s). ", Flags[i].name); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n\n"); j = 0; for (i = 0; i < Next_parm; i++) { /* print parms */ fprintf(fp, "assign("); fprintf(fp, "%s, %d). ", Parms[i].name, Parms[i].val); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n\n"); j = 0; for (i = 0; i < Next_floatparm; i++) { /* print parms */ fprintf(fp, "assign("); fprintf(fp, "%s, \"%.3f\"). ", Floatparms[i].name, Floatparms[i].val); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n\n"); j = 0; for (i = 0; i < Next_stringparm; i++) { /* print stringparms */ struct stringparm *sp = &(Stringparms[i]); fprintf(fp, "assign("); fprintf(fp, "%s, %s). ", sp->name, sp->val); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n"); fflush(fp); } /* fprint_options */ /************* * * p_options() * *************/ /* DOCUMENTATION This routine prints (to stdout) the current values of the the options (flags, parms, and stringparms). */ /* PUBLIC */ void p_options(void) { fprint_options(stdout); } /* p_options */ /************* * * flag() * *************/ /* DOCUMENTATION This Boolean routine returns the value of a flag. If the Flag index is out of range, bad things can happen. */ /* PUBLIC */ int flag(int flag_id) { return Flags[flag_id].val; } /* flag */ /************* * * parm() * *************/ /* DOCUMENTATION This integer routine returns the value of a parameter. If the parm index is out of range, bad things can happen. */ /* PUBLIC */ int parm(int parm_id) { return Parms[parm_id].val; } /* parm */ /************* * * at_parm_limit() * *************/ /* DOCUMENTATION This assumes that -1 represents infinity. */ /* PUBLIC */ BOOL at_parm_limit(int value, int parm_id) { int limit = Parms[parm_id].val; if (limit == -1) return FALSE; /* no limit */ else return value >= limit; } /* at_parm_limit */ /************* * * over_parm_limit() * *************/ /* DOCUMENTATION This assumes that -1 represents infinity. */ /* PUBLIC */ BOOL over_parm_limit(int value, int parm_id) { int limit = Parms[parm_id].val; if (limit == -1) return FALSE; /* no limit */ else return value > limit; } /* over_parm_limit */ /************* * * floatparm() * *************/ /* DOCUMENTATION This integer routine returns the value of a parameter. If the floatparm index is out of range, bad things can happen. */ /* PUBLIC */ double floatparm(int floatparm_id) { return Floatparms[floatparm_id].val; } /* floatparm */ /************* * * stringparm() * *************/ /* DOCUMENTATION This routine checks if the current value of a stringparm matches the given string. The ID must be valid. */ /* PUBLIC */ BOOL stringparm(int id, char *s) { return str_ident(Stringparms[id].val, s); } /* stringparm */ /************* * * stringparm1() * *************/ /* DOCUMENTATION This routine returns the current value of a stringparm. The ID must be valid. */ /* PUBLIC */ char *stringparm1(int id) { return Stringparms[id].val; } /* stringparm1 */ /************* * * update_flag() * *************/ /* DOCUMENTATION This performs the role of set_flag() and clear_flag(). In addition, an output file is given for dependency messages. */ /* PUBLIC */ void update_flag(FILE *fout, int id, BOOL val, BOOL echo) { if (id < 0 || id >= Next_flag) { fprintf(fout, "update_flag: flag id %d, is out of range.\n", id); fprintf(stderr, "update_flag: flag id %d, is out of range.\n", id); fatal_error("update_flag, flag out of range"); } else { Optdep p; Flags[id].val = val; Option_updates++; /* special case */ if (str_ident(Flags[id].name, "ignore_option_dependencies")) Ignore_dependencies = val; if (!Ignore_dependencies) { for (p = Flags[id].dependencies; p; p = p->next) { if (p->flag_trigger == val) { if (p->type == FLAGT) { if (echo) { fprintf(fout, " %% %s(%s) -> %s(%s).\n", val ? "set" : "clear", Flags[id].name, p->val ? "set" : "clear", Flags[p->id].name); } update_flag(fout, p->id, p->val, echo); } else if (p->type == PARMT) { if (echo) { fprintf(fout, " %% %s(%s) -> assign(%s, %d).\n", val ? "set" : "clear", Flags[id].name, Parms[p->id].name, p->val); } assign_parm(p->id, p->val, echo); } else if (p->type == FLOATPARMT) { if (echo) { fprintf(fout, " %% %s(%s) -> assign(%s, \"%.3f\").\n", val ? "set" : "clear", Flags[id].name, Floatparms[p->id].name, p->dval); } assign_floatparm(p->id, p->dval, echo); } else { /* assume it's a stringparm */ if (echo) { fprintf(fout, " %% %s(%s) -> assign(%s, %s).\n", val ? "set" : "clear", Flags[id].name, Stringparms[p->id].name, p->sval); } assign_stringparm(p->id, p->sval, echo); } } } } } } /* update_flag */ /************* * * set_flag() * *************/ /* DOCUMENTATION This routine sets a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs. */ /* PUBLIC */ void set_flag(int id, BOOL echo) { update_flag(stdout, id, TRUE, echo); } /* set_flag */ /************* * * clear_flag() * *************/ /* DOCUMENTATION This routine clears a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs. */ /* PUBLIC */ void clear_flag(int id, BOOL echo) { update_flag(stdout, id, FALSE, echo); } /* clear_flag */ /************* * * assign_parm() * *************/ /* DOCUMENTATION This routine assigns a value to a parm. The parm is identified by its integer ID (which is available from str_to_parm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs. */ /* PUBLIC */ void assign_parm(int id, int val, BOOL echo) { if (id < 0 || id >= Next_parm) { fprintf(stdout, "assign_parm: parm id %d, is out of range.\n", id); fprintf(stderr, "assign_parm: parm id %d, is out of range.\n", id); fatal_error("assign_parm"); } else if (val < Parms[id].min || val > Parms[id].max) { fprintf(stdout, "assign_parm: parm %s, value %d out of range [%d..%d].\n", Parms[id].name, val, Parms[id].min, Parms[id].max); fprintf(stderr, "assign_parm: parm %s, value %d out of range [%d..%d].\n", Parms[id].name, val, Parms[id].min, Parms[id].max); fatal_error("assign_parm"); } else { Optdep p; Parms[id].val = val; Option_updates++; if (!Ignore_dependencies) { for (p = Parms[id].dependencies; p; p = p->next) { if (p->type == PARMT) { /* parm -> parm */ int dval = p->multiply ? p->val * val : p->val; if (echo) { fprintf(stdout, " %% assign(%s, %d) -> assign(%s, %d).\n", Parms[id].name, val, Parms[p->id].name, dval); } assign_parm(p->id, dval, echo); } else { /* parm -> flag */ if (echo) { fprintf(stdout, " %% assign(%s, %d) -> %s(%s).\n", Parms[id].name, val, p->val ? "set" : "clear", Flags[p->id].name); } update_flag(stdout, p->id, p->val, echo); } } } } } /* assign_parm */ /************* * * assign_floatparm() * *************/ /* DOCUMENTATION This routine assigns a value to a floatparm. The floatparm is identified by its integer ID (which is available from str_to_floatparm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs. */ /* PUBLIC */ void assign_floatparm(int id, double val, BOOL echo) { if (id < 0 || id >= Next_floatparm) { fprintf(stdout, "assign_floatparm: id %d, is out of range.\n", id); fprintf(stderr, "assign_floatparm: id %d, is out of range.\n", id); fatal_error("assign_floatparm"); } else if (val < Floatparms[id].min || val > Floatparms[id].max) { fprintf(stdout, "assign_floatparm: parm %s, value %.3f out of range [%.3f..%.3f].\n", Floatparms[id].name, val, Floatparms[id].min, Floatparms[id].max); fprintf(stderr, "assign_floatparm: parm %s, value %.3f out of range [%.3f..%.3f].\n", Floatparms[id].name, val, Floatparms[id].min, Floatparms[id].max); fatal_error("assign_floatparm"); } else { Floatparms[id].val = val; Option_updates++; /* Currently, nothing depends on floatparms. */ } } /* assign_floatparm */ /************* * * assign_stringparm() * *************/ /* DOCUMENTATION This routine assigns a value to a stringparm. The stringparm is identified by its integer ID (which is available from str_to_stringparm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs. */ /* PUBLIC */ void assign_stringparm(int id, char *val, BOOL echo) { if (id < 0 || id >= Next_stringparm) { fprintf(stdout, "assign_stringparm: id %d, is out of range.\n", id); fprintf(stderr, "assign_stringparm: id %d, is out of range.\n", id); fatal_error("assign_stringparm"); } else { struct stringparm *sp = &(Stringparms[id]); int i = 0;; while (i < sp->n && !str_ident(sp->range[i], val)) i++; if (i < sp->n) { sp->val = sp->range[i]; Option_updates++; } else { printf("range of values for stringparm %s:\n", sp->name); for (i = 0; i < sp->n; i++) printf(" %s\n", sp->range[i]); fatal_error("assign_stringparm, value out of range"); } } } /* assign_stringparm */ /************* * * str_to_flag_id() * *************/ /* DOCUMENTATION This routine converts the string name of a flag to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_flag_id(char *name) { int i; for (i = 0; i < Next_flag; i++) if (str_ident(name, Flags[i].name)) return i; return -1; } /* str_to_flag_id */ /************* * * str_to_parm_id() * *************/ /* DOCUMENTATION This routine converts the string name of a parm to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_parm_id(char *name) { int i; for (i = 0; i < Next_parm; i++) if (str_ident(name, Parms[i].name)) return i; return -1; } /* str_to_parm_id */ /************* * * str_to_floatparm_id() * *************/ /* DOCUMENTATION This routine converts the string name of a parm to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_floatparm_id(char *name) { int i; for (i = 0; i < Next_floatparm; i++) if (str_ident(name, Floatparms[i].name)) return i; return -1; } /* str_to_floatparm_id */ /************* * * str_to_stringparm_id() * *************/ /* DOCUMENTATION This routine converts the string name of a stringparm to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_stringparm_id(char *name) { int i; for (i = 0; i < Next_stringparm; i++) if (str_ident(name, Stringparms[i].name)) return i; return -1; } /* str_to_stringparm_id */ /************* * * flag_id_to_str() * *************/ /* DOCUMENTATION Given a flag ID, return the corresponding name of the flag. */ /* PUBLIC */ char *flag_id_to_str(int id) { if (id < 0 || id >= Next_flag) fatal_error("flag_id_to_str, bad id"); return Flags[id].name; } /* flag_id_to_str */ /************* * * parm_id_to_str() * *************/ /* DOCUMENTATION Given a parm ID, return the corresponding name of the parm. */ /* PUBLIC */ char *parm_id_to_str(int id) { if (id < 0 || id >= Next_parm) fatal_error("parm_id_to_str, bad id"); return Parms[id].name; } /* parm_id_to_str */ /************* * * floatparm_id_to_str() * *************/ /* DOCUMENTATION Given a floatparm ID, return the corresponding name of the floatparm. */ /* PUBLIC */ char *floatparm_id_to_str(int id) { if (id < 0 || id >= Next_floatparm) fatal_error("floatparm_id_to_str, bad id"); return Floatparms[id].name; } /* floatparm_id_to_str */ /************* * * stringparm_id_to_str() * *************/ /* DOCUMENTATION Given a stringparm ID, return the corresponding name of the stringparm. */ /* PUBLIC */ char *stringparm_id_to_str(int id) { if (id < 0 || id >= Next_stringparm) fatal_error("stringparm_id_to_str, bad id"); return Stringparms[id].name; } /* stringparm_id_to_str */ /************* * * append_dep() * *************/ static Optdep append_dep(Optdep d1, Optdep d2) { if (d1 == NULL) return d2; else { d1->next = append_dep(d1->next, d2); return d1; } } /* append_dep */ /************* * * flag_flag_dependency() * *************/ /* DOCUMENTATION This routine declares that a flag depends on another flag. If flag "id" gets value "val", then flag "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_flag_dependency(int id, BOOL val, int dep_id, BOOL dep_val) { Optdep dep = get_optdep(); dep->type = FLAGT; dep->id = dep_id; dep->val = dep_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_flag_dependency */ /************* * * flag_flag_dep_default() * *************/ /* DOCUMENTATION This routine declares that a flag depends on another flag. If flag "id" gets value "val", then flag "dep_id" is automatically given its default value. */ /* PUBLIC */ void flag_flag_dep_default(int id, BOOL val, int dep_id) { Optdep dep = get_optdep(); dep->type = FLAGT; dep->id = dep_id; dep->val = Flags[dep_id].default_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_flag_dep_default */ /************* * * flag_parm_dependency() * *************/ /* DOCUMENTATION This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_parm_dependency(int id, BOOL val, int dep_id, int dep_val) { Optdep dep = get_optdep(); dep->type = PARMT; dep->id = dep_id; dep->val = dep_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_parm_dependency */ /************* * * flag_floatparm_dependency() * *************/ /* DOCUMENTATION This routine declares that a floatparm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_floatparm_dependency(int id, BOOL val, int dep_id, double dep_val) { Optdep dep = get_optdep(); dep->type = FLOATPARMT; dep->id = dep_id; dep->dval = dep_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_floatparm_dependency */ /************* * * flag_parm_dep_default() * *************/ /* DOCUMENTATION This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given its default value. */ /* PUBLIC */ void flag_parm_dep_default(int id, BOOL val, int dep_id) { Optdep dep = get_optdep(); dep->type = PARMT; dep->id = dep_id; dep->val = Parms[dep_id].default_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_parm_dep_default */ /************* * * flag_floatparm_dep_default() * *************/ /* DOCUMENTATION This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given its default value. */ /* PUBLIC */ void flag_floatparm_dep_default(int id, BOOL val, int dep_id) { Optdep dep = get_optdep(); dep->type = FLOATPARMT; dep->id = dep_id; dep->dval = Floatparms[dep_id].default_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_floatparm_dep_default */ /************* * * parm_flag_dependency() * *************/ /* DOCUMENTATION This routine declares that a flag depends on a parm. If parm "id" gets changed, then flag "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void parm_flag_dependency(int id, int dep_id, int dep_val) { Optdep dep = get_optdep(); dep->type = FLAGT; dep->id = dep_id; dep->val = dep_val; Parms[id].dependencies = append_dep(Parms[id].dependencies, dep); } /* parm_flag_dependency */ /************* * * parm_parm_dependency() * *************/ /* DOCUMENTATION This routine declares that a parm depends on a parm. If (multiply == TRUE), then dep_val is a multiplier instead of a value. */ /* PUBLIC */ void parm_parm_dependency(int id, int dep_id, int dep_val, BOOL multiply) { Optdep dep = get_optdep(); dep->type = PARMT; dep->id = dep_id; dep->val = dep_val; dep->multiply = multiply; Parms[id].dependencies = append_dep(Parms[id].dependencies, dep); } /* parm_parm_dependency */ /************* * * flag_stringparm_dependency() * *************/ /* DOCUMENTATION This routine declares that a stringparm depends on a flag. If flag "id" gets value "val", then stringparm "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_stringparm_dependency(int id, BOOL val, int dep_id, char *dep_val) { Optdep dep = get_optdep(); dep->type = STRINGPARMT; dep->id = dep_id; dep->sval = dep_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_stringparm_dependency */ /************* * * flag_stringparm_dep_default() * *************/ /* DOCUMENTATION This routine declares that a stringparm depends on a flag. If flag "id" gets value "val", then stringparm "dep_id" is automatically given its default value. */ /* PUBLIC */ void flag_stringparm_dep_default(int id, BOOL val, int dep_id) { Optdep dep = get_optdep(); dep->type = STRINGPARMT; dep->id = dep_id; dep->sval = Stringparms[dep_id].default_val; dep->flag_trigger = val; Flags[id].dependencies = append_dep(Flags[id].dependencies, dep); } /* flag_stringparm_dep_default */ /************* * * option_updates() * *************/ /* DOCUMENTATION How many times have Flags, Parms, or Stringparms been updated? */ /* PUBLIC */ int option_updates(void) { return Option_updates; } /* option_updates */ /************* * * flag_default() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int flag_default(int flag_id) { return Flags[flag_id].default_val; } /* flag_default */ /************* * * parm_default() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int parm_default(int parm_id) { return Parms[parm_id].default_val; } /* parm_default */ /************* * * floatparm_default() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int floatparm_default(int floatparm_id) { return Floatparms[floatparm_id].default_val; } /* floatparm_default */ /************* * * stringparm1_default() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *stringparm1_default(int id) { return Stringparms[id].default_val; } /* stringparm1_default */ LADR-2009-11A/ladr/options.h0000644000175000017500000000775711151265363014627 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_OPTIONS_H #define TP_OPTIONS_H #include "string.h" /* INTRODUCTION There are 3 types of option:

  • Flags: Boolean
  • Parms: Integer
  • Stringparm: String

To introduce a new option, choose an integer ID that is unique for the type of option, and call the appropriate initialization routine. Then you can change the value of the option and check its value as you like.

The routine read_commands() (in the "commands" package) will parse the user's set, clear, and assign commands, making the appropriate changes to the values of the options.

In most cases, the applications programmer will be using the following routines.

  • Flags: init_flag(), flag().
  • Parms: init_parm(), parm().
  • Stringparm: init_stringparm(), stringparm().
*/ /* Public definitions */ #define MAX_FLAGS 100 #define MAX_PARMS 100 #define MAX_STRINGPARMS 100 #define MAX_FLOATPARMS 100 /* End of public definitions */ /* Public function prototypes from options.c */ void fprint_options_mem(FILE *fp, BOOL heading); void p_options_mem(); void enable_option_dependencies(void); void disable_option_dependencies(void); BOOL option_dependencies_state(void); int init_flag(char *name, BOOL default_value); int init_parm(char *name, int default_value, int min_value, int max_value); int init_floatparm(char *name, double default_value, double min_value, double max_value); int init_stringparm(char *name, int n, ...); void fprint_options(FILE *fp); void p_options(void); int flag(int flag_id); int parm(int parm_id); BOOL at_parm_limit(int value, int parm_id); BOOL over_parm_limit(int value, int parm_id); double floatparm(int floatparm_id); BOOL stringparm(int id, char *s); char *stringparm1(int id); void update_flag(FILE *fout, int id, BOOL val, BOOL echo); void set_flag(int id, BOOL echo); void clear_flag(int id, BOOL echo); void assign_parm(int id, int val, BOOL echo); void assign_floatparm(int id, double val, BOOL echo); void assign_stringparm(int id, char *val, BOOL echo); int str_to_flag_id(char *name); int str_to_parm_id(char *name); int str_to_floatparm_id(char *name); int str_to_stringparm_id(char *name); char *flag_id_to_str(int id); char *parm_id_to_str(int id); char *floatparm_id_to_str(int id); char *stringparm_id_to_str(int id); void flag_flag_dependency(int id, BOOL val, int dep_id, BOOL dep_val); void flag_flag_dep_default(int id, BOOL val, int dep_id); void flag_parm_dependency(int id, BOOL val, int dep_id, int dep_val); void flag_floatparm_dependency(int id, BOOL val, int dep_id, double dep_val); void flag_parm_dep_default(int id, BOOL val, int dep_id); void flag_floatparm_dep_default(int id, BOOL val, int dep_id); void parm_flag_dependency(int id, int dep_id, int dep_val); void parm_parm_dependency(int id, int dep_id, int dep_val, BOOL multiply); void flag_stringparm_dependency(int id, BOOL val, int dep_id, char *dep_val); void flag_stringparm_dep_default(int id, BOOL val, int dep_id); int option_updates(void); int flag_default(int flag_id); int parm_default(int parm_id); int floatparm_default(int floatparm_id); char *stringparm1_default(int id); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/accanon.c0000644000175000017500000001370011107057121014502 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "accanon.h" /* Private definitions and types */ /************* * * flatten - given an AC term, store arguments in an array * * The index (*ip) must be initialized by the calling routine. * *************/ /* DOCUMENTATION This routine */ /* PUBLIC */ void flatten(Term t, Term *a, int *ip) { Term t1; int sn, i; sn = SYMNUM(t); for (i = 0; i < ARITY(t); i++) { t1 = ARG(t,i); if (SYMNUM(t1) == sn) flatten(t1, a, ip); else { if (*ip >= MAX_ACM_ARGS) { fprint_term(stdout, t); fatal_error("flatten, too many arguments."); } a[*ip] = t1; (*ip)++; } } } /* flatten */ /************* * * right_associate(t) * * Given a term (t) with a binary symbol, say f, right associate the * the binary tree with respect to f. Do only the top of the tree, * not subtrees under a symbol different from f. After the reassociation, * the term has the same (physical) top node. * *************/ static void right_associate(Term t) { Term fab, a, b, c, d; int sn; sn = SYMNUM(t); if (SYMNUM(ARG(t,1)) == sn) right_associate(ARG(t,1)); if (SYMNUM(ARG(t,0)) == sn) { right_associate(ARG(t,0)); /* Let t be f(f(a,b),c). */ fab = ARG(t,0); a = ARG(fab,0); b = ARG(fab,1); c = ARG(t,1); if (SYMNUM(b) != sn) { /* This is easy---just reassociate. */ ARG(t,0) = a; ARG(t,1) = fab; ARG(fab,0) = b; ARG(fab,1) = c; } else { /* This is tricky---append the two lists w/o changing top node. */ d = b; while (SYMNUM(ARG(d,1)) == sn) d = ARG(d,1); ARG(t,0) = a; ARG(t,1) = b; ARG(fab,0) = ARG(d,1); ARG(fab,1) = c; ARG(d,1) = fab; } } } /* right_associate */ /************* * * ac_canonical2 * *************/ /* DOCUMENTATION */ /* PUBLIC */ void ac_canonical2(Term t, int bit, Ordertype (*term_compare_proc) (Term, Term)) { Term args[MAX_ACM_ARGS], work[MAX_ACM_ARGS]; Term t1; int n, i; /* if (!Internal_flags[AC_PRESENT]) return; WORK */ if (is_assoc_comm(SYMNUM(t))) { /* Get array of arguments, sort, right assoc tree, then insert. */ n = 0; flatten(t, args, &n); for (i = 0; i < n; i++) if (bit == -1 || !term_flag(args[i], bit)) /* if not reduced */ ac_canonical2(args[i], bit, term_compare_proc); merge_sort_recurse((void **) args, (void **) work, 0, n-1, (Ordertype (*)(void*,void*)) term_compare_proc); right_associate(t); for (t1 = t, i = 0; i < n-2; t1 = ARG(t1,1), i++) { ARG(t1,0) = args[i]; /* clear "reduced" flag, because changed. */ if (bit != -1) term_flag_clear(t1, bit); } ARG(t1,0) = args[n-2]; ARG(t1,1) = args[n-1]; } else { /* Top symbol is not AC, so just recurse on arguments. */ for (i = 0; i < ARITY(t); i++) ac_canonical2(ARG(t,i), bit, term_compare_proc); } } /* ac_canonical2 */ /************* * * ac_canonical * *************/ /* DOCUMENTATION This routine transforms a term into AC canonical form, which means that all AC subterms are right associated and sorted. The routine term_compare_ncv() is used to compare AC arguments, and the order is CONSTANT < COMPLEX < VARIABLE; within type, the order is by VARNUM and lexigocgaphic by SYMNUM.

Terms can be marked as fully reduced (which implies AC canonical). The argument "bit" tells which term bit is used for the mark (bit=-1 means to ignore marks). If such a term is found, it is skipped. Also, we make sure that any transformed terms are not marked (they will be AC canonical, but they might not be reduced).

The top node of the term is not changed, so this is a void routine. */ /* PUBLIC */ void ac_canonical(Term t, int bit) { #if 1 ac_canonical2(t, bit, term_compare_ncv); #else Term args[MAX_ACM_ARGS], work[MAX_ACM_ARGS]; Term t1; int n, i; /* if (!Internal_flags[AC_PRESENT]) return; WORK */ if (is_assoc_comm(SYMNUM(t))) { /* Get array of arguments, sort, right assoc tree, then insert. */ n = 0; flatten(t, args, &n); for (i = 0; i < n; i++) if (bit == -1 || !term_flag(args[i], bit)) /* if not reduced */ ac_canonical(args[i], bit); merge_sort_recurse((void **) args, (void **) work, 0, n-1, (Ordertype (*)(void*,void*)) term_compare_ncv); right_associate(t); for (t1 = t, i = 0; i < n-2; t1 = ARG(t1,1), i++) { ARG(t1,0) = args[i]; /* clear "reduced" flag, because changed. */ if (bit != -1) term_flag_clear(t1, bit); } ARG(t1,0) = args[n-2]; ARG(t1,1) = args[n-1]; } else { /* Top symbol is not AC, so just recurse on arguments. */ for (i = 0; i < ARITY(t); i++) ac_canonical(ARG(t,i), bit); } #endif } /* ac_canonical */ /************* * * check_ac_canonical(t) * *************/ /* DOCUMENTATION This Boolean routine simply checks if a term is AC canonical. It should only be used if you suspect something is wrong, because it is inefficient (it copies the term, calls ac_canonical() on the copy, then does term_ident() with the original term). */ /* PUBLIC */ int check_ac_canonical(Term t) { int rc; Term t1 = copy_term(t); ac_canonical(t1, -1); rc = term_ident(t, t1); zap_term(t1); return(rc); } /* check_ac_canonical */ LADR-2009-11A/ladr/clause_eval.c0000644000175000017500000002403011075151633015370 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clause_eval.h" #include "just.h" #include "interp.h" /* (signs of literals) positive, negative, mixed (matches a hint) hint (semantics) true, false not_evaluated (e.g., too many variables) (other properties) has_equality, horn, definite, unit, initial (for integer or double n) weight = n, weight < n, weight > n, vars = n, vars < n, vars > n, depth = n, depth < n, depth > n, literals = n, literals < n, literals > n, level = n, level < n, level > n */ /* Private definitions and types */ enum { CL_EVAL_AND, CL_EVAL_OR, CL_EVAL_NOT, CL_EVAL_ALL, CL_EVAL_LESS, CL_EVAL_LESS_EQUAL, CL_EVAL_GREATER, CL_EVAL_GREATER_EQUAL, CL_EVAL_EQUAL, CL_EVAL_POSITIVE, CL_EVAL_NEGATIVE, CL_EVAL_MIXED, CL_EVAL_HINT, CL_EVAL_TRUE, CL_EVAL_FALSE, CL_EVAL_HAS_EQUALITY, CL_EVAL_HORN, CL_EVAL_DEFINITE, CL_EVAL_UNIT, CL_EVAL_INITIAL, CL_EVAL_RESOLVENT, CL_EVAL_UR_RESOLVENT, CL_EVAL_HYPER_RESOLVENT, CL_EVAL_FACTOR, CL_EVAL_PARAMODULANT, CL_EVAL_BACK_DEMODULANT, CL_EVAL_SUBSUMER, CL_EVAL_WEIGHT, CL_EVAL_VARIABLES, CL_EVAL_DEPTH, CL_EVAL_LITERALS, CL_EVAL_LEVEL }; /* type of clause eval nodes */ /* Following for the commpiled form of an evaluation rule. */ struct clause_eval { int type; Clause_eval left; /* for AND, OR, NOT */ Clause_eval right; /* for AND, OR */ Ordertype relation; /* <, >, = */ double test_val; /* for comparison, e.g., weight < 3 */ }; /* struct clause_eval */ /* * memory management */ #define PTRS_EVAL_RULE CEILING(sizeof(struct clause_eval), BYTES_POINTER) static unsigned Clause_eval_gets, Clause_eval_frees; /************* * * Clause_eval get_clause_eval() * *************/ static Clause_eval get_clause_eval(void) { Clause_eval p = get_cmem(PTRS_EVAL_RULE); Clause_eval_gets++; return(p); } /* get_clause_eval */ /************* * * free_clause_eval() * *************/ static void free_clause_eval(Clause_eval p) { free_mem(p, PTRS_EVAL_RULE); Clause_eval_frees++; } /* free_clause_eval */ /* * end memory management */ /************* * * zap_clause_eval_rule() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_clause_eval_rule(Clause_eval p) { if (p->type == CL_EVAL_AND || p->type == CL_EVAL_OR) { zap_clause_eval_rule(p->left); zap_clause_eval_rule(p->right); } else if (p->type == CL_EVAL_OR) zap_clause_eval_rule(p->left); free_clause_eval(p); } /* zap_clause_eval_rule */ /************* * * compile_clause_eval_rule() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Clause_eval compile_clause_eval_rule(Term t) { Clause_eval p = get_clause_eval(); if (is_term(t, "&", 2)) { p->type = CL_EVAL_AND; p->left = compile_clause_eval_rule(ARG(t,0)); if (p->left == NULL) return NULL; p->right = compile_clause_eval_rule(ARG(t,1)); if (p->right == NULL) return NULL; } else if (is_term(t, "|", 2)) { p->type = CL_EVAL_OR; p->left = compile_clause_eval_rule(ARG(t,0)); if (p->left == NULL) return NULL; p->right = compile_clause_eval_rule(ARG(t,1)); if (p->right == NULL) return NULL; } else if (is_term(t, "-", 1)) { p->type = CL_EVAL_NOT; p->left = compile_clause_eval_rule(ARG(t,0)); if (p->left == NULL) return NULL; } else if (is_term(t, "all", 0)) p->type = CL_EVAL_ALL; else if (is_term(t, "positive", 0)) p->type = CL_EVAL_POSITIVE; else if (is_term(t, "negative", 0)) p->type = CL_EVAL_NEGATIVE; else if (is_term(t, "mixed", 0)) p->type = CL_EVAL_MIXED; else if (is_term(t, "true", 0)) p->type = CL_EVAL_TRUE; else if (is_term(t, "false", 0)) p->type = CL_EVAL_FALSE; else if (is_term(t, "has_equality", 0)) p->type = CL_EVAL_HAS_EQUALITY; else if (is_term(t, "horn", 0)) p->type = CL_EVAL_HORN; else if (is_term(t, "definite", 0)) p->type = CL_EVAL_DEFINITE; else if (is_term(t, "unit", 0)) p->type = CL_EVAL_UNIT; else if (is_term(t, "hint", 0)) p->type = CL_EVAL_HINT; else if (is_term(t, "initial", 0)) p->type = CL_EVAL_INITIAL; else if (is_term(t, "resolvent", 0)) p->type = CL_EVAL_RESOLVENT; else if (is_term(t, "hyper_resolvent", 0)) p->type = CL_EVAL_HYPER_RESOLVENT; else if (is_term(t, "ur_resolvent", 0)) p->type = CL_EVAL_UR_RESOLVENT; else if (is_term(t, "factor", 0)) p->type = CL_EVAL_FACTOR; else if (is_term(t, "paramodulant", 0)) p->type = CL_EVAL_PARAMODULANT; else if (is_term(t, "back_demodulant", 0)) p->type = CL_EVAL_BACK_DEMODULANT; else if (is_term(t, "subsumer", 0)) p->type = CL_EVAL_SUBSUMER; else if (is_term(t, "<", 2) || is_term(t, ">", 2) || is_term(t, "<=", 2) || is_term(t, ">=", 2) || is_term(t, "=", 2)) { Term a0 = ARG(t,0); Term a1 = ARG(t,1); if (is_term(a0, "weight", 0)) p->type = CL_EVAL_WEIGHT; else if (is_term(a0, "variables", 0)) p->type = CL_EVAL_VARIABLES; else if (is_term(a0, "depth", 0)) p->type = CL_EVAL_DEPTH; else if (is_term(a0, "literals", 0)) p->type = CL_EVAL_LITERALS; else if (is_term(a0, "level", 0)) p->type = CL_EVAL_LEVEL; else return NULL; if (!term_to_number(a1, &(p->test_val))) return NULL; if (is_term(t, "<", 2)) p->relation = LESS_THAN; else if (is_term(t, ">", 2)) p->relation = GREATER_THAN; else if (is_term(t, "<=", 2)) p->relation = LESS_THAN_OR_SAME_AS; else if (is_term(t, ">=", 2)) p->relation = GREATER_THAN_OR_SAME_AS; else if (is_term(t, "=", 2)) p->relation = SAME_AS; } else return NULL; return p; } /* compile_clause_eval_rule */ /************* * * eval_clause_in_rule() * *************/ /* DOCUMENTATION The following properties have fields in the clause, and if they hold, those flags should already be set: matching_hint, weight, semantics. */ /* PUBLIC */ BOOL eval_clause_in_rule(Topform c, Clause_eval p) { Literals lits = c->literals; switch (p->type) { case CL_EVAL_AND: return eval_clause_in_rule(c, p->left) && eval_clause_in_rule(c, p->right); case CL_EVAL_OR: return eval_clause_in_rule(c, p->left) || eval_clause_in_rule(c, p->right); case CL_EVAL_NOT: return !eval_clause_in_rule(c, p->left); case CL_EVAL_ALL: return TRUE; case CL_EVAL_POSITIVE: return positive_clause(lits); case CL_EVAL_NEGATIVE: return negative_clause(lits); case CL_EVAL_MIXED: return mixed_clause(lits); case CL_EVAL_HINT: return c->matching_hint != NULL; case CL_EVAL_HAS_EQUALITY: return contains_eq(lits); case CL_EVAL_HORN: return horn_clause(lits); case CL_EVAL_DEFINITE: return definite_clause(lits); case CL_EVAL_UNIT: return unit_clause(lits); case CL_EVAL_INITIAL: return c->initial; case CL_EVAL_RESOLVENT: return primary_just_type(c, BINARY_RES_JUST); case CL_EVAL_HYPER_RESOLVENT: return primary_just_type(c, HYPER_RES_JUST); case CL_EVAL_UR_RESOLVENT: return primary_just_type(c, UR_RES_JUST); case CL_EVAL_FACTOR: return primary_just_type(c, FACTOR_JUST); case CL_EVAL_PARAMODULANT: return primary_just_type(c, PARA_JUST); case CL_EVAL_BACK_DEMODULANT: return primary_just_type(c, BACK_DEMOD_JUST); case CL_EVAL_SUBSUMER: return c->subsumer; case CL_EVAL_TRUE: return c->semantics == SEMANTICS_TRUE || c->semantics == SEMANTICS_NOT_EVALUABLE; case CL_EVAL_FALSE: return c->semantics == SEMANTICS_FALSE; case CL_EVAL_WEIGHT: case CL_EVAL_VARIABLES: case CL_EVAL_DEPTH: case CL_EVAL_LITERALS: case CL_EVAL_LEVEL: { double val = 0; switch (p->type) { case CL_EVAL_WEIGHT: val = c->weight; break; case CL_EVAL_VARIABLES: val = number_of_variables(lits); break; case CL_EVAL_DEPTH: val = literals_depth(lits); break; case CL_EVAL_LITERALS: val = number_of_literals(lits); break; case CL_EVAL_LEVEL: val = clause_level(c); break; } switch (p->relation) { case LESS_THAN: return val < p->test_val; case GREATER_THAN: return val > p->test_val; case LESS_THAN_OR_SAME_AS: return val <= p->test_val; case GREATER_THAN_OR_SAME_AS: return val >= p->test_val; case SAME_AS: return val == p->test_val; default: fatal_error("eval_clause_in_rule, bad relation"); } } default: fatal_error("eval_clause_in_rule, unknown operation"); } /* outer switch */ return FALSE; } /* eval_clause_in_rule */ /************* * * rule_contains_semantics() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL rule_contains_semantics(Clause_eval p) { if (p->type == CL_EVAL_AND || p->type == CL_EVAL_OR) { return (rule_contains_semantics(p->left) || rule_contains_semantics(p->right)); } else if (p->type == CL_EVAL_OR) return rule_contains_semantics(p->left); else return p->type == CL_EVAL_TRUE || p->type == CL_EVAL_FALSE; } /* rule_contains_semantics */ LADR-2009-11A/ladr/weight.c0000644000175000017500000002371311117313562014401 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "weight.h" #include "weight2.h" #include "parse.h" #include "complex.h" /* Private definitions and types */ static Plist Rules; static double Constant_weight; static double Sk_constant_weight; static double Not_weight; static double Or_weight; static double Prop_atom_weight; static double Variable_weight; static double Nest_penalty; static double Depth_penalty; static double Var_penalty; static double Complexity; static BOOL Not_rules; /* any rules for not_sym()? */ static BOOL Or_rules; /* any rules for or_sym()? */ /* Cache the symnums */ static int Eq_sn; /* equality */ static int Weight_sn; /* weight function*/ static int Sum_sn; /* integer arithmetic */ static int Prod_sn; /* integer arithmetic */ static int Neg_sn; /* integer arithmetic */ static int Div_sn; /* integer arithmetic */ static int Max_sn; /* integer arithmetic */ static int Min_sn; /* integer arithmetic */ static int Depth_sn; /* depth */ static int Vars_sn; /* vars */ static int Call_sn; /* vars */ static int Avar_sn; /* anonymous variable */ /************* * * weight_beta_check() * *************/ static BOOL weight_beta_check(Term b) { if (SYMNUM(b) == Sum_sn || SYMNUM(b) == Prod_sn || SYMNUM(b) == Div_sn || SYMNUM(b) == Min_sn || SYMNUM(b) == Max_sn) return weight_beta_check(ARG(b,0)) && weight_beta_check(ARG(b,1)); else if (SYMNUM(b) == Neg_sn) return weight_beta_check(ARG(b,0)); else if (SYMNUM(b) == Depth_sn) return TRUE; else if (SYMNUM(b) == Vars_sn) return TRUE; else if (SYMNUM(b) == Call_sn) return TRUE; else if (SYMNUM(b) == Weight_sn) return TRUE; else { double d; if (term_to_number(b, &d)) return TRUE; else { printf("weight_rule_check, right side of rule not understood\n"); return FALSE; } } } /* weight_beta_check */ /************* * * weight_rule_check() * *************/ static BOOL weight_rule_check(Term rule) { if (!is_eq_symbol(SYMNUM(rule))) { printf("weight_rule_check, rule is not equality\n"); return FALSE; } else if (SYMNUM(ARG(rule, 0)) != Weight_sn) { printf("weight_rule_check, left side must be weight(...)\n"); return FALSE; } else return weight_beta_check(ARG(rule, 1)); } /* weight_rule_check */ /************* * * init_weight() * *************/ /* DOCUMENTATION Initialize weighting. The rules are copied. */ /* PUBLIC */ void init_weight(Plist rules, double variable_weight, double constant_weight, double not_weight, double or_weight, double sk_constant_weight, double prop_atom_weight, double nest_penalty, double depth_penalty, double var_penalty, double complexity) { Plist p; Variable_weight = variable_weight; Constant_weight = constant_weight; Not_weight = not_weight; Or_weight = or_weight; Prop_atom_weight = prop_atom_weight; Sk_constant_weight = sk_constant_weight; Nest_penalty = nest_penalty; Depth_penalty = depth_penalty; Var_penalty = var_penalty; Complexity = complexity; /* Cache symbol numbers. */ Weight_sn = str_to_sn("weight", 1); Eq_sn = str_to_sn(eq_sym(), 2); Sum_sn = str_to_sn("+", 2); Prod_sn = str_to_sn("*", 2); Div_sn = str_to_sn("/", 2); Max_sn = str_to_sn("max", 2); Min_sn = str_to_sn("min", 2); Depth_sn = str_to_sn("depth", 1); Vars_sn = str_to_sn("vars", 1); Call_sn = str_to_sn("call", 2); Neg_sn = str_to_sn("-", 1); Avar_sn = str_to_sn("_", 0); /* Process the rules. */ Rules = NULL; for (p = rules; p; p = p->next) { Term rule = copy_term(p->v); if (!weight_rule_check(rule)) { p_term(rule); fatal_error("init_weight, bad rule"); } else { term_set_variables(rule, MAX_VARS); Rules = plist_append(Rules, rule); if (is_term(ARG(ARG(rule,0),0), not_sym(), 1)) Not_rules = TRUE; if (is_term(ARG(ARG(rule,0),0), or_sym(), 2)) Or_rules = TRUE; } } } /* init_weight */ /************* * * apply_depth() * *************/ static int apply_depth(Term t, Context subst) { if (VARIABLE(t)) return term_depth(subst->terms[VARNUM(t)]); else if (CONSTANT(t)) return 0; else { int depth = 0; int i; for (i = 0; i < ARITY(t); i++) { int d = apply_depth(ARG(t,i), subst); depth = IMAX(d, depth); } return depth + 1; } } /* apply_depth */ /************* * * weight_calc() -- mutually recursive with weight * *************/ static double weight_calc(Term b, Context subst) { /* Apply a rule. Term b is the right side of the rule. The substitution matches the left side of the rule with the term being weighed. This routine is recursive, applying arithmetic rules to the top of b as much as possible. When a non-arithmetic expression is encountered, the substition is applied to it and then it is weighed as usual. */ if (VARIABLE(b)) { fatal_error("weight_calc, variable in rule"); return 0; /* to please the compiler */ } else if (SYMNUM(b) == Weight_sn) { Term b_prime = apply(ARG(b,0), subst); Context subst2 = get_context(); double wt = weight(b_prime, subst2); free_context(subst2); zap_term(b_prime); return wt; } else if (SYMNUM(b) == Sum_sn) return weight_calc(ARG(b,0), subst) + weight_calc(ARG(b,1), subst); else if (SYMNUM(b) == Prod_sn) return weight_calc(ARG(b,0), subst) * weight_calc(ARG(b,1), subst); else if (SYMNUM(b) == Div_sn) return weight_calc(ARG(b,0), subst) / weight_calc(ARG(b,1), subst); else if (SYMNUM(b) == Max_sn) { int w1 = weight_calc(ARG(b,0), subst); int w2 = weight_calc(ARG(b,1), subst); return IMAX(w1,w2); } else if (SYMNUM(b) == Min_sn) { int w1 = weight_calc(ARG(b,0), subst); int w2 = weight_calc(ARG(b,1), subst); return IMIN(w1,w2); } else if (SYMNUM(b) == Neg_sn) { return -weight_calc(ARG(b,0), subst); } else if (SYMNUM(b) == Depth_sn) return apply_depth(ARG(b,0), subst); else if (SYMNUM(b) == Vars_sn) { Term b_prime = apply(ARG(b,0), subst); int n = number_of_vars_in_term(b_prime); zap_term(b_prime); return n; } else if (SYMNUM(b) == Call_sn) { char *prog = term_symbol(ARG(b,0)); Term b_prime = apply(ARG(b,1), subst); double x = call_weight(prog, b_prime); zap_term(b_prime); return x; } else { double wt; if (term_to_number(b, &wt)) return wt; else { fatal_error("weight_calc, bad rule"); return 0; /* to please the compiler */ } } } /* weight_calc */ /************* * * weight() -- mutually recursive with weight_calc * *************/ /* DOCUMENTATION */ /* PUBLIC */ double weight(Term t, Context subst) { if (VARIABLE(t)) return Variable_weight; else { /* Look for a rule to apply. */ Plist p; for (p = Rules; p; p = p->next) { Term rule = p->v; /* weight(f(x)) = 3 + weight(x) */ Term alpha = ARG(rule,0); Term beta = ARG(rule,1); Trail tr = NULL; if (match_weight(ARG(alpha,0), subst, t, &tr, Avar_sn)) { /* We found a rule. Now calculate the weight. */ double wt = weight_calc(beta, subst); undo_subst(tr); return wt; } } /* Nothing matches; return the default. */ if (CONSTANT(t)) { if (skolem_term(t) && Sk_constant_weight != 1) return Sk_constant_weight; else if (relation_symbol(SYMNUM(t))) return Prop_atom_weight; else return Constant_weight; } else { /* sum of weights of subterms, plus 1 */ double wt = 1; int i; for (i = 0; i < ARITY(t); i++) { double arg_wt = weight(ARG(t, i), subst); if (Nest_penalty != 0 && ARITY(t) <= 2 && SYMNUM(t) == SYMNUM(ARG(t,i))) wt += Nest_penalty; wt += arg_wt; } return wt; } } } /* weight */ /************* * * clause_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ double clause_weight(Literals lits) { double wt; if (!Not_rules && !Or_rules) { /* There are no rules for OR or NOT, so we don't need to construct a Term representation of the clause. */ Literals lit; wt = 0; for (lit = lits; lit; lit = lit->next) { Context subst = get_context(); wt += weight(lit->atom, subst); free_context(subst); } wt += (negative_literals(lits) * Not_weight); wt += ((number_of_literals(lits)-1) * Or_weight); } else { /* Build a temporary Term representation of the clause and weigh that. This is done in case there are weight rules for OR or NOT. */ Term temp = lits_to_term(lits); Context subst = get_context(); wt = weight(temp, subst); free_context(subst); free_lits_to_term(temp); /* If there are no Not_rules, we have already added one for each not; so we undo that and add the correct amount. Same for Or_rules. */ if (!Not_rules) wt += (negative_literals(lits) * (Not_weight - 1)); if (!Or_rules) wt += ((number_of_literals(lits) - 1) * (Or_weight - 1)); } if (Depth_penalty != 0) wt += Depth_penalty * literals_depth(lits); if (Var_penalty != 0) wt += Var_penalty * number_of_variables(lits); if (Complexity != 0) wt += Complexity * (1 - clause_complexity(lits, 4, 0)); return wt; } /* clause_weight */ LADR-2009-11A/ladr/complex.c0000644000175000017500000002174611117565706014576 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef SOLO #include #include #include #define IMAX(a,b) ((a) > (b) ? (a) : (b)) #else #include "complex.h" #endif /* Private definitions and types */ #ifdef SOLO /************* * * complexity1() * * This is translated from some Matlab code I found: * * FUNCTION: kolmogorov.m * DATE: 9th Feb 2005 * AUTHOR: Stephen Faul (stephenf@rennes.ucc.ie) * * Function for estimating the Kolmogorov Complexity as per: * "Easily Calculable Measure for the Complexity of Spatiotemporal Patterns" * by F Kaspar and HG Schuster, Physical Review A, vol 36, num 2 pg 842 * * (WWM) I believe this is desiend for binary strings. * *************/ static double complexity1(int *s, int n) { /* NOTE: s is indexed from 1 .. n. (not 0 .. n-1) */ if (n == 1) return 1.0; /* this case not in Faul's code */ else { int c = 1; int l = 1; int i = 0; int k = 1; int kmax = 1; int stop = 0; while (!stop) { if (s[i+k] != s[l+k]) { kmax = IMAX(k, kmax); i++; if (i == l) { c++; /* This must be designed for binary strings: we jump over (don't look at) the character following a match. If binary, we know what the skipped character is. */ l += kmax; if (l+1 > n) stop = 1; else { i = 0; k = 1; kmax = 1; } } else k = 1; } else { k++; if (l + k > n) { /* Faul's code increments c here, but that doesn't make sense to me. If incremented, abb has a different complexity from bba. */ /* c++; */ stop = 1; } } } /* Normalize so that 0 < result <= 1. Faul's code normalizes: return c / (n / log2(n)) */ return ((double) c) / n; } } /* complexity1 */ #endif /************* * * complexity2() - a recoding of complexity1 * *************/ static double complexity2(int *s, int n) { /* NOTE: s is indexed from 0 .. n-1. */ int c = 1; int b = 1; int a, k, kmax; a = k = kmax = 0; while (b+k < n) { if (s[a+k] == s[b+k]) { k++; } else { kmax = IMAX(k, kmax); a++; if (a != b) k = 0; else { c++; b += (kmax+1); a = k = kmax = 0; } } } return ((double) c) / n; } /* complexity2 */ /************* * * complexity3() - similar to complexity2, but it makes more sense to me. * * complexity1 (also complexity2) gives the same answer for * ABBA * ABBC * (I believe that's because they are designed for binary strings, * where the problem doesn't arise.) * * complexity3 is designed for arbitrary strings. * *************/ static double complexity3(int *s, int n, int adjustment) { /* NOTE: s is indexed from 0 .. n-1. */ int c = 1; int b = 1; int x = 0; while (b < n) { int a = 0; int fmax = 0; while (a < b) { int f = 0; while (b+f < n && s[a+f] == s[b+f]) f++; fmax = IMAX(f, fmax); a++; } b += IMAX(1,fmax); c++; if (fmax > 0) x += ((adjustment+1) * fmax) - adjustment; } return 1 - (((double) x) / (((adjustment+1) * (n - 1)) - adjustment)); } /* complexity3 */ #ifndef SOLO /************* * * complex4_devar() - change variables to constants in a kludgey way * *************/ static Term complex4_devar(Term t, int base) { if (VARIABLE(t)) { Term new = get_rigid_term_dangerously(base + VARNUM(t), 0); free_term(t); return new; } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = complex4_devar(ARG(t,i), base); return t; } } /* complex4_devar */ /************* * * complex4_revar() - restore variables after call to complex4_devar * *************/ static Term complex4_revar(Term t, int base) { if (CONSTANT(t) && SYMNUM(t) >= base) { Term var = get_variable_term(SYMNUM(t) - base); free_term(t); return var; } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = complex4_revar(ARG(t,i), base); return t; } } /* complex4_revar */ /************* * * complex4_compare() * *************/ static void complex4_compare(Term a, Term b, int *n) { /* There should be no variables in a or b. Recurse through a and b in paralle, incrementing *n for each node where they agree. Don't look below nodes where they disagree. */ if (SYMNUM(a) == SYMNUM(b)) { int i; (*n)++; for (i = 0; i < ARITY(a); i++) complex4_compare(ARG(a,i), ARG(b,i), n); } } /* complex4_compare */ /************* * * complex4_p2() * *************/ static BOOL complex4_p2(Term s, Term t, int *n) { /* Recurse through t, stopping when we get to s. */ if (s == t) return FALSE; else { int i; BOOL go; for (i = 0, go = TRUE; i < ARITY(t) && go; i++) go = complex4_p2(s, ARG(t,i), n); complex4_compare(s, t, n); return go; } } /* complex4_p2 */ /************* * * complex4_p1() * *************/ static void complex4_p1(Term s, Term t, int *n) { /* Traverse the term and call complex4_p2 for each. We will consider all pairs of distinct subterms. */ BOOL dummy; int i; for (i = 0; i < ARITY(s); i++) complex4_p1(ARG(s,i), t, n); dummy = complex4_p2(s, t, n); } /* complex4_p1 */ /************* * * complex4() * *************/ /* DOCUMENTATION A tree-based complexity measure. For each pair of (distinct) subterms, compare, starting at the roots; increment the counter for each position where they agree (do not look past positions that disagree). The result must be between 0 and 1. If there are n nodes in the term, the only bound I know for the counter is n^3. However, the worst cases I can come up with are a bit over n^2. Therefore, we'll divide the counter by n^2, and if the result is >= 1, we'll make it .999. We want more complex terms to be greater, so we'll subtract from 1. */ /* PUBLIC */ double complex4(Term t) { double d; int count = 0; int size = symbol_count(t); /* for changing vars to constants */ int base = greatest_symnum()+1; /* for changing vars to constants */ /* For technical reasons having to do with sharing of variables, we have to temporarily change variables to constants. */ t = complex4_devar(t, base); /* change variables to constants */ complex4_p1(t, t, &count); t = complex4_revar(t, base); /* restore variables */ d = ((double) count) / (size*size); /* make sure 0 < d < 1 */ if (d >= 1.0) d = 0.999; else if (d == 0) d = 0.001; return 1.0 - d; } /* complex4 */ /************* * * term_to_ints() * *************/ static void term_to_ints(Term t, int *a, int *i) { if (VARIABLE(t)){ a[(*i)++] = -VARNUM(t); } else { int j; a[(*i)++] = SYMNUM(t); for (j = 0; j < ARITY(t); j++) term_to_ints(ARG(t,j), a, i); } } /* term_to_ints */ /************* * * term_complexity() * *************/ /* DOCUMENTATION */ /* PUBLIC */ double term_complexity(Term t, int func, int adjustment) { if (func == 4) { return complex4(t); } else { int n = symbol_count(t); int *a = malloc(n * sizeof(int)); int i = 0; double x = 0.0; term_to_ints(t, a, &i); if (func == 2) x = complexity2(a, n); else if (func == 3) x = complexity3(a, n, adjustment); else fatal_error("term_complexity, bad func"); free(a); return x; } } /* term_complexity */ /************* * * clause_complexity() * *************/ /* DOCUMENTATION */ /* PUBLIC */ double clause_complexity(Literals lits, int func, int adjustment) { Term t = lits_to_term(lits); /* shallow */ double x = term_complexity(t, func, adjustment); free_lits_to_term(t); /* shallow */ return x; } /* clause_complexity */ #endif /* not SOLO */ #ifdef SOLO int main(int argc, char **argv) { char s[1000]; int a[1001]; char *t; int i, n; while (1) { /* printf("\nenter string: "); */ t = fgets(s, 1000, stdin); if (t == NULL) exit(0); n = strlen(s); if (n > 0) s[n] = '\0'; /* get rid of newline */ n--; for (i = 0; i < n; i++) a[i+1] = s[i]; printf("complex1: %.5f\n", complexity1(a, n)); printf("complex2: %.5f\n", complexity2(a+1, n)); printf("complex3: %.5f\n", complexity3(a+1, n, 1)); } } #endif /* SOLO */ LADR-2009-11A/ladr/index.h0000644000175000017500000000230510607745010014220 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_INDEX_H #define TP_INDEX_H #include "header.h" /* INTRODUCTION */ /* types of retrieval */ typedef enum { UNIFY, INSTANCE, GENERALIZATION, VARIANT, IDENTICAL } Querytype; /* types of operation */ typedef enum { INSERT, DELETE } Indexop; /* Public definitions */ /* End of public definitions */ /* Public function prototypes */ #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/fpa.c0000644000175000017500000007052310771037647013675 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "fpa.h" /* Private definitions and types */ static unsigned Fpa_id_count = 0; static unsigned Next_calls = 0; static unsigned Next_calls_overflows = 0; #define BUMP_NEXT_CALLS {Next_calls++; if (Next_calls == 0) Next_calls_overflows++;} typedef struct fpa_trie * Fpa_trie; struct fpa_trie { Fpa_trie parent, next, kids; int label; Fpa_list terms; #ifdef FPA_DEBUG Ilist path; #endif }; struct fpa_index { Fpa_trie root; int depth; Fpa_index next; }; struct fpa_state { int type; Fpa_state left, right; Term left_term, right_term; struct fposition fpos; #ifdef FPA_DEBUG Ilist path; #endif }; /* A path is a sequence of integers. We have to do some operations to the end of a path, and an Ilist is singly-linked; but we can get away with just keeping a pointer to the end of the list. */ struct path { Ilist first; Ilist last; }; enum { LEAF, UNION, INTERSECT }; /* types of fpa_state (node in FPA tree) */ /* for a mutual recursion */ static Fpa_state build_query(Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index); /* * memory management */ #define PTRS_FPA_TRIE PTRS(sizeof(struct fpa_trie)) static unsigned Fpa_trie_gets, Fpa_trie_frees; #define PTRS_FPA_STATE PTRS(sizeof(struct fpa_state)) static unsigned Fpa_state_gets, Fpa_state_frees; #define PTRS_FPA_INDEX PTRS(sizeof(struct fpa_index)) static unsigned Fpa_index_gets, Fpa_index_frees; /************* * * Fpa_trie get_fpa_trie() * *************/ static Fpa_trie get_fpa_trie(void) { Fpa_trie p = get_cmem(PTRS_FPA_TRIE); p->label = -1; Fpa_trie_gets++; return(p); } /* get_fpa_trie */ /************* * * free_fpa_trie() * *************/ static void free_fpa_trie(Fpa_trie p) { free_mem(p, PTRS_FPA_TRIE); Fpa_trie_frees++; } /* free_fpa_trie */ /************* * * Fpa_state get_fpa_state() * *************/ static Fpa_state get_fpa_state(void) { Fpa_state p = get_cmem(PTRS_FPA_STATE); Fpa_state_gets++; return(p); } /* get_fpa_state */ /************* * * free_fpa_state() * *************/ static void free_fpa_state(Fpa_state p) { free_mem(p, PTRS_FPA_STATE); Fpa_state_frees++; } /* free_fpa_state */ /************* * * Fpa_index get_fpa_index() * *************/ static Fpa_index get_fpa_index(void) { Fpa_index p = get_cmem(PTRS_FPA_INDEX); p->depth = -1; Fpa_index_gets++; return(p); } /* get_fpa_index */ /************* * * free_fpa_index() * *************/ static void free_fpa_index(Fpa_index p) { free_mem(p, PTRS_FPA_INDEX); Fpa_index_frees++; } /* free_fpa_index */ /************* * * fprint_fpa_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpa package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_fpa_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct fpa_trie); fprintf(fp, "fpa_trie (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_trie_gets, Fpa_trie_frees, Fpa_trie_gets - Fpa_trie_frees, ((Fpa_trie_gets - Fpa_trie_frees) * n) / 1024.); n = sizeof(struct fpa_state); fprintf(fp, "fpa_state (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_state_gets, Fpa_state_frees, Fpa_state_gets - Fpa_state_frees, ((Fpa_state_gets - Fpa_state_frees) * n) / 1024.); n = sizeof(struct fpa_index); fprintf(fp, "fpa_index (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_index_gets, Fpa_index_frees, Fpa_index_gets - Fpa_index_frees, ((Fpa_index_gets - Fpa_index_frees) * n) / 1024.); } /* fprint_fpa_mem */ /************* * * p_fpa_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the fpa package. */ /* PUBLIC */ void p_fpa_mem() { fprint_fpa_mem(stdout, TRUE); } /* p_fpa_mem */ /* * end of memory management */ /************* * * fprint_path() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) an FPA Path. A newline is NOT printed. */ /* PUBLIC */ void fprint_path(FILE *fp, Ilist p) { int i; fprintf(fp, "("); for (i = 0; p != NULL; p = p->next, i++) { if (i%2 == 0) { if (p->i == 0) fprintf(fp, "*"); else fprint_sym(fp, p->i); } else fprintf(fp, "%d", p->i); if (p->next != NULL) fprintf(fp, " "); } fprintf(fp, ")"); } /* fprint_path */ /************* * * p_path() * *************/ /* DOCUMENTATION This routine prints (to stdout) an FPA Path. A newline is NOT printed. */ /* PUBLIC */ void p_path(Ilist p) { fprint_path(stdout, p); fflush(stdout); } /* p_path */ /************* * * fprint_fpa_trie -- Print an FPA trie to stdout. * *************/ static void fprint_fpa_trie(FILE *fp, Fpa_trie p, int depth) { int i; Fpa_trie q; for (i = 0; i < depth; i++) fprintf(fp, " - "); if (depth == 0) fprintf(fp, "root"); else if (depth % 2 == 1) { if (p->label == 0) fprintf(fp, "*"); else fprint_sym(fp, p->label); } else fprintf(fp, "%2d", p->label); if (p->terms) p_fpa_list(p->terms->chunks); #ifdef FPA_DEBUG if (p->path != NULL) fprint_path(fp, p->path); #endif fprintf(fp, "\n"); for (q = p->kids; q != NULL; q = q->next) fprint_fpa_trie(fp, q, depth+1); } /* fprint_fpa_trie */ /************* * * fprint_fpa_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first. */ /* PUBLIC */ void fprint_fpa_index(FILE *fp, Fpa_index idx) { fprintf(fp, "FPA/Path index, depth is %d.\n", idx->depth); fprint_fpa_trie(fp, idx->root, 0); } /* fprint_fpa_index */ /************* * * p_fpa_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first. */ /* PUBLIC */ void p_fpa_index(Fpa_index idx) { fprint_fpa_index(stdout, idx); } /* p_fpa_index */ /************* * * fpa_trie_member_insert (recursive) -- This routine takes a trie * and a path, and looks for a node in the trie that corresponds * to the path. If such a node does not exist, it is created, and * the trie is updated. * *************/ static Fpa_trie fpa_trie_member_insert(Fpa_trie node, Ilist path) { if (path == NULL) return node; else { /* Find child node that matches first member of path; * if it doesn't exist, create it. Children are in increasing order. */ int val = path->i; Fpa_trie curr = node->kids; Fpa_trie prev = NULL; while (curr != NULL && curr->label < val) { prev = curr; curr = curr->next; } if (curr != NULL && curr->label == val) return fpa_trie_member_insert(curr, path->next); else { /* Get a new node and insert it before curr (which may be NULL). */ Fpa_trie new = get_fpa_trie(); new->parent = node; new->label = val; new->next = curr; if (prev == NULL) node->kids = new; else prev->next = new; return fpa_trie_member_insert(new, path->next); } } } /* fpa_trie_member_insert */ /************* * * fpa_trie_member (recursive) -- This routine looks for a trie * node that corresponds to a given path. * *************/ static Fpa_trie fpa_trie_member(Fpa_trie node, Ilist path) { if (path == NULL) return node; else { /* Find child node that matches first member of path; * Children are in increasing order. */ int val = path->i; Fpa_trie curr = node->kids; while (curr != NULL && curr->label < val) curr = curr->next; if (curr != NULL && curr->label == val) return fpa_trie_member(curr, path->next); else return NULL; } } /* fpa_trie_member */ /************* * * fpa_trie_possible_delete (recursive) -- This routine checks if * a trie node should be deleted. If so, it is deleted, and a * recursive call is made on the parent node. The trie node should * be deleted if (1) it is not the root, (2) there is no FPA list, * and (3) it has no children. * *************/ static void fpa_trie_possible_delete(Fpa_trie node) { if (node->parent && node->terms && fpalist_empty(node->terms) && node->kids == NULL) { if (node->parent->kids == node) node->parent->kids = node->next; else { Fpa_trie p = node->parent->kids; while (p->next != node) p = p->next; p->next = node->next; } fpa_trie_possible_delete(node->parent); free_fpa_trie(node); } } /* fpa_trie_possible_delete */ /************* * * path_insert -- Given (term,path,index), insert a pointer * to the term into the path list of the index. * *************/ static void path_insert(Term t, Ilist path, Fpa_trie index) { Fpa_trie node = fpa_trie_member_insert(index, path); #ifdef FPA_DEBUG if (node->path == NULL) node->path = copy_ilist(path); #endif if (node->terms == NULL) node->terms = get_fpa_list(); fpalist_insert(node->terms, t); } /* path_insert */ /************* * * path_delete -- Given (term,path,index), try to delete a pointer * to the term from the path list of the index. * *************/ static void path_delete(Term t, Ilist path, Fpa_trie index) { Fpa_trie node = fpa_trie_member(index, path); if (node == NULL) { fatal_error("path_delete, trie node not found."); } fpalist_delete(node->terms, t); #ifdef FPA_DEBUG if (fpalist_empty(node->terms)) { zap_ilist(node->path); node->path = NULL; } #endif fpa_trie_possible_delete(node); } /* path_delete */ /************* * * path_push -- append an integer to a path. "save" is used because * we have a pointer to the last member, but the list is singly linked. * *************/ static Ilist path_push(struct path *p, int i) { Ilist new = get_ilist(); Ilist save = p->last; new->i = i; new->next = NULL; if (p->last == NULL) p->first = new; else p->last->next = new; p->last = new; return save; } /* path_push */ /************* * * path_restore -- pop and throw away the last member of a path. * We assume that "save" points to the next-to-last member. * *************/ static void path_restore(struct path *p, Ilist save) { free_ilist(p->last); p->last = save; if (save != NULL) save->next = NULL; else p->first = NULL; } /* path_restore */ /************* * * fpa_paths (recursive) -- This routine traverses a term, keeping a * path, and either inserts or deletes pointers to the term into/from the * appropriate path lists of an FPA/PATH index. * *************/ static void fpa_paths(Term root, Term t, struct path *p, int bound, Indexop op, Fpa_trie index) { Ilist save1; if (VARIABLE(t)) save1 = path_push(p, 0); else save1 = path_push(p, SYMNUM(t)); if (COMPLEX(t) && bound > 0 && !is_assoc_comm(SYMNUM(t))) { int i; Ilist save2 = path_push(p, 0); for (i = 0; i < ARITY(t); i++) { p->last->i = i+1; /* Count arguments from 1. */ fpa_paths(root, ARG(t,i), p, bound-1, op, index); } path_restore(p, save2); } else { /* printf(" "); p_path(p->first); */ if (op == INSERT) path_insert(root, p->first, index); else path_delete(root, p->first, index); } path_restore(p, save1); } /* fpa_paths */ /************* * * fpa_init_index() * *************/ /* DOCUMENTATION This routine allocates and returns an empty FPA/Path index. Parameter depth tells how deep to index the terms. For example, depth=0 means to index on the root symbol only. */ /* PUBLIC */ Fpa_index fpa_init_index(int depth) { Fpa_index f = get_fpa_index(); f->depth = depth; f->root = get_fpa_trie(); return f; } /* fpa_init_index */ /************* * * fpa_update -- Insert/delete a term into/from a FPA-PATH index. * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) a term into an Fpa_index or deletes (op==DELETE) a term from an Fpa_index.

IMPORTANT: FPA indexing owns the FPA_ID field of the term.

A fatal error occurs if you try to delete a term that was not previously inserted. */ /* PUBLIC */ void fpa_update(Term t, Fpa_index idx, Indexop op) { struct path p; if (FPA_ID(t) == 0) { if (op == INSERT) FPA_ID(t) = ++Fpa_id_count; else fatal_error("fpa_update: FPA_ID=0."); } p.first = p.last = NULL; fpa_paths(t, t, &p, idx->depth, op, idx->root); } /* fpa_update */ /************* * * query_leaf_full - for testing only * * Ordinarily, with query_leaf(), if an FPA list doesn't exist, * the query will be simplified. If you wish to get the whole * query tree, with NULL leaves for nonexistant FPA lists, you * can use this instead of query_leaf(). This is useful if you * want to print the query tree. * *************/ #ifdef FPA_DEBUG static Fpa_state query_leaf_full(Ilist path, Fpa_trie index) { Fpa_trie n = fpa_trie_member(index, path); Fpa_state q = get_fpa_state(); q->type = LEAF; q->terms = (n == NULL ? NULL : n->terms); q->path = copy_ilist(path); return q; } /* query_leaf_full */ #endif /************* * * query_leaf * *************/ static Fpa_state query_leaf(Ilist path, Fpa_trie index) { Fpa_trie n; /* return query_leaf_full(path, index); */ n = fpa_trie_member(index, path); if (n == NULL) return NULL; else { Fpa_state q = get_fpa_state(); q->type = LEAF; q->fpos = first_fpos(n->terms); #ifdef FPA_DEBUG q->path = copy_ilist(path); #endif return q; } } /* query_leaf */ /************* * * query_intersect * *************/ static Fpa_state query_intersect(Fpa_state q1, Fpa_state q2) { /* Assume neither is NULL. */ Fpa_state q = get_fpa_state(); q->type = INTERSECT; q->left = q1; q->right = q2; return q; } /* query_intersect */ /************* * * query_union * *************/ static Fpa_state query_union(Fpa_state q1, Fpa_state q2) { if (q1 == NULL) return q2; else if (q2 == NULL) return q1; else { Fpa_state q = get_fpa_state(); q->type = UNION; q->left = q1; q->right = q2; return q; } } /* query_union */ /************* * * query_special (recursive) * *************/ static Fpa_state query_special(Fpa_trie n) { /* There are 2 kinds of nodes: argument position (1,2,3,...) and * symbol (a,b,f,g,h); the two types alternate in a path. The * given node n is a symbol node. What we wish to do is construct * the union of all leaves, excluding those that have an argument * position greater than 1. This should contain all terms that * have a path corresponding to node n. */ if (n->kids == NULL) { Fpa_state q = get_fpa_state(); q->type = LEAF; q->fpos = first_fpos(n->terms); #ifdef FPA_DEBUG q->path = copy_ilist(n->path); #endif return q; } else { Fpa_state q1 = NULL; Fpa_trie pos_child; for (pos_child=n->kids; pos_child!=NULL; pos_child=pos_child->next) { if (pos_child->label == 1) { Fpa_trie sym_child; for (sym_child=pos_child->kids; sym_child!=NULL; sym_child=sym_child->next) { Fpa_state q2 = query_special(sym_child); q1 = query_union(q1, q2); } } } return q1; } } /* query_special */ /************* * * zap_fpa_state (recursive) * * This (recursive) routine frees an Fpa_state. * It should NOT be called if you retrieve all answers to * a query, because the query tree is freed as it is processsed * by fpa_next_answer(). This routine should be called only if * you decide not to get all of the answers. * *************/ static void zap_fpa_state(Fpa_state q) { if (q != NULL) { zap_fpa_state(q->left); zap_fpa_state(q->right); #ifdef FPA_DEBUG zap_ilist(q->path); #endif free_fpa_state(q); } } /* zap_fpa_state */ /************* * * union_commuted() * *************/ static Fpa_state union_commuted(Fpa_state q, Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index) { Fpa_state q1; int empty, i; #if 0 printf("enter union_commuted with\n"); p_fpa_state(q); #endif q1 = NULL; empty = 0; for (i = 0; i < 2 && !empty; i++) { p->last->i = (i == 0 ? 2 : 1); /* Skip this arg if VARIABLE && (UNIFY || INSTANCE). */ if (!VARIABLE(ARG(t,i)) || type==GENERALIZATION || type==VARIANT || type==IDENTICAL) { Fpa_state q2 = build_query(ARG(t,i), c, type, p, bound-1, index); if (q2 == NULL) { empty = 1; zap_fpa_state(q1); q1 = NULL; } else if (q1 == NULL) q1 = q2; else q1 = query_intersect(q1, q2); } } if (q1 != NULL) q1 = query_union(q, q1); else q1 = q; #if 0 printf("exit union_commuted with\n"); p_fpa_state(q1); #endif return(q1); } /* union_commuted */ /************* * * var_in_context() * *************/ static BOOL var_in_context(Term t, Context c) { DEREFERENCE(t, c); return VARIABLE(t); } /* var_in_context */ /************* * * all_args_vars_in_context() * *************/ static BOOL all_args_vars_in_context(Term t, Context c) { /* Assume t is not a variable. */ int i = 0; BOOL ok = TRUE; while (i < ARITY(t) && ok) { ok = var_in_context(ARG(t,i), c); i++; } return ok; } /* all_args_vars_in_context */ /************* * * build_query() * *************/ static Fpa_state build_query(Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index) { if (VARIABLE(t)) { int i = VARNUM(t); if (c != NULL && c->terms[i] != NULL) return build_query(c->terms[i], c->contexts[i], type, p, bound, index); else if (type == UNIFY || type == INSTANCE) { fatal_error("build_query, variable."); return NULL; /* to quiet compiler */ } else { Ilist save = path_push(p, 0); Fpa_state q = query_leaf(p->first, index); path_restore(p, save); return q; } } else { /* non-variable */ Fpa_state q1 = NULL; Ilist save1 = path_push(p, SYMNUM(t)); if (CONSTANT(t) || bound <= 0 || is_assoc_comm(SYMNUM(t))) { q1 = query_leaf(p->first, index); } else if ((type == INSTANCE || type == UNIFY) && all_args_vars_in_context(t, c)) { Fpa_trie n = fpa_trie_member(index, p->first); q1 = (n == NULL ? NULL : query_special(n)); } else { Ilist save2 = path_push(p, 0); int empty = 0; int i; for (i = 0; i < ARITY(t) && !empty; i++) { p->last->i = i+1; /* Skip this arg if VARIABLE && (UNIFY || INSTANCE). */ if (!var_in_context(ARG(t,i),c) || type==GENERALIZATION || type==VARIANT || type==IDENTICAL) { Fpa_state q2 = build_query(ARG(t,i), c, type, p, bound-1, index); if (q2 == NULL) { empty = 1; zap_fpa_state(q1); q1 = NULL; } else if (q1 == NULL) q1 = q2; else q1 = query_intersect(q1, q2); } } if (is_commutative(SYMNUM(t)) && !term_ident(ARG(t,0), ARG(t,1))) q1 = union_commuted(q1, t, c, type, p, bound, index); path_restore(p, save2); } if (type == UNIFY || type == GENERALIZATION) { Fpa_state q2; p->last->i = 0; q2 = query_leaf(p->first, index); q1 = query_union(q1, q2); } path_restore(p, save1); return q1; } } /* build_query */ /************* * * fprint_fpa_state (recursive) * *************/ /* DOCUMENTATION This (recursive) routine prints (to FILE *fp) an Fpa_state tree. The depth parameter should be 0 on the top call. This is an AND/OR tree, with lists of terms (ordered by FPA_ID) at the leaves. If FPA_DEBUG is not defined in fpa.h, the paths corresponding to the leaves are not printed, and the tree is hard to understand without the paths. */ /* PUBLIC */ void fprint_fpa_state(FILE *fp, Fpa_state q, int depth) { int i; for (i = 0; i < depth; i++) fprintf(fp, "- - "); switch (q->type) { case UNION: fprintf(fp, "OR\n"); break; case INTERSECT: fprintf(fp, "AND\n"); break; case LEAF: #ifdef FPA_DEBUG fprint_path(fp, q->path); fprintf(fp, " "); #endif p_fpa_list(q->fpos.f); { #if 0 Plist p; fprintf(fp, "["); for (p = q->terms; p != NULL; p = p->next) fprintf(fp, "%u%s", (unsigned) FPA_ID(p->v), p->next == NULL ? "" : ","); fprintf(fp, "]\n"); #endif } break; } fflush(fp); if (q->type == UNION || q->type == INTERSECT) { fprint_fpa_state(fp, q->right, depth+1); fprint_fpa_state(fp, q->left, depth+1); } } /* fprint_fpa_state */ /************* * * p_fpa_state * *************/ /* DOCUMENTATION This routine prints (to stdout) an Fpa_state tree. See the description of fprint_fpa_state(). */ /* PUBLIC */ void p_fpa_state(Fpa_state q) { fprint_fpa_state(stdout, q, 0); } /* fprint_fpa_state */ /************* * * p_fpa_query * *************/ /* DOCUMENTATION This routine constructs an fpa_query tree and prints it to stdout. */ /* PUBLIC */ void p_fpa_query(Term t, Querytype query_type, Fpa_index idx) { Fpa_state q; char *s; struct path p; p.first = p.last = NULL; switch (query_type) { case UNIFY: s = "UNIFY "; break; case INSTANCE: s = "INSTANCE "; break; case GENERALIZATION: s = "GENERALIZATION"; break; case VARIANT: s = "VARIANT "; break; case IDENTICAL: s = "IDENTICAL "; break; default: s = "FPA_?? "; break; } printf("\n%s with term %u: ", s, (unsigned) FPA_ID(t)); p_term(t); fflush(stdout); q = build_query(t, NULL, query_type, &p, idx->depth, idx->root); p_fpa_state(q); zap_fpa_state(q); } /* fprint_fpa_query */ /************* * * next_term() * * Get the first or next term that satisfies a unification condition. * (Unification conditions are provided by build_query.) * `max' should be FPA_ID_MAX on top calls. A return of NULL indicates * that there are none or no more terms that satisfy (and the tree has * been deallocated). If you want to stop getting terms before a NULL * is returned, then please deallocate the tree with zap_fpa_state(tree). * * Warning: a return of NULL means that the tree has been deallocated. * *************/ static Term next_term(Fpa_state q, FPA_ID_TYPE max) { BUMP_NEXT_CALLS; if (q == NULL) return NULL; else if (q->type == LEAF) { Term t = FTERM(q->fpos); while (t != NULL && FPA_ID(t) > max) { q->fpos = next_fpos(q->fpos); t = FTERM(q->fpos); } if (t == NULL) { zap_fpa_state(q); return NULL; } else { q->fpos = next_fpos(q->fpos); return t; } } else if (q->type == INTERSECT) { Term t1, t2; t1 = next_term(q->left, max); if (t1 != NULL) t2 = next_term(q->right, FPA_ID(t1)); else t2 = (Term) &t2; /* anything but NULL */ while (t1 != t2 && t1 != NULL && t2 != NULL) { if (FGT(t1,t2)) t1 = next_term(q->left, FPA_ID(t2)); else t2 = next_term(q->right, FPA_ID(t1)); } if (t1 == NULL || t2 == NULL) { if (t1 == NULL) q->left = NULL; if (t2 == NULL) q->right = NULL; zap_fpa_state(q); return NULL; } else return t1; } else { /* UNION node */ Term t1, t2; /* first get the left term */ t1 = q->left_term; if (t1 == NULL) { /* it must be brought up */ if (q->left) { t1 = next_term(q->left, max); if (t1 == NULL) q->left = NULL; } } else /* it was saved from a previous call */ q->left_term = NULL; /* now do the same for the right side */ t2 = q->right_term; if (t2 == NULL) { if (q->right) { t2 = next_term(q->right, max); if (t2 == NULL) q->right = NULL; } } else q->right_term = NULL; /* At this point, both left_term and right_term are NULL. * Now decide which of t1 and t2 to return. If both are * non-NULL (and different), save the smaller for the next * call, and return the larger. */ if (t1 == NULL) { if (t2 == NULL) { zap_fpa_state(q); return NULL; } else return t2; } else if (t2 == NULL) return t1; else if (t1 == t2) return t1; else if (FGT(t1,t2)) { q->right_term = t2; /* save t2 for next time */ return t1; } else { q->left_term = t1; /* save t1 for next time */ return t2; } } } /* next_term */ /************* * * fpa_next_answer() * *************/ /* DOCUMENTATION This routine extracts and returns the next answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree. */ /* PUBLIC */ Term fpa_next_answer(Fpa_state q) { return next_term(q, FPA_ID_MAX); } /* fpa_next_answer */ /************* * * fpa_first_answer() * *************/ /* DOCUMENTATION This routine extracts and returns the first answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree.

The query types are UNIFY, INSTANCE, GENERALIZATION, VARIANT, and IDENTICAL.

If Context c is not NULL, then the instance of the term (in the context) is used for the query. */ /* PUBLIC */ Term fpa_first_answer(Term t, Context c, Querytype query_type, Fpa_index idx, Fpa_state *ppos) { struct path p; p.first = p.last = NULL; *ppos = build_query(t, c, query_type, &p, idx->depth, idx->root); return fpa_next_answer(*ppos); } /* fpa_first_answer */ /************* * * fpa_cancel * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all answers to an fpa query. See fpa_first_answer() and fpa_next_answer(). */ /* PUBLIC */ void fpa_cancel(Fpa_state q) { zap_fpa_state(q); } /* fpa_cancel */ /************* * * zap_fpa_trie() * *************/ static void zap_fpa_trie(Fpa_trie n) { Fpa_trie k, prev; k = n->kids; while (k != NULL) { prev = k; k = k->next; zap_fpa_trie(prev); } zap_fpalist(n->terms); #ifdef FPA_DEBUG zap_ilist(n->path); #endif free_fpa_trie(n); } /* zap_fpa_trie */ /************* * * zap_fpa_index() * *************/ /* DOCUMENTATION This routine removes all the entries from an Fpa_index idx and frees all of the associated memory. */ /* PUBLIC */ void zap_fpa_index(Fpa_index idx) { zap_fpa_trie(idx->root); free_fpa_index(idx); } /* zap_fpa_index */ /************* * * fpa_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an FPA/Path index is empty. */ /* PUBLIC */ BOOL fpa_empty(Fpa_index idx) { return (idx == NULL ? TRUE : idx->root->kids == NULL); } /* fpa_empty */ /************* * * fpa_density() * *************/ static void fpa_density(Fpa_trie p) { Fpa_trie q; for (q = p->kids; q; q = q->next) fpa_density(q); if (p->terms != NULL) { printf("Fpa_list: chunks=%d, size=%d, terms=%d\n", p->terms->num_chunks, p->terms->chunksize, p->terms->num_terms); } } /* fpa_density */ /************* * * p_fpa_density() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_fpa_density(Fpa_index idx) { fpa_density(idx->root); } /* p_fpa_density */ /************* * * mega_next_calls() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned mega_next_calls(void) { return (Next_calls / 1000000) + ((UINT_MAX / 1000000) * Next_calls_overflows); } /* mega_next_calls */ LADR-2009-11A/ladr/clist.h0000644000175000017500000000645011151265364014240 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLIST_H #define TP_CLIST_H #include "topform.h" /* INTRODUCTION This package handles Clists, which are doubly-linked lists of (pointers to) clauses. This is the "official" way of building lists of clauses. (If you need a temporary, singly linked list, you can use Plist instead.)

An important property of Clists is that each clause knows what Clists it is on. In particular, each clause has a (singly linked) list of containing Clists, constructed from the same nodes as the ordinary Clist (see the definition of struct clist_pos). */ /* Public definitions */ typedef struct clist_pos * Clist_pos; typedef struct clist * Clist; struct clist { char *name; Clist_pos first, last; int length; }; struct clist_pos { Clist_pos prev, next; /* previous and next member of Clist */ Clist_pos nocc; /* next member of containment list */ Clist list; /* the head of the list */ Topform c; /* pointer to the clause */ }; /* End of public definitions */ /* Public function prototypes from clist.c */ void fprint_clist_mem(FILE *fp, BOOL heading); void p_clist_mem(); Clist clist_init(char *name); void name_clist(Clist p, char *name); void clist_free(Clist p); void clist_append(Topform c, Clist l); void clist_prepend(Topform c, Clist l); void clist_insert_before(Topform c, Clist_pos pos); void clist_insert_after(Topform c, Clist_pos pos); void clist_remove(Topform c, Clist l); void clist_remove_all_clauses(Clist l); int clist_remove_all(Topform c); int clist_member(Topform c, Clist l); void fprint_clist(FILE *fp, Clist l); void p_clist(Clist l); void clist_zap(Clist l); void clist_check(Clist l); void clist_append_all(Clist l1, Clist l2); BOOL clist_empty(Clist lst); int clist_length(Clist l); int max_wt_in_clist(Clist l); BOOL horn_clist(Clist l); BOOL unit_clist(Clist l); BOOL equality_in_clist(Clist l); BOOL neg_nonunit_in_clist(Clist l); Plist clauses_in_clist(Plist p, Clist l); void clist_swap(Topform a, Topform b); void clist_move_clauses(Clist a, Clist b); Plist move_clist_to_plist(Clist a); Plist copy_clist_to_plist_shallow(Clist a); Clist plist_to_clist(Plist p, char *name); void clist_reverse(Clist l); Clist_pos pos_in_clist(Clist lst, Topform c); void clist_append_plist(Clist lst, Plist clauses); Plist prepend_clist_to_plist(Plist p, Clist c); int clist_number_of_weight(Clist lst, int weight); void sort_clist_by_id(Clist lst); Plist neg_clauses_in_clist(Clist a); void fprint_clause_clist(FILE *fp, Clist lst); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/discrimw.c0000644000175000017500000005127610637466321014750 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "discrimw.h" /* Private definitions and types */ typedef struct flat * Flat; struct flat { /* for building a stack of states for backtracking */ Term t; Flat prev, next, last; Discrim alternatives; int bound; /* (tame) */ int varnum; /* (tame) */ int place_holder; int num_ac_args; /* for AC symbols (wild) */ int num_ac_nv_args; /* for AC symbols (wild) */ int commutative; /* for commutative symbols (wild) */ int flip; /* for commutative symbols (wild) */ }; #define GO 1 #define BACKTRACK 2 #define SUCCESS 3 #define FAILURE 4 /* * memory management */ #define PTRS_FLAT PTRS(sizeof(struct flat)) static unsigned Flat_gets, Flat_frees; /************* * * Flat get_flat() * *************/ static Flat get_flat(void) { Flat p = get_cmem(PTRS_FLAT); Flat_gets++; #if 0 /* assume these will be set by the caller? */ p->t = NULL; p->prev = NULL; p->last = NULL; #endif p->next = NULL; p->alternatives = NULL; p->bound = 0; p->place_holder = 0; p->commutative = 0; p->flip = 0; return(p); } /* get_flat */ /************* * * free_flat() * *************/ static void free_flat(Flat p) { free_mem(p, PTRS_FLAT); Flat_frees++; } /* free_flat */ /************* * * fprint_discrimw_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrimw package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_discrimw_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct flat); fprintf(fp, "flat (%4d) %11u%11u%11u%9.1f K\n", n, Flat_gets, Flat_frees, Flat_gets - Flat_frees, ((Flat_gets - Flat_frees) * n) / 1024.); } /* fprint_discrimw_mem */ /************* * * p_discrimw_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the discrimw package. */ /* PUBLIC */ void p_discrimw_mem(void) { fprint_discrimw_mem(stdout, TRUE); } /* p_discrimw_mem */ /* * end of memory management */ /************* * * check_flat * *************/ static Flat check_flat(Flat f) { Flat last; int i, arity; if (f->next != NULL && f->next->prev != f) fprintf(stderr, "check_flat: next-prev error\n"); if (f->place_holder) arity = 0; else arity = ARITY(f->t); last = f; for (i = 0; i < arity; i++) last = check_flat(last->next); if (f->last != last) fprintf(stderr, "check_flat: last is wrong\n"); return last; } /* check_flat */ /************* * * p_flat * *************/ void p_flat(Flat f) { while (f != NULL) { printf("%s", VARIABLE(f->t) ? "*" : sn_to_str(SYMNUM(f->t))); if (f->place_holder) printf("[]"); f = f->next; if (f != NULL) printf("-"); } printf("\n"); } /* p_flat */ /************* * * flip_flat * *************/ static void flip_flat(Flat f) { /* Assume f is binary. */ Flat arg1 = f->next; Flat arg2 = arg1->last->next; Flat after = f->last->next; Flat p; f->next = arg2; arg2->last->next = arg1; arg1->last->next = after; f->last = arg1->last; arg2->prev = f; arg1->prev = arg2->last; if (after != NULL) after->prev = arg1->last; /* arg2->last is the old end of f */ for (p = f->prev; p != NULL; p = p->prev) if (p->last == arg2->last) p->last = f->last; #if 0 for (p = f; p->prev != NULL; p = p->prev); check_flat(p); #endif } /* flip_flat */ /* ******************************** WILD **************************** */ /************* * * num_ac_args(t, symbol) * *************/ static int num_ac_args(struct term *t, int symbol) { if (!COMPLEX(t) || SYMNUM(t) != symbol) return 1; else return (num_ac_args(ARG(t,0), symbol) + num_ac_args(ARG(t,1), symbol)); } /* num_ac_args */ /************* * * num_ac_nv_args(t, symbol) * *************/ static int num_ac_nv_args(struct term *t, int symbol) { if (!COMPLEX(t) || SYMNUM(t) != symbol) return (VARIABLE(t) ? 0 : 1); else return (num_ac_nv_args(ARG(t,0), symbol) + num_ac_nv_args(ARG(t,1), symbol)); } /* num_ac_nv_args */ /************* * * print_discrim_wild_tree() * *************/ static void print_discrim_wild_tree(FILE *fp, Discrim d, int n, int depth) { int arity, i; for (i = 0; i < depth; i++) fprintf(fp, " -"); if (depth == 0) fprintf(fp, "\nroot"); else if (d->type == AC_ARG_TYPE) fprintf(fp, "AC %d args", d->symbol); else if (d->type == AC_NV_ARG_TYPE) fprintf(fp, "AC %d NV args", d->symbol); else if (DVAR(d)) fprintf(fp, "*"); else fprintf(fp, "%s", sn_to_str(d->symbol)); fprintf(fp, " (%p)", d); if (n == 0) { Plist p; for (i = 0, p = d->u.data; p; i++, p = p->next); fprintf(fp, ": leaf has %d objects.\n", i); } else { Discrim d1; fprintf(fp, "\n"); for (d1 = d->u.kids; d1 != NULL; d1 = d1->next) { if (d1->type == AC_ARG_TYPE || d1->type == AC_NV_ARG_TYPE) arity = 0; else if (DVAR(d1)) arity = 0; else arity = sn_to_arity(d1->symbol); print_discrim_wild_tree(fp, d1, n+arity-1, depth+1); } } } /* print_discrim_wild_tree */ /************* * * fprint_discrim_wild_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a wild discrimination index. */ /* PUBLIC */ void fprint_discrim_wild_index(FILE *fp, Discrim d) { print_discrim_wild_tree(fp, d, 1, 0); } /* fprint_discrim_wild_index */ /************* * * p_discrim_wild_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) a wild discrimination index. */ /* PUBLIC */ void p_discrim_wild_index(Discrim d) { fprint_discrim_wild_index(stdout, d); } /* p_discrim_wild_index */ /************* * * discrim_wild_insert_ac(t, d) * *************/ static Discrim discrim_wild_insert_ac(Term t, Discrim d) { int num_args, num_nv_args; Discrim d1, d2, dnew, prev; num_args = num_ac_args(t, SYMNUM(t)); for (d1 = d->u.kids, prev = NULL; d1 && d1->symbol < num_args; prev = d1, d1 = d1->next); if (d1 == NULL || d1->symbol != num_args) { dnew = get_discrim(); dnew->type = AC_ARG_TYPE; dnew->symbol = num_args; dnew->next = d1; if (prev != NULL) prev->next = dnew; else d->u.kids = dnew; d1 = dnew; } num_nv_args = num_ac_nv_args(t, SYMNUM(t)); for (d2 = d1->u.kids, prev = NULL; d2 && d2->symbol < num_nv_args; prev = d2, d2 = d2->next); if (!d2 || d2->symbol != num_nv_args) { dnew = get_discrim(); dnew->type = AC_NV_ARG_TYPE; dnew->symbol = num_nv_args; dnew->next = d2; if (prev != NULL) prev->next = dnew; else d1->u.kids = dnew; d2 = dnew; } return d2; } /* discrim_wild_insert_ac */ /************* * * Discrim discrim_wild_insert_rec(t, d) * *************/ static Discrim discrim_wild_insert_rec(Term t, Discrim d) { Discrim d1, prev, d2; int sym; if (VARIABLE(t)) { d1 = d->u.kids; if (d1 == NULL || !DVAR(d1)) { d2 = get_discrim(); d2->type = DVARIABLE; d2->symbol = 0; /* HERE */ d2->next = d1; d->u.kids = d2; return d2; } else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; prev = NULL; /* arities fixed: handle both NAME and COMPLEX */ sym = SYMNUM(t); if (d1 && DVAR(d1)) { /* skip variable */ prev = d1; d1 = d1->next; } while (d1 && d1->symbol < sym) { prev = d1; d1 = d1->next; } if (d1 == NULL || d1->symbol != sym) { d2 = get_discrim(); d2->type = DRIGID; d2->symbol = sym; d2->next = d1; d1 = d2; } else d2 = NULL; /* new node not required at this level */ if (is_assoc_comm(SYMNUM(t))) { d1 = discrim_wild_insert_ac(t, d1); } else { int i; for (i = 0; i < ARITY(t); i++) d1 = discrim_wild_insert_rec(ARG(t,i), d1); } if (d2 != NULL) { /* link in new subtree (possibly a leaf) */ if (prev == NULL) d->u.kids = d2; else prev->next = d2; } return d1; /* d1 is leaf corresp. to end of input term */ } } /* discrim_wild_insert_rec */ /************* * * discrim_wild_insert(t, root, object) * *************/ static void discrim_wild_insert(Term t, Discrim root, void *object) { Discrim d; Plist gp1, gp2; d = discrim_wild_insert_rec(t, root); gp1 = get_plist(); gp1->v = object; gp1->next = NULL; /* Install at end of list. */ if (d->u.data == NULL) d->u.data = gp1; else { for (gp2 = d->u.data; gp2->next; gp2 = gp2->next); gp2->next = gp1; } } /* discrim_wild_insert */ /************* * * Discrim discrim_wild_end(t, is, path_p) * * Given a discrimination tree (or a subtree) and a term, return the * node in the tree that corresponds to the last symbol in t (or NULL * if the node doesn't exist). *path_p is a list that is extended by * this routine. It is a list of pointers to the * nodes in path from the parent of the returned node up to imd. * (It is needed for deletions, because nodes do not have pointers to * parents.) * *************/ static Discrim discrim_wild_end(Term t, Discrim d, Plist *path_p) { Discrim d1; Plist p; int sym; /* add current node to the front of the path list. */ p = get_plist(); p->v = d; p->next = *path_p; *path_p = p; if (VARIABLE(t)) { d1 = d->u.kids; if (d1 && DVAR(d1)) return d1; else return NULL; } else { /* constant || complex */ d1 = d->u.kids; sym = SYMNUM(t); if (d1 && DVAR(d1)) /* skip variables */ d1 = d1->next; while (d1 && d1->symbol < sym) d1 = d1->next; if (d1 == NULL || d1->symbol != sym) return NULL; else if (is_assoc_comm(SYMNUM(t))) { int num_args, num_nv_args; Discrim d2, d3; num_args = num_ac_args(t, SYMNUM(t)); num_nv_args = num_ac_nv_args(t, SYMNUM(t)); for (d2 = d1->u.kids; d2 && d2->symbol != num_args; d2 = d2->next); if (d2 == NULL) return NULL; else { for (d3 = d2->u.kids; d3 && d3->symbol != num_nv_args; d3 = d3->next); if (d3 == NULL) return NULL; else { p = get_plist(); p->v = d1; p->next = *path_p; *path_p = p; p = get_plist(); p->v = d2; p->next = *path_p; *path_p = p; return d3; } } } else { int i; for (i = 0; d1 && i < ARITY(t); i++) d1 = discrim_wild_end(ARG(t,i), d1, path_p); return d1; } } } /* discrim_wild_end */ /************* * * discrim_wild_delete(t, root, object) * *************/ static void discrim_wild_delete(Term t, Discrim root, void *object) { Discrim end, i2, i3, parent; Plist tp1, tp2; Plist isp1, path; /* First find the correct leaf. path is used to help with */ /* freeing nodes, because nodes don't have parent pointers. */ path = NULL; end = discrim_wild_end(t, root, &path); if (end == NULL) { fatal_error("discrim_wild_delete, cannot find end."); } /* Free the pointer in the leaf-list */ tp1 = end->u.data; tp2 = NULL; while(tp1 && tp1->v != object) { tp2 = tp1; tp1 = tp1->next; } if (tp1 == NULL) { fatal_error("discrim_wild_delete, cannot find term."); } if (tp2 == NULL) end->u.data = tp1->next; else tp2->next = tp1->next; free_plist(tp1); if (!end->u.data) { /* free tree nodes from bottom up, using path to get parents */ end->u.kids = NULL; /* not really necessary */ isp1 = path; while (!end->u.kids && end != root) { parent = (Discrim) isp1->v; isp1 = isp1->next; i2 = parent->u.kids; i3 = NULL; while (i2 != end) { i3 = i2; i2 = i2->next; } if (i3 == NULL) parent->u.kids = i2->next; else i3->next = i2->next; free_discrim(i2); end = parent; } } /* free path list */ while (path) { isp1 = path; path = path->next; free_plist(isp1); } } /* discrim_wild_delete */ /************* * * discrim_wild_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a wild discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted. */ /* PUBLIC */ void discrim_wild_update(Term t, Discrim root, void *object, Indexop op) { if (op == INSERT) discrim_wild_insert(t, root, object); else discrim_wild_delete(t, root, object); } /* discrim_wild_update */ /************* * * discrim_wild_retrieve_leaf(t_in, root, ppos) * *************/ static Plist discrim_wild_retrieve_leaf(Term t_in, Discrim root, Flat *ppos) { Flat f, f1, f2; Flat f_save = NULL; Term t; Discrim d = NULL; int symbol, status; f = *ppos; /* Don't forget to reset before return. */ t = t_in; if (t != NULL) { /* if first call */ d = root->u.kids; if (d != NULL) { f = get_flat(); f->t = t; f->last = f; f->prev = NULL; f->next = NULL; f->place_holder = COMPLEX(t); status = GO; } else status = FAILURE; } else status = BACKTRACK; while (status == GO || status == BACKTRACK) { /* Three things determine the state at this point. * 1. d is the current node in the discrimination tree. * 2. f is the current node in the stack of flats. * 3. status is either GO or BACKTRACK. * * Commutative symbols: * This is more complicated than it needs to be, because * alternatives are handled awkwardly. * flip == 0 means that we haven't descended into the commutative term. * flip == 1 means that we are in the unflipped commutative term, and * flip == 2 means that we are in the flipped commutative term. */ if (status == BACKTRACK) { #if 0 printf("backtracking\n"); #endif /* Back up to a place with an aternate branch. */ while (f != NULL && f->alternatives == NULL) { if (f->commutative && f->flip == 2) { /* commutative with no alternative */ flip_flat(f); /* un-flip */ #if 0 printf("AFTER un-flip: "); p_flat(f); #endif f->flip = 0; } f_save = f; f = f->prev; } if (f != NULL) { #if 0 printf("alternative: (%x)\n", (unsigned) f->alternatives); #endif if (f->commutative && f->flip == 1) { flip_flat(f); /* flip */ #if 0 printf("AFTER flip: "); p_flat(f); #endif f->flip = 2; } d = f->alternatives; f->alternatives = NULL; status = GO; } else { /* Free stack of flats and fail. */ while (f_save != NULL) { f1 = f_save; f_save = f_save->next; free_flat(f1); } status = FAILURE; } } /* backtrack */ if (status == GO) { #if 0 printf("go with (%x) %s\n", (unsigned) d, DVAR(d) ? "*" : sn_to_str(d->symbol)); #endif if (d && d->type == AC_ARG_TYPE) { if (d->symbol <= f->num_ac_args) f->alternatives = d->next; else status = BACKTRACK; } else if (d && d->type == AC_NV_ARG_TYPE) { if (d->symbol <= f->num_ac_nv_args) f->alternatives = d->next; else status = BACKTRACK; } else if (d && DVAR(d)) { /* push alternatives */ f->alternatives = d->next; f = f->last; } else if (VARIABLE(f->t)) status = BACKTRACK; else { symbol = SYMNUM(f->t); while (d && d->symbol < symbol) d = d->next; if (!d || d->symbol != symbol) status = BACKTRACK; else { if (f->place_holder) { /* Insert skeleton in place_holder. This is tricky, because * someone's "last" pointer may be pointing to f. Therefore, * f becomes the last argument of the skeleton. */ if (is_assoc_comm(SYMNUM(f->t))) { /* AC case */ f1 = get_flat(); f1->t = f->t; f1->prev = f->prev; f1->last = f; if (f1->prev) f1->prev->next = f1; f2 = get_flat(); f2->prev = f1; f2->last = f2; f2->next = f; f->prev = f2; f1->next = f2; f->last = f; /* Now, f2 is the AC_ARGS node, and f is the AC_NV_ARGS node. */ f2->num_ac_args = num_ac_args(f1->t, SYMNUM(f1->t)); f->num_ac_nv_args = num_ac_nv_args(f1->t, SYMNUM(f1->t)); f = f1; } else { /* non AC case */ int i; f1 = get_flat(); f1->t = f->t; f1->prev = f->prev; f1->last = f; f_save = f1; if (f1->prev) f1->prev->next = f1; t = f->t; for (i = 0; i < ARITY(t); i++) { if (i < ARITY(t)-1) f2 = get_flat(); else f2 = f; f2->place_holder = COMPLEX(ARG(t,i)); f2->t = ARG(t,i); f2->last = f2; f2->prev = f1; f1->next = f2; f1 = f2; } f = f_save; if (is_commutative(SYMNUM(f->t)) && !term_ident(ARG(f->t,0), ARG(f->t,1))) f->commutative = 1; } /* non-AC */ } /* if f->place_holder */ if (f->commutative && f->flip == 0) { f->alternatives = d; f->flip = 1; } } /* rigid symbols match */ } /* non-variable */ if (status == GO) { if (f->next) { f = f->next; d = d->u.kids; } else status = SUCCESS; } /* if go */ } /* if go */ } /* while go or backtrack */ if (status == SUCCESS) { *ppos = f; return d->u.data; } else return NULL; } /* discrim_wild_retrieve_leaf */ /************* * * discrim_wild_retrieve_first(t, root, ppos) * * Get the first object associated with a term more general than t. * * Remember to call discrim_wild_cancel(pos) if you don't * want the whole sequence. * *************/ /* DOCUMENTATION This routine, along with discrim_wild_retrieve_next(), gets answers from a wild discrimination index. This routine retrieves the first object associated with a term more general than Term t. (NULL is returned if there is none.)

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_wild_cancel() to clear the substitution and free memory associated with the Discrim_pos. */ /* PUBLIC */ void *discrim_wild_retrieve_first(Term t, Discrim root, Discrim_pos *ppos) { Plist tp; Flat f; Discrim_pos gp; tp = discrim_wild_retrieve_leaf(t, root, &f); if (tp == NULL) return NULL; else { gp = get_discrim_pos(); gp->backtrack = f; gp->data = tp; *ppos = gp; return tp->v; } } /* discrim_wild_retrieve_first */ /************* * * discrim_wild_retrieve_next(pos) * * Get the next object associated with a term more general than t. * * Remember to call discrim_wild_cancel(pos) if you don't * want the whole sequence. * *************/ /* DOCUMENTATION This routine retrieves the next object in the sequence of answers to a query of a wild discrimination tree. See discrim_wild_retrieve_first(). */ /* PUBLIC */ void *discrim_wild_retrieve_next(Discrim_pos pos) { Plist tp; tp = pos->data->next; if (tp != NULL) { /* if any more terms in current leaf */ pos->data = tp; return tp->v; } else { /* try for another leaf */ tp = discrim_wild_retrieve_leaf(NULL, NULL, (Flat *) &(pos->backtrack)); if (tp != NULL) { pos->data = tp; return tp->v; } else { free_discrim_pos(pos); return NULL; } } } /* discrim_wild_retrieve_next */ /************* * * discrim_wild_cancel(pos) * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all answers to a wild discrimintaion query. The memory associated the retrieval state is freed. */ /* PUBLIC */ void discrim_wild_cancel(Discrim_pos pos) { Flat f1 = pos->backtrack; while (f1) { Flat f2 = f1; f1 = f1->prev; free_flat(f2); } free_discrim_pos(pos); } /* discrim_wild_cancel */ LADR-2009-11A/ladr/mindex.h0000644000175000017500000000743311151265364014410 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_MINDEX_H #define TP_MINDEX_H #include "fpa.h" #include "discrimb.h" #include "discrimw.h" #include "btu.h" #include "btm.h" /* INTRODUCTION This is an indexing/unification package to store terms and to retrieve unifiable terms. (It is really just an interface to the various indexing and unification packages.) Several types of indexing and unification are supported. When you allocate an index (with mindex_init()), you specify the type of index and the type of unification.

Types of Retrieval

UNIFY, INSTANCE, GENERALIZATION, VARIANT, IDENTICAL.

Types of Unification

Associative-commutative (AC) and commutative/symmetric (C) symbols are supported in most cases. If you have any AC or C symbols, you must use backtrack unification, which handles more than one unifier for a pair of terms; otherwise, you can use ordinary unification, which assumes at most one unifier for a pair of terms. (For the empty theory, ordinary unification is a bit faster than backtrack unification.)

Types of Indexing

  • LINEAR : This is indexing without an index. The terms you insert are put on a list, and each is tested in turn. This supports AC and C symbols.
  • FPA : This is FPA/Path indexing. Supports AC symbols (in a primitive way, by treating them as constants) and C symbols.
  • DISCRIM_WILD : Discrimination indexing, where matching is separate from unidexing. This supports AC symbols and C symbols. With C symbols, you can get duplicate answers. Supports GENERALIZATION retrieval only.
  • DISCRIM_BIND : Discrimination indexing, where matching occurs during indexing. This supports C symbols, but not AC symbols. Supports GENERALIZATION retrieval only.
*/ /* Public definitions */ /* types of index */ typedef enum { LINEAR, FPA, DISCRIM_WILD, DISCRIM_BIND } Mindextype; /* types of unification */ typedef enum { ORDINARY_UNIF, BACKTRACK_UNIF } Uniftype; typedef struct mindex * Mindex; typedef struct mindex_pos * Mindex_pos; struct mindex { Mindextype index_type; Uniftype unif_type; /* FPA */ Fpa_index fpa; /* LINEAR */ Plist linear_first; Plist linear_last; /* DISCRIM_WILD and DISCRIM_BIND */ Discrim discrim_tree; Mindex next; /* for avail list */ }; /* End of public definitions */ /* Public function prototypes from mindex.c */ void fprint_mindex_mem(FILE *fp, BOOL heading); void p_mindex_mem(); Mindex mindex_init(Mindextype mtype, Uniftype utype, int fpa_depth); BOOL mindex_empty(Mindex mdx); void mindex_free(Mindex mdx); void mindex_destroy(Mindex mdx); void mindex_update(Mindex mdx, Term t, Indexop op); Term mindex_retrieve_first(Term t, Mindex mdx, Querytype qtype, Context query_subst, Context found_subst, BOOL partial_match, Mindex_pos *ppos); Term mindex_retrieve_next(Mindex_pos pos); void mindex_retrieve_cancel(Mindex_pos pos); void fprint_mindex(FILE *fp, Mindex mdx); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/complex.h0000644000175000017500000000235711151265364014573 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_COMPLEX_H #define TP_COMPLEX_H #include "topform.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from complex.c */ double complex4(Term t); double term_complexity(Term t, int func, int adjustment); double clause_complexity(Literals lits, int func, int adjustment); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/memory.c0000644000175000017500000001616311274053600014421 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "memory.h" #define MALLOC_MEGS 20 /* size of blocks malloced by palloc */ #define DEFAULT_MAX_MEGS 500 /* change with set_max_megs(n) */ #define MAX_MEM_LISTS 500 /* number of lists of available nodes */ static void ** M[MAX_MEM_LISTS]; static BOOL Max_megs_check = TRUE; static int Max_megs = DEFAULT_MAX_MEGS; /* change with set_max_megs(n) */ static void (*Exit_proc) (void); /* set with set_max_megs_proc() */ static int Malloc_calls = 0; /* number of calls to malloc by palloc */ static unsigned Bytes_palloced = 0; static void *Block = NULL; /* location returned by most recent malloc */ static void *Block_pos = NULL; /* current position in block */ static unsigned Mem_calls = 0; static unsigned Mem_calls_overflows = 0; #define BUMP_MEM_CALLS {Mem_calls++; if (Mem_calls==0) Mem_calls_overflows++;} /************* * * void *palloc(n) -- assume n is a multiple of BYTES_POINTER. * *************/ static void *palloc(size_t n) { if (n == 0) return NULL; else { void *chunk; size_t malloc_bytes = MALLOC_MEGS*1024*1024; if (Block==NULL || Block + malloc_bytes - Block_pos < n) { /* First call or not enough in the current block, so get a new block. */ if (n > malloc_bytes) { printf("palloc, n=%d\n", (int) n); fatal_error("palloc, request too big; reset MALLOC_MEGS"); } else if (Max_megs_check && (Malloc_calls+1)*MALLOC_MEGS > Max_megs) { if (Exit_proc) (*Exit_proc)(); else fatal_error("palloc, Max_megs parameter exceeded"); } else { Block_pos = Block = malloc(malloc_bytes); Malloc_calls++; if (Block_pos == NULL) fatal_error("palloc, operating system is out of memory"); } } chunk = Block_pos; Block_pos += n; Bytes_palloced += n; return(chunk); } } /* palloc */ /************* * * get_cmem() * *************/ /* DOCUMENTATION Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is initialized to all 0. */ /* PUBLIC */ void *get_cmem(unsigned n) { if (n == 0) return NULL; else { void **p = NULL; BUMP_MEM_CALLS; if (n >= MAX_MEM_LISTS) return calloc(n, BYTES_POINTER); else if (M[n] == NULL) p = palloc(n * BYTES_POINTER); else { /* the first pointer is used for the avail list */ p = M[n]; M[n] = *p; } { int i; for (i = 0; i < n; i++) p[i] = 0; } return p; } } /* get_cmem */ /************* * * get_mem() * *************/ /* DOCUMENTATION Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is NOT initialized. */ /* PUBLIC */ void *get_mem(unsigned n) { if (n == 0) return NULL; else { void **p = NULL; BUMP_MEM_CALLS; if (n >= MAX_MEM_LISTS) p = malloc(n * BYTES_POINTER); else if (M[n] == NULL) p = palloc(n * BYTES_POINTER); else { /* the first pointer is used for the avail list */ p = M[n]; M[n] = *p; } return p; } } /* get_mem */ /************* * * free_mem() * *************/ /* DOCUMENTATION Free a chunk of memory that holds n pointers (not n bytes) that was returned from a previous get_mem() or get_cmem() call. */ /* PUBLIC */ void free_mem(void *q, unsigned n) { if (n == 0) ; /* do nothing */ else { /* put it on the appropriate avail list */ void **p = q; if (n >= MAX_MEM_LISTS) free(p); else { /* the first pointer is used for the avail list */ *p = M[n]; M[n] = p; } } } /* free_mem */ /************* * * mlist_length() * *************/ static int mlist_length(void **p) { int n; for (n = 0; p; p = *p, n++); return n; } /* mlist_length */ /************* * * memory_report() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void memory_report(FILE *fp) { int i; fprintf(fp, "\nMemory report, %d @ %d = %d megs (%.2f megs used).\n", Malloc_calls, MALLOC_MEGS, Malloc_calls * MALLOC_MEGS, Bytes_palloced / (1024 * 1024.0)); for (i = 0; i < MAX_MEM_LISTS; i++) { int n = mlist_length(M[i]); if (n != 0) fprintf(fp, "List %3d, length %7d, %8.1f K\n", i, n, i * n * BYTES_POINTER / 1024.); } } /* memory_report */ /************* * * int megs_malloced() -- How many MB have been dynamically allocated? * *************/ /* DOCUMENTATION This routine returns the number of megabytes that palloc() has obtained from the operating system by malloc(); */ /* PUBLIC */ int megs_malloced(void) { return Malloc_calls * MALLOC_MEGS; } /* megs_malloced */ /************* * * set_max_megs() * *************/ /* DOCUMENTATION This routine changes the limit on the amount of memory obtained from malloc() by palloc(). The argument is in megabytes. The default value is DEFAULT_MAX_MEGS. */ /* PUBLIC */ void set_max_megs(int megs) { Max_megs = (megs == -1 ? INT_MAX : megs); } /* set_max_megs */ /************* * * set_max_megs_proc() * *************/ /* DOCUMENTATION This routine is used to specify the routine that will be called if max_megs is exceeded. */ /* PUBLIC */ void set_max_megs_proc(void (*proc)(void)) { Exit_proc = proc; } /* set_max_megs_proc */ /************* * * bytes_palloced() * *************/ /* DOCUMENTATION How many bytes have been allocated by the palloc() routine? This includes all of the get_mem() calls. */ /* PUBLIC */ int bytes_palloced(void) { return Bytes_palloced; } /* bytes_palloced */ /************* * * tp_alloc() * *************/ /* DOCUMENTATION Allocate n bytes of memory, aligned on a pointer boundary. The memory is not initialized, and it cannot be freed. */ /* PUBLIC */ void *tp_alloc(size_t n) { /* If n is not a multiple of BYTES_POINTER, round up so that it is. */ if (n % BYTES_POINTER != 0) { n += (BYTES_POINTER - (n % BYTES_POINTER)); } return palloc(n); } /* tp_alloc */ /************* * * mega_mem_calls() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned mega_mem_calls(void) { return (Mem_calls / 1000000) + ((UINT_MAX / 1000000) * Mem_calls_overflows); } /* mega_mem_calls */ /************* * * disable_max_megs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void disable_max_megs(void) { Max_megs_check = FALSE; } /* disable_max_megs */ /************* * * enable_max_megs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void enable_max_megs(void) { Max_megs_check = TRUE; } /* enable_max_megs */ LADR-2009-11A/ladr/clauseid.h0000644000175000017500000000247411151265364014715 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSEID_H #define TP_CLAUSEID_H #include "topform.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from clauseid.c */ int clause_ids_assigned(void); void assign_clause_id(Topform c); void unassign_clause_id(Topform c); Topform find_clause_by_id(int id); void fprint_clause_id_tab(FILE *fp); void p_clause_id_tab(); Plist insert_clause_into_plist(Plist p, Topform c, BOOL increasing); BOOL clause_plist_member(Plist p, Topform c, BOOL increasing); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/backdemod.h0000644000175000017500000000242411151265364015030 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_BACKDEMOD_H #define TP_BACKDEMOD_H #include "demod.h" #include "clist.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from backdemod.c */ void index_clause_back_demod(Topform c, Mindex idx, Indexop op); BOOL rewritable_clause(Topform demod, Topform c); Plist back_demod_linear(Topform demod, Clist lst, Plist rewritables); Plist back_demod_indexed(Topform demod, int type, Mindex idx, BOOL lex_order_vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/banner.c0000644000175000017500000000437010701210302014337 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "banner.h" #include /* for toupper, tolower */ /* Private definitions and types */ /* * memory management */ /************* * * print_separator() * *************/ /* DOCUMENTATION Print the standard separator line. */ /* PUBLIC */ void print_separator(FILE *fp, char *str, BOOL initial_newline) { int len = 70; /* total length of line */ int n, i; char *first_half = "=============================="; if (initial_newline) fprintf(fp, "\n"); fprintf(fp, "%s %s ", first_half, str); n = len - (strlen(first_half) + strlen(str) + 2); for (i = 0; i < n; i++) fprintf(fp, "="); fprintf(fp, "\n"); fflush(fp); } /* print_separator */ /************* * * void print_banner(argc, argv, name, version, date, as_comments) * *************/ /* DOCUMENTATION Print the standard banner. */ /* PUBLIC */ void print_banner(int argc, char **argv, char *name, char *version, char *date, BOOL as_comments) { int i; char *com = (as_comments ? "% " : ""); if (!as_comments) print_separator(stdout, name, FALSE); printf("%s%s (%d) version %s, %s.\n", com, name, get_bits(), version, date); printf("%sProcess %d was started by %s on %s,\n%s%s", com, my_process_id(), username(), hostname(), com, get_date()); printf("%sThe command was \"", com); for(i = 0; i < argc; i++) printf("%s%s", argv[i], (i < argc-1 ? " " : "")); printf("\".\n"); if (!as_comments) print_separator(stdout, "end of head", FALSE); fflush(stdout); } /* print_banner */ LADR-2009-11A/ladr/random.h0000644000175000017500000000351611151265364014402 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_RANDOM_H #define TP_RANDOM_H #include "topform.h" /* INTRODUCTION These are some routines I used for testing and debugging some of the low-level code. The main reason I wrote these is so that I could write and test the early code without having to input terms. Maybe I'll see how far I can go before I have to write a term parser.

And, who knows, maybe the next big breakthrough in automated theorem proving will depend on randonly generated terms! */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from random.c */ Term random_term(int v, int a0, int a1, int a2, int a3, int max_depth); Term random_nonvariable_term(int v, int a0, int a1, int a2, int a3, int max_depth); Term random_complex_term(int v, int a0, int a1, int a2, int a3, int max_depth); Ilist random_path(int length_max, int value_max); void random_permutation(int *a, int size); Topform random_clause(int v, int a0, int a1, int a2, int a3, int max_depth, int max_lits); Term random_op_term(int depth); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/subsume.h0000644000175000017500000000317511151265364014606 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_SUBSUME_H #define TP_SUBSUME_H #include "parautil.h" #include "lindex.h" #include "features.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from subsume.c */ int nonunit_subsumption_tests(void); BOOL subsumes(Topform c, Topform d); BOOL subsumes_bt(Topform c, Topform d); Topform forward_subsume(Topform d, Lindex idx); Plist back_subsume(Topform c, Lindex idx); Topform back_subsume_one(Topform c, Lindex idx); void unit_conflict_by_index(Topform c, Lindex idx, void (*empty_proc) (Topform)); Topform try_unit_conflict(Topform a, Topform b); void unit_delete(Topform c, Lindex idx); Plist back_unit_del_by_index(Topform unit, Lindex idx); void simplify_literals(Topform c); BOOL eq_removable_literal(Topform c, Literals lit); void simplify_literals2(Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/kol.pl0000755000175000017500000000306311024317302014060 0ustar mccunemccune#!/usr/bin/perl use strict; use warnings; #print "Hello, world!\n"; my $MIN = 2; open(INFILE, "/dev/stdin") or die "Can't open the input file...\n"; while () { # print "% Here's the line: $_"; my $total = 0; my $string = $_; # foobarfoobar my $length = (length ($string)) - 2; my $index = $MIN; # print "Will check from index $index to $length.\n"; # print "Length of string is $length.\n"; while($index <= $length) { # index of where the search begins my $maxlook = ($length - $index) + 2; if ($maxlook > $index) { $maxlook = $index; }# don't check for occurences longer than head of string # print "Checking at index: $index.\n"; # print "Will check strings of length $MIN through $maxlook.\n"; my $flen = 0; # length of found redundancy for(my $window = $MIN; $window <= $maxlook; $window++) { # index of length of lookahead to check my $tocheck = substr( $string, $index, $window ); # print "Want to know if $tocheck occurs in positions 0 until $index.\n"; my $ind = index($string, $tocheck, 0); if( $ind < $index ) {$flen = $window; } } # end lookahead buffer loop if($flen == 0) { $index++; } else { $index = $index + $flen; $total = $total + $flen } # print "total: $total\n"; # print "index: $index\n"; # print "length: $length\n"; # print "MIN: $MIN\n"; } # end outer while loop # print "DONE.\n"; my $kolmogorov = ($total / ($length-1)); # print "TOTAL REDUNDANCY: $total\n"; print "$kolmogorov\n" } # end of while loop close(INFILE); LADR-2009-11A/ladr/fastparse.c0000644000175000017500000001622410637466321015111 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "fastparse.h" /* Private definitions and types */ static int Arity[256]; /* table of arities for each symbol */ static int Symnum[256]; /* table of arities for each symbol */ static int Pos; /* index for parsing */ #define MAX_LINE 1000 /************* * * fast_set_symbol() * *************/ /* DOCUMENTATION Call this routine to declare a symbol/arity for fast parsing. Since fast parsing handles single-characters symbols only, you send character/arity to this routine.

For fast parsing, variables are always 'r' -- 'z', and those symbols should not be declared.

Also, you don't need to call this routine for constants. */ /* PUBLIC */ void fast_set_symbol(char c, int arity) { if (c >= 'r' && c <= 'z') { fatal_error("fast_set_symbol, r--z are variables and cannot be declared"); } else { char str[2]; str[0] = c; str[1] = '\0'; Arity[(int) c] = arity; Symnum[(int) c] = str_to_sn(str, arity); } } /* fast_set_symbol */ /************* * * fast_set_defaults() * *************/ /* DOCUMENTATION Call this routine to declare a fixed set of symbols for fast parsing.

  • binary: [=mjfd*+/]
  • unary: [cgi-~']
The defaults can be overridden by nsubsequent calls to fast_set_symbol */ /* PUBLIC */ void fast_set_defaults(void) { fast_set_symbol('=', 2); fast_set_symbol('m', 2); fast_set_symbol('j', 2); fast_set_symbol('f', 2); fast_set_symbol('d', 2); fast_set_symbol('*', 2); fast_set_symbol('+', 2); fast_set_symbol('/', 2); fast_set_symbol('c', 1); fast_set_symbol('g', 1); fast_set_symbol('i', 1); fast_set_symbol('-', 1); fast_set_symbol('~', 1); fast_set_symbol('\'', 1); } /* fast_set_defaults */ /************* * * fast_parse() * *************/ static Term fast_parse(char *s) { char c = s[Pos++]; Term t; if (c >= 'r' && c <= 'z') { switch (c) { case 'z': t = get_variable_term(0); break; case 'y': t = get_variable_term(1); break; case 'x': t = get_variable_term(2); break; case 'w': t = get_variable_term(3); break; case 'v': t = get_variable_term(4); break; case 'u': t = get_variable_term(5); break; case 't': t = get_variable_term(6); break; case 's': t = get_variable_term(7); break; case 'r': t = get_variable_term(8); break; default: t = NULL; } return t; } else { int i; if (Symnum[(int) c] == 0) { /* Undeclared symbol; make it a constant. */ char str[2]; str[0] = c; str[1] = '\0'; Symnum[(int) c] = str_to_sn(str, 0); } t = get_rigid_term_dangerously(Symnum[(int) c], Arity[(int) c]); for (i = 0; i < Arity[(int) c]; i++) { ARG(t,i) = fast_parse(s); } return t; } } /* fast_parse */ /************* * * fast_read_term() * *************/ /* DOCUMENTATION This routine reads a prefix term.
  • The term must start on a new line and end with a period.
  • Without parentheses, commas, or spaces.
  • Each symbol is one character.
  • Variables are 'r' -- 'z'.
  • Symbols with arity > 0 (including '=') must declared first by calling fast_set_symbol().
  • If the first character is '%', the line is a comment and sent directly to the output stream fout.
  • Example:
    =mxxx.
    =jxyjyx.
    =jxxmxx.
    =jjxyzjxjyz.
    
*/ /* PUBLIC */ Term fast_read_term(FILE *fin, FILE *fout) { char line[MAX_LINE]; char *s; Term t; s = fgets(line, MAX_LINE, fin); while (s != NULL && s[0] == '%') { /* send comment lines to stdout */ fprintf(stdout, "%s", s); fflush(stdout); s = fgets(line, MAX_LINE, fin); } if (s == NULL) return NULL; else { Pos = 0; t = fast_parse(s); if (s[Pos] != '.') { fprintf(stderr, s); fprintf(stdout, s); fatal_error("fast_read_term, term ends before period."); } return t; } } /* fast_read_term */ /************* * * fast_fwrite_term() * *************/ static void fast_fwrite_term(FILE *fp, Term t) { char c; if (VARIABLE(t)) { switch (VARNUM(t)) { case 0: c = 'z'; break; case 1: c = 'y'; break; case 2: c = 'x'; break; case 3: c = 'w'; break; case 4: c = 'v'; break; case 5: c = 'u'; break; case 6: c = 't'; break; case 7: c = 's'; break; case 8: c = 'r'; break; default: c = '?'; break; } fprintf(fp, "%c", c); } else { int i; fprintf(fp, "%s", sn_to_str(SYMNUM(t))); for (i = 0; i < ARITY(t); i++) fast_fwrite_term(fp, ARG(t,i)); } } /* fast_fwrite_term */ /************* * * fast_fwrite_term_nl() * *************/ /* DOCUMENTATION This routine writes a term in prefix form, without parentheses, commas, or spaces, followed by ".\n". If a variable number is >= 9, then '?' is printed for that variable.

If each symbol is one character, then terms written by this routine should be readable by fast_read_term().

There is nothing particularly "fast" about this routine. */ /* PUBLIC */ void fast_fwrite_term_nl(FILE *fp, Term t) { fast_fwrite_term(fp, t); fprintf(fp, ".\n"); } /* fast_fwrite_term_nl */ /************* * * fast_read_clause() * *************/ /* DOCUMENTATION This routine reads a clause in fast-parse form.

If the clause has more than one literal, then '|' must first be declared as binary with fast_set_symbol(), and if the clause has any negative literals, then '~' must first be declared as unary.

For example, the fast-parse form of p(a,b) | ~q | ~(f(x)=x) is

|pab|~q~=fxx.
*/ /* PUBLIC */ Topform fast_read_clause(FILE *fin, FILE *fout) { /* This is different from read_clause() in the following way. Read_clause() first calls read_term(), which does NOT set variables. Variables are set after term_to_clause(). Fast_read_clause() first calls fast_read_term(), which DOES set variables, so a call to clause_set_variables() is not needed. */ Term t; t = fast_read_term(fin, fout); if (t == NULL) return NULL; else { Topform c = term_to_clause(t); zap_term(t); upward_clause_links(c); return c; } } /* fast_read_clause */ /************* * * fast_fwrite_clause() * *************/ /* DOCUMENTATION This routine writes a clause in fastparse form. */ /* PUBLIC */ void fast_fwrite_clause(FILE *fp, Topform c) { Term t = topform_to_term(c); if (t == NULL) fatal_error("fwrite_clause, clause_to_term returns NULL."); fast_fwrite_term_nl(fp, t); fflush(fp); zap_term(t); } /* fast_fwrite_clause */ LADR-2009-11A/ladr/clash.h0000644000175000017500000000356111151265364014214 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLASH_H #define TP_CLASH_H #include "mindex.h" #include "parautil.h" /* INTRODUCTION This package deals with clash structures, which are used for binary resolution, hyperresolution, and UR-resolution. The inference rule sets up a clash list (corresponding to the nucleus), and then calls clash() to compute all of the resolvents. */ /* Public definitions */ typedef struct clash * Clash; struct clash { BOOL clashable; BOOL clashed; BOOL flipped; /* Is nuc_lit or sat_lit a flipped equality? */ Literals nuc_lit; Context nuc_subst; Literals sat_lit; Context sat_subst; Mindex mate_index; Mindex_pos mate_pos; Clash next; }; /* End of public definitions */ /* Public function prototypes from clash.c */ void fprint_clash_mem(FILE *fp, BOOL heading); void p_clash_mem(); Clash append_clash(Clash p); void zap_clash(Clash p); Literals atom_to_literal(Term atom); Literals apply_lit(Literals lit, Context c); void clash(Clash c, BOOL (*sat_test) (Literals), Just_type rule, void (*proc_proc) (Topform)); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/flatterm.h0000644000175000017500000000521011167671414014735 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FLATTERM_H #define TP_FLATTERM_H #include "term.h" /* INTRODUCTION

The Term macros VARIABLE(f), CONSTANT(f), COMPLEX(f), SYMNUM(f), VARNUM(f), ARITY(f) are used for Flatterms as well. The Term macro ARG(t,i) is NOT used for Flatterms.

Traversing Flatterms. It can be done recursively or iteratively. When building flatterms, recursive is better, because you have to make a Flatterm point to its end. Iterative: Flatterm fi; for (f = fi; fi != f->end->next; fi = fi->next) ... Recursive: int i; Flatterm fi = f->next; for (i = 0; i < ARITY(f); i++) { ... fi = fi->end->next; } */ /* Public definitions */ typedef struct flatterm * Flatterm; struct flatterm { short private_symbol; /* const/func/pred/var symbol ID */ unsigned char arity; /* number of auguments */ Flatterm prev, next, end; /* The rest of the fields are for index retrieval and demodulation. */ int size; /* symbol count */ struct discrim *alternative; /* subtree to try next */ int varnum_bound_to; /* -1 for not bound */ BOOL reduced_flag; /* fully demodulated */ }; /* End of public definitions */ /* Public function prototypes from flatterm.c */ Flatterm get_flatterm(void); void free_flatterm(Flatterm p); void fprint_flatterm_mem(FILE *fp, BOOL heading); void p_flatterm_mem(); BOOL flatterm_ident(Flatterm a, Flatterm b); void zap_flatterm(Flatterm f); Flatterm term_to_flatterm(Term t); Term flatterm_to_term(Flatterm f); Flatterm copy_flatterm(Flatterm f); void print_flatterm(Flatterm f); int flatterm_symbol_count(Flatterm f); void p_flatterm(Flatterm f); BOOL flat_occurs_in(Flatterm t1, Flatterm t2); I2list flat_multiset_vars(Flatterm f); BOOL flat_variables_multisubset(Flatterm a, Flatterm b); int flatterm_count_without_vars(Flatterm f); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clause_misc.h0000644000175000017500000000272211151265364015407 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSE_MISC_H #define TP_CLAUSE_MISC_H #include "clist.h" #include "mindex.h" #include "just.h" #include "basic.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from clause_misc.c */ Clist clist_copy(Clist a, BOOL assign_ids); Clist copy_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids); Clist move_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids); Plist input_clauses(Plist a); void delete_clause(Topform c); void delete_clist(Clist l); Topform copy_clause_ija(Topform c); Plist copy_clauses_ija(Plist p); void delete_clauses(Plist p); void make_clause_basic(Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/cnf.c0000644000175000017500000005435310637466321013674 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "cnf.h" #include /* Yikes! */ #include #include /* The following has an optimization in which formulas are shared. The main benefit of this is that when checking for identical formulas, we can compare pointers instead of traversing the formulas. Another benefit is that when copying formulas (i.e., applying distributivity), we can copy pointers instead of whole formulas. The routine consolidate_formula() causes some subformulas to be shared. It is currently applied to quantifier-free nnf formulas. shared: ATOM, NOT not shared: AND, OR, ALL, EXISTS */ /* Private definitions and types */ static jmp_buf Jump_env; /* for setjmp/longjmp */ static unsigned Fid_call_limit = UINT_MAX; static unsigned Fid_calls = 0; /************* * * share_formula() * *************/ static Formula share_formula(Formula f, Hashtab h) { if (f->type == AND_FORM || f->type == OR_FORM || f->type == ALL_FORM || f->type == EXISTS_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = share_formula(f->kids[i], h); return f; } else { unsigned hashval; Formula g; if (f->type == NOT_FORM) f->kids[0] = share_formula(f->kids[0], h); hashval = hash_formula(f); g = hash_lookup(f, hashval, h, (BOOL (*)(void *, void *)) formula_ident); if (g) { zap_formula(f); g->excess_refs++; return g; } else { hash_insert(f, hashval, h); return f; } } } /* share_formula */ /************* * * consolidate_formula() * *************/ static Formula consolidate_formula(Formula f) { Hashtab h = hash_init(10000); f = share_formula(f, h); /* hash_info(h); */ hash_destroy(h); return f; } /* consolidate_formula */ /************* * * formula_ident_share() * *************/ /* DOCUMENTATION This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality. */ /* PUBLIC */ BOOL formula_ident_share(Formula f, Formula g) { if (Fid_call_limit != 0 && ++Fid_calls > Fid_call_limit) { printf("\n%% Fid_call limit; jumping home.\n"); longjmp(Jump_env, 1); } if (f->type != g->type || f->arity != g->arity) return FALSE; else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) if (!formula_ident_share(f->kids[i], g->kids[i])) return FALSE; return TRUE; } else if (f->type == ALL_FORM || f->type == EXISTS_FORM) { return str_ident(f->qvar, g->qvar) && formula_ident_share(f->kids[0], g->kids[0]); } else return f == g; } /* formula_ident_share */ /************* * * formula_copy_share() * *************/ /* DOCUMENTATION This function returns a copy of the given formula. All subformulas, including the atoms, are copied. */ /* PUBLIC */ Formula formula_copy_share(Formula f) { if (f->type == AND_FORM || f->type == OR_FORM) { Formula g = formula_get(f->arity, f->type); int i; for (i = 0; i < f->arity; i++) g->kids[i] = formula_copy_share(f->kids[i]); return g; } else if (f->type == ALL_FORM || f->type == EXISTS_FORM) { Formula g = formula_get(1, f->type); g->qvar = f->qvar; g->kids[0] = formula_copy_share(f->kids[0]); return g; } else { f->excess_refs++; return f; } } /* formula_copy_share */ /************* * * complementary_share() * *************/ static BOOL complementary_share(Formula a, Formula b) { return (a->type == NOT_FORM && formula_ident_share(a->kids[0], b)) || (b->type == NOT_FORM && formula_ident_share(a, b->kids[0])); } /* complementary_share */ /************* * * contains_complements_share() * * Assume AND_FORM or OR_FORM. * *************/ static BOOL contains_complements_share(Formula f) { int i, j; for (i = 0; i < f->arity-1; i++) { for (j = i+1; j < f->arity; j++) { if (complementary_share(f->kids[i], f->kids[j])) return TRUE; } } return FALSE; } /* contains_complements_share */ /************* * * prop_member_share() -- is f an argument of g? * *************/ static BOOL prop_member_share(Formula f, Formula g) { int i; for (i = 0; i < g->arity; i++) if (formula_ident_share(f, g->kids[i])) return TRUE; return FALSE; } /* prop_member_share */ /************* * * prop_subset_share() -- are the arguments of f a subset of the arguments of g? * *************/ static BOOL prop_subset_share(Formula f, Formula g) { int i; for (i = 0; i < f->arity; i++) if (!prop_member_share(f->kids[i], g)) return FALSE; return TRUE; } /* prop_subset_share */ /************* * * prop_subsume_share() * * Assume disjunctions, atomic, TRUE, or FALSE * *************/ static BOOL prop_subsume_share(Formula f, Formula g) { if (FALSE_FORMULA(f)) return TRUE; else if (TRUE_FORMULA(g)) return TRUE; else if (g->type == OR_FORM) { if (f->type == OR_FORM) return prop_subset_share(f, g); else return prop_member_share(f, g); } return formula_ident_share(f, g); } /* prop_subsume_share */ /************* * * remove_subsumed_share() * * Assume flat conjunction. Always return conjunction. * *************/ static Formula remove_subsumed_share(Formula f) { if (f->type != AND_FORM) return f; else { Formula h; int new_arity = f->arity; int i, j; for (i = 0; i < f->arity; i++) { for (j = i+1; j < f->arity; j++) { if (f->kids[i] && f->kids[j] && prop_subsume_share(f->kids[i], f->kids[j])) { zap_formula(f->kids[j]); f->kids[j] = NULL; new_arity--; } else if (f->kids[i] && f->kids[j] && prop_subsume_share(f->kids[j], f->kids[i])) { zap_formula(f->kids[i]); f->kids[i] = NULL; new_arity--; } } } h = formula_get(new_arity, AND_FORM); j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]) h->kids[j++] = f->kids[i]; } free_formula(f); return h; } } /* remove_subsumed_share */ /************* * * bbt() * *************/ static Formula bbt(Formula f, int start, int end) { if (start == end) return f->kids[start]; else { int mid = (start + end) / 2; Formula b = formula_get(2, f->type); b->kids[0] = bbt(f, start, mid); b->kids[1] = bbt(f, mid+1, end); return b; } } /* bbt */ /************* * * balanced_binary() * * Take a flat OR or AND, and make it into a balanced binary tree. * *************/ static Formula balanced_binary(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else if (f->arity == 0) return f; else { Formula b = bbt(f, 0, f->arity-1); free_formula(f); return b; } } /* balanced_binary */ /************* * * disjoin_flatten_simplify(a, b) a OR b * * Remove duplicates; if it contains complements, return TRUE. * *************/ static Formula disjoin_flatten_simplify(Formula a, Formula b) { Formula c; int new_arity, i, j; a = make_disjunction(a); b = make_disjunction(b); new_arity = a->arity + b->arity; for (i = 0; i < a->arity; i++) { for (j = 0; j < b->arity; j++) { if (b->kids[j] != NULL) { if (complementary_share(a->kids[i], b->kids[j])) { zap_formula(a); zap_formula(b); /* this can handle NULL kids */ return formula_get(0, AND_FORM); /* TRUE formula */ } else if (formula_ident_share(a->kids[i], b->kids[j])) { /* Note that this makes b non-well-formed. */ zap_formula(b->kids[j]); /* really FALSE */ b->kids[j] = NULL; new_arity--; } } } } c = formula_get(new_arity, OR_FORM); j = 0; for (i = 0; i < a->arity; i++) c->kids[j++] = a->kids[i]; for (i = 0; i < b->arity; i++) if (b->kids[i] != NULL) c->kids[j++] = b->kids[i]; free_formula(a); free_formula(b); return c; } /* disjoin_flatten_simplify */ /************* * * simplify_and_share() * * Assume flattened conjunction, and all kids are simplified flat * disjunctions (or atomic, TRUE, FALSE). * * *************/ static Formula simplify_and_share(Formula f) { if (f->type != AND_FORM) return f; else { f = remove_subsumed_share(f); /* still AND */ if (f->arity == 1) { Formula g = f->kids[0]; free_formula(f); return g; } else if (contains_complements_share(f)) { zap_formula(f); return formula_get(0, OR_FORM); /* FALSE */ } else return f; } } /* simplify_and_share */ /************* * * distribute_top() * * Assume it's a binary disjunction. * *************/ static Formula distribute_top(Formula h) { Formula f = h->kids[0]; Formula g = h->kids[1]; int arity, i, j, k; Formula a; free_formula(h); /* If not conjunctions, make them so. */ f = make_conjunction(f); g = make_conjunction(g); /* printf("DT: %5d x %5d\n", f->arity, g->arity); fflush(stdout); */ arity = f->arity * g->arity; a = formula_get(arity, AND_FORM); k = 0; for (i = 0; i < f->arity; i++) { for (j = 0; j < g->arity; j++) { Formula fi = formula_copy_share(f->kids[i]); Formula gj = formula_copy_share(g->kids[j]); a->kids[k++] = disjoin_flatten_simplify(fi, gj); } } zap_formula(f); zap_formula(g); a = simplify_and_share(a); return a; } /* distribute_top */ /************* * * distribute() * *************/ static Formula distribute(Formula f) { if (f->type != OR_FORM || f->arity == 0) return f; else { if (f->arity != 2) fatal_error("distribute: not binary"); f->kids[0] = distribute(f->kids[0]); f->kids[1] = distribute(f->kids[1]); f = distribute_top(f); return f; } } /* distribute */ /************* * * cnf() * * Assume NNF and flattened. * * This does not go below quantifiers; that is, * quantified formulas are treated as atomic. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula cnf(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = cnf(f->kids[i]); if (f->type == AND_FORM) { f = flatten_top(f); f = simplify_and_share(f); return f; } else { /* OR_FORM */ f = dual(remove_subsumed_share(dual(f))); f = balanced_binary(f); /* make the top OR-tree binary */ f = distribute(f); return f; } } } /* cnf */ /************* * * dnf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula dnf(Formula f) { return dual(cnf(dual(f))); } /* dnf */ /************* * * skolem() * *************/ static Formula skolem(Formula f, Ilist uvars) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return f; else if (f->type == ALL_FORM) { Term var = get_rigid_term(f->qvar, 0); Ilist uvars_plus; if (ilist_member(uvars, SYMNUM(var))) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = gen_new_symbol("x", 0, uvars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } uvars_plus = ilist_prepend(uvars, SYMNUM(var)); f->kids[0] = skolem(f->kids[0], uvars_plus); free_term(var); free_ilist(uvars_plus); /* frees first node only; uvars still good */ return f; } else if (f->type == EXISTS_FORM) { Formula g; int n = ilist_count(uvars); int sn = next_skolem_symbol(n); Term sk = get_rigid_term(sn_to_str(sn), n); Term evar = get_rigid_term(f->qvar, 0); Ilist p; int i; /* uvars is backward */ for (p = uvars, i = n-1; p; p = p->next, i--) ARG(sk,i) = get_rigid_term(sn_to_str(p->i), 0); subst_free_var(f->kids[0], evar, sk); zap_term(sk); zap_term(evar); g = skolem(f->kids[0], uvars); free_formula(f); return g; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) { f->kids[i] = skolem(f->kids[i], uvars); } return f; } else { /* Not in NNF! Let the caller beware! */ return f; } } /* skolem */ /************* * * skolemize() * *************/ /* DOCUMENTATION This routine Skolemizes an NNF formula. The quantified variables need not be named in any particular way. If there are universally quantified variables with the same name, one in the scope of another, the inner variable will be renamed. (Existential nodes are removed.) */ /* PUBLIC */ Formula skolemize(Formula f) { f = skolem(f, NULL); return f; } /* skolemize */ /************* * * unique_qvars() * *************/ static Ilist unique_qvars(Formula f, Ilist vars) { if (f->type == ATOM_FORM) return vars; else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); if (ilist_member(vars, SYMNUM(var))) { /* Rename this variable. */ int sn = gen_new_symbol("x", 0, vars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } vars = ilist_prepend(vars, SYMNUM(var)); return unique_qvars(f->kids[0], vars); } else { int i; for (i = 0; i < f->arity; i++) vars = unique_qvars(f->kids[i], vars); return vars; } } /* unique_qvars */ /************* * * unique_quantified_vars() * *************/ /* DOCUMENTATION Rename quantified variables, if necessary, so that each is unique. This works for any formula.

If you wish to rename a quantified variable only if it occurs in the scope of of a quantified variable with the same name, you can use the routine eliminate_rebinding() instead.

(This could be a void routine, because none of the formula nodes is changed.) */ /* PUBLIC */ Formula unique_quantified_vars(Formula f) { Ilist uvars = unique_qvars(f, NULL); zap_ilist(uvars); return f; } /* unique_quantified_vars */ /************* * * mark_free_vars_formula() * *************/ /* Replace all free occurrences of CONSTANT *varname with * a VARIABLE of index varnum. */ static void mark_free_vars_formula(Formula f, char *varname, int varnum) { if (f->type == ATOM_FORM) f->atom = subst_var_term(f->atom, str_to_sn(varname, 0), varnum); else if (quant_form(f) && str_ident(f->qvar, varname)) return; else { int i; for (i = 0; i < f->arity; i++) mark_free_vars_formula(f->kids[i], varname, varnum); } } /* mark_free_vars_formula */ /************* * * remove_uni_quant() * *************/ static Formula remove_uni_quant(Formula f, int *varnum_ptr) { if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = remove_uni_quant(f->kids[i], varnum_ptr); return f; } else if (f->type == ALL_FORM) { Formula g = f->kids[0]; mark_free_vars_formula(g, f->qvar, *varnum_ptr); *varnum_ptr += 1; free_formula(f); return remove_uni_quant(g, varnum_ptr); } else { /* If not ATOM_FORM, something's probably wrong, * but let the caller beware! */ return f; } } /* remove_uni_quant */ /************* * * remove_universal_quantifiers() * *************/ /* DOCUMENTATION For each universally quantified variable in the given formula, */ /* PUBLIC */ Formula remove_universal_quantifiers(Formula f) { int varnum = 0; return remove_uni_quant(f, &varnum); } /* remove_universal_quantifiers */ /************* * * clausify_prepare() * *************/ /* DOCUMENTATION This routine gets a formula all ready for translation into clauses. The sequence of transformations is

  • change to negation normal form;
  • propositional simplification;
  • make the universally quantified variables unique;
  • skolemize (nothing fancy here);
  • remove universal quantifiers, changing the constants-which-represent-variables into genuine variables;
  • change to conjunctive normal form (with basic propositional simplification).
The caller should not refer to the given formula f after the call; A good way to call is f = clausify_prepare(f) */ /* PUBLIC */ Formula clausify_prepare(Formula f) { formula_canon_eq(f); f = nnf(f); f = unique_quantified_vars(f); f = skolemize(f); f = remove_universal_quantifiers(f); f = formula_flatten(f); f = consolidate_formula(f); /* causes sharing of some subformulas */ #if 0 printf("%% CNF translation, nnf_size=%d, ", formula_size(f)); fflush(stdout); #endif f = cnf(f); #if 0 printf("cnf_size=%d, cnf_clauses=%d\n", formula_size(f), f->type == AND_FORM ? f->arity : 1); fflush(stdout); #endif return f; } /* clausify_prepare */ /************* * * ms_free_vars() * *************/ static Formula ms_free_vars(Formula f) { /* f is ALL_FORM, kids are rms, kids not AND_FORM */ Formula child = f->kids[0]; if (child->type != OR_FORM) { if (free_variable(f->qvar, child)) return f; else { free_formula(f); return child; } } else { Plist free = NULL; /* children with qvar free */ Plist notfree = NULL; /* children without qvar free */ int free_count = 0; /* size of free */ int notfree_count = 0; /* size of notfree */ int i; for (i = child->arity-1; i >= 0; i--) { if (!free_variable(f->qvar, child->kids[i])) { notfree = plist_prepend(notfree, child->kids[i]); notfree_count++; } else { free = plist_prepend(free, child->kids[i]); free_count++; } } if (notfree_count == 0) return f; /* all children have qvar free */ else if (free_count == 0) { free_formula(f); return child; /* no child has qvar free */ } else { Formula or_free = formula_get(free_count , OR_FORM); Formula or_top = formula_get(notfree_count + 1 , OR_FORM); Plist p; for (p = free, i = 0; p; p = p->next, i++) or_free->kids[i] = p->v; for (p = notfree, i = 0; p; p = p->next, i++) or_top->kids[i] = p->v; or_top->kids[i] = f; f->kids[0] = or_free; free_formula(child); return or_top; } } } /* ms_free_vars */ /************* * * miniscope() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula miniscope(Formula f) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return f; if (f->type == AND_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = miniscope(f->kids[i]); f = flatten_top(f); f = simplify_and_share(f); return f; } else if (f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = miniscope(f->kids[i]); f = flatten_top(f); f = dual(remove_subsumed_share(dual(f))); f = balanced_binary(f); /* make the top OR-tree binary */ f = distribute(f); return f; } else if (f->type == EXISTS_FORM) { f = dual(f); f = miniscope(f); f = dual(f); return f; } else if (f->type == ALL_FORM) { f->kids[0] = miniscope(f->kids[0]); if (f->kids[0]->type == AND_FORM) { /* distribute all to children */ int i; Formula and = f->kids[0]; free_formula(f); /* shallow */ for (i = 0; i < and->arity; i++) { Formula g = get_quant_form(ALL_FORM, f->qvar, and->kids[i]); g = ms_free_vars(g); and->kids[i] = g; } return and; /* need to simplify first? */ } else { f = ms_free_vars(f); return f; } } /* ALL */ else { fatal_error("miniscope: formula not in nnf"); return NULL; /* to please the complier */ } } /* miniscope */ /************* * * miniscope_formula() * *************/ typedef void (*sighandler_t)(int); /* DOCUMENTATION */ /* PUBLIC */ Formula miniscope_formula(Formula f, unsigned mega_fid_call_limit) { int return_code; if (mega_fid_call_limit <= 0) Fid_call_limit = 0; /* no limit */ else { Fid_call_limit = mega_fid_call_limit * 1000000; Fid_calls = 0; } return_code = setjmp(Jump_env); if (return_code != 0) { /* We just landed from longjmp(), because the limit was exceeded. (I'd like to reclaim the formula memory, but that would take some thought, because the partly transformed formula is not well formed.) */ Fid_call_limit = 0; /* no limit */ return NULL; } else { /* ordinary execution */ Formula f2 = NULL; formula_canon_eq(f); /* canonicalize (naively) eqs for maximum sharing */ f = nnf(f); f = formula_flatten(f); f = consolidate_formula(f); /* share some subformulas */ f = miniscope(f); /* do the work */ /* return a formula without shared subformulas */ f2 = formula_copy(f); zap_formula(f); Fid_call_limit = 0; /* no limit */ return f2; } } /* miniscope_formula */ /************* * * cnf_max_clauses() * *************/ /* DOCUMENTATION Given an NNF formula, return the maximum number of clauses that it can produce. (The maximum happens if no simplification occurs.) */ /* PUBLIC */ int cnf_max_clauses(Formula f) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return 1; else if (f->type == ALL_FORM || f->type == EXISTS_FORM) return cnf_max_clauses(f->kids[0]); else if (f->type == AND_FORM) { int i; int n = 0; for (i = 0; i < f->arity; i++) n += cnf_max_clauses(f->kids[i]); return n; } else if (f->type == OR_FORM) { int i; int n = 1; for (i = 0; i < f->arity; i++) n *= cnf_max_clauses(f->kids[i]); return n; } else { fatal_error("cnf_max_clauses, formula not NNF"); return -1; /* won't happen */ } } /* cnf_max_clauses */ LADR-2009-11A/ladr/cnf.h0000644000175000017500000000264211151265364013667 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CNF_H #define TP_CNF_H #include "formula.h" #include "clock.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from cnf.c */ BOOL formula_ident_share(Formula f, Formula g); Formula formula_copy_share(Formula f); Formula cnf(Formula f); Formula dnf(Formula f); Formula skolemize(Formula f); Formula unique_quantified_vars(Formula f); Formula remove_universal_quantifiers(Formula f); Formula clausify_prepare(Formula f); Formula miniscope(Formula f); Formula miniscope_formula(Formula f, unsigned mega_fid_call_limit); int cnf_max_clauses(Formula f); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/int_code.h0000644000175000017500000000220111151265364014674 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_INT_CODE_H #define TP_INT_CODE_H #include "just.h" #include "ibuffer.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from int_code.c */ void put_clause_to_ibuf(Ibuffer ibuf, Topform c); Topform get_clause_from_ibuf(Ibuffer ibuf); void check_ibuf_clause(Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/interp.h0000644000175000017500000000704211151265364014421 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_INTERP_H #define TP_INTERP_H #include "parse.h" #include "topform.h" /* INTRODUCTION */ /* Public definitions */ typedef struct interp *Interp; enum { SEMANTICS_NOT_EVALUATED, SEMANTICS_NOT_EVALUABLE, SEMANTICS_TRUE, SEMANTICS_FALSE }; /* End of public definitions */ /* Public function prototypes from interp.c */ void fprint_interp_mem(FILE *fp, BOOL heading); void p_interp_mem(); int int_power(int n, int exp); Interp compile_interp(Term t, BOOL allow_incomplete); void transpose_binary(Term t); void zap_interp(Interp p); void fprint_interp_tex(FILE *fp, Interp p); void fprint_interp_xml(FILE *fp, Interp p); void fprint_interp_standard(FILE *fp, Interp p); void fprint_interp_standard2(FILE *fp, Interp p); void fprint_interp_portable(FILE *fp, Interp p); void p_interp(Interp p); void fprint_interp_cooked(FILE *fp, Interp p); void fprint_interp_tabular(FILE *fp, Interp p); void fprint_interp_raw(FILE *fp, Interp p); int eval_term_ground(Term t, Interp p, int *vals); BOOL eval_literals(Literals lits, Interp p); int eval_literals_true_instances(Literals lits, Interp p); int eval_literals_false_instances(Literals lits, Interp p); BOOL eval_formula(Formula f, Interp p); Term interp_remove_constants_recurse(Term ops); void interp_remove_constants(Term t); Term interp_remove_others_recurse(Term ops, Plist keepers); void interp_remove_others(Term t, Plist keepers); Interp copy_interp(Interp p); Interp permute_interp(Interp source, int *p); BOOL ident_interp_perm(Interp a, Interp b, int *p); Interp normal_interp(Interp a); BOOL isomorphic_interps(Interp a, Interp b, BOOL normal); int interp_size(Interp a); Term interp_comments(Interp a); int *interp_table(Interp p, char *sym, int arity); long unsigned iso_checks(void); long unsigned iso_perms(void); BOOL evaluable_term(Term t, Interp p); BOOL evaluable_atom(Term a, Interp p); BOOL evaluable_literals(Literals lits, Interp p); BOOL evaluable_formula(Formula f, Interp p); BOOL evaluable_topform(Topform tf, Interp p); void update_interp_with_constant(Interp p, Term constant, int val); BOOL eval_topform(Topform tf, Interp p); Ordertype compare_interp(Interp a, Interp b); BOOL ident_interp(Interp a, Interp b); Interp canon_interp(Interp a); void assign_discriminator_counts(Interp a, Plist discriminators); BOOL same_discriminator_counts(Interp a, Interp b); void update_profile(Topform c, Interp a, int *next); /* vecs[domain_element][profile_component] */ void create_profile(Interp a, Plist discriminators); void p_interp_profile(Interp a, Plist discriminators); Interp normal3_interp(Interp a, Plist discriminators); BOOL same_profiles(Interp a, Interp b); long unsigned perms_required(Interp a); long unsigned factorial(int n); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/backdemod.c0000644000175000017500000001315710637466321015034 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "backdemod.h" /* Private definitions and types */ /************* * * index_term_back_demod() * *************/ static void index_term_back_demod(Term t, Mindex idx, Indexop op) { if (!VARIABLE(t)) { int i; mindex_update(idx, t, op); for (i = 0; i < ARITY(t); i++) index_term_back_demod(ARG(t,i), idx, op); } } /* index_term_back_demod */ /************* * * index_clause_back_demod() * *************/ /* DOCUMENTATION This routine indexes or unindexes a clause for back demodulation. */ /* PUBLIC */ void index_clause_back_demod(Topform c, Mindex idx, Indexop op) { Literals lit; for (lit = c->literals; lit != NULL; lit = lit->next) { Term atom = lit->atom; int i; for (i = 0; i < ARITY(atom); i++) { index_term_back_demod(ARG(atom,i), idx, op); } } } /* index_clause_back_demod */ /************* * * rewritable_term() * *************/ static BOOL rewritable_term(Term alpha, Term t, Context subst) { Trail tr = NULL; if (match(alpha, subst, t, &tr)) { undo_subst(tr); return TRUE; } else { int i; BOOL ok = FALSE; for (i = 0; i < ARITY(t) && !ok; i++) ok = rewritable_term(alpha, ARG(t,i), subst); return ok; } } /* rewritable_term */ /************* * * rewritable_clause() * *************/ /* DOCUMENTATION This Boolean function checks if Topform c is can be rewritten by Topform demod, which is assumed to be an oriented (left-to-right) equation. */ /* PUBLIC */ BOOL rewritable_clause(Topform demod, Topform c) { Term alpha = ARG(demod->literals->atom,0); Literals lit; BOOL ok = FALSE; Context subst = get_context(); for (lit = c->literals; lit != NULL && !ok; lit = lit->next) { Term atom = lit->atom; int i; for (i = 0; i < ARITY(atom) && !ok; i++) ok = rewritable_term(alpha, ARG(atom,i), subst); } free_context(subst); return ok; } /* rewritable_clause */ /************* * * back_demod_linear() * *************/ /* DOCUMENTATION This routine returns a Plist: the subset of Clist lst that can be rewritten with Topform demod (which is assumed to be an oriented equation). The Plist which is returned is ordered by decreasing clause ID. */ /* PUBLIC */ Plist back_demod_linear(Topform demod, Clist lst, Plist rewritables) { Clist_pos p; for (p = lst->first; p != NULL; p = p->next) { Topform c = p->c; if (c != demod && rewritable_clause(demod, c)) { rewritables = insert_clause_into_plist(rewritables, c, FALSE); } } return(rewritables); } /* back_demod_linear */ /************* * * lex_rewritable() * *************/ static BOOL lex_rewritable(Term subject, Context subst, Term gen, BOOL lex_order_vars) { /* Apply subst to gen, and check if it's less than subject. */ Term instance = apply(gen, subst); BOOL result = term_greater(subject, instance, lex_order_vars); zap_term(instance); return result; } /* lex_rewritable */ /************* * * back_demod_indexed() * *************/ /* DOCUMENTATION This routine returns a Plist: the set clauses that have terms that can be rewritten with Topform demod.

If demod is oriented, demodulation is assumed to be left-to-right. If demod is not oriented, either way is allowed.

The Plist which is returned is ordered by decreasing clause ID. */ /* PUBLIC */ Plist back_demod_indexed(Topform demod, int type, Mindex idx, BOOL lex_order_vars) { Term atom = demod->literals->atom; Term alpha = ARG(atom,0); Term beta = ARG(atom,1); Plist rewritables = NULL; Context subst = get_context(); if (type == ORIENTED) { Mindex_pos pos; Term t = mindex_retrieve_first(alpha,idx,INSTANCE,subst,NULL,FALSE,&pos); while (t != NULL) { Topform c = t->container; if (c != demod) { /* in case demod is already in idx */ rewritables = insert_clause_into_plist(rewritables, c, FALSE); } t = mindex_retrieve_next(pos); } } else { if (type == LEX_DEP_LR || type == LEX_DEP_BOTH) { Mindex_pos pos; Term t; /* Find clauses that can be rewritten left-to-right. */ t = mindex_retrieve_first(alpha,idx,INSTANCE,subst,NULL,FALSE,&pos); while (t != NULL) { Topform c = t->container; if (c != demod && lex_rewritable(t, subst, beta, lex_order_vars)) { rewritables = insert_clause_into_plist(rewritables, c, FALSE); } t = mindex_retrieve_next(pos); } } if (type == LEX_DEP_RL || type == LEX_DEP_BOTH) { Mindex_pos pos; Term t; /* Find clauses that can be rewritten right-to-left. */ t = mindex_retrieve_first(beta,idx,INSTANCE,subst,NULL,FALSE,&pos); while (t != NULL) { Topform c = t->container; if (c != demod && lex_rewritable(t, subst, alpha, lex_order_vars)) { rewritables = insert_clause_into_plist(rewritables, c, FALSE); } t = mindex_retrieve_next(pos); } } } free_context(subst); return rewritables; } /* back_demod_indexed */ LADR-2009-11A/ladr/hints.c0000644000175000017500000002017211073744026014237 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "hints.h" /* Private definitions and types */ static Lindex Hints_idx = NULL; /* FPA index for hints */ static Clist Redundant_hints = NULL; /* list of hints not indexed */ static Mindex Back_demod_idx; /* to index hints for back demodulation */ static int Bsub_wt_attr; static BOOL Back_demod_hints; static BOOL Collect_labels; /* pointer to procedure for demodulating hints (when back demod hints) */ static void (*Demod_proc) (Topform, int, int, BOOL, BOOL); /* stats */ static int Hint_id_count = 0; static int Active_hints_count = 0; static int Redundant_hints_count = 0; /************* * * init_hints() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_hints(Uniftype utype, int bsub_wt_attr, BOOL collect_labels, BOOL back_demod_hints, void (*demod_proc) (Topform, int, int, BOOL, BOOL)) { Bsub_wt_attr = bsub_wt_attr; Collect_labels = collect_labels; Back_demod_hints = back_demod_hints; Demod_proc = demod_proc; Hints_idx = lindex_init(FPA, utype, 10, FPA, utype, 10); if (Back_demod_hints) Back_demod_idx = mindex_init(FPA, utype, 10); Redundant_hints = clist_init("redundant_hints"); } /* init_hints */ /************* * * done_with_hints() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void done_with_hints(void) { if (!lindex_empty(Hints_idx) || !clist_empty(Redundant_hints)) printf("ERROR: Hints index not empty!\n"); lindex_destroy(Hints_idx); if (Back_demod_hints) mindex_destroy(Back_demod_idx); Hints_idx = NULL; clist_free(Redundant_hints); Redundant_hints = NULL; } /* done_with_hints */ /************* * * redundant_hints() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int redundant_hints(void) { return clist_length(Redundant_hints); } /* redundant_hints */ /************* * * find_equivalent_hint() * *************/ static Topform find_equivalent_hint(Topform c, Lindex idx) { Topform equiv_hint = NULL; Plist subsumees = back_subsume(c, idx); Plist p; for (p = subsumees; p && equiv_hint == NULL; p = p->next) { if (subsumes(p->v, c)) equiv_hint = p->v; } zap_plist(subsumees); return equiv_hint; } /* find_equivalent_hint */ /************* * * find_matching_hint() * * Return the first equivalent hint; if none, return the last * subsumed hint. * * "First" and "last" refer to the order returned by the index, * which is not necessarily the order in which the hints were * inserted into the index. In fact, it is likely that the * clauses are returned in the reverse order. * *************/ static Topform find_matching_hint(Topform c, Lindex idx) { Topform hint = NULL; Plist subsumees = back_subsume(c, idx); Plist p; BOOL equivalent = FALSE; for (p = subsumees; p && !equivalent; p = p->next) { /* printf("subsumee: "); f_clause(p->v); */ hint = p->v; if (subsumes(p->v, c)) equivalent = TRUE; } zap_plist(subsumees); return hint; } /* find_matching_hint */ /************* * * index_hint() * *************/ /* DOCUMENTATION Index a clause C as a hint (make sure to call init_hints first). If the clause is equivalent to a previously indexed hint H, any labels on C are copied to H, and C is not indexed. */ /* PUBLIC */ void index_hint(Topform c) { Topform h = find_equivalent_hint(c, Hints_idx); c->weight = 0; /* this is used in hints degradation to count matches */ if (h != NULL) { /* copy any bsub_hint_wt attrs from rundundant hint to the indexed hint */ h->attributes = copy_int_attribute(c->attributes, h->attributes, Bsub_wt_attr); if (Collect_labels) { /* copy any labels from rundundant hint to the indexed hint */ h->attributes = copy_string_attribute(c->attributes, h->attributes, label_att()); } clist_append(c, Redundant_hints); Redundant_hints_count++; /* printf("redundant hint: "); f_clause(c); printf(" original: "); f_clause(h); */ } else { Active_hints_count++; Hint_id_count++; c->id = Hint_id_count; /* need IDs so that back_subsume() will work */ lindex_update(Hints_idx, c, INSERT); if (Back_demod_hints) index_clause_back_demod(c, Back_demod_idx, INSERT); } } /* index_hint */ /************* * * unindex_hint() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void unindex_hint(Topform c) { if (clist_member(c, Redundant_hints)) { clist_remove(c, Redundant_hints); Redundant_hints_count--; } else { lindex_update(Hints_idx, c, DELETE); if (Back_demod_hints) index_clause_back_demod(c, Back_demod_idx, DELETE); Active_hints_count--; } } /* unindex_hint */ /************* * * adjust_weight_with_hints() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void adjust_weight_with_hints(Topform c, BOOL degrade, BOOL breadth_first_hints) { Topform hint = find_matching_hint(c, Hints_idx); if (hint == NULL && unit_clause(c->literals) && eq_term(c->literals->atom) && !oriented_eq(c->literals->atom)) { /* Try to find a hint that matches the flipped equality. */ Term save_atom = c->literals->atom; c->literals->atom = top_flip(save_atom); hint = find_matching_hint(c, Hints_idx); zap_top_flip(c->literals->atom); c->literals->atom = save_atom; if (hint != NULL) c->attributes = set_string_attribute(c->attributes, label_att(), "flip_matches_hint"); } if (hint != NULL) { int bsub_wt = get_int_attribute(hint->attributes, Bsub_wt_attr, 1); if (bsub_wt != INT_MAX) c->weight = bsub_wt; else if (breadth_first_hints) c->weight = 0; /* If the hint has label attributes, copy them to the clause. */ { int i = 0; char *s = get_string_attribute(hint->attributes, label_att(), ++i); while (s) { if (!string_attribute_member(c->attributes, label_att(), s)) c->attributes = set_string_attribute(c->attributes, label_att(), s); s = get_string_attribute(hint->attributes, label_att(), ++i); } } /* Veroff's hint degradation strategy. */ if (degrade) { /* for now, add 1000 for each previous match */ int i; for (i = 0; i < hint->weight; i++) c->weight = c->weight + 1000; } c->matching_hint = hint; /* If/when c is eventually kept, the hint will have its weight field incremented in case hint degradation is being used. */ } } /* adjust_weight_with_hints */ /************* * * keep_hint_matcher() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void keep_hint_matcher(Topform c) { Topform hint = c->matching_hint; hint->weight++; } /* keep_hint_matcher */ /************* * * back_demod_hints() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void back_demod_hints(Topform demod, int type, BOOL lex_order_vars) { if (Back_demod_hints) { Plist rewritables = back_demod_indexed(demod, type, Back_demod_idx, lex_order_vars); Plist p; for (p = rewritables; p; p = p->next) { Topform hint = p->v; /* printf("\nBEFORE: "); f_clause(hint); */ unindex_hint(hint); (*Demod_proc)(hint, 1000, 1000, FALSE, lex_order_vars); orient_equalities(hint, TRUE); simplify_literals2(hint); merge_literals(hint); renumber_variables(hint, MAX_VARS); /* printf("AFTER : "); f_clause(hint); */ index_hint(hint); hint->weight = 0; /* reset count of number of matches */ } } } /* back_demod_hints */ LADR-2009-11A/ladr/order.h0000644000175000017500000000345711151265363014240 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_ORDER_H #define TP_ORDER_H #include /* for malloc/free */ /* INTRODUCTION This package defines Ordertype and has a generic sorting routine merge_sort() that can be used to sort any kind of data. */ /* Public definitions */ /* basic order relations */ typedef enum { NOT_COMPARABLE, SAME_AS, LESS_THAN, GREATER_THAN, LESS_THAN_OR_SAME_AS, GREATER_THAN_OR_SAME_AS, NOT_LESS_THAN, NOT_GREATER_THAN } Ordertype; /* End of public definitions */ /* Public function prototypes from order.c */ void merge_sort_recurse(void *a[], /* array to sort */ void *w[], /* work array */ int start, /* index of first element */ int end, /* index of last element */ Ordertype (*comp_proc) (void *, void *)); void merge_sort(void *a[], /* array to sort */ int n, /* size of array */ Ordertype (*comp_proc) (void *, void *)); Ordertype compare_vecs(int *a, int *b, int n); void copy_vec(int *a, int *b, int n); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/ladr.h0000644000175000017500000000206711136256436014047 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "banner.h" #include "nonport.h" #include "avltree.h" #include "flatdemod.h" #include "backdemod.h" #include "compress.h" #include "weight.h" #include "hints.h" #include "clausify.h" #include "ac_redun.h" #include "int_code.h" #include "di_tree.h" #include "definitions.h" #include "dollar.h" #include "top_input.h" LADR-2009-11A/ladr/glist.c0000644000175000017500000010203011150620745014223 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "glist.h" /* * memory management */ #define PTRS_ILIST PTRS(sizeof(struct ilist)) static unsigned Ilist_gets, Ilist_frees; #define PTRS_PLIST PTRS(sizeof(struct plist)) static unsigned Plist_gets, Plist_frees; #define PTRS_I2LIST PTRS(sizeof(struct i2list)) static unsigned I2list_gets, I2list_frees; #define PTRS_I3LIST PTRS(sizeof(struct i3list)) static unsigned I3list_gets, I3list_frees; /************* * * Ilist get_ilist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist get_ilist(void) { Ilist p = get_mem(PTRS_ILIST); p->next = NULL; Ilist_gets++; return(p); } /* get_ilist */ /************* * * free_ilist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_ilist(Ilist p) { free_mem(p, PTRS_ILIST); Ilist_frees++; } /* free_ilist */ /************* * * Plist get_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist get_plist(void) { Plist p = get_mem(PTRS_PLIST); p->next = NULL; Plist_gets++; return(p); } /* get_plist */ /************* * * free_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_plist(Plist p) { free_mem(p, PTRS_PLIST); Plist_frees++; } /* free_plist */ /************* * * I2list get_i2list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list get_i2list(void) { I2list p = get_mem(PTRS_I2LIST); p->next = NULL; I2list_gets++; return(p); } /* get_i2list */ /************* * * free_i2list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_i2list(I2list p) { free_mem(p, PTRS_I2LIST); I2list_frees++; } /* free_i2list */ /************* * * I3list get_i3list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I3list get_i3list(void) { I3list p = get_mem(PTRS_I3LIST); p->next = NULL; I3list_gets++; return(p); } /* get_i3list */ /************* * * free_i3list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_i3list(I3list p) { free_mem(p, PTRS_I3LIST); I3list_frees++; } /* free_i3list */ /************* * * fprint_glist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the glist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_glist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct ilist); fprintf(fp, "ilist (%4d) %11u%11u%11u%9.1f K\n", n, Ilist_gets, Ilist_frees, Ilist_gets - Ilist_frees, ((Ilist_gets - Ilist_frees) * n) / 1024.); n = sizeof(struct plist); fprintf(fp, "plist (%4d) %11u%11u%11u%9.1f K\n", n, Plist_gets, Plist_frees, Plist_gets - Plist_frees, ((Plist_gets - Plist_frees) * n) / 1024.); n = sizeof(struct i2list); fprintf(fp, "i2list (%4d) %11u%11u%11u%9.1f K\n", n, I2list_gets, I2list_frees, I2list_gets - I2list_frees, ((I2list_gets - I2list_frees) * n) / 1024.); } /* fprint_glist_mem */ /************* * * p_glist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the glist package. */ /* PUBLIC */ void p_glist_mem() { fprint_glist_mem(stdout, TRUE); } /* p_glist_mem */ /* * end of memory management */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /************* * * plist_cat() * *************/ /* DOCUMENTATION Concatenate two Plists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both args are destroyed. */ /* PUBLIC */ Plist plist_cat(Plist p1, Plist p2) { if (p1 == NULL) return p2; else if (p2 == NULL) return p1; else { Plist p = p1; while (p->next != NULL) p = p->next; p->next = p2; return p1; } } /* plist_cat */ /************* * * plist_cat2() * *************/ /* DOCUMENTATION Concatenate two Plists and return the result. In this version, the second plist is copied and placed at the end of p1.

That is, the first arg is destroyed, and the second is preserved. */ /* PUBLIC */ Plist plist_cat2(Plist p1, Plist p2) { return plist_cat(p1, copy_plist(p2)); } /* plist_cat2 */ /************* * * plist_pop() * *************/ /* DOCUMENTATION This routine takes a nonempty Plist, removes and frees the first node (ignoring the contents), and returns the remainder of the list. */ /* PUBLIC */ Plist plist_pop(Plist p) { Plist q = p; p = p->next; free_plist(q); return p; } /* plist_pop */ /************* * * plist_count() * *************/ /* DOCUMENTATION This routine returns the length of a Plist. */ /* PUBLIC */ int plist_count(Plist p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* plist_count */ /************* * * rev_app_plist(p1, p2) * *************/ static Plist rev_app_plist(Plist p1, Plist p2) { Plist p3; if (p1 == NULL) return(p2); else { p3 = p1->next; p1->next = p2; return(rev_app_plist(p3, p1)); } } /* rev_app_plist */ /************* * * reverse_plist(p1) * *************/ /* DOCUMENTATION This routine reverses a Plist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:

p = reverse_plist(p);
*/ /* PUBLIC */ Plist reverse_plist(Plist p) { return rev_app_plist(p, NULL); } /* reverse_plist */ /************* * * copy_plist(p) * *************/ /* DOCUMENTATION This routine copies a Plist (the whole list) and returns the copy. */ /* PUBLIC */ Plist copy_plist(Plist p) { Plist start, p1, p2; start = NULL; p2 = NULL; for ( ; p; p = p->next) { p1 = get_plist(); p1->v = p->v; p1->next = NULL; if (p2) p2->next = p1; else start = p1; p2 = p1; } return(start); } /* copy_plist */ /************* * * zap_plist(p) * *************/ /* DOCUMENTATION This routine frees a Plist (the whole list). The things to which the members point are not freed. */ /* PUBLIC */ void zap_plist(Plist p) { Plist curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_plist(prev); } } /* zap_plist */ /************* * * plist_append() * *************/ /* DOCUMENTATION This routine appends a pointer to a Plist. The updated Plist is returned. */ /* PUBLIC */ Plist plist_append(Plist lst, void *v) { if (lst == NULL) { Plist g = get_plist(); g->v = v; g->next = NULL; return g; } else { lst->next = plist_append(lst->next, v); return lst; } } /* plist_append */ /************* * * plist_prepend() * *************/ /* DOCUMENTATION This routine inserts a pointer as the first member of a Plist. The updated Plist is returned. */ /* PUBLIC */ Plist plist_prepend(Plist lst, void *v) { Plist g = get_plist(); g->v = v; g->next = lst; return g; } /* plist_prepend */ /************* * * plist_member() * *************/ /* DOCUMENTATION This function checks if a pointer is a member of a Plist. */ /* PUBLIC */ BOOL plist_member(Plist lst, void *v) { if (lst == NULL) return FALSE; else if (lst->v == v) return TRUE; else return plist_member(lst->next, v); } /* plist_member */ /************* * * plist_subtract() * *************/ /* DOCUMENTATION Return the members of p1 that are not in p2.

The arguments are not changed. */ /* PUBLIC */ Plist plist_subtract(Plist p1, Plist p2) { if (p1 == NULL) return NULL; else { Plist r = plist_subtract(p1->next, p2); if (plist_member(p2, p1->v)) return r; else return plist_prepend(r, p1->v); } } /* plist_subtract */ /************* * * plist_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL plist_subset(Plist a, Plist b) { if (a == NULL) return TRUE; else if (!plist_member(b, a->v)) return FALSE; else return plist_subset(a->next, b); } /* plist_subset */ /************* * * plist_remove() * *************/ /* DOCUMENTATION Remove the first occurrence of a pointer from a Plist. */ /* PUBLIC */ Plist plist_remove(Plist p, void *v) { if (p == NULL) fatal_error("plist_remove: pointer not found"); if (p->v == v) { Plist x = p; p = p->next; free_plist(x); return p; } else { p->next = plist_remove(p->next, v); return p; } } /* plist_remove */ /************* * * plist_remove_string() * *************/ /* DOCUMENTATION Remove the first occurrence of a pointer from a Plist. */ /* PUBLIC */ Plist plist_remove_string(Plist p, char *s) { if (p == NULL) fatal_error("plist_remove_string: pointer not found"); if (str_ident(p->v, s)) { Plist x = p; p = p->next; free_plist(x); return p; } else { p->next = plist_remove_string(p->next, s); return p; } } /* plist_remove_string */ /************* * * sort_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist sort_plist(Plist objects, Ordertype (*comp_proc) (void *, void *)) { int n = plist_count(objects); void **a = malloc(n * sizeof(void *)); int i; Plist p; for (p = objects, i = 0; p; p = p->next, i++) a[i] = p->v; merge_sort(a, n, comp_proc); for (p = objects, i = 0; p; p = p->next, i++) p->v = a[i]; free(a); return objects; } /* sort_plist */ /************* * * plist_remove_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist plist_remove_last(Plist p) { if (p == NULL) return NULL; else if (p->next == NULL) { free_plist(p); return NULL; } else { p->next = plist_remove_last(p->next); return p; } } /* plist_remove_last */ /************* * * position_of_string_in_plist() * *************/ /* DOCUMENTATION Count from 1; return -1 if the string is not in the Plist. */ /* PUBLIC */ int position_of_string_in_plist(char *s, Plist p) { if (p == NULL) return -1; else if (str_ident(s, p->v)) return 1; else { int pos = position_of_string_in_plist(s, p->next); if (pos == -1) return -1; else return pos+1; } } /* position_of_string_in_plist */ /************* * * string_member_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL string_member_plist(char *s, Plist p) { return position_of_string_in_plist(s, p) >= 0; } /* string_member_plist */ /************* * * longest_string_in_plist() * *************/ /* DOCUMENTATION Return -1 if the Plist is empty. */ /* PUBLIC */ int longest_string_in_plist(Plist p) { if (p == NULL) return -1; else { int n1 = strlen(p->v); int n2 = longest_string_in_plist(p->next); return IMAX(n1,n2); } } /* longest_string_in_plist */ /************* * * ith_in_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void *ith_in_plist(Plist p, int i) { if (p == NULL || i <= 0) return NULL; else if (i == 1) return p->v; else return ith_in_plist(p->next, i-1); } /* ith_in_plist */ /************* * * plist_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void *plist_last(Plist p) { if (p == NULL) return NULL; else if (p->next == NULL) return p->v; else return plist_last(p->next); } /* plist_last */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /************* * * ilist_cat() * *************/ /* DOCUMENTATION Concatenate two Ilists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both arguments are "used up". */ /* PUBLIC */ Ilist ilist_cat(Ilist p1, Ilist p2) { if (p1 == NULL) return p2; else if (p2 == NULL) return p1; else { Ilist p = p1; while (p->next != NULL) p = p->next; p->next = p2; return p1; } } /* ilist_cat */ /************* * * ilist_cat2() * *************/ /* DOCUMENTATION Concatenate two Ilists and return the result. In this version, the second ilist is copied and placed at the end of p1. That is, p1 is "used up", but p2 is not. */ /* PUBLIC */ Ilist ilist_cat2(Ilist p1, Ilist p2) { if (p1 == NULL) return copy_ilist(p2); else { p1->next = ilist_cat2(p1->next, p2); return p1; } } /* ilist_cat2 */ /************* * * ilist_pop() * *************/ /* DOCUMENTATION This routine takes a nonempty Ilist, removes and frees the first node (ignoring the contents), and returns the remainder of the list. */ /* PUBLIC */ Ilist ilist_pop(Ilist p) { Ilist q = p; p = p->next; free_ilist(q); return p; } /* ilist_pop */ /************* * * ilist_count() * *************/ /* DOCUMENTATION This routine returns the length of a Ilist. */ /* PUBLIC */ int ilist_count(Ilist p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* ilist_count */ /************* * * rev_app_ilist(p1, p2) * *************/ static Ilist rev_app_ilist(Ilist p1, Ilist p2) { Ilist p3; if (p1 == NULL) return(p2); else { p3 = p1->next; p1->next = p2; return(rev_app_ilist(p3, p1)); } } /* rev_app_ilist */ /************* * * reverse_ilist(p1) * *************/ /* DOCUMENTATION This routine reverses a Ilist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:

p = reverse_ilist(p);
*/ /* PUBLIC */ Ilist reverse_ilist(Ilist p) { return rev_app_ilist(p, NULL); } /* reverse_ilist */ /************* * * copy_ilist(p) * *************/ /* DOCUMENTATION This routine copies a Ilist (the whole list) and returns the copy. */ /* PUBLIC */ Ilist copy_ilist(Ilist p) { Ilist start, p1, p2; start = NULL; p2 = NULL; for ( ; p; p = p->next) { p1 = get_ilist(); p1->i = p->i; p1->next = NULL; if (p2) p2->next = p1; else start = p1; p2 = p1; } return(start); } /* copy_ilist */ /************* * * zap_ilist(p) * *************/ /* DOCUMENTATION This routine frees a Ilist (the whole list). */ /* PUBLIC */ void zap_ilist(Ilist p) { Ilist curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_ilist(prev); } } /* zap_ilist */ /************* * * ilist_append() * *************/ /* DOCUMENTATION This routine appends an integer to a Ilist. The updated Ilist is returned. */ /* PUBLIC */ Ilist ilist_append(Ilist lst, int i) { if (lst == NULL) { Ilist g = get_ilist(); g->i = i; g->next = NULL; return g; } else { lst->next = ilist_append(lst->next, i); return lst; } } /* ilist_append */ /************* * * ilist_prepend() * *************/ /* DOCUMENTATION This routine inserts an integer as the first member of a Ilist. The updated Ilist is returned. */ /* PUBLIC */ Ilist ilist_prepend(Ilist lst, int i) { Ilist g = get_ilist(); g->i = i; g->next = lst; return g; } /* ilist_prepend */ /************* * * ilist_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_last(Ilist lst) { if (lst == NULL) return NULL; else if (lst->next == NULL) return lst; else return ilist_last(lst->next); } /* ilist_last */ /************* * * ilist_member() * *************/ /* DOCUMENTATION This function checks if an integer is a member of a Ilist. (If a node in the Ilist contains a pointer instead of an integer, the result is undefined.) */ /* PUBLIC */ BOOL ilist_member(Ilist lst, int i) { if (lst == NULL) return FALSE; else if (lst->i == i) return TRUE; else return ilist_member(lst->next, i); } /* ilist_member */ /************* * * ilist_subtract() * *************/ /* DOCUMENTATION Return the members of p1 that are not in p2.

The arguments are not changed. */ /* PUBLIC */ Ilist ilist_subtract(Ilist p1, Ilist p2) { if (p1 == NULL) return NULL; else { Ilist r = ilist_subtract(p1->next, p2); if (ilist_member(p2, p1->i)) return r; else return ilist_prepend(r, p1->i); } } /* ilist_subtract */ /************* * * ilist_removeall() * *************/ /* DOCUMENTATION Remove all occurrences of i.

The argument is "used up". */ /* PUBLIC */ Ilist ilist_removeall(Ilist p, int i) { if (p == NULL) return NULL; else if (p->i == i) { Ilist r = p->next; free_ilist(p); return ilist_removeall(r, i); } else { p->next = ilist_removeall(p->next, i); return p; } } /* ilist_removeall */ /************* * * ilist_intersect() * *************/ /* DOCUMENTATION Construct the intersection (as a new Ilist).

The arguments are not changed. */ /* PUBLIC */ Ilist ilist_intersect(Ilist a, Ilist b) { if (a == NULL) return NULL; else { Ilist r = ilist_intersect(a->next, b); if (ilist_member(b, a->i)) return ilist_prepend(r, a->i); else return r; } } /* ilist_intersect */ /************* * * ilist_union() * *************/ /* DOCUMENTATION Construct the union (as a new Ilist).

The arguments need not be sets, the result is a set.

The arguments are not changed. */ /* PUBLIC */ Ilist ilist_union(Ilist a, Ilist b) { if (a == NULL) return ilist_set(b); /* copies members of b (does not change b) */ else if (ilist_member(b, a->i)) return ilist_union(a->next, b); else return ilist_prepend(ilist_union(a->next, b), a->i); } /* ilist_union */ /************* * * ilist_set() * *************/ /* DOCUMENTATION Take a list of integers and remove duplicates. This creates a new list and leave the old list as it was. Don't make any assumptions about the order of the result. */ /* PUBLIC */ Ilist ilist_set(Ilist m) { if (m == NULL) return NULL; else { Ilist s = ilist_set(m->next); if (ilist_member(s, m->i)) return s; else return ilist_prepend(s, m->i); } } /* ilist_set */ /************* * * ilist_rem_dups() * *************/ /* DOCUMENTATION Take a list of integers and remove duplicates.

This version "uses up" the argument. */ /* PUBLIC */ Ilist ilist_rem_dups(Ilist m) { if (m == NULL) return NULL; else { Ilist s = ilist_rem_dups(m->next); if (ilist_member(s, m->i)) { free_ilist(m); return s; } else { m->next = s; return m; } } } /* ilist_rem_dups */ /************* * * ilist_is_set() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ilist_is_set(Ilist a) { if (a == NULL) return TRUE; else if (ilist_member(a->next, a->i)) return FALSE; else return ilist_is_set(a->next); } /* ilist_is_set */ /************* * * ilist_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ilist_subset(Ilist a, Ilist b) { if (a == NULL) return TRUE; else if (!ilist_member(b, a->i)) return FALSE; else return ilist_subset(a->next, b); } /* ilist_subset */ /************* * * fprint_ilist() * *************/ /* DOCUMENTATION The list of integers is printed to FILE *fp like this: (4 5 1 3), without a newline. */ /* PUBLIC */ void fprint_ilist(FILE *fp, Ilist p) { fprintf(fp, "("); for (; p != NULL; p = p->next) { fprintf(fp, "%d", p->i); fprintf(fp, "%s", p->next ? " " : ""); } fprintf(fp, ")"); fflush(fp); } /* fprint_ilist */ /************* * * p_ilist() * *************/ /* DOCUMENTATION The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end. */ /* PUBLIC */ void p_ilist(Ilist p) { fprint_ilist(stdout, p); printf("\n"); fflush(stdout); } /* p_ilist */ /************* * * ilist_copy() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_copy(Ilist p) { if (p == NULL) return NULL; else { Ilist new = get_ilist(); new->i = p->i; new->next = ilist_copy(p->next); return new; } } /* ilist_copy */ /************* * * ilist_remove_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_remove_last(Ilist p) { if (p == NULL) return NULL; else if (p->next == NULL) { free_ilist(p); return NULL; } else { p->next = ilist_remove_last(p->next); return p; } } /* ilist_remove_last */ /************* * * ilist_occurrences() * *************/ /* DOCUMENTATION How many times does an integer occur in an ilist? */ /* PUBLIC */ int ilist_occurrences(Ilist p, int i) { if (p == NULL) return 0; else return ilist_occurrences(p->next, i) + (p->i == i ? 1 : 0); } /* ilist_occurrences */ /************* * * ilist_insert_up() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_insert_up(Ilist p, int i) { if (p == NULL || p->i >= i) { Ilist g = get_ilist(); g->i = i; g->next = p; return g; } else { p->next = ilist_insert_up(p->next, i); return p; } } /* ilist_insert_up */ /************* * * position_in_ilist() * *************/ /* DOCUMENTATION Count from 1; return -1 if the int is not in the Ilist. */ /* PUBLIC */ int position_in_ilist(int i, Ilist p) { if (p == NULL) return -1; else if (p->i == i) return 1; else { int pos = position_in_ilist(i, p->next); if (pos == -1) return -1; else return pos+1; } } /* position_in_ilist */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /************* * * zap_i2list(p) * *************/ /* DOCUMENTATION This routine frees an I2list (the whole list). */ /* PUBLIC */ void zap_i2list(I2list p) { I2list curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_i2list(prev); } } /* zap_i2list */ /************* * * i2list_append() * *************/ /* DOCUMENTATION This routine appends an integer to a I2list. The updated I2list is returned. */ /* PUBLIC */ I2list i2list_append(I2list lst, int i, int j) { if (lst == NULL) { I2list g = get_i2list(); g->i = i; g->j = j; g->next = NULL; return g; } else { lst->next = i2list_append(lst->next, i, j); return lst; } } /* i2list_append */ /************* * * i2list_prepend() * *************/ /* DOCUMENTATION This routine inserts an integer triple as the first member of a I2list. The updated I2list is returned. */ /* PUBLIC */ I2list i2list_prepend(I2list lst, int i, int j) { I2list g = get_i2list(); g->i = i; g->j = j; g->next = lst; return g; } /* i2list_prepend */ /************* * * i2list_removeall() * *************/ /* DOCUMENTATION Remove all occurrences of i.

The argument is "used up". */ /* PUBLIC */ I2list i2list_removeall(I2list p, int i) { if (p == NULL) return NULL; else if (p->i == i) { I2list r = p->next; free_i2list(p); return i2list_removeall(r, i); } else { p->next = i2list_removeall(p->next, i); return p; } } /* i2list_removeall */ /************* * * i2list_member() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list i2list_member(I2list lst, int i) { if (lst == NULL) return NULL; else if (lst->i == i) return lst; else return i2list_member(lst->next, i); } /* i2list_member */ /************* * * p_i2list() * *************/ /* DOCUMENTATION The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end. */ /* PUBLIC */ void p_i2list(I2list p) { printf("("); for (; p != NULL; p = p->next) { printf("%d/%d", p->i, p->j); printf("%s", p->next ? " " : ""); } printf(")\n"); fflush(stdout); } /* p_i2list */ /************* * * i2list_count() * *************/ /* DOCUMENTATION This routine returns the length of a I2list. */ /* PUBLIC */ int i2list_count(I2list p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* i2list_count */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /************* * * i3list_member() * *************/ /* DOCUMENTATION This function checks if a triple of integers is a member of a I3list. */ /* PUBLIC */ BOOL i3list_member(I3list lst, int i, int j, int k) { if (lst == NULL) return FALSE; else if (lst->i == i && lst->j == j && lst->k == k) return TRUE; else return i3list_member(lst->next, i, j, k); } /* i3list_member */ /************* * * i3list_append() * *************/ /* DOCUMENTATION This routine appends an integer to a I3list. The updated I3list is returned. */ /* PUBLIC */ I3list i3list_append(I3list lst, int i, int j, int k) { if (lst == NULL) { I3list g = get_i3list(); g->i = i; g->j = j; g->k = k; g->next = NULL; return g; } else { lst->next = i3list_append(lst->next, i, j, k); return lst; } } /* i3list_append */ /************* * * i3list_prepend() * *************/ /* DOCUMENTATION This routine inserts an integer triple as the first member of a I3list. The updated I3list is returned. */ /* PUBLIC */ I3list i3list_prepend(I3list lst, int i, int j, int k) { I3list g = get_i3list(); g->i = i; g->j = j; g->k = k; g->next = lst; return g; } /* i3list_prepend */ /************* * * zap_i3list(p) * *************/ /* DOCUMENTATION This routine frees a I3list (the whole list). */ /* PUBLIC */ void zap_i3list(I3list p) { I3list curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_i3list(prev); } } /* zap_i3list */ /************* * * rev_app_i3list(p1, p2) * *************/ static I3list rev_app_i3list(I3list p1, I3list p2) { I3list p3; if (p1 == NULL) return(p2); else { p3 = p1->next; p1->next = p2; return(rev_app_i3list(p3, p1)); } } /* rev_app_i3list */ /************* * * reverse_i3list(p1) * *************/ /* DOCUMENTATION This routine reverses a I3list. The 3list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:

p = reverse_i3list(p);
*/ /* PUBLIC */ I3list reverse_i3list(I3list p) { return rev_app_i3list(p, NULL); } /* reverse_i3list */ /************* * * copy_i3list(p) * *************/ /* DOCUMENTATION This routine copies a I3list (the whole 3list) and returns the copy. */ /* PUBLIC */ I3list copy_i3list(I3list p) { I3list start, p1, p2; start = NULL; p2 = NULL; for ( ; p; p = p->next) { p1 = get_i3list(); p1->i = p->i; p1->j = p->j; p1->k = p->k; p1->next = NULL; if (p2) p2->next = p1; else start = p1; p2 = p1; } return(start); } /* copy_i3list */ /************* * * i3list_count() * *************/ /* DOCUMENTATION This routine returns the length of a I3list. */ /* PUBLIC */ int i3list_count(I3list p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* i3list_count */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /************* * * alist_insert() * *************/ /* DOCUMENTATION Alists (association list) for integers. Insert key/value pairs. With assoc(key), retreive value. If a key has more than one value, the most recent is returned. It an key is not in the alist, INT_MIN is returned. An alist can be freed with zap_i2list(alist). This is not efficient, because no hashing is done; lookups are linear. */ /* PUBLIC */ I2list alist_insert(I2list p, int key, int val) { return i2list_prepend(p, key, val); } /* alist_insert */ /************* * * assoc() * *************/ /* DOCUMENTATION See alist_insert. */ /* PUBLIC */ int assoc(I2list p, int key) { if (p == NULL) return INT_MIN; else if (p->i == key) return p->j; else return assoc(p->next, key); } /* assoc */ /************* * * alist2_insert() * *************/ /* DOCUMENTATION Alist2 (association list) for pairs of integers. Insert key/ pairs. With assoc2a(key), retreive value-a. With assoc2b(key), retreive value-b. If a key has more than one value pair, the most recent is returned. It a key is not in the alist2, INT_MIN is returned. An alist2 can be freed with zap_i3list(alist2). */ /* PUBLIC */ I3list alist2_insert(I3list p, int key, int a, int b) { return i3list_prepend(p, key, a, b); } /* alist2_insert */ /************* * * assoc2a() * *************/ /* DOCUMENTATION See alist2_insert. */ /* PUBLIC */ int assoc2a(I3list p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return INT_MIN; else if (p->i == key) return p->j; else return assoc2a(p->next, key); } /* assoc2a */ /************* * * assoc2b() * *************/ /* DOCUMENTATION See alist2_insert. */ /* PUBLIC */ int assoc2b(I3list p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return INT_MIN; else if (p->i == key) return p->k; else return assoc2b(p->next, key); } /* assoc2a */ /************* * * alist2_remove() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I3list alist2_remove(I3list p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return NULL; else { p->next= alist2_remove(p->next, key); if (p->i == key) { I3list a = p; p = p->next; free_i3list(a); } return p; } } /* alist2_remove */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /* Multiset of integers is implemented with I2list, that is, list of pairs of integers: . */ /************* * * i2list_multimember() * *************/ /* DOCUMENTATION Is a multimember of multiset b? */ /* PUBLIC */ BOOL i2list_multimember(I2list b, int i, int n) { if (b == NULL) return FALSE; else if (i == b->i) return n <= b->j; else return i2list_multimember(b->next, i, n); } /* i2list_multimember */ /************* * * i2list_multisubset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL i2list_multisubset(I2list a, I2list b) { if (a == NULL) return TRUE; else if (!i2list_multimember(b, a->i, a->j)) return FALSE; else return i2list_multisubset(a->next, b); } /* i2list_multisubset */ /************* * * multiset_add_n() * *************/ /* DOCUMENTATION Add n occurrences of i to multiset a. */ /* PUBLIC */ I2list multiset_add_n(I2list a, int i, int n) { if (a == NULL) { a = get_i2list(); a->i = i; a->j = n; } else if (a->i == i) a->j += n; else a->next = multiset_add_n(a->next, i, n); return a; } /* multiset_add_n */ /************* * * multiset_add() * *************/ /* DOCUMENTATION Add 1 occurrence of i to multiset a. */ /* PUBLIC */ I2list multiset_add(I2list a, int i) { return multiset_add_n(a, i, 1); } /* multiset_add */ /************* * * multiset_union() * *************/ /* DOCUMENTATION The result is constructed from the arguments, so do not refer to either of the arguments after the call. That is, both arguments are "used up". */ /* PUBLIC */ I2list multiset_union(I2list a, I2list b) { I2list p; for (p = b; p; p = p->next) a = multiset_add_n(a, p->i, p->j); zap_i2list(b); return a; } /* multiset_union */ /************* * * multiset_to_set() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist multiset_to_set(I2list m) { if (m == NULL) return NULL; else { Ilist p = get_ilist(); p->i = m->i; p->next = multiset_to_set(m->next); return p; } } /* multiset_to_set */ /************* * * multiset_occurrences() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int multiset_occurrences(I2list m, int i) { I2list a = i2list_member(m, i); return (a == NULL ? 0 : a->j); } /* multiset_occurrences */ LADR-2009-11A/ladr/clauses.c0000644000175000017500000001400211225461462014543 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clauses.h" #include /* Private definitions and types */ /* * memory management */ /************* * * clause_member_plist() * *************/ /* DOCUMENTATION Is a clause a member of a Plist? A deep identity check is done (clause_ident). */ /* PUBLIC */ Topform clause_member_plist(Plist p, Topform c) { while (p) { Topform d = p->v; if (clause_ident(c->literals, d->literals)) return p->v; p = p->next; } return NULL; } /* clause_member_plist */ /************* * * intersect_clauses() * *************/ /* DOCUMENTATION Intersect 2 Plists of clauses. The order of the result is determined by the order of the first list. A deep identity check is done (clause_ident). */ /* PUBLIC */ Plist intersect_clauses(Plist a, Plist b) { if (a == NULL) return NULL; else { Plist c = intersect_clauses(a->next, b); if (clause_member_plist(b, a->v)) return plist_prepend(c, a->v); else return c; } } /* intersect_clauses */ /************* * * max_clause_weight() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the weight of the heaviest clause. The weight field of the clause is used. */ /* PUBLIC */ double max_clause_weight(Plist p) { if (p == NULL) return DBL_MIN; else { double max_rest = max_clause_weight(p->next); Topform c = p->v; return (c->weight > max_rest ? c->weight : max_rest); } } /* max_clause_weight */ /************* * * max_clause_symbol_count() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the symbol_count of a clause with most symbols. */ /* PUBLIC */ int max_clause_symbol_count(Plist p) { if (p == NULL) return INT_MIN; else { int max_rest = max_clause_symbol_count(p->next); Topform c = p->v; return IMAX(clause_symbol_count(c->literals), max_rest); } } /* max_clause_symbol_count */ /************* * * nonneg_clauses() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the subset of nonnegative clauses. */ /* PUBLIC */ Plist nonneg_clauses(Plist clauses) { Plist nonneg = NULL; Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; if (!negative_clause(c->literals)) nonneg = plist_append(nonneg, c); } return nonneg; } /* nonneg_clauses */ /************* * * all_clauses_horn() * *************/ /* DOCUMENTATION Is every clause in the Plist a Horn clause? */ /* PUBLIC */ BOOL all_clauses_horn(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!horn_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_horn */ /************* * * all_clauses_unit() * *************/ /* DOCUMENTATION Is every clause in the Plist a unit clause? */ /* PUBLIC */ BOOL all_clauses_unit(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!unit_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_unit */ /************* * * all_clauses_positive() * *************/ /* DOCUMENTATION Is every clause in the Plist a unit clause? */ /* PUBLIC */ BOOL all_clauses_positive(Plist l) { Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (!positive_clause(c->literals)) return FALSE; } return TRUE; } /* all_clauses_positive */ /************* * * neg_nonunit_clauses() * *************/ /* DOCUMENTATION How many negative nonunits are in a Plist of clauses? */ /* PUBLIC */ int neg_nonunit_clauses(Plist l) { int n = 0; Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (negative_clause(c->literals) && number_of_literals(c->literals) > 1) n++; } return n; } /* neg_nonunit_clauses */ /************* * * negative_clauses() * *************/ /* DOCUMENTATION How many negative clauses are in a Plist of clauses? */ /* PUBLIC */ int negative_clauses(Plist l) { int n = 0; Plist p; for (p = l; p; p = p->next) { Topform c = p->v; if (negative_clause(c->literals)) n++; } return n; } /* negative_clauses */ /************* * * most_literals() * *************/ /* DOCUMENTATION Given a Plist of clauses, what is the maximum number of literals in a clause. */ /* PUBLIC */ int most_literals(Plist clauses) { int max = -1; Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; int n = number_of_literals(c->literals); max = IMAX(max,n); } return max; } /* most_literals */ /************* * * pos_equality_in_clauses() * *************/ /* DOCUMENTATION Does the Plist contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL pos_equality_in_clauses(Plist clauses) { if (clauses == NULL) return FALSE; else { Topform c = clauses->v; if (contains_pos_eq(c->literals)) return TRUE; else return pos_equality_in_clauses(clauses->next); } } /* pos_equality_in_clauses */ /************* * * equality_in_clauses() * *************/ /* DOCUMENTATION Does the Plist contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL equality_in_clauses(Plist clauses) { if (clauses == NULL) return FALSE; else { Topform c = clauses->v; if (contains_eq(c->literals)) return TRUE; else return equality_in_clauses(clauses->next); } } /* equality_in_clauses */ LADR-2009-11A/ladr/sed20000644000175000017500000000010010462276044013514 0ustar mccunemccunes/Tformula/Topform/g s/tformula/topform/g s/TFORMULA/TOPFORM/g LADR-2009-11A/ladr/di_tree.h0000644000175000017500000000356611151265364014542 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DI_TREE_H #define TP_DI_TREE_H #include "features.h" #include "topform.h" /* INTRODUCTION */ /* Public definitions */ typedef struct di_tree * Di_tree; struct di_tree { /* node in an integer vector discrimination tree */ int label; /* label of node */ Di_tree next; /* sibling */ union { Di_tree kids; /* for internal nodes */ Plist data; /* for leaves */ } u; }; /* End of public definitions */ /* Public function prototypes from di_tree.c */ int nonunit_fsub_tests(void); int nonunit_bsub_tests(void); Di_tree get_di_tree(void); void free_di_tree(Di_tree p); void fprint_di_tree_mem(FILE *fp, BOOL heading); void p_di_tree_mem(void); Di_tree init_di_tree(void); void di_tree_insert(Ilist vec, Di_tree node, void *datum); BOOL di_tree_delete(Ilist vec, Di_tree node, void *datum); void zap_di_tree(Di_tree node, int depth); void p_di_tree(Ilist vec, Di_tree node, int depth); Topform forward_feature_subsume(Topform d, Di_tree root); Plist back_feature_subsume(Topform c, Di_tree root); unsigned mega_sub_calls(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/t1.in0000644000175000017500000000000011140422165013576 0ustar mccunemccuneLADR-2009-11A/ladr/accanon.h0000644000175000017500000000256011151265364014522 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_ACCANON_H #define TP_ACCANON_H #include "termflag.h" #include "termorder.h" /* INTRODUCTION */ /* Public definitions */ /* If you get an error message "flatten, too many arguments", increase * the following symbol (2500 is enough for the dem_alu problem.) */ #define MAX_ACM_ARGS 2500 /* End of public definitions */ /* Public function prototypes from accanon.c */ void flatten(Term t, Term *a, int *ip); void ac_canonical2(Term t, int bit, Ordertype (*term_compare_proc) (Term, Term)); void ac_canonical(Term t, int bit); int check_ac_canonical(Term t); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/weight2.c0000644000175000017500000001126111113107236014451 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /* This file is for experimental weighting functions. To add a new one, say test2, look for test1 in this file and do something similar with test2. In the prover9 input, you can then have a weighting rule with expressions like call(test2, x) on the right side. */ /* This file is set up so that it can be compiled and linked by itself for testing. To do so, use a command like % gcc -DSOLO -o weighttest weight2.c See "main" at the end of the file. */ #ifdef SOLO #include #include #include #define IMAX(a,b) ((a) > (b) ? (a) : (b)) #else #include "weight2.h" #include "parse.h" #endif /************* * * char_array_ident() - identical arrays of characters * *************/ static int char_array_ident(char *s, char *t, int n) { int i; for (i = 0; i < n; i++) if (s[i] != t[i]) return 0; return 1; } /* char_array_ident */ /************* * * char_array_find() - this is like looking for a substring, except * that the objects are arrays of characters * *************/ static int char_array_find(char *b, int nb, char *a, int na) { if (nb <= na) { int i; for (i = 0; i <= na - nb; i++) { if (char_array_ident(a+i, b, nb)) return i; /* b is a subsequence of a at position i */ } } return -1; /* b is not a subsequence */ } /* char_array_find */ /************* * * complexity_1() * *************/ static double complexity_1(char *s) { /* This is based on Zac's original perl code. It's not quite right. */ int length = strlen(s); int min = 2; int index = min; int total = 0; if (length < 3) return 0.0; while (index <= length-2) { /* index of where the search begins */ int flen = 0; /* length of found redundancy */ int maxlook = (length - index); int window; /* don't check for occurences longer than head of string */ if (maxlook > index) maxlook = index; /* printf("checking at index %d\n", index); */ /* printf("will chack strings of length %d through %d.\n", min, maxlook); */ for (window = min; window < maxlook+1; window++) { char *tocheck = s + index; int ind = char_array_find(tocheck, window, s, length); /* printf("Want to know if %s occurs in pos 0 until %d.\n", tocheck,index); */ /* ind = string.find(tocheck); */ if (ind < index) flen = window; } if (flen == 0) index += 1; else { index += flen; total += flen; } } /* printf("total=%d,index=%d,length=%d,MIN=%d\n",total,index,length,min); */ /* printf("TOTAL REDUNDANCY: %d\n", total); */ return ((double) total) / (length-2); } /* complexity_1 */ #ifndef SOLO /************* * * test1() * *************/ static double test1(Term t) { char *s = term_to_string(t); /* remember to free(s) below */ /* The complexity function returns a double in the range 0.0--1.0. */ double c = complexity_1(s); /* printf("s=%s, complexity=%d: ", s, c); p_term(t); */ free(s); return c; } /* test1 */ /************* * * call_weight() * *************/ /* DOCUMENTATION This is the entry function, called by the general weighting code. It receives a string (the name of the function), and a term (the term to be weighed). */ /* PUBLIC */ double call_weight(char *func, Term t) { if (str_ident(func, "test1")) return test1(t); else { fatal_error("call_weight, unknown function"); return 0; /* to appease the compiler */ } } /* call_weight */ #endif #ifdef SOLO int main(int argc, char **argv) { char s[1000]; char *t; while (1) { /* printf("\nenter string: "); */ t = fgets(s, 1000, stdin); if (t == NULL) exit(0); if (strlen(s) > 0) s[strlen(s)-1] = '\0'; /* get rid of newline */ /* printf("\nchecking %s\n", s); */ printf("%.5f\n", 1 - complexity_1(s)); } } #endif LADR-2009-11A/ladr/definitions.h0000644000175000017500000000267011151265364015435 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DEFINITIONS_H #define TP_DEFINITIONS_H #include "formula.h" #include "topform.h" #include "clauseid.h" #include "just.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from definitions.c */ BOOL is_definition(Formula f); Formula expand_with_definition(Formula f, Formula def); void process_definitions(Plist formulas, Plist *results, Plist *defs, Plist *rewritten); void expand_with_definitions(Plist formulas, Plist defs, Plist *results, Plist *rewritten); void separate_definitions(Plist formulas, Plist *defs, Plist *nondefs); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/topform.c0000644000175000017500000004466511140517364014613 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "topform.h" /* Private definitions and types */ /* * memory management */ #define PTRS_TOPFORM PTRS(sizeof(struct topform)) static unsigned Topform_gets, Topform_frees; /************* * * Topform get_topform() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform get_topform(void) { Topform p = get_cmem(PTRS_TOPFORM); Topform_gets++; return(p); } /* get_topform */ /************* * * free_topform() * *************/ static void free_topform(Topform p) { free_mem(p, PTRS_TOPFORM); Topform_frees++; } /* free_topform */ /************* * * fprint_topform_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clause package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_topform_mem(FILE *fp, int heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct topform); fprintf(fp, "topform (%4d) %11u%11u%11u%9.1f K\n", n, Topform_gets, Topform_frees, Topform_gets - Topform_frees, ((Topform_gets - Topform_frees) * n) / 1024.); } /* fprint_topform_mem */ /************* * * p_topform_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clause package. */ /* PUBLIC */ void p_topform_mem() { fprint_topform_mem(stdout, 1); } /* p_topform_mem */ /* * end of memory management */ /************* * * zap_topform(c) * *************/ /* DOCUMENTATION This routine frees a Topform (but not any justification list). The caller should make sure that nothing (e.g., indexes) refer to the clause or any of its subterms.

If the clause has a justification or an official ID, use the higher-level routine delete_clause(c) instead. */ /* PUBLIC */ void zap_topform(Topform tf) { zap_literals(tf->literals); zap_formula(tf->formula); zap_attributes(tf->attributes); free_topform(tf); } /* zap_topform */ /************* * * fprint_clause() * *************/ /* DOCUMENTATION This routine prints a clause to a file. */ /* PUBLIC */ void fprint_clause(FILE *fp, Topform c) { if (c == NULL) fprintf(fp, "fprint_clause: NULL clause\n"); else { Literals lit; if (c->id > 0) fprintf(fp, "%d: ", c->id); if (c->literals == NULL) fprintf(fp, "%s", false_sym()); else { for (lit = c->literals; lit != NULL; lit = lit->next) { if (!lit->sign) fprintf(fp, "%s", not_sym()); fprint_term(fp, lit->atom); #if 0 if (maximal_literal_check(lit)) fprintf(fp, "[max]"); #endif if (lit->next != NULL) fprintf(fp, " %s ", or_sym()); } } fprintf(fp, ".\n"); } fflush(fp); } /* fprint_clause */ /************* * * p_clause() * *************/ /* DOCUMENTATION This routine prints a clause to stdout. */ /* PUBLIC */ void p_clause(Topform c) { fprint_clause(stdout, c); } /* p_clause */ /************* * * term_to_clause() * *************/ /* DOCUMENTATION This routine takes a Term t (presumably a disjunction with binary symbol or_sym()), and constructs a Topform. The Topform is entirely new.

The main use of this routine is intended to be as follows: a Term representing a clause is parsed (using mixfix notation) from the input, then here it is copied translated into a Topform data structure. */ /* PUBLIC */ Topform term_to_clause(Term t) { Topform c = get_topform(); Term t_start; if (is_term(t, attrib_sym(), 2)) { c->attributes = term_to_attributes(ARG(t,1), attrib_sym()); t_start = ARG(t,0); } else t_start = t; c->literals = term_to_literals(t_start, NULL); upward_clause_links(c); return(c); } /* term_to_clause */ /************* * * term_to_topform() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform term_to_topform(Term t, BOOL is_formula) { Topform c = get_topform(); Term t_start; if (is_term(t, attrib_sym(), 2)) { c->attributes = term_to_attributes(ARG(t,1), attrib_sym()); t_start = ARG(t,0); } else t_start = t; c->is_formula = is_formula; if (is_formula) c->formula = term_to_formula(t_start); else { c->literals = term_to_literals(t_start, NULL); upward_clause_links(c); } return(c); } /* term_to_topform */ /************* * * topform_to_term() * *************/ /* DOCUMENTATION This routine takes a Topform and returns an entirely new Term which represents the clause. The disjunction symbol for the term is binary or_sym(), and the negation symbols is not_sym(). The attributes are included, but not the id or justifiction. */ /* PUBLIC */ Term topform_to_term(Topform tf) { Term t; if (tf->is_formula) t = formula_to_term(tf->formula); else { if (tf->literals == NULL) t = get_rigid_term(false_sym(), 0); else t = literals_to_term(tf->literals); } if (tf->attributes == NULL) return t; else return build_binary_term(str_to_sn(attrib_sym(), 2), t, attributes_to_term(tf->attributes, attrib_sym())); } /* topform_to_term */ /************* * * topform_to_term_without_attributes() * *************/ /* DOCUMENTATION This routine takes a Topform and returns an entirely new Term which represents the clause. The disjunction symbol for the term is binary or_sym(), and the negation symbols is not_sym(). The attributes, id, and justifiction are NOT included. */ /* PUBLIC */ Term topform_to_term_without_attributes(Topform tf) { Term t; if (tf->is_formula) t = formula_to_term(tf->formula); else { if (tf->literals == NULL) t = get_rigid_term(false_sym(), 0); else t = literals_to_term(tf->literals); } return t; } /* topform_to_term_without_attributes */ /************* * * clause_set_variables() * *************/ /* DOCUMENTATION This routine traverses a clause and changes the constants that should be variables, into variables. On input, the clause should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input clauses that are built without regard to variable/constant distinction. */ /* PUBLIC */ void clause_set_variables(Topform c, int max_vars) { char *a[MAX_VARS], **vmap; int i; Literals lit; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; for (lit = c->literals; lit != NULL; lit = lit->next) lit->atom = set_vars_recurse(lit->atom, vmap, max_vars); /* Now do any answer literals (with the same vmap). */ if (c->attributes) { Plist clause_vars = vars_in_clause(c->literals); Plist attr_vars; set_vars_attributes(c->attributes, vmap, max_vars); attr_vars = vars_in_attributes(c->attributes); /* Make sure that answer vars also occur in ordinary literals. */ if (!plist_subset(attr_vars, clause_vars)) { Plist p; printf("Variables in answers must also occur ordinary literals:\n"); p_clause(c); for (p = attr_vars; p; p = p->next) { if (!plist_member(clause_vars, p->v)) { Term t = p->v; printf("Answer variable not in ordinary literal: %s.\n", vmap[VARNUM(t)]); } } fatal_error("clause_set_variables, answer variable not in literal"); } zap_plist(clause_vars); zap_plist(attr_vars); } if (max_vars > MAX_VARS) free(vmap); c->normal_vars = TRUE; } /* clause_set_variables */ /************* * * renumber_variables() * *************/ /* DOCUMENTATION This routine renumbers the variables of a clause. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

The intended is use is for inferred clauses that may contain variable indexes greater than max_vars. */ /* PUBLIC */ void renumber_variables(Topform c, int max_vars) { int a[MAX_VARS], *vmap; int i; Literals lit; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(int))); else vmap = a; for (i = 0; i < max_vars; i++) a[i] = -1; for (lit = c->literals; lit != NULL; lit = lit->next) { /* There's a special case in which the atom can be null. */ if (lit->atom) lit->atom = renum_vars_recurse(lit->atom, vmap, max_vars); } /* Now do any inheritable attributes (with the same vmap). */ renumber_vars_attributes(c->attributes, vmap, max_vars); if (max_vars > MAX_VARS) free(vmap); c->normal_vars = TRUE; } /* renumber_variables */ /************* * * term_renumber_variables() * *************/ /* DOCUMENTATION This routine renumbers the variables of a term. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

Do not use this to renumber variables of a clause (see renumber_variables). */ /* PUBLIC */ void term_renumber_variables(Term t, int max_vars) { int a[MAX_VARS], *vmap; int i; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(int))); else vmap = a; for (i = 0; i < max_vars; i++) a[i] = -1; t = renum_vars_recurse(t, vmap, max_vars); if (max_vars > MAX_VARS) free(vmap); } /* term_renumber_variables */ /************* * * renum_vars_map() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist renum_vars_map(Topform c) { int a[MAX_VARS]; int i; Literals lit; Plist pairs = NULL; for (i = 0; i < MAX_VARS; i++) a[i] = -1; for (lit = c->literals; lit != NULL; lit = lit->next) lit->atom = renum_vars_recurse(lit->atom, a, MAX_VARS); /* Now renumber any inheritable attributes (with the same vmap). */ renumber_vars_attributes(c->attributes, a, MAX_VARS); /* Build the list of pairs. */ for (i = 0; i < MAX_VARS; i++) { /* a[i] -> i */ if (a[i] != -1 && a[i] != i) { Term v1 = get_variable_term(a[i]); Term v2 = get_variable_term(i); Term pair = listterm_cons(v1, v2); pairs = plist_append(pairs, pair); } } c->normal_vars = TRUE; return pairs; } /* renum_vars_map */ /************* * * upward_clause_links() * *************/ /* DOCUMENTATION In the given Topform c, make the "container" field of each subterm point to c. */ /* PUBLIC */ void upward_clause_links(Topform c) { Literals lit; for (lit = c->literals; lit != NULL; lit = lit->next) upward_term_links(lit->atom, c); } /* upward_clause_links */ /************* * * check_upward_clause_links() * *************/ /* DOCUMENTATION In the given Topform c, check that the "container" field of each subterm point to c. */ /* PUBLIC */ BOOL check_upward_clause_links(Topform c) { Literals lit; for (lit = c->literals; lit != NULL; lit = lit->next) { if (!check_upward_term_links(lit->atom, c)) return FALSE; } return TRUE; } /* check_upward_clause_links */ /************* * * copy_clause() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The container field of each nonvariable subterm points to the clause. */ /* PUBLIC */ Topform copy_clause(Topform c) { Topform c2 = get_topform(); c2->literals = copy_literals(c->literals); upward_clause_links(c2); return c2; } /* copy_clause */ /************* * * copy_clause_with_flags() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. All termflags are copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Topform copy_clause_with_flags(Topform c) { Topform c2 = get_topform(); c2->literals = copy_literals_with_flags(c->literals); upward_clause_links(c2); return c2; } /* copy_clause_with_flags */ /************* * * copy_clause_with_flag() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The given termflag is copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Topform copy_clause_with_flag(Topform c, int flag) { Topform c2 = get_topform(); c2->literals = copy_literals_with_flag(c->literals, flag); upward_clause_links(c2); return c2; } /* copy_clause_with_flag */ /************* * * inherit_attributes() * *************/ /* DOCUMENTATION This takes two parent clauses and their associated substitutions, and a child clause. All inheritable attributes on the parents are instantiated and appended to the child's attributes.

Either parent can be NULL. */ /* PUBLIC */ void inherit_attributes(Topform par1, Context s1, Topform par2, Context s2, Topform child) { Attribute a1 = par1 ? inheritable_att_instances(par1->attributes, s1) : NULL; Attribute a2 = par2 ? inheritable_att_instances(par2->attributes, s2) : NULL; child->attributes = cat_att(child->attributes, cat_att(a1, a2)); } /* inherit_attributes */ /************* * * gather_symbols_in_topform() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void gather_symbols_in_topform(Topform c, I2list *rsyms, I2list *fsyms) { if (c->is_formula) gather_symbols_in_formula(c->formula, rsyms, fsyms); else { Literals lit; for (lit = c->literals; lit; lit = lit->next) gather_symbols_in_formula_term(lit->atom, rsyms, fsyms); } } /* gather_symbols_in_topform */ /************* * * gather_symbols_in_topforms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void gather_symbols_in_topforms(Plist lst, I2list *rsyms, I2list *fsyms) { Plist p; for (p = lst; p; p = p->next) gather_symbols_in_topform(p->v, rsyms, fsyms); } /* gather_symbols_in_topforms */ /************* * * fsym_set_in_topforms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist fsym_set_in_topforms(Plist lst) { Ilist p; I2list rsyms = NULL; I2list fsyms = NULL; gather_symbols_in_topforms(lst, &rsyms, &fsyms); p = multiset_to_set(fsyms); zap_i2list(rsyms); zap_i2list(fsyms); return p; } /* fsym_set_in_topforms */ /************* * * rsym_set_in_topforms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist rsym_set_in_topforms(Plist lst) { Ilist p; I2list rsyms = NULL; I2list fsyms = NULL; gather_symbols_in_topforms(lst, &rsyms, &fsyms); p = multiset_to_set(rsyms); zap_i2list(rsyms); zap_i2list(fsyms); return p; } /* rsym_set_in_topforms */ /************* * * min_depth() * *************/ /* DOCUMENTATION Does the Literals have minimum depth of all literals the containing clause? */ /* PUBLIC */ BOOL min_depth(Literals lit) { Topform c = lit->atom->container; int d = term_depth(lit->atom); Literals l; for (l = c->literals; l; l = l->next) { if (term_depth(l->atom) < d) return FALSE; } return TRUE; } /* min_depth */ /************* * * initial_clause() * *************/ /* DOCUMENTATION Is (was) the clause part of the initial sos (after processing input clauses, before starting search)/ */ /* PUBLIC */ BOOL initial_clause(Topform c) { return c->initial; } /* initial_clause */ /************* * * negative_clause_possibly_compressed() * *************/ /* DOCUMENTATION Is (was) the clause part of the initial sos (after processing input clauses, before starting search)/ */ /* PUBLIC */ BOOL negative_clause_possibly_compressed(Topform c) { if (c->compressed) return c->neg_compressed; else return negative_clause(c->literals); } /* negative_clause_possibly_compressed */ /************* * * topform_properties() * *************/ /* DOCUMENTATION Construct a term containing a list of miscellaneous properties of a Topform. This is meant to be used as an attribute on Topforms for debugging. */ /* PUBLIC */ Term topform_properties(Topform c) { Term lst; Literals lit; int i; Term props = get_nil_term(); /* maximal literals */ lst = get_nil_term(); for (lit = c->literals, i = 1; lit; lit = lit->next, i++) { if (maximal_literal(c->literals, lit, FLAG_CHECK)) lst = listterm_cons(nat_to_term(i),lst); } lst = listterm_reverse(lst); props = listterm_cons(build_unary_term_safe("maximal", lst), props); /* maximal_signed literals */ lst = get_nil_term(); for (lit = c->literals, i = 1; lit; lit = lit->next, i++) { if (maximal_signed_literal(c->literals, lit, FLAG_CHECK)) lst = listterm_cons(nat_to_term(i),lst); } lst = listterm_reverse(lst); props = listterm_cons(build_unary_term_safe("maximal_signed",lst),props); /* maximal_signed literals */ lst = get_nil_term(); for (lit = c->literals, i = 1; lit; lit = lit->next, i++) { if (selected_literal(lit)) lst = listterm_cons(nat_to_term(i),lst); } lst = listterm_reverse(lst); props = listterm_cons(build_unary_term_safe("selected",lst),props); return listterm_reverse(props); } /* topform_properties */ /************* * * append_label_attribute() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void append_label_attribute(Topform tf, char *s) { tf->attributes = set_string_attribute(tf->attributes, label_att(), s); } /* append_label_attribute */ /************* * * cl_id_compare() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype cl_id_compare(Topform c1, Topform c2) { if (c1->id < c2->id) return LESS_THAN; else if (c1->id > c2->id) return GREATER_THAN; else return SAME_AS; } /* cl_id_compare */ /************* * * cl_wt_id_compare() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype cl_wt_id_compare(Topform c1, Topform c2) { if (c1->weight < c2->weight) return LESS_THAN; else if (c1->weight > c2->weight) return GREATER_THAN; else if (c1->id < c2->id) return LESS_THAN; else if (c1->id > c2->id) return GREATER_THAN; else return SAME_AS; } /* cl_wt_id_compare */ LADR-2009-11A/ladr/clauseid.c0000644000175000017500000001262210637466321014710 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clauseid.h" /* Private definitions and types */ #define CLAUSE_ID_TAB_SIZE 50000 static Plist Topform_id_tab[CLAUSE_ID_TAB_SIZE]; static unsigned Topform_id_count = 0; /************* * * next_clause_id() * *************/ static int next_clause_id(void) { return ++Topform_id_count; } /* next_clause_id */ /************* * * clause_ids_assigned() * *************/ /* DOCUMENTATION What is the most recently assigned clause ID? */ /* PUBLIC */ int clause_ids_assigned(void) { return Topform_id_count; } /* clause_ids_assigned */ /************* * * assign_clause_id(c) * *************/ /* DOCUMENTATION This routine assigns a unique identifier to the id field of a clause. It also inserts the clause into a hash table so that given an id number, the corresponding clause can be retrieved quickly (see find_clause_by_id()). */ /* PUBLIC */ void assign_clause_id(Topform c) { int i; if (c->id > 0) { p_clause(c); fatal_error("assign_clause_id, clause already has ID."); } c->id = next_clause_id(); i = c->id % CLAUSE_ID_TAB_SIZE; Topform_id_tab[i] = insert_clause_into_plist(Topform_id_tab[i], c, TRUE); c->official_id = 1; } /* assign_clause_id */ /************* * * unassign_clause_id(c) * *************/ /* DOCUMENTATION This routine removes a clause from the ID hash table and resets the ID of the clause to 0. A fatal error occurs if the clause has not been assigned an ID. */ /* PUBLIC */ void unassign_clause_id(Topform c) { if (c->official_id) { int i; Plist p1, p2; i = c->id % CLAUSE_ID_TAB_SIZE; for (p2 = NULL, p1 = Topform_id_tab[i]; p1 && ((Topform) p1->v)->id < c->id; p2 = p1, p1 = p1->next); if (p1 == NULL || ((Topform) p1->v)->id != c->id) { p_clause(c); fatal_error("unassign_clause_id, cannot find clause."); } if (p2) p2->next = p1->next; else Topform_id_tab[i] = p1->next; c->id = 0; free_plist(p1); c->official_id = 0; } } /* unassign_clause_id */ /************* * * find_clause_by_id(id) * * Given a clause ID, retrieve the clause (or NULL). * *************/ /* DOCUMENTATION This routine retrieves the clause with the given ID number (or NULL, if there is no such clause). */ /* PUBLIC */ Topform find_clause_by_id(int id) { int i; Plist p1; i = id % CLAUSE_ID_TAB_SIZE; for (p1 = Topform_id_tab[i]; p1 && ((Topform) p1->v)->id < id; p1 = p1->next); if (p1 != NULL && ((Topform) p1->v)->id == id) return(p1->v); else return(NULL); } /* find_clause_by_id */ /************* * * fprint_clause_id_tab(fp) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) all the clauses in the ID hash table. */ /* PUBLIC */ void fprint_clause_id_tab(FILE *fp) { int i; Plist p; fprintf(fp, "\nID clause table:\n"); for (i=0; inext) fprint_clause(fp, p->v); fflush(fp); } /* fprint_clause_id_tab */ /************* * * p_clause_id_tab(tab) * *************/ /* DOCUMENTATION This routine prints (to stdout) all the clauses in the ID hash table. */ /* PUBLIC */ void p_clause_id_tab() { fprint_clause_id_tab(stdout); } /* p_clause_id_tab */ /************* * * insert_clause_into_plist() * *************/ /* DOCUMENTATION This routine inserts a clause into a sorted (by ID) Plist of clauses. Boolean paramemeter "increasing" tells whether the list is increasing or decreasing. The updated Plist is returned. If the clause is already there, nothing happens. */ /* PUBLIC */ Plist insert_clause_into_plist(Plist p, Topform c, BOOL increasing) { Plist prev, curr, new; prev = NULL; curr = p; while (curr != NULL && (increasing ? ((Topform) curr->v)->id < c->id : ((Topform) curr->v)->id > c->id)) { prev = curr; curr = curr->next; } if (curr == NULL || ((Topform) curr->v)->id != c->id) { new = get_plist(); new->v = c; new->next = curr; if (prev != NULL) prev->next = new; else p = new; } return p; } /* insert_clause_into_plist */ /************* * * clause_plist_member() * *************/ /* DOCUMENTATION This routine checks if a clause occurs in a sorted (by ID) Plist of clauses. Boolean paramemeter "increasing" tells whether the list is increasing or decreasing. */ /* PUBLIC */ BOOL clause_plist_member(Plist p, Topform c, BOOL increasing) { Plist curr = p; while (curr != NULL && (increasing ? ((Topform) curr->v)->id < c->id : ((Topform) curr->v)->id > c->id)) { curr = curr->next; } return (curr != NULL && ((Topform) curr->v)->id == c->id); } /* clause_plist_member */ LADR-2009-11A/ladr/compile0000644000175000017500000000172110462270205014312 0ustar mccunemccunecd /home/mccune/LADR/ladr/ make ladr make libladr.a make[1]: Entering directory `/home/mccune/LADR/ladr' gcc -O -Wall -c -o literals.o literals.c gcc -O -Wall -c -o parautil.o parautil.c ar rs libladr.a fatal.o string.o memory.o clock.o strbuf.o hash.o order.o glist.o symbols.o options.o nonport.o ibuffer.o term.o termflag.o listterm.o tlist.o termorder.o parse.o accanon.o attrib.o flatterm.o unify.o fpalist.o fpa.o discrim.o discrimb.o discrimw.o dioph.o btu.o btm.o mindex.o flatdemod.o literals.o tformula.o clist.o formula.o cnf.o clausify.o pindex.o ioutil.o clauseid.o subsume.o lindex.o clause2.o fastparse.o sos.o weight.o symbolcheck.o maximal.o just.o random.o features.o di_tree.o compress.o int_code.o clause3.o ivy.o demod.o clash.o resolve.o parautil.o paramod.o backdemod.o hints.o basic.o ac_redun.o xproofs.o interp.o std_options.o top_input.o banner.o make[1]: Leaving directory `/home/mccune/LADR/ladr' Compilation finished at Thu Jul 27 21:03:40 LADR-2009-11A/ladr/flatterm.c0000644000175000017500000001653611167762642014751 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "flatterm.h" /* Private definitions and types */ /* * memory management */ #define PTRS_FLATTERM PTRS(sizeof(struct flatterm)) static unsigned Flatterm_gets, Flatterm_frees; /************* * * Flatterm get_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Flatterm get_flatterm(void) { Flatterm p = get_mem(PTRS_FLATTERM); /* get uninitialized memory */ Flatterm_gets++; p->prev = NULL; p->next = NULL; p->varnum_bound_to = -1; p->alternative = NULL; p->reduced_flag = FALSE; p->size = 0; /* end, arity, private_symbol not initilized */ return(p); } /* get_flatterm */ /************* * * free_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_flatterm(Flatterm p) { free_mem(p, PTRS_FLATTERM); Flatterm_frees++; } /* free_flatterm */ /************* * * fprint_flatterm_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the flatterm package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_flatterm_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct flatterm); fprintf(fp, "flatterm (%4d) %11u%11u%11u%9.1f K\n", n, Flatterm_gets, Flatterm_frees, Flatterm_gets - Flatterm_frees, ((Flatterm_gets - Flatterm_frees) * n) / 1024.); } /* fprint_flatterm_mem */ /************* * * p_flatterm_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the flatterm package. */ /* PUBLIC */ void p_flatterm_mem() { fprint_flatterm_mem(stdout, TRUE); } /* p_flatterm_mem */ /* * end of memory management */ /************* * * flatterm_ident() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL flatterm_ident(Flatterm a, Flatterm b) { Flatterm ai, bi; for (ai = a, bi = b; ai != a->end->next; ai = ai->next, bi = bi->next) if (ai->private_symbol != bi->private_symbol) return FALSE; return TRUE; } /* flatterm_ident */ /************* * * zap_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_flatterm(Flatterm f) { Flatterm fi = f; while (fi != f->end->next) { Flatterm tmp = fi; fi = fi->next; free_flatterm(tmp); } } /* zap_flatterm */ /************* * * term_to_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Flatterm term_to_flatterm(Term t) { Flatterm f = get_flatterm(); f->private_symbol = t->private_symbol; ARITY(f) = ARITY(t); if (VARIABLE(t)) { f->end = f; f->size = 1; return f; } else { int n = 1; int i; Flatterm end = f; for (i = 0; i < ARITY(t); i++) { Flatterm arg = term_to_flatterm(ARG(t,i)); n += arg->size; end->next = arg; arg->prev = end; end = arg->end; } f->end = end; f->size = n; return f; } } /* term_to_flatterm */ /************* * * flatterm_to_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term flatterm_to_term(Flatterm f) { if (VARIABLE(f)) return get_variable_term(VARNUM(f)); else { Term t = get_rigid_term_dangerously(SYMNUM(f),ARITY(f)); int i; Flatterm g = f->next; for (i = 0; i < ARITY(f); i++) { ARG(t,i) = flatterm_to_term(g); g = g->end->next; } return t; } } /* flatterm_to_term */ /************* * * copy_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Flatterm copy_flatterm(Flatterm f) { int i; int n = 1; Flatterm g = get_flatterm(); Flatterm end = g; Flatterm arg = f->next; g->private_symbol = f->private_symbol; ARITY(g) = ARITY(f); for (i = 0; i < ARITY(f); i++) { Flatterm b = copy_flatterm(arg); n += b->size; end->next = b; b->prev = end; end = b->end; arg = arg->end->next; } g->end = end; g->size = n; return g; } /* copy_flatterm */ /************* * * print_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_flatterm(Flatterm f) { if (VARIABLE(f)) { if (VARNUM(f) < 3) printf("%c", 'x' + VARNUM(f)); else if (VARNUM(f) < 6) printf("%c", 'r' + VARNUM(f)); else printf("v%d", VARNUM(f)); } else if (CONSTANT(f)) printf("%s", sn_to_str(SYMNUM(f))); else { int i; Flatterm g = f->next; printf("%s(", sn_to_str(SYMNUM(f))); for (i = 0; i < ARITY(f); i++) { print_flatterm(g); if (i < ARITY(f) - 1) printf(","); g = g->end->next; } printf(")"); } } /* print_flatterm */ /************* * * flatterm_symbol_count() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int flatterm_symbol_count(Flatterm f) { if (VARIABLE(f)) return 1; else { int n = 1; int i; Flatterm g = f->next; for (i = 0; i < ARITY(f); i++) { n += flatterm_symbol_count(g); g = g->end->next; } return n; } } /* flatterm_symbol_count */ /************* * * p_flatterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_flatterm(Flatterm f) { print_flatterm(f); printf("\n"); fflush(stdout); } /* p_flatterm */ /************* * * flat_occurs_in() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL flat_occurs_in(Flatterm t1, Flatterm t2) { Flatterm t2i; for (t2i = t2; t2i != t2->end->next; t2i = t2i->next) if (flatterm_ident(t1, t2i)) return TRUE; return FALSE; } /* flat_occurs_in */ /************* * * flat_multiset_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list flat_multiset_vars(Flatterm f) { I2list vars = NULL; Flatterm fi; for (fi = f; fi != f->end->next; fi = fi->next) if (VARIABLE(fi)) vars = multiset_add(vars, VARNUM(fi)); return vars; } /* flat_multiset_vars */ /************* * * flat_variables_multisubset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL flat_variables_multisubset(Flatterm a, Flatterm b) { I2list a_vars = flat_multiset_vars(a); I2list b_vars = flat_multiset_vars(b); BOOL ok = i2list_multisubset(a_vars, b_vars); zap_i2list(a_vars); zap_i2list(b_vars); return ok; } /* flat_variables_multisubset */ /************* * * flatterm_count_without_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int flatterm_count_without_vars(Flatterm f) { if (VARIABLE(f)) return 0; else { int n = 1; int i; Flatterm g = f->next; for (i = 0; i < ARITY(f); i++) { n += flatterm_count_without_vars(g); g = g->end->next; } return n; } } /* flatterm_count_without_vars */ LADR-2009-11A/ladr/clause_misc.c0000644000175000017500000001272410637466321015411 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clause_misc.h" /* Private definitions and types */ /* * memory management */ /************* * * clist_copy() * *************/ /* DOCUMENTATION Copy a clist of clauses. Justificatons and attributes are copied, and the clauses get new IDs. */ /* PUBLIC */ Clist clist_copy(Clist a, BOOL assign_ids) { Clist b = clist_init(a->name); Clist_pos p; for(p = a->first; p; p = p->next) { Topform c = copy_clause(p->c); c->justification = copy_justification(p->c->justification); c->attributes = copy_attributes(p->c->attributes); if (assign_ids) assign_clause_id(c); clist_append(c, b); } return b; } /* clist_copy */ /************* * * copy_clauses_to_clist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Clist copy_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids) { Clist b = clist_init(name); Plist p; for (p = clauses; p; p = p->next) { Topform x = p->v; Topform c = copy_clause(x); c->justification = copy_justification(x->justification); c->attributes = copy_attributes(x->attributes); if (assign_ids) assign_clause_id(c); clist_append(c, b); } return b; } /* copy_clauses_to_clist */ /************* * * move_clauses_to_clist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Clist move_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids) { Clist b = clist_init(name); Plist p; for (p = clauses; p; p = p->next) { Topform c = p->v; if (assign_ids && c->id == 0) assign_clause_id(c); clist_append(c, b); } return b; } /* move_clauses_to_clist */ /************* * * input_clauses() * *************/ /* DOCUMENTATION Given a Plist of clauses, return the Plist of input clauses (in the same order). */ /* PUBLIC */ Plist input_clauses(Plist a) { if (a == NULL) return NULL; else { Plist c = input_clauses(a->next); if (has_input_just(a->v)) return plist_prepend(c, a->v); else return c; } } /* input_clauses */ /************* * * delete_clause() * *************/ /* DOCUMENTATION This routine frees a clause and all of its subterms. If the clause has an ID, it is unassigned. If the clause has a justification list, it is freed.

This routine is not in the clause package, because (at this time) the clause package doesn't know about just.h or clauseid.h. */ /* PUBLIC */ void delete_clause(Topform c) { zap_just(c->justification); /* ok if NULL */ unassign_clause_id(c); /* ok if ID is not "official" */ zap_topform(c); /* zaps attributes */ } /* delete_clause */ /************* * * delete_clist() * *************/ /* DOCUMENTATION For each Topform in the Clist, remove it from the Clist; if it occurs in no other Clists, call delete_clause(). Finally, free the Clist.

This routine is not in the clist package, because (at this time) the clist package doesn't know about just.h or clauseid.h. */ /* PUBLIC */ void delete_clist(Clist l) { Clist_pos p; Topform c; p = l->first; while (p) { c = p->c; p = p->next; clist_remove(c, l); if (c->containers == NULL) delete_clause(c); } clist_free(l); } /* delete_clist */ /************* * * copy_clause_ija() * *************/ /* DOCUMENTATION Copy a clause, including ID, justification, attributes, and termflags. Clauses constructed with this routine should be deallocated with delete_clause(). */ /* PUBLIC */ Topform copy_clause_ija(Topform c) { Topform d = copy_clause_with_flags(c); d->id = c->id; d->justification = copy_justification(c->justification); d->attributes = copy_attributes(c->attributes); return d; } /* copy_clause_ija */ /************* * * copy_clauses_ija() * *************/ /* DOCUMENTATION Copy a Plist of clauses. Clauses are coped with copy_clause_ija(), which copies ID, justification, attributes, and termflags. */ /* PUBLIC */ Plist copy_clauses_ija(Plist p) { Plist a; Plist b = NULL; /* the new list */ for (a = p; a; a = a->next) { Topform old = a->v; Topform new = copy_clause_ija(old); b = plist_prepend(b, new); /* build it backward */ } return reverse_plist(b); } /* copy_clauses_ija */ /************* * * delete_clauses() * *************/ /* DOCUMENTATION Delete (deep) a Pist of clauses. */ /* PUBLIC */ void delete_clauses(Plist p) { if (p != NULL) { delete_clauses(p->next); delete_clause(p->v); free_plist(p); } } /* delete_clauses */ /************* * * make_clause_basic() * *************/ /* DOCUMENTATION This routine clears all of the "nonbasic" marks in a clause. */ /* PUBLIC */ void make_clause_basic(Topform c) { Literals lit; for (lit = c->literals; lit; lit = lit->next) clear_all_nonbasic_marks(lit->atom); } /* make_clause_basic */ LADR-2009-11A/ladr/just.h0000644000175000017500000001365111151265364014110 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_JUST_H #define TP_JUST_H #include "clauseid.h" #include "parse.h" /* INTRODUCTION */ /* Public definitions */ typedef enum { INPUT_JUST, /* Primary */ GOAL_JUST, /* Primary */ DENY_JUST, /* Primary int (ID) */ CLAUSIFY_JUST, /* Primary int (ID) */ COPY_JUST, /* Primary int (ID) */ BACK_DEMOD_JUST, /* Primary int (ID) */ BACK_UNIT_DEL_JUST, /* Primary int (ID) */ NEW_SYMBOL_JUST, /* Primary int (ID) */ EXPAND_DEF_JUST, /* Primary Ilist (ID,def-ID) */ BINARY_RES_JUST, /* Primary Ilist */ HYPER_RES_JUST, /* Primary Ilist */ UR_RES_JUST, /* Primary Ilist */ FACTOR_JUST, /* Primary Ilist (ID,lit1,lit2) */ XXRES_JUST, /* Primary Ilist (ID,lit) */ PARA_JUST, /* Primary Parajust */ PARA_FX_JUST, /* Primary Parajust */ PARA_IX_JUST, /* Primary Parajust */ PARA_FX_IX_JUST, /* Primary Parajust */ INSTANCE_JUST, /* Primary Instancejust */ PROPOSITIONAL_JUST, /* Primary int (ID) */ DEMOD_JUST, /* Secondary I3list */ UNIT_DEL_JUST, /* Secondary Ilist (lit,ID) */ FLIP_JUST, /* Secondary int (lit) */ XX_JUST, /* Secondary int (lit) */ MERGE_JUST, /* Secondary int (lit) */ EVAL_JUST, /* Secondary int (count) */ IVY_JUST, /* Primary Ivyjust */ UNKNOWN_JUST /* probably an error */ } Just_type; typedef struct parajust * Parajust; struct parajust { int from_id; int into_id; Ilist from_pos; Ilist into_pos; }; typedef struct instancejust * Instancejust; struct instancejust { int parent_id; Plist pairs; }; typedef struct ivyjust * Ivyjust; struct ivyjust { Just_type type; /* input,resolve,paramod,instantiate,flip,propositional */ int parent1; int parent2; Ilist pos1; Ilist pos2; Plist pairs; /* for instantiate */ }; typedef struct just * Just; struct just { Just_type type; Just next; union { int id; Ilist lst; Parajust para; I3list demod; Instancejust instance; Ivyjust ivy; } u; }; /* A justification starts with a Primary part and then has a sequence (maybe none) of Secondary parts. Each type has some data, an integer or Ilist (integer list) giving clause IDs, or positions of literals or subterms. */ /* End of public definitions */ /* Public function prototypes from just.c */ Just get_just(void); Parajust get_parajust(void); Instancejust get_instancejust(void); void fprint_just_mem(FILE *fp, BOOL heading); void p_just_mem(); Just ivy_just(Just_type type, int parent1, Ilist pos1, int parent2, Ilist pos2, Plist pairs); Just input_just(void); Just goal_just(void); Just deny_just(Topform tf); Just clausify_just(Topform tf); Just expand_def_just(Topform tf, Topform def); Just copy_just(Topform c); Just propositional_just(Topform c); Just new_symbol_just(Topform c); Just back_demod_just(Topform c); Just back_unit_deletion_just(Topform c); Just binary_res_just(Topform c1, int n1, Topform c2, int n2); Just binary_res_just_by_id(int c1, int n1, int c2, int n2); Just factor_just(Topform c, int lit1, int lit2); Just xxres_just(Topform c, int lit); Just resolve_just(Ilist g, Just_type type); Just demod_just(I3list steps); Just para_just(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec); Just instance_just(Topform parent, Plist pairs); Just para_just_rev_copy(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec); Just unit_del_just(Topform deleter, int literal_num); Just flip_just(int n); Just xx_just(int n); Just merge_just(int n); Just eval_just(int n); Just append_just(Just j1, Just j2); Just copy_justification(Just j); char *jstring(Just j); int jmap1(I3list map, int i); char *jmap2(I3list map, int i, char *a); void sb_append_id(String_buf sb, int id, I3list map); void sb_write_ids(String_buf sb, Ilist p, I3list map); void sb_write_just(String_buf sb, Just just, I3list map); void sb_xml_write_just(String_buf sb, Just just, I3list map); void p_just(Just j); void zap_just(Just just); Ilist get_parents(Just just, BOOL all); Topform first_negative_parent(Topform c); Plist get_clause_ancestors(Topform c); int proof_length(Plist proof); void map_just(Just just, I2list map); int just_count(Just j); void mark_parents_as_used(Topform c); int clause_level(Topform c); Just term_to_just(Term lst); BOOL primary_just_type(Topform c, Just_type t); BOOL has_input_just(Topform c); BOOL has_copy_just(Topform c); BOOL has_copy_flip_just(Topform c); void sb_tagged_write_just(String_buf sb, Just just, I3list map); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/sed30000644000175000017500000000007610462276407013534 0ustar mccunemccunes/get_clause(/get_topform(/g s/free_clause(/free_topform(/g LADR-2009-11A/ladr/header.h0000644000175000017500000000214611075034033014340 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_HEADER_H #define TP_HEADER_H /* The most basic includes and definitions. */ #include #include #include #include typedef enum { FALSE=0, TRUE=1 } BOOL; #define IMAX(a,b) ((a) > (b) ? (a) : (b)) #define IMIN(a,b) ((a) < (b) ? (a) : (b)) #define DBL_LARGE 10E11 #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/flatdemod.c0000644000175000017500000002570311170011336015043 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "flatdemod.h" /* Private definitions and types */ static int Fdemod_attempts = 0; static int Fdemod_rewrites = 0; /************* * * fapply_demod() * *************/ /* DOCUMENTATION Special-purpose apply for Flatterm demodulation. Apply a substitution to a (ordinary) Term, building a Flatterm. Assumptions: (1) the terms in the substitution are Flatterms; (2) every variable in the term is bound. In the result, Flatterms that are copied from the substitution have the "reduced_flag" set. */ /* PUBLIC */ Flatterm fapply_demod(Term t, Context c) { Flatterm f; if (VARIABLE(t)) { f = copy_flatterm((Flatterm) c->terms[VARNUM(t)]); f->reduced_flag = TRUE; } else { int n = 1; int i; Flatterm end; f = get_flatterm(); f->private_symbol = t->private_symbol; ARITY(f) = ARITY(t); end = f; for (i = 0; i < ARITY(t); i++) { Flatterm a = fapply_demod(ARG(t,i), c); n += a->size; end->next = a; a->prev = end; end = a->end; } f->size = n; f->end = end; } return f; } /* fapply_demod */ enum { GO, BACKTRACK }; /************* * * discrim_flat_retrieve_leaf() * *************/ #if 0 static void maybe_unbind(Flatterm f, Context subst) { if (f->varnum_bound_to >= 0) { subst->terms[f->varnum_bound_to] = NULL; f->varnum_bound_to = -1; } } /* maybe_unbind */ #endif #define MAYBE_UNBIND(f,c) if (f->varnum_bound_to >= 0) { c->terms[f->varnum_bound_to] = NULL; f->varnum_bound_to = -1; } /* DOCUMENTATION */ /* PUBLIC */ Plist discrim_flat_retrieve_leaf(Flatterm fin, Discrim root, Context subst, Flatterm *ppos) { Flatterm f = NULL; Discrim d = NULL; BOOL status = GO; if (root) { /* first call */ d = root->u.kids; f = fin; if (d == NULL) return NULL; else status = GO; } else { f = *ppos; status = BACKTRACK; } while (TRUE) { if (status == BACKTRACK) { while (f != fin && f->alternative == NULL) { MAYBE_UNBIND(f, subst); f = f->prev; } if (f == fin) return NULL; /* fail */ else { MAYBE_UNBIND(f, subst); d = f->alternative; f->alternative = NULL; status = GO; } } /* backtrack */ if (DVAR(d)) { int varnum = d->symbol; Flatterm b = (Flatterm) subst->terms[varnum]; if (b) { f->alternative = d->next; if (flatterm_ident(f, b)) f = f->end; /* already bound to identical term */ else status = BACKTRACK; /* already bound to something else */ } else { subst->terms[varnum] = (Term) f; f->varnum_bound_to = varnum; f->alternative = d->next; f = f->end; } } else if (VARIABLE(f)) status = BACKTRACK; else { int symnum = SYMNUM(f); Discrim dd = NULL; while (d && d->symbol < symnum) { dd = d; d = d->next; } if (!d || d->symbol != symnum) status = BACKTRACK; } if (status == GO) { if (f == fin->end) { *ppos = f; return d->u.data; /* succeed */ } else { f = f->next; d = d->u.kids; } } /* go */ } /* while */ } /* discrim_flat_retrieve_leaf */ /************* * * discrim_flat_retrieve_first(t, root, subst, ppos) * *************/ /* DOCUMENTATION */ /* PUBLIC */ void *discrim_flat_retrieve_first(Flatterm f, Discrim root, Context subst, Discrim_pos *ppos) { Plist tp; Flatterm f2 = NULL; tp = discrim_flat_retrieve_leaf(f, root, subst, &f2); if (tp == NULL) return NULL; else { Discrim_pos pos = get_discrim_pos(); pos->query = f; pos->subst = subst; pos->data = tp; pos->backtrack = f2; *ppos = pos; return tp->v; } } /* discrim_flat_retrieve_first */ /************* * * discrim_flat_retrieve_next(ppos) * *************/ /* DOCUMENTATION */ /* PUBLIC */ void *discrim_flat_retrieve_next(Discrim_pos pos) { Plist tp; tp = pos->data->next; if (tp != NULL) { /* if any more terms in current leaf */ pos->data = tp; return tp->v; } else { /* try for another leaf */ tp = discrim_flat_retrieve_leaf(pos->query, NULL, pos->subst, (Flatterm *) &(pos->backtrack)); if (tp != NULL) { pos->data = tp; return tp->v; } else { free_discrim_pos(pos); return NULL; } } } /* discrim_flat_retrieve_next */ /************* * * discrim_flat_cancel(pos) * *************/ /* DOCUMENTATION */ /* PUBLIC */ void discrim_flat_cancel(Discrim_pos pos) { Flatterm f = pos->backtrack; Flatterm query = (Flatterm) pos->query; while (f != query->prev) { if (f->varnum_bound_to >= 0) { pos->subst->terms[f->varnum_bound_to] = NULL; f->varnum_bound_to = -1; } f->alternative = NULL; f = f->prev; } free_discrim_pos(pos); } /* discrim_flat_cancel */ /************* * * fdemod() * *************/ static Flatterm fdemod(Flatterm f, Discrim root, Context subst, int *step_limit, int size_limit, int *current_size, int *sequence, I3list *just_head, BOOL lex_order_vars) { if (*step_limit == 0 || *current_size > size_limit) return f; else if (VARIABLE(f)) return f; else if (f->reduced_flag) { (*sequence) += flatterm_count_without_vars(f); return f; } else { int sequence_save = *sequence; { /* demodulate subterms */ Flatterm arg = f->next; Flatterm end = f; int n = 1; int i; for (i = 0; i < ARITY(f); i++) { Flatterm next = arg->end->next; Flatterm a2 = fdemod(arg, root, subst, step_limit, size_limit, current_size, sequence, just_head, lex_order_vars); n += a2->size; end->next = a2; a2->prev = end; end = a2->end; arg = next; } f->size = n; f->end = end; f->prev = end->next = NULL; /* helpful for debugging */ } /* end: demodulate subterms */ if (*current_size > size_limit) return f; /* size limit has been reached */ else if (*step_limit == 0) return f; /* step limit has been reached */ else { /* try to rewrite top */ Discrim_pos dpos; Term candidate = discrim_flat_retrieve_first(f, root, subst, &dpos); BOOL rewrite = FALSE; Fdemod_attempts++; (*sequence)++; while (candidate && !rewrite) { Topform demodulator = candidate->container; Term atom = demodulator->literals->atom; Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); BOOL match_left = (candidate == alpha); Term other = (match_left ? beta : alpha); Flatterm contractum = fapply_demod(other, subst); if (oriented_eq(atom)) rewrite = TRUE; else if (flat_greater(f, contractum, lex_order_vars)) { rewrite = TRUE; /* printf("kbo=%d ", rewrite); p_flatterm(f); printf(" " ); p_flatterm(contractum); printf("\n"); */ } else rewrite = FALSE; if (rewrite) { int increase_in_size = contractum->size - f->size; (*current_size) += increase_in_size; /* likely to be negative */ (*step_limit)--; Fdemod_rewrites++; discrim_flat_cancel(dpos); zap_flatterm(f); *just_head = i3list_prepend(*just_head, demodulator->id, *sequence, match_left ? 1 : 2); *sequence = sequence_save; f = fdemod(contractum, root, subst, step_limit, size_limit, current_size, sequence, just_head, lex_order_vars); } else { zap_flatterm(contractum); candidate = discrim_flat_retrieve_next(dpos); } } } /* end: try to rewrite top */ f->reduced_flag = TRUE; return(f); } } /* fdemod */ /************* * * fdemodulate() * *************/ /* DOCUMENTATION This routine demodulates a term. ID numbers of demodulators are put on the front of just_head, so you'll probably want to reverse the list before putting it into the clause justification.

This version uses flatterm retrieval. */ /* PUBLIC */ Term fdemodulate(Term t, Discrim root, int *step_limit, int *increase_limit, int *sequence, I3list *just_head, BOOL lex_order_vars) { Flatterm f = term_to_flatterm(t); Context subst = get_context(); int current_size = f->size; int size_limit = (*increase_limit==INT_MAX) ? INT_MAX : current_size + *increase_limit; Flatterm f2 = fdemod(f, root, subst, step_limit, size_limit, ¤t_size, sequence, just_head, lex_order_vars); free_context(subst); if (current_size > size_limit) *increase_limit = -1; /* lets callers know that limit has been exceeded */ if (*just_head == NULL) { zap_flatterm(f2); return t; } else { Term t2 = flatterm_to_term(f2); zap_flatterm(f2); zap_term(t); return t2; } } /* fdemodulate */ /************* * * fdemod_attempts() * *************/ /* DOCUMENTATION Return the number of flatterm rewrite attempts so far. */ /* PUBLIC */ int fdemod_attempts() { return Fdemod_attempts; } /* fdemod_attempts */ /************* * * fdemod_rewrites() * *************/ /* DOCUMENTATION Return the number of successful flatterm rewrites so far. */ /* PUBLIC */ int fdemod_rewrites() { return Fdemod_rewrites; } /* fdemod_rewrites */ /************* * * fdemod_clause() * *************/ /* DOCUMENTATION Demodulate Topform c, using demodulators in Mindex idx. If any rewriting occurs, the justification is appended to the clause's existing justification.

This version uses flatterm retrievel. */ /* PUBLIC */ void fdemod_clause(Topform c, Mindex idx, int *step_limit, int *increase_limit, BOOL lex_order_vars) { if (mindex_empty(idx)) return; else { Literals lit; I3list steps = NULL; /* The "sequence" variable counts the (nonvariable) subterms that are visited as we demodulate. Bottom-up, left-to-right. When a term is rewritten, the justification is a triple of integers: . The sequence number n means that the n-th node is rewritten, counting as if this is the only demodulation step applied to the clause. */ int sequence = 0; for (lit = c->literals; lit != NULL; lit = lit->next) lit->atom = fdemodulate(lit->atom, idx->discrim_tree, step_limit, increase_limit, &sequence, &steps, lex_order_vars); upward_clause_links(c); if (steps != NULL) { steps = reverse_i3list(steps); c->justification = append_just(c->justification, demod_just(steps)); } } } /* fdemod_clause */ LADR-2009-11A/ladr/strbuf.h0000644000175000017500000000423411151265363014424 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_STRBUF_H #define TP_STRBUF_H #include "string.h" /* INTRODUCTION A String_buf is a kind of string that can grow as big as you need. This is implemented as a list of dynamically allocated character arrays of fixed size. The only problem with using String_bufs is that you have to remember to free a String_buf when you are finished with it.

This is similar to the StringBuffer class in Java, and the cstrings of our old theorem prover LMA/ITP. We didn't have anything like this in Otter, but there were times when I wish we had, so here it is. */ /* Public definitions */ typedef struct string_buf * String_buf; /* End of public definitions */ /* Public function prototypes from strbuf.c */ String_buf get_string_buf(void); void fprint_strbuf_mem(FILE *fp, BOOL heading); void p_strbuf_mem(); String_buf init_string_buf(char *s); void fprint_sb(FILE *fp, String_buf sb); void p_sb(String_buf sb); void sb_append(String_buf sb, char *s); void sb_append_char(String_buf sb, char c); void sb_replace_char(String_buf sb, int i, char c); char sb_char(String_buf sb, int n); void sb_cat_copy(String_buf sb1, String_buf sb2); void sb_cat(String_buf sb1, String_buf sb2); void zap_string_buf(String_buf sb); char *sb_to_malloc_string(String_buf sb); char *sb_to_malloc_char_array(String_buf sb); int sb_size(String_buf sb); void sb_append_int(String_buf sb, int i); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/nonport.h0000644000175000017500000000252111151265363014613 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_NONPORT_H #define TP_NONPORT_H /* #define PRIMITIVE_ENVIRONMENT */ /* INTRODUCTION This package has some utilities that might not be portable to other environments. If you get errors trying to compile this package, you can either modify nonport.c, or

#define PRIMITIVE_ENVIRONMENT
in nonport.h, which disables everything. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from nonport.c */ char *username(void); char *hostname(void); int my_process_id(void); int get_bits(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/error0000644000175000017500000000042310674567502014027 0ustar mccunemccune fprintf(fout, "%%%%ERROR: unrecognized command or list:\n\n"); fprintf(fout, "%%%%START ERROR%%%%\n"); fprint_term(fout, t); fprintf(fout, "\n"); fprintf(fout, "%%%%END ERROR%%%%\n"); fatal_error("read_from_file, unrecognized command or list"); LADR-2009-11A/ladr/interp.c0000644000175000017500000017277211035236214014422 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "interp.h" #include "ioutil.h" /* TO DO: 1. Get rid of arity limits. */ /* Private definitions and types */ struct interp { Term t; /* the term representation (maybe NULL) */ Term comments; /* list of comments (maybe NULL) */ int size; /* domain size */ /* Array of pointers to tables, one for each constant, function, * or predicate symbol (indexed by symbol number). The arity and * print symbol can be obtained from the symbol number. */ int num_tables; /* number of tables */ int **tables; int *arities; /* arity of tables[i] */ int *types; /* type of tables[i]: FUNCTION or RELATION */ int *occurrences; /* number of occurrences of each element */ int num_discriminators; int *discriminator_counts; int **profile; /* [size,profile_components] */ int num_profile_components; int *blocks; /* of identical components */ BOOL incomplete; }; #define ISWAP(x,y) {int t = x; x = y; y = t;} /* We're using 1D arrays to for higher dimensions. */ #define I2(n,i,j) ((i) * (n) + (j)) #define I3(n,i,j,k) ((i) * (n) * (n) + (j) * (n) + (k)) #define UNDEFINED 0 #define FUNCTION 1 #define RELATION 2 #define MAX_VARS_EVAL 100 /* statistics */ static long unsigned Iso_checks = 0; static long unsigned Iso_perms = 0; /* * memory management */ #define PTRS_INTERP PTRS(sizeof(struct interp)) static unsigned Interp_gets, Interp_frees; /************* * * Interp get_interp() * *************/ static Interp get_interp(void) { Interp p = get_cmem(PTRS_INTERP); Interp_gets++; return(p); } /* get_interp */ /************* * * free_interp() * *************/ static void free_interp(Interp p) { free_mem(p, PTRS_INTERP); Interp_frees++; } /* free_interp */ /************* * * fprint_interp_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the interp package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_interp_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct interp); fprintf(fp, "interp (%4d) %11u%11u%11u%9.1f K\n", n, Interp_gets, Interp_frees, Interp_gets - Interp_frees, ((Interp_gets - Interp_frees) * n) / 1024.); } /* fprint_interp_mem */ /************* * * p_interp_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the interp package. */ /* PUBLIC */ void p_interp_mem() { fprint_interp_mem(stdout, TRUE); } /* p_interp_mem */ /* * end of memory management */ /************* * * trivial_permutation() * *************/ static int *trivial_permutation(int n) { int *p = malloc(sizeof(int) * n); int i; for (i = 0; i < n; i++) p[i] = i; return p; } /* trivial_permutation */ /************* * * int_power() * *************/ /* DOCUMENTATION Return n^exp. If exp is negative, return -1. If the result is too big to fit into an int, return INT_MAX. */ /* PUBLIC */ int int_power(int n, int exp) { if (exp < 0) return -1; else { int i; int r = 1; for (i = 0; i < exp; i++) { int x = r * n; if (x < r) return INT_MAX; /* overflow */ r = x; } return r; } } /* int_power */ /************* * * compile_interp() * *************/ /* DOCUMENTATION This routine takes a term representing an interpretation and builds a data structure that allows fast evaluation of clauses and formulas w.r.t. the interpretation. Here is an example of the term form of an interpretation.
   interpretation(3, [
       function(e,      [0]),
       function(*(_,_), [0,1,2,1,2,0,2,0,1]),
       relation(p,      [1])
       relation(q(_),   [1,0,1])
       ])
The given Term t is not changed. */ /* PUBLIC */ Interp compile_interp(Term t, BOOL allow_incomplete) { Interp p; int number_of_ops, domain_size, arity; int i, j, n, symnum, val, max, rc; BOOL function = FALSE; int *table; Term comments = NULL; Term size = NULL; Term operations = NULL; if (ARITY(t) == 3) { /* interpretation(size, comments, ops). */ size = ARG(t,0); comments = ARG(t,1); operations = ARG(t,2); } else fatal_error("compile_interp, arity must be 3 (size, comments, ops)."); rc = str_to_int(sn_to_str(SYMNUM(size)), &domain_size); if (!rc || domain_size < 1) fatal_error("compile_interp, domain size out of range."); number_of_ops = listterm_length(operations); /* if (number_of_ops == 0) fatal_error("compile_interp, interpretation has no operations."); */ /* Get the largest symnum, so we can get a table array big enough. */ max = 0; for (i = 1; i <= number_of_ops; i++) { Term f = listterm_i(operations, i); if (ARITY(f) != 2 || VARIABLE(ARG(f,0))) fatal_error("compile_interp, bad operation."); symnum = SYMNUM(ARG(f,0)); max = symnum > max ? symnum : max; } p = get_interp(); p->t = copy_term(t); p->comments = copy_term(comments); p->size = domain_size; p->num_tables = max + 100 + 1; /* allow 100 extra in case of new symbols */ p->occurrences = malloc(domain_size * sizeof(int)); p->blocks = malloc(domain_size * sizeof(int)); p->profile = malloc(domain_size * sizeof(int *)); for (i = 0; i < domain_size; i++) { p->occurrences[i] = 0; p->blocks[i] = -1; p->profile[i] = NULL; } p->tables = malloc(p->num_tables * sizeof(int *)); p->types = malloc(p->num_tables * sizeof(int)); p->arities = malloc(p->num_tables * sizeof(int)); for (i = 0; i < p->num_tables; i++) { p->tables[i] = NULL; p->types[i] = UNDEFINED; p->arities[i] = -1; } for (i = 1; i <= number_of_ops; i++) { Term lst; Term f = listterm_i(operations, i); if (is_symbol(SYMNUM(f), "function", 2)) function = TRUE; else if (is_symbol(SYMNUM(f), "relation", 2) || is_symbol(SYMNUM(f), "predicate", 2)) { function = FALSE; } else fatal_error("compile_interp, bad function/relation"); symnum = SYMNUM(ARG(f,0)); arity = ARITY(ARG(f,0)); /* n = domain_size^arity */ for (j = 0, n = 1; j < arity; j++) n = n * domain_size; lst = ARG(f,1); if (listterm_length(lst) != n) fatal_error("compile_interp, list of elements is wrong " "length for arity/domain_size."); p->types[symnum] = (function ? FUNCTION : RELATION); p->arities[symnum] = arity; p->tables[symnum] = malloc(n * sizeof(int)); table = p->tables[symnum]; for (j = 0; j < n; j++, lst = ARG(lst,1)) { char *str = sn_to_str(SYMNUM(ARG(lst,0))); rc = str_to_int(str, &val); if (!rc) { if (allow_incomplete && str_ident(str, "-")) { table[j] = -1; p->incomplete = TRUE; } else fatal_error("compile_interp, bad domain elemnt."); } else if (function && (val < 0 || val > domain_size-1)) fatal_error("compile_interp, function element out of range."); else if (!function && (val < 0 || val > 1)) fatal_error("compile_interp, relation element out of range."); else { table[j] = val; if (function) p->occurrences[val]++; } } } return p; } /* compile_interp */ /************* * * transpose_binary() * *************/ /* DOCUMENTATION This routine takes a term representing an interpretation and (destructively) transposes all of the binary functions and relations. It is assumed that the interpretation is well-formed. You can check well-formedness first by calling compile_interp(). */ /* PUBLIC */ void transpose_binary(Term t) { int number_of_ops, n; int i, rc; Term operations; rc = str_to_int(sn_to_str(SYMNUM(ARG(t,0))), &n); operations = ARG(t,2); number_of_ops = listterm_length(operations); for (i = 1; i <= number_of_ops; i++) { Term f = listterm_i(operations, i); /* e.g., function(j(_,_), [0,1,1,0]) */ if (ARITY(ARG(f,0)) == 2) { int j, k; Term lst = ARG(f,1); /* e.g., [0,1,1,0] */ for (j = 0; j < n; j++) { for (k = j+1; k < n; k++) { Term t1 = listterm_i(lst, j*n+k+1); Term t2 = listterm_i(lst, k*n+j+1); int tmp = t1->private_symbol; t1->private_symbol = t2->private_symbol; t2->private_symbol = tmp; } } } } } /* transpose_binary */ /************* * * zap_interp() * *************/ /* DOCUMENTATION Free a compiled interpretation. */ /* PUBLIC */ void zap_interp(Interp p) { int i; free(p->occurrences); free(p->blocks); free(p->types); free(p->arities); if (p->discriminator_counts) free(p->discriminator_counts); for (i = 0; i < p->size; i++) if (p->profile[i]) free(p->profile[i]); free(p->profile); for (i = 0; i < p->num_tables; i++) if (p->tables[i] != NULL) free(p->tables[i]); free(p->tables); if (p->t != NULL) zap_term(p->t); if (p->comments != NULL) zap_term(p->comments); free_interp(p); } /* zap_interp */ /************* * * fprint_interp_tex() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in a form that might be useful as input to LaTeX. */ /* PUBLIC */ void fprint_interp_tex(FILE *fp, Interp p) { int n = p->size; int i; BOOL first = TRUE; if (p->comments) { Term comment = p->comments; while (cons_term(comment)) { fprintf(fp, "%% "); fwrite_term(fp, ARG(comment,0)); fprintf(fp, "\n"); comment = ARG(comment,1); } } fprintf(fp, "\\begin{table}[H] \\centering %% size %d\n", p->size); for (i = 0; i < p->num_tables; i++) { /* arity 0 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 0) { if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "%s: %d", sn_to_str(i), table[0]); } } for (i = 0; i < p->num_tables; i++) { /* arity 1 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 1) { int j; if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "\\begin{tabular}{r|"); for (j = 0; j < n; j++) fprintf(fp, "r"); fprintf(fp, "}\n"); fprintf(fp, "%s: & ", sn_to_str(i)); for (j = 0; j < n; j++) fprintf(fp, "%d%s", j, j < n-1 ? " & " : "\\\\\n\\hline\n & "); for (j = 0; j < n; j++) fprintf(fp, "%d%s", table[j], j < n-1 ? " & " : "\n"); fprintf(fp, "\\end{tabular}"); } } for (i = 0; i < p->num_tables; i++) { /* arity 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 2) { int j, k; if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "\\begin{tabular}{r|"); for (j = 0; j < n; j++) fprintf(fp, "r"); fprintf(fp, "}\n"); fprintf(fp, "%s: & ", sn_to_str(i)); for (j = 0; j < n; j++) fprintf(fp, "%d%s", j, j < n-1 ? " & " : "\\\\\n\\hline\n"); for (j = 0; j < n; j++) { fprintf(fp, " %d & ", j); for (k = 0; k < n; k++) { fprintf(fp, "%d%s", table[(n*j) + k], k < n-1 ? " & " : (j < n-1 ? " \\\\\n" : "\n")); } } fprintf(fp, "\\end{tabular}"); } } for (i = 0; i < p->num_tables; i++) { /* arity > 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity > 2) { fprintf(fp, "\n\n%% table for arity %d %s %s not printed.\n\n", arity, p->types[i] == FUNCTION ? "function" : "relation", sn_to_str(i)); } } fprintf(fp, "\n\\caption{ }\n"); fprintf(fp, "\\end{table}\n"); } /* fprint_interp_tex */ /************* * * compute_args() * *************/ static void compute_args(int *a, int arity, int n, int i) { int x = i; int r; for (r = arity-1; r >= 0; r--) { a[r] = x % n; x = x - a[r]; x = x / n; } } /* compute_args */ /************* * * fprint_interp_xml() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in a form that might be useful as input to LaTeX. */ /* PUBLIC */ void fprint_interp_xml(FILE *fp, Interp p) { int n = p->size; int i; fprintf(fp, "\n comments && !nil_term(p->comments)) { Term comment = p->comments; while (cons_term(comment)) { Term pair = ARG(comment,0); char *name = sn_to_str(SYMNUM(ARG(pair,0))); char *value = sn_to_str(SYMNUM(ARG(pair,1))); fprintf(fp, " %s=\"%s\"", name, value); comment = ARG(comment,1); } } fprintf(fp, ">\n"); for (i = 0; i < p->num_tables; i++) { /* arity 0 */ int *table = p->tables[i]; int arity = sn_to_arity(i); char *type = p->types[i] == FUNCTION ? "function" : "relation"; if (table != NULL && arity == 0) { fprintf(fp, "\n \n", type); fprintf(fp, " \n", sn_to_str(i)); fprintf(fp, " %d\n", table[0]); fprintf(fp, " \n"); } } for (i = 0; i < p->num_tables; i++) { /* arity 1 */ int *table = p->tables[i]; int arity = sn_to_arity(i); char *type = p->types[i] == FUNCTION ? "function" : "relation"; if (table != NULL && arity == 1) { int j; fprintf(fp, "\n \n", type); fprintf(fp, " \n", sn_to_str(i)); fprintf(fp, " "); for (j = 0; j < n; j++) fprintf(fp, "%d", j); fprintf(fp, "\n"); fprintf(fp, " "); for (j = 0; j < n; j++) fprintf(fp, "%d", table[j]); fprintf(fp, "\n"); fprintf(fp, " \n"); } } for (i = 0; i < p->num_tables; i++) { /* arity 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); char *type = p->types[i] == FUNCTION ? "function" : "relation"; if (table != NULL && arity == 2) { int j, k; fprintf(fp, "\n \n", type); fprintf(fp, " \n", sn_to_str(i)); fprintf(fp, " "); for (j = 0; j < n; j++) fprintf(fp, "%d", j); fprintf(fp, "\n"); for (j = 0; j < n; j++) { fprintf(fp, " %d ", j); for (k = 0; k < n; k++) fprintf(fp, "%d", table[(n*j) + k]); fprintf(fp, "\n"); } fprintf(fp, " \n"); } } for (i = 0; i < p->num_tables; i++) { /* arity > 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); char *type = p->types[i] == FUNCTION ? "function" : "relation"; if (table != NULL && arity > 2) { int *a = malloc(arity * sizeof(int)); int m = int_power(p->size, arity); int j; fprintf(fp, "\n \n", type, arity); fprintf(fp, " \n", sn_to_str(i)); for (j = 0; j < m; j++) { int k; compute_args(a, arity, p->size, j); fprintf(fp, " "); for (k = 0; k < arity; k++) fprintf(fp, "%d", a[k]); fprintf(fp, " %d \n", table[j]); } free(a); fprintf(fp, " \n"); } } fprintf(fp, " \n"); } /* fprint_interp_xml */ /************* * * fprint_interp_standard() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in standard form, with each operation on a separate line. */ /* PUBLIC */ void fprint_interp_standard(FILE *fp, Interp p) { int i; fprintf(fp, "interpretation( %d, ", p->size); if (p->comments) { fwrite_term(fp, p->comments); fprintf(fp, ", [\n"); } else fprintf(fp, "[], [\n"); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; if (table != NULL) { int j, n; int arity = sn_to_arity(i); fprintf(fp," %s(",p->types[i] == FUNCTION ? "function" : "relation"); if (arity == 0) fprintf(fp, "%s, [", sn_to_str(i)); else { fprintf(fp, "%s(", sn_to_str(i)); for (j = 0; j < arity; j++) fprintf(fp, "_%s", j == arity-1 ? "), [" : ","); } for (j = 0, n = 1; j < arity; j++, n = n * p->size); for (j = 0; j < n; j++) { if (table[j] == -1) fprintf(fp, "-%s" , j == n-1 ? "])" : ","); else fprintf(fp, "%d%s", table[j], j == n-1 ? "])" : ","); } /* ugly: decide if there are any more symbols */ for (j = i+1; j < p->num_tables && p->tables[j] == NULL; j++); if (j < p->num_tables && p->tables[j] != NULL) fprintf(fp, ",\n"); } } fprintf(fp, "]).\n"); } /* fprint_interp_standard */ /************* * * fprint_interp_standard2() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in standard form, with each operation on a separate line, except that binary operations are printed on multiple lines. */ /* PUBLIC */ void fprint_interp_standard2(FILE *fp, Interp p) { int i; fprintf(fp, "interpretation( %d, ", p->size); if (p->comments) { fwrite_term(fp, p->comments); fprintf(fp, ", [\n"); } else fprintf(fp, "[], [\n"); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; if (table != NULL) { int j, n; int arity = sn_to_arity(i); BOOL w = (arity == 2 && p->size > 10); fprintf(fp," %s(",p->types[i] == FUNCTION ? "function" : "relation"); if (arity == 0) fprintf(fp, "%s, [", sn_to_str(i)); else { fprintf(fp, "%s(", sn_to_str(i)); for (j = 0; j < arity; j++) fprintf(fp, "_%s", j == arity-1 ? "), " : ","); fprintf(fp, "[%s", arity== 2 ? "\n " : ""); } for (j = 0, n = 1; j < arity; j++, n = n * p->size); for (j = 0; j < n; j++) { if (table[j] == -1) fprintf(fp, w ? " -%s" : "-%s", j == n-1 ? "])" : ","); else fprintf(fp, w ? "%2d%s" : "%d%s", table[j], j == n-1 ? "])" : ","); if (arity == 2 && (j+1) % p->size == 0 && j != n-1) fprintf(fp, "\n "); } /* ugly: decide if there are any more symbols */ for (j = i+1; j < p->num_tables && p->tables[j] == NULL; j++); if (j < p->num_tables && p->tables[j] != NULL) fprintf(fp, ",\n"); } } fprintf(fp, "]).\n"); } /* fprint_interp_standard2 */ /************* * * portable_indent() * *************/ static void portable_indent(FILE *fp, int n) { int i; fprintf(fp, " "); for (i = 0; i < n; i++) fprintf(fp, " "); } /* portable_indent */ /************* * * portable_recurse() * *************/ static void portable_recurse(FILE *fp, int arity, int domain_size, int *table, int *idx_ptr, int depth) { if (arity == 0) fprintf(fp, "%2d", table[(*idx_ptr)++]); else { int i; portable_indent(fp, depth); fprintf(fp, "[%s", arity > 1 ? "\n" : ""); for (i = 0; i < domain_size; i++) { portable_recurse(fp, arity-1, domain_size, table, idx_ptr, depth+1); if (i < domain_size-1) fprintf(fp, ","); fprintf(fp, "%s", arity > 1 ? "\n" : ""); } if (arity > 1) portable_indent(fp, depth); fprintf(fp, "]"); } } /* portable_recurse */ /************* * * fprint_interp_portable() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in portable form. */ /* PUBLIC */ void fprint_interp_portable(FILE *fp, Interp p) { int i; Term t; fprintf(fp, " [%d,\n [", p->size); for (t = p->comments; t && !nil_term(t) ; t = ARG(t,1)) { fprintf(fp, " \""); fprint_term(fp, ARG(t,0)); fprintf(fp, "\"%s ", nil_term(ARG(t,1)) ? "" : ","); } fprintf(fp, "],\n"); fprintf(fp, " [\n"); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; if (table != NULL) { int j; int arity = sn_to_arity(i); int idx = 0; /* BOOL w = (arity == 2 && p->size > 10); */ fprintf(fp," [\"%s\", \"%s\", %d,\n", p->types[i] == FUNCTION ? "function" : "relation", sn_to_str(i), arity); if (arity == 0) portable_indent(fp, 1); portable_recurse(fp, arity, p->size, table, &idx, 1); fprintf(fp, "\n ]"); /* ugly: decide if there are any more symbols */ for (j = i+1; j < p->num_tables && p->tables[j] == NULL; j++); if (j < p->num_tables && p->tables[j] != NULL) fprintf(fp, ",\n"); else fprintf(fp, "\n ]\n ]"); } } } /* fprint_interp_portable */ /************* * * p_interp() * *************/ /* DOCUMENTATION This routine prints (to stdout) a compiled interpretation, in portable form, with each operation on a separate line. */ /* PUBLIC */ void p_interp(Interp p) { fprint_interp_standard(stdout, p); } /* p_interp */ /************* * * fprint_interp_cooked() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in cooked form, e.g., f(0,2)=1. */ /* PUBLIC */ void fprint_interp_cooked(FILE *fp, Interp p) { int i; if (p->comments) { Term comment = p->comments; while (cons_term(comment)) { fprintf(fp, "%% "); fwrite_term(fp, ARG(comment,0)); fprintf(fp, "\n"); comment = ARG(comment,1); } } fprintf(fp, "\n%% Interpretation of size %d\n", p->size); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; BOOL function = (p->types[i] == FUNCTION); if (table != NULL) { int j, n; int arity = sn_to_arity(i); fprintf(fp, "\n"); if (arity == 0) { if (table[0] == -1) fprintf(fp, "%s = -.\n", sn_to_str(i)); else fprintf(fp, "%s = %d.\n", sn_to_str(i), table[0]); } else { int *a = malloc(arity * sizeof(int)); n = int_power(p->size, arity); for (j = 0; j < n; j++) { int k; compute_args(a, arity, p->size, j); if (function) { fprintf(fp, "%s(", sn_to_str(i)); for (k = 0; k < arity; k++) fprintf(fp, "%d%s", a[k], k == arity-1 ? "" : ","); if (table[j] == -1) fprintf(fp, ") = -.\n"); else fprintf(fp, ") = %d.\n", table[j]); } else { fprintf(fp, "%s %s(", table[j] ? " " : not_sym(), sn_to_str(i)); for (k = 0; k < arity; k++) fprintf(fp, "%d%s", a[k], k == arity-1 ? "" : ","); fprintf(fp, ").\n"); } } free(a); } } } } /* fprint_interp_cooked */ /************* * * fprint_interp_tabular() * *************/ /* DOCUMENTATION This routine pretty prints (to FILE *fp) an interpretation in tabular (not easily parsable). Arities > 2 are not pretty. */ /* PUBLIC */ void fprint_interp_tabular(FILE *fp, Interp p) { int f, i, j; if (p->comments) { Term comment = p->comments; while (cons_term(comment)) { fprintf(fp, "%% "); fwrite_term(fp, ARG(comment,0)); fprintf(fp, "\n"); comment = ARG(comment,1); } } fprintf(fp, "\n%% Interpretation of size %d\n", p->size); for (f = 0; f < p->num_tables; f++) { int *table = p->tables[f]; if (table != NULL) { int n = p->size; int arity = sn_to_arity(f); fprintf(fp, "\n %s : ", sn_to_str(f)); if (arity == 0) fprintf(fp, "%d\n", table[0]); else if (arity == 1) { fprintf(fp, "\n "); for (i = 0; i < n; i++) fprintf(fp, "%2d", i); fprintf(fp, "\n ----"); for (i = 0; i < n; i++) fprintf(fp, "--"); fprintf(fp, "\n "); for (i = 0; i < n; i++) { if (table[i] == -1) fprintf(fp, " -"); else fprintf(fp, "%2d", table[i]); } fprintf(fp, "\n"); } else if (arity == 2) { fprintf(fp, "\n |"); for (i = 0; i < n; i++) fprintf(fp, "%2d", i); fprintf(fp, "\n ---+"); for (i = 0; i < n; i++) fprintf(fp, "--"); for (i = 0; i < n; i++) { fprintf(fp, "\n %2d |", i); for (j = 0; j < n; j++) { if (table[I2(n,i,j)] == -1) fprintf(fp, " -"); else fprintf(fp, "%2d", table[I2(n,i,j)]); } } fprintf(fp, "\n"); } else { int m = int_power(n, arity); fprintf(fp, "["); for (i = 0; i < m; i++) { if (table[i] == -1) fprintf(fp, "-%s", i == m-1 ? "]\n" : ","); else fprintf(fp, "%d%s", table[i], i == m-1 ? "]\n" : ","); } } } } /* for each function or relation */ } /* fprint_interp_tabular */ /************* * * fprint_interp_raw() * *************/ /* DOCUMENTATION This routine pretty prints (to FILE *fp) an interpretation in raw form. */ /* PUBLIC */ void fprint_interp_raw(FILE *fp, Interp p) { int f, i; if (p->comments) { Term comment = p->comments; while (cons_term(comment)) { fprintf(fp, "%% "); fwrite_term(fp, ARG(comment,0)); fprintf(fp, "\n"); comment = ARG(comment,1); } } fprintf(fp, "\n%% Interpretation of size %d\n", p->size); for (f = 0; f < p->num_tables; f++) { int *table = p->tables[f]; if (table != NULL) { int n = p->size; int arity = sn_to_arity(f); int m = int_power(n, arity); BOOL function = (p->types[f] == FUNCTION); fprintf(fp, "\n%% %s %s / %d : \n\n", function ? "Function" : "Relation", sn_to_str(f), arity); for (i = 0; i < m; i++) { if (table[i] == -1) fprintf(fp, " -"); else fprintf(fp, " %2d", table[i]); if (i % n == n-1) fprintf(fp, "\n"); } if (arity == 0) fprintf(fp, "\n"); } } /* for each function or relation */ } /* fprint_interp_raw */ /************* * * eval_term_ground() * * This version is for clauses, where variables are represented as VARIABLEs. * It works for terms and atoms. All natural numbers are interpreted as * domain values, and if any are out of range, a fatal error occurs. * *************/ /* DOCUMENTATION */ /* PUBLIC */ int eval_term_ground(Term t, Interp p, int *vals) { if (VARIABLE(t)) return vals[VARNUM(t)]; else { int n = p->size; int sn = SYMNUM(t); int domain_element; if (CONSTANT(t) && term_to_int(t, &domain_element)) { if (domain_element < 0 || domain_element >= n) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_term_ground, domain element out of range"); } return domain_element; } else { int *table; int i, j, mult; if (sn >= p->num_tables || p->tables[sn] == NULL) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_term_ground, symbol not in interpretation"); } table = p->tables[sn]; j = 0; /* we'll build up the index with j */ mult = 1; for (i = ARITY(t)-1; i >= 0; i--) { int v = eval_term_ground(ARG(t,i), p, vals); j += v * mult; mult = mult * n; } return table[j]; } } } /* eval_term_ground */ /************* * * eval_literals_ground() * * Given a ground clause and an interpretation, * return "at least one literal is true in the interpretation". * *************/ static BOOL eval_literals_ground(Literals lits, Interp p, int *vals) { Literals lit; BOOL atom_val, true_literal; true_literal = FALSE; for (lit = lits; lit && !true_literal; lit = lit->next) { if (is_eq_symbol(SYMNUM(lit->atom))) atom_val = (eval_term_ground(ARG(lit->atom,0), p, vals) == eval_term_ground(ARG(lit->atom,1), p, vals)); else atom_val = eval_term_ground(lit->atom, p, vals); true_literal = (lit->sign ? atom_val : !atom_val); } return true_literal; } /* eval_literals_ground */ /************* * * all_recurse() * *************/ static BOOL all_recurse(Literals lits, Interp p, int *vals, int nextvar, int nvars) { if (nextvar == nvars) return eval_literals_ground(lits, p, vals); else if (vals[nextvar] >= 0) return all_recurse(lits, p, vals, nextvar+1, nvars); else { int i, rc; for (i = 0; i < p->size; i++) { vals[nextvar] = i; rc = all_recurse(lits, p, vals, nextvar+1, nvars); if (!rc) return FALSE; } vals[nextvar] = -1; return TRUE; } } /* all_recurse */ /************* * * eval_literals() * *************/ /* DOCUMENTATION This routine evaluates a clause in an interpretation. If all instances (over the domain of the interpretation) of the clause are true in the interpretaion, TRUE is returned. If any instance is false, FALSE is returned.

Note that if the interpretation has d elements and the clause has v variables, it takes d^v evaluations to verify the clause.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the clause (other than eq_sym(), which is always built in) is absent from the interpetation. */ /* PUBLIC */ BOOL eval_literals(Literals lits, Interp p) { int vals[MAX_VARS_EVAL]; int nvars, i; BOOL rc; nvars = greatest_variable_in_clause(lits) + 1; if (nvars > MAX_VARS_EVAL) fatal_error("eval_literals: too many variables"); for (i = 0; i < nvars; i++) vals[i] = -1; rc = all_recurse(lits, p, vals, 0, nvars); return rc; } /* eval_literals */ /************* * * all_recurse2() * *************/ static int all_recurse2(Literals lits, Interp p, int *vals, int nextvar, int nvars) { if (nextvar == nvars) { return eval_literals_ground(lits, p, vals) ? 1 : 0; } else if (vals[nextvar] >= 0) return all_recurse2(lits, p, vals, nextvar+1, nvars); else { int i; int true_instances = 0; for (i = 0; i < p->size; i++) { vals[nextvar] = i; true_instances += all_recurse2(lits, p, vals, nextvar+1, nvars); } vals[nextvar] = -1; return true_instances; } } /* all_recurse2 */ /************* * * eval_literals_true_instances() * *************/ /* DOCUMENTATION This routine evaluates a clause in an interpretation. The number of false instances is returned.f The variables in the clause must be normal (0,1,2,...). */ /* PUBLIC */ int eval_literals_true_instances(Literals lits, Interp p) { int vals[MAX_VARS_EVAL]; int nvars, i, true_instances; nvars = greatest_variable_in_clause(lits) + 1; if (nvars > MAX_VARS_EVAL) fatal_error("eval_literals_true_instances: too many variables"); for (i = 0; i < nvars; i++) vals[i] = -1; true_instances = all_recurse2(lits, p, vals, 0, nvars); return true_instances; } /* eval_literals_true_instances */ /************* * * eval_literals_false_instances() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int eval_literals_false_instances(Literals lits, Interp p) { int true_instances = eval_literals_true_instances(lits, p); int nvars = greatest_variable_in_clause(lits) + 1; return int_power(p->size, nvars) - true_instances; } /* eval_literals_false_instances */ /************* * * eval_fterm_ground() * * This version is for formulas, where variables are * represented as CONSTANTs. * It works for terms and atoms. * *************/ static int eval_fterm_ground(Term t, Interp p, int *vals) { if (VARIABLE(t)) fatal_error("eval_fterm_ground, VARIABLE encountered."); if (vals[SYMNUM(t)] != -1) return vals[SYMNUM(t)]; else { int n = p->size; int sn = SYMNUM(t); int domain_element; if (CONSTANT(t) && term_to_int(t, &domain_element)) { if (domain_element < 0 || domain_element >= n) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_fterm_ground, domain element out of range"); } return domain_element; } else { int *table; int i, j, mult; if (sn >= p->num_tables || p->tables[sn] == NULL) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_fterm_ground, symbol not in interpretation"); } table = p->tables[sn]; j = 0; /* we'll build up the index with j */ mult = 1; for (i = ARITY(t)-1; i >= 0; i--) { int v = eval_fterm_ground(ARG(t,i), p, vals); j += v * mult; mult = mult * n; } return table[j]; } } } /* eval_fterm_ground */ /************* * * eval_form() * *************/ static BOOL eval_form(Formula f, Interp p, int vals[]) { if (f->type == ATOM_FORM) { if (is_eq_symbol(SYMNUM(f->atom))) return (eval_fterm_ground(ARG(f->atom,0), p, vals) == eval_fterm_ground(ARG(f->atom,1), p, vals)); else return eval_fterm_ground(f->atom, p, vals); } else if (f->type == ALL_FORM) { /* ok if true for every element of domain */ int i; BOOL ok = TRUE; int sn = str_to_sn(f->qvar, 0); int saved_value = vals[sn]; /* in case in scope of this variable */ for (i = 0; i < p->size && ok; i++) { vals[sn] = i; if (!eval_form(f->kids[0], p, vals)) ok = FALSE; } vals[sn] = saved_value; return ok; } else if (f->type == EXISTS_FORM) { /* ok if true for any element of domain */ int i; BOOL ok = FALSE; int sn = str_to_sn(f->qvar, 0); int saved_value = vals[sn]; /* in case in scope of this variable */ for (i = 0; i < p->size && !ok; i++) { vals[sn] = i; if (eval_form(f->kids[0], p, vals)) ok = TRUE; } vals[sn] = saved_value; return ok; } else if (f->type == AND_FORM) { int i; BOOL ok = TRUE; for (i = 0; i < f->arity && ok; i++) if (!eval_form(f->kids[i], p, vals)) ok = FALSE; return ok; } else if (f->type == OR_FORM) { int i; BOOL ok = FALSE; for (i = 0; i < f->arity && !ok; i++) if (eval_form(f->kids[i], p, vals)) ok = TRUE; return ok; } else if (f->type == NOT_FORM) { return !eval_form(f->kids[0], p, vals); } else if (f->type == IFF_FORM) { return (eval_form(f->kids[0], p, vals) == eval_form(f->kids[1], p, vals)); } else if (f->type == IMP_FORM) { return (!eval_form(f->kids[0], p, vals) || eval_form(f->kids[1], p, vals)); } else if (f->type == IMPBY_FORM) { return (eval_form(f->kids[0], p, vals) || !eval_form(f->kids[1], p, vals)); } else { fatal_error("eval_form, bad formula."); return 0; /* to please the compiler */ } } /* eval_form */ /************* * * eval_formula() * *************/ /* DOCUMENTATION This routine evaluates a closed formula in an interpretation.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the formula (other than eq_sym(), which is always built in) is absent from the interpetation.

A fatal error occurs if the formula contains any terms of type VARIABLE. (Variables bound by quantifier are represented as terms of type CONSTANT.) */ /* PUBLIC */ BOOL eval_formula(Formula f, Interp p) { int a[MAX_VARS_EVAL], *vals; int nsyms, i; BOOL rc; nsyms = greatest_symnum_in_formula(f) + 1; if (nsyms > MAX_VARS_EVAL) vals = malloc((nsyms * sizeof(int))); else vals = a; for (i = 0; i < nsyms; i++) vals[i] = -1; rc = eval_form(f, p, vals); if (nsyms > MAX_VARS_EVAL) free(vals); #if 0 if (rc) printf("Formula is TRUE in this interpretation.\n"); else { printf("Formula is FALSE in this interpretation.\n"); } #endif return rc; } /* eval_formula */ /************* * * interp_remove_constants_recurse() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all constants. */ /* PUBLIC */ Term interp_remove_constants_recurse(Term ops) { if (nil_term(ops)) return ops; else { if (sn_to_arity(SYMNUM(ARG(ARG(ops,0),0))) == 0) { zap_term(ARG(ops,0)); /* deep */ free_term(ops); /* shallow */ return interp_remove_constants_recurse(ARG(ops,1)); } else { ARG(ops,1) = interp_remove_constants_recurse(ARG(ops,1)); return ops; } } } /* interp_remove_constants_recurse */ /************* * * interp_remove_constants() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all constants. */ /* PUBLIC */ void interp_remove_constants(Term t) { ARG(t,2) = interp_remove_constants_recurse(ARG(t,2)); } /* interp_remove_constants */ /************* * * interp_remove_others_recurse() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all others. */ /* PUBLIC */ Term interp_remove_others_recurse(Term ops, Plist keepers) { if (nil_term(ops)) return ops; else { if (!string_member_plist(sn_to_str(SYMNUM(ARG(ARG(ops,0),0))), keepers)) { zap_term(ARG(ops,0)); /* deep */ free_term(ops); /* shallow */ return interp_remove_others_recurse(ARG(ops,1), keepers); } else { ARG(ops,1) = interp_remove_others_recurse(ARG(ops,1), keepers); return ops; } } } /* interp_remove_others_recurse */ /************* * * interp_remove_others() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all others. */ /* PUBLIC */ void interp_remove_others(Term t, Plist keepers) { ARG(t,2) = interp_remove_others_recurse(ARG(t,2), keepers); } /* interp_remove_others */ /************* * * copy_interp() * *************/ /* DOCUMENTATION This routine copies an interpretation. We don't check for errors. */ /* PUBLIC */ Interp copy_interp(Interp p) { int i, j; Interp q = get_interp(); q->t = copy_term(p->t); q->comments = copy_term(p->comments); q->size = p->size; q->incomplete = p->incomplete; q->num_tables = p->num_tables; /* discriminators */ q->num_discriminators = p->num_discriminators; q->discriminator_counts = malloc(sizeof(int) * q->num_discriminators); for (i = 0; i < q->num_discriminators; i++) q->discriminator_counts = p->discriminator_counts; /* occurrences */ q->occurrences = malloc(q->size * sizeof(int)); for (i = 0; i < q->size; i++) q->occurrences[i] = p->occurrences[i]; /* blocks */ q->blocks = malloc(q->size * sizeof(int)); for (i = 0; i < q->size; i++) q->blocks[i] = p->blocks[i]; /* profile */ q->num_profile_components = p->num_profile_components; q->profile = malloc(sizeof(int *) * q->size); for (i = 0; i < q->size; i++) { q->profile[i] = malloc(sizeof(int) * q->num_profile_components); for (j = 0; j < q->num_profile_components; j++) q->profile[i][j] = p->profile[i][j]; } /* types, arities */ q->types = malloc(q->num_tables * sizeof(int)); q->arities = malloc(q->num_tables * sizeof(int)); for (i = 0; i < q->num_tables; i++) { q->types[i] = p->types[i]; q->arities[i] = p->arities[i]; } /* tables */ q->tables = malloc(q->num_tables * sizeof(int *)); for (i = 0; i < q->num_tables; i++) q->tables[i] = NULL; for (i = 0; i < q->num_tables; i++) if (p->tables[i] != NULL) { int arity = p->arities[i]; int n = 1; int *ptable, *qtable, j; for (j = 0; j < arity; j++) n = n * p->size; q->tables[i] = malloc(n * sizeof(int)); ptable = p->tables[i]; qtable = q->tables[i]; for (j = 0; j < n; j++) qtable[j] = ptable[j]; } return q; } /* copy_interp */ /************* * * permute_interp() * *************/ /* DOCUMENTATION This routine returns a permutation of an interpretation. The permuted interpretation does not contain the term representation (because it would be nontrivial to construct it). */ /* PUBLIC */ Interp permute_interp(Interp source, int *p) { Interp dest = copy_interp(source); int n = source->size; int f; for (f = 0; f < source->num_tables; f++) { if (source->tables[f] != NULL) { int *st = source->tables[f]; int *dt = dest->tables[f]; int arity = source->arities[f]; BOOL function = (source->types[f] == FUNCTION); if (arity == 0) dt[0] = (function ? p[st[0]] : st[0]); else if (arity == 1) { int i; for (i = 0; i < n; i++) dt[p[i]] = (function ? p[st[i]] : st[i]); } else if (arity == 2) { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) dt[I2(n,p[i],p[j])] = (function ? p[st[I2(n,i,j)]] : st[I2(n,i,j)]); } else if (arity == 3) { int i, j, k; for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) dt[I3(n,p[i],p[j],p[k])] = (function ? p[st[I3(n,i,j,k)]] : st[I3(n,i,j,k)]); } else fatal_error("permute_interp: arity > 3"); } } { int i; for (i = 0; i < n; i++) { dest->occurrences[p[i]] = source->occurrences[i]; copy_vec(source->profile[i], dest->profile[p[i]], source->num_profile_components); } } /* The term representation is no longer correct. */ if (dest->t) zap_term(dest->t); dest->t = NULL; return dest; } /* permute_interp */ /************* * * ident_interp_perm() * *************/ /* DOCUMENTATION Is interpretation B identical to a given permutation of interpretation A? If so, then A and B are isomorphic. It is assumed that A and B are the same size and have the same symbols. */ /* PUBLIC */ BOOL ident_interp_perm(Interp a, Interp b, int *p) { int n = a->size; int f; for (f = 0; f < a->num_tables; f++) { if (a->tables[f] != NULL) { int *at = a->tables[f]; int *bt = b->tables[f]; int arity = a->arities[f]; BOOL function = (a->types[f] == FUNCTION); if (arity == 0) { if (bt[0] != (function ? p[at[0]] : at[0])) return FALSE; } else if (arity == 1) { int i; for (i = 0; i < n; i++) { if (bt[p[i]] != (function ? p[at[i]] : at[i])) return FALSE; } } else if (arity == 2) { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { if (bt[I2(n,p[i],p[j])] != (function ? p[at[I2(n,i,j)]] : at[I2(n,i,j)])) return FALSE; } } else if (arity == 3) { int i, j, k; for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) { if (bt[I3(n,p[i],p[j],p[k])] != (function ? p[at[I3(n,i,j,k)]] : at[I3(n,i,j,k)])) return FALSE; } } else fatal_error("ident_interp_perm: arity > 3"); } } return TRUE; } /* ident_interp_perm */ /************* * * normal_interp() * *************/ /* DOCUMENTATION This routine returns a normalized copy of an interpretation. Normalized interpretations are used to speed up isomorphism checking.

Consider, in all of the function tables, the number of occurrences of each element. If we have a size-4 interpretation with a binary function, a unary function, and a constant, the occurrence array might be something like [7,6,4,4], meaning that there are 7 occurrences of 0, 6, occurrences of 1, 4 occurrences of 2, and 4 occurrences of 3. If the occurrence array is nonincreasing, the interpretation is in a normal form. (Normal forms are not unique; otherwise, isomorphism checking would be trivial.)

If 2 normal interpretations have different occurrence arrays, they cannot be isomorphic. That's the first check we make.

When checking whether two interpretations are isomorphic, we look at permutations of one of the interpretations, and we can use occurrence array to eliminate some of the permutations. Examples: with occurrence array [7,6,4,4], we look at only 2 permutations: (0,1,2,3) and (0,1,3,2); with occurrence array [4,4,4,3,3], we'd look at 12 (6*2) permutations instead of 120 (5!). */ /* PUBLIC */ Interp normal_interp(Interp a) { int i; int *occ = malloc(sizeof(int) * a->size); /* remember to free this */ int *perm = malloc(sizeof(int) * a->size); /* remember to free this */ int size = a->size; Interp can; /* Determine the permutation we'll use to normalize the interpretation. */ for (i = 0; i < size; i++) occ[i] = a->occurrences[i]; for (i = 0; i < size; i++) { int max = -1; int index_of_max = -1; int j; for (j = 0; j < size; j++) { if (occ[j] > max) { index_of_max = j; max = occ[j]; } } perm[index_of_max] = i; occ[index_of_max] = -1; } free(occ); /* This is now useless (all members are -1). */ /* Apply the permutation to the interpretation. */ can = permute_interp(a, perm); free(perm); return can; } /* normal_interp */ /************* * * iso_interp_recurse() * *************/ static BOOL iso_interp_recurse(int *p, int k, int n, Interp a, Interp b, BOOL normal) { int i; if (k == n) { /* We have a permutation. */ Iso_perms++; return ident_interp_perm(a, b, p); } else { /* Continue building permutations. */ if (iso_interp_recurse(p, k+1, n, a, b, normal)) return TRUE; for (i = k+1; i < n; i++) { /* If normal, and if i and k are in the same block, don't swap them. */ if (!normal || a->blocks[i] == a->blocks[k]) { ISWAP(p[k], p[i]); if (iso_interp_recurse(p, k+1, n, a, b, normal)) return TRUE; ISWAP(p[k], p[i]); } } return FALSE; } } /* iso_interp_recurse */ /************* * * isomorphic_normal_interps() * *************/ /* DOCUMENTATION Are interpretations A and B isomorphic? We assume they are compatible (same operations/arities). If the flag normal is set, it is assumed that both interps were produced by normal_interp(); this allows some optimization. */ /* PUBLIC */ BOOL isomorphic_interps(Interp a, Interp b, BOOL normal) { BOOL isomorphic; int *perm; if (a->size != b->size) return FALSE; /* If normal, make sure the interps have the same profiles. */ if (normal) { if (!same_profiles(a, b)) return FALSE; } if (!same_discriminator_counts(a, b)) return FALSE; Iso_checks++; perm = trivial_permutation(a->size); /* remember to free this */ isomorphic = iso_interp_recurse(perm, 0, a->size, a, b, normal); free(perm); return isomorphic; } /* isomorphic_normal_interps */ /************* * * interp_size() * *************/ /* DOCUMENTATION Return the domain size of an interpretation. */ /* PUBLIC */ int interp_size(Interp a) { return a->size; } /* interp_size */ /************* * * interp_comments() * *************/ /* DOCUMENTATION Return the comments of an interpretation. */ /* PUBLIC */ Term interp_comments(Interp a) { return a->comments; } /* interp_comments */ /************* * * interp_table() * *************/ /* DOCUMENTATION Given a symbol and arity, return the corresponding table. */ /* PUBLIC */ int *interp_table(Interp p, char *sym, int arity) { int f; for (f = 0; f < p->num_tables; f++) if (is_symbol(f, sym, arity)) return p->tables[f]; return NULL; } /* interp_table */ /************* * * iso_checks() * *************/ /* DOCUMENTATION Return the number of isomorphism checks. For normal checks, ones where the occurrence-types don't match are not counted. */ /* PUBLIC */ long unsigned iso_checks(void) { return Iso_checks; } /* iso_checks */ /************* * * iso_perms() * *************/ /* DOCUMENTATION Return the number of permutations seen during isomorphism checks. */ /* PUBLIC */ long unsigned iso_perms(void) { return Iso_perms; } /* iso_perms */ /************* * * evaluable_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_term(Term t, Interp p) { if (VARIABLE(t)) return TRUE; else { int domain_element; if (CONSTANT(t) && term_to_int(t, &domain_element)) return domain_element >= 0 && domain_element < p->size; else if (SYMNUM(t) >= p->num_tables || p->tables[SYMNUM(t)] == NULL) { return FALSE; } else { int i; BOOL ok; for (i = 0, ok = TRUE; i < ARITY(t) && ok; i++) ok = evaluable_term(ARG(t,i), p); return ok; } } } /* evaluable_term */ /************* * * evaluable_atom() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_atom(Term a, Interp p) { if (is_eq_symbol(SYMNUM(a))) return evaluable_term(ARG(a,0), p) && evaluable_term(ARG(a,1), p); else { int b; if (CONSTANT(a) && term_to_int(a, &b)) return b == 0 || b == 1; else if (SYMNUM(a) >= p->num_tables || p->tables[SYMNUM(a)] == NULL) { return FALSE; } else { int i; BOOL ok; for (i = 0, ok = TRUE; i < ARITY(a) && ok; i++) ok = evaluable_term(ARG(a,i), p); return ok; } } } /* evaluable_atom */ /************* * * evaluable_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_literals(Literals lits, Interp p) { if (lits == NULL) return TRUE; else return (evaluable_atom(lits->atom, p) && evaluable_literals(lits->next, p)); } /* evaluable_literals */ /************* * * evaluable_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_formula(Formula f, Interp p) { if (f->type == ATOM_FORM) return evaluable_atom(f->atom, p); else { int i; for (i = 0; i < f->arity; i++) if (!evaluable_formula(f->kids[i], p)) return FALSE; return TRUE; } } /* evaluable_formula */ /************* * * evaluable_topform() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL evaluable_topform(Topform tf, Interp p) { if (tf->is_formula) return evaluable_formula(tf->formula, p); else return evaluable_literals(tf->literals, p); } /* evaluable_topform */ /************* * * update_interp_with_constant() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void update_interp_with_constant(Interp p, Term constant, int val) { int sn = SYMNUM(constant); printf("NOTE: sn=%d, num_tables=%d\n", sn, p->num_tables); if (sn >= p->num_tables) fatal_error("update_interp_with_constat, not enough tables"); else if (p->tables[sn] != NULL) fatal_error("update_interp_with_constat, table not NULL"); else { p->tables[sn] = malloc(sizeof(int)); p->tables[sn][0] = val; } } /* update_interp_with_constant */ /************* * * eval_topform() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL eval_topform(Topform tf, Interp p) { if (tf->is_formula) return eval_formula(tf->formula, p); else return eval_literals(tf->literals, p); } /* eval_topform */ /************* * * compare_interp() * *************/ /* DOCUMENTATION Compare two compatible interpretations. Return SAME_AS, GREATER_THAN, or LESS_THAN. */ /* PUBLIC */ Ordertype compare_interp(Interp a, Interp b) { int f; for (f = 0; f < a->num_tables; f++) { if (a->tables[f] != NULL) { int *at = a->tables[f]; int *bt = b->tables[f]; int n = int_power(a->size, a->arities[f]); int i; for (i = 0; i < n; i++) { if (at[i] < bt[i]) return LESS_THAN; else if (at[i] > bt[i]) return GREATER_THAN; } } } return TRUE; } /* compare_interp */ /************* * * ident_interp() * *************/ /* DOCUMENTATION Are interpretations A and B identical? It is assumed that A and B are the same size and have the same symbols. */ /* PUBLIC */ BOOL ident_interp(Interp a, Interp b) { return compare_interp(a,b) == SAME_AS; } /* ident_interp */ static Ordertype compare_ints(int a, int b) { if (a < b) return LESS_THAN; else if (a > b) return GREATER_THAN; else return SAME_AS; } /* compare_ints */ static void invert_perm(int *a, int *b, int n) { int i; for (i = 0; i < n; i++) b[a[i]] = i; } /* invert_perm */ static void copy_perm(int *a, int *b, int n) { int i; for (i = 0; i < n; i++) b[i] = a[i]; } /* copy_perm */ /************* * * compare_permed_interps() * * Compare two permutations of an interpretation. * * x : perm1 * y : perm2 * xx : inverse(perm1) * yy : inverse(perm2) * a : interpretation * *************/ static Ordertype compare_permed_interps(int *x, int *y, int *xx, int *yy, Interp a) { int n = a->size; int f; for (f = 0; f < a->num_tables; f++) { if (a->tables[f] != NULL) { int *t = a->tables[f]; int arity = a->arities[f]; BOOL function = (a->types[f] == FUNCTION); if (arity == 0) { Ordertype result; if (function) result = compare_ints(x[t[0]], y[t[0]]); else result = SAME_AS; if (result != SAME_AS) return result; } else if (arity == 1) { int i; for (i = 0; i < n; i++) { Ordertype result; if (function) result = compare_ints(x[t[xx[i]]], y[t[yy[i]]]); else result = compare_ints(t[xx[i]], t[yy[i]]); if (result != SAME_AS) return result; } } else if (arity == 2) { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { Ordertype result; if (function) result = compare_ints(x[t[I2(n,xx[i],xx[j])]], y[t[I2(n,yy[i],yy[j])]]); else result = compare_ints(t[I2(n,xx[i],xx[j])], t[I2(n,yy[i],yy[j])]); if (result != SAME_AS) return result; } } else if (arity == 3) { int i, j, k; for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) { Ordertype result; if (function) result = compare_ints(x[t[I3(n,xx[i],xx[j],xx[k])]], y[t[I3(n,yy[i],yy[j],yy[k])]]); else result = compare_ints(t[I3(n,xx[i],xx[j],xx[k])], t[I3(n,yy[i],yy[j],yy[k])]); if (result != SAME_AS) return result; } } else fatal_error("compare_permed_interps: arity > 3"); } } return SAME_AS; } /* compare_permed_interps */ /************* * * canon_recurse() * *************/ static void canon_recurse(int k, int *perm, int *best, int *perm1, int *best1, Interp a) { /* k: current position in working permutation perm: working permutation best: best permutation so far perm1: inverse of perm best1: inverse of best a: base interp */ int n = a->size; if (k == n) { /* We have a permutation. */ Iso_perms++; invert_perm(perm, perm1, a->size); if (compare_permed_interps(perm, best, perm1, best1, a) == LESS_THAN) { /* copy working permutation to best-so-far. */ copy_perm(perm, best, a->size); copy_perm(perm1, best1, a->size); } } else { /* Continue building permutations. */ int i; canon_recurse(k+1, perm, best, perm1, best1, a); for (i = k+1; i < n; i++) { /* If i and k are in different blocks, don't swap them. */ if (a->blocks[i] == a->blocks[k]) { ISWAP(perm[k], perm[i]); canon_recurse(k+1, perm, best, perm1, best1, a); ISWAP(perm[k], perm[i]); } } } } /* canon_recurse */ /************* * * canon_interp() * *************/ /* DOCUMENTATION Return the (unique) canonical form of the interp. The input interp (which is not changed) is assumed to be in normal form. */ /* PUBLIC */ Interp canon_interp(Interp a) { Interp canon; int *perm = trivial_permutation(a->size); /* remember to free this */ int *best = trivial_permutation(a->size); /* remember to free this */ int *perm1 = trivial_permutation(a->size); /* remember to free this */ int *best1 = trivial_permutation(a->size); /* remember to free this */ invert_perm(best, best1, a->size); /* let best1 be the inverse of best */ /* perm gets inverted when needed */ canon_recurse(0, perm, best, perm1, best1, a); canon = permute_interp(a, best); /* makes new copy */ free(perm); free(best); free(perm1); free(best1); return canon; } /* canon_interp */ /************* * * assign_discriminator_counts() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void assign_discriminator_counts(Interp a, Plist discriminators) { int n = plist_count(discriminators); int *counts = malloc(sizeof(int) * n); int i; Plist p; for (p = discriminators, i = 0; p; p = p->next, i++) { Topform c = p->v; counts[i] = eval_literals_true_instances(c->literals, a); } a->discriminator_counts = counts; a->num_discriminators = n; } /* assign_discriminator_counts */ /************* * * same_discriminator_counts() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL same_discriminator_counts(Interp a, Interp b) { if (a->num_discriminators != b->num_discriminators) fatal_error("different number of discriminators"); return (compare_vecs(a->discriminator_counts, b->discriminator_counts, a->num_discriminators) == SAME_AS); } /* same_discriminator_counts */ /************* * * update_profile() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void update_profile(Topform c, Interp a, int *next) /* vecs[domain_element][profile_component] */ { int vals[MAX_VARS_EVAL]; int nvars, v, i, true_instances; nvars = greatest_variable_in_clause(c->literals) + 1; if (nvars > MAX_VARS_EVAL) fatal_error("update_profile: too many variables"); for (v = 0; v < nvars; v++) vals[v] = -1; for (v = 0; v < nvars; v++) { for (i = 0; i < a->size; i++) { vals[v] = i; true_instances = all_recurse2(c->literals, a, vals, 0, nvars); a->profile[i][*next] = true_instances; } vals[v] = -1; (*next)++; } } /* update_profile */ /************* * * create_profile() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void create_profile(Interp a, Plist discriminators) { int i, next; Plist p; a->num_profile_components = 1; /* first is occurrences */ for (p = discriminators; p; p = p->next) { Topform c = p->v; int nvars = greatest_variable_in_clause(c->literals) + 1; a->num_profile_components += nvars; } for (i = 0; i < a->size; i++) { a->profile[i] = malloc(sizeof(int) * a->num_profile_components); a->profile[i][0] = a->occurrences[i]; } next = 1; for (p = discriminators; p; p = p->next) update_profile(p->v, a, &next); if (next != a->num_profile_components) fatal_error("create_profile, counts do not match"); } /* create_profile */ /************* * * p_interp_profile() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_interp_profile(Interp a, Plist discriminators) { int i, j, k; char str[10]; Plist p; printf("\n========================== PROFILE\n"); fprint_interp_standard2(stdout, a); if (discriminators) { printf("\n blocks: "); for (k = 0; k < a->size; k++) printf(" %3c", 'A' + a->blocks[k]); printf("\n"); printf("Permutations: %lu\n", perms_required(a)); printf("occurrences: "); for (k = 0; k < a->size; k++) printf(" %3d", a->profile[k][0]); printf("\n"); i = 1; for (p = discriminators; p; p = p->next) { Topform c = p->v; int nvars = greatest_variable_in_clause(c->literals) + 1; fwrite_clause(stdout, c, CL_FORM_BARE); for (j = 0; j < nvars; j++, i++) { symbol_for_variable(str, j); printf(" %s: ", str); for (k = 0; k < a->size; k++) { printf(" %3d", a->profile[k][i]); } printf("\n"); } } } else { for (i = 0; i < a->num_profile_components; i++) { for (k = 0; k < a->size; k++) printf(" %2d", a->profile[k][i]); printf("\n"); } } } /* p_interp_profile */ /************* * * normal3_interp() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Interp normal3_interp(Interp a, Plist discriminators) { int i, b; int **prof = malloc(sizeof(int *) * a->size); /* remember to free this */ int *perm = malloc(sizeof(int) * a->size); /* remember to free this */ int size = a->size; Interp norm; create_profile(a, discriminators); /* Determine the permutation we'll use to normalize the interpretation. */ for (i = 0; i < size; i++) prof[i] = a->profile[i]; for (i = 0; i < size; i++) { int *max = NULL; int index_of_max = -1; int j; for (j = 0; j < size; j++) { if (prof[j] != NULL) { if (max == NULL || compare_vecs(prof[j], max, a->num_profile_components) == GREATER_THAN) { index_of_max = j; max = prof[j]; } } } perm[index_of_max] = i; prof[index_of_max] = NULL; } free(prof); /* This is now useless (all members are NULL). */ /* Apply the permutation to the interpretation. */ norm = permute_interp(a, perm); free(perm); /* Set up blocks of identical profile components. Note that identical profile components are alreay adjacent. The blocks are specified by a vector of integers, e.g., [1,1,1,1,2,3,3,4] says there are 4 blocks (domain size 8), with the first 4 identical, etc. */ b = 0; /* block counter */ norm->blocks[0] = 0; for (i = 1; i < norm->size; i++) { if (compare_vecs(norm->profile[i-1], norm->profile[i], norm->num_profile_components) != SAME_AS) b++; norm->blocks[i] = b; } return norm; } /* normal3_interp */ /************* * * same_profiles() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL same_profiles(Interp a, Interp b) { int i, j; for (i = 0; i < a->size; i++) for (j = 0; j < a->num_profile_components; j++) if (a->profile[i][j] != b->profile[i][j]) return FALSE; return TRUE; } /* same_profiles */ /************* * * perms_required() * *************/ /* DOCUMENTATION */ /* PUBLIC */ long unsigned perms_required(Interp a) { int i, n; long unsigned p, r; p = 1; i = 0; while (i < a->size) { int c = a->blocks[i]; n = 0; while (i < a->size && a->blocks[i] == c) { i++; n++; } r = factorial(n); if (r < 1 || r == ULONG_MAX) return 0; r = p * r; if (r < p || r == ULONG_MAX) return 0; p = r; } return p; } /* perms_required */ /************* * * factorial() * *************/ /* DOCUMENTATION If overflow, return 0. */ /* PUBLIC */ long unsigned factorial(int n) { long unsigned f, x; int i; f = 1; for (i = 1; i <= n; i++) { x = f * i; if (x == ULONG_MAX || x < f) return 0; f = x; } return f; } /* factorial */ LADR-2009-11A/ladr/basic.c0000644000175000017500000001667610637466321014215 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "basic.h" /* In "Basic Paramodlation", we do not paramodulate into terms that arise by instantiation. Another way to look at it (and the way it is rigorously defined), is that substitutions (instantiations) are kept separate from clauses. The skeleton of the clause stays the same (except that paramoulation substitutes the skeleton from the "from" parent), and all instantiations occur in the associationed substitution. In this implementation, we do not keep separate substitutions. Instead, we mark the subterms that arose by substitution; that is the "nonbasic" subterms which are inadmissible "into" terms. Basic paramodulation is complete; but more important, it can be powerful (e.g., the Robbins proof). The paper [McCune, "33 Basic Test Problems"] reports on experiments showing that it can be useful. Things to be aware of: 1. The terms that are marked are the "nonbasic" terms, that is, the inadmissible "into" terms. Variables are always inadmissible, and are never marked. 2. Things get messy for subsumption and demodulation, and I'm not clear on what's exactly what's required for completeness. 3. Forward subsumption. If the subsumer is less basic than the new clause, the subsumer should acquire some of the nonbasic marks of the new clause. Not implemented. Similar for back subsumption 4. Should demodulation be applied to nonbasic terms? I think yes, from a practical point of view (I don't know about completeness). If it is, then a nonbasic term can have a basic subterm. Should we paramodulate into those? I think not. 5. Basic paramodulation can require a greater max_weight. */ /* Private definitions and types */ static BOOL Basic_paramodulation = FALSE; /* Is basic paramod enabled? */ static int Nonbasic_flag = -1; /* termflag to mark nonbasic terms */ /************* * * init_basic_paramod(void) * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_basic_paramod(void) { if (Nonbasic_flag != -1) fatal_error("init_basic_paramod, called more than once"); Nonbasic_flag = claim_term_flag(); /* allocate a termflag */ } /* init_basic_paramod */ /************* * * set_basic_paramod() * *************/ /* DOCUMENTATION Set or clear basic paramodulation. */ /* PUBLIC */ void set_basic_paramod(BOOL flag) { Basic_paramodulation = flag; } /* set_basic_paramod */ /************* * * basic_paramod() * *************/ /* DOCUMENTATION Is basic paramodulation enabled? */ /* PUBLIC */ BOOL basic_paramod(void) { return Basic_paramodulation; } /* basic_paramod */ /************* * * mark_term_nonbasic() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_term_nonbasic(Term t) { if (Nonbasic_flag == -1) fatal_error("mark_term_nonbasic: init_basic() was not called"); term_flag_set(t, Nonbasic_flag); } /* mark_term_nonbasic */ /************* * * mark_all_nonbasic() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_all_nonbasic(Term t) { /* Even though variables are nonbasic, don't mark them. */ if (!VARIABLE(t)) { int i; mark_term_nonbasic(t); for (i = 0; i < ARITY(t); i++) mark_all_nonbasic(ARG(t,i)); } } /* mark_all_nonbasic */ /************* * * nonbasic_term() * *************/ /* DOCUMENTATION Check if a term is nonbasic. This simply checks the "nonbasic" mark. */ /* PUBLIC */ BOOL nonbasic_term(Term t) { return term_flag(t, Nonbasic_flag); } /* nonbasic_term */ /************* * * basic_term() * *************/ /* DOCUMENTATION Check if a term is basic. This simply checks the "nonbasic" mark. */ /* PUBLIC */ BOOL basic_term(Term t) { return !term_flag(t, Nonbasic_flag); } /* basic_term */ /************* * * nonbasic_flag() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int nonbasic_flag(void) { return Nonbasic_flag; } /* nonbasic_flag */ /************* * * Term apply_basic(term, context) -- Apply a substitution to a term. * *************/ /* DOCUMENTATION This is similar to apply(), but it makes "nonbasic" marks for "basic paramodulation". */ /* PUBLIC */ Term apply_basic(Term t, Context c) { Term raw = t; /* save original (nondereferenced) term */ DEREFERENCE(t, c) /* A NULL context is ok. It happens when c is built by match. */ /* If the context is NULL, then apply just copies the term. */ if (VARIABLE(t)) { if (!c) return get_variable_term(VARNUM(t)); else return get_variable_term(c->multiplier * MAX_VARS + VARNUM(t)); } else { /* constant or complex term */ Term t2 = get_rigid_term_like(t); int i; for (i = 0; i < ARITY(t); i++) ARG(t2,i) = apply_basic(ARG(t,i), c); /* If the raw term is a variable, the result and all of its nonvariable subterms are marked as nonbasic; if the dereferenced term is nonbasic, the rood of the result is marked as nonbasic (subterms have already been marked as nonbasic; recall that all nonvariable subterms of a nonbasic term are nonbasic). */ if (VARIABLE(raw)) mark_all_nonbasic(t2); else if (nonbasic_term(t)) mark_term_nonbasic(t2); return t2; } } /* apply_basic */ /************* * * apply_basic_substitute() * *************/ /* DOCUMENTATION This is similar to apply_substitute(), but it makes "nonbasic" marks for "basic paramodulation". */ /* PUBLIC */ Term apply_basic_substitute(Term t, Term beta, Context c_from, Term into_term, Context c_into) { if (t == into_term) return apply_basic(beta, c_from); else if (VARIABLE(t)) return apply_basic(t, c_into); else { int i; Term t2 = get_rigid_term_like(t); if (nonbasic_term(t)) mark_term_nonbasic(t2); for (i = 0; i < ARITY(t); i++) ARG(t2,i) = apply_basic_substitute(ARG(t,i), beta, c_from, into_term, c_into); return t2; } } /* apply_basic_substitute */ /************* * * clear_all_nonbasic_marks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clear_all_nonbasic_marks(Term t) { /* recall that variables never have nonbasic marks */ if (!VARIABLE(t)) { int i; term_flag_clear(t, Nonbasic_flag); for (i = 0; i < ARITY(t); i++) clear_all_nonbasic_marks(ARG(t,i)); } } /* clear_all_nonbasic_marks */ /************* * * p_term_basic() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_term_basic(Term t) { if (VARIABLE(t)) printf("v%d", VARNUM(t)); else { if (basic_term(t)) printf("#"); fprint_sym(stdout, SYMNUM(t)); if (COMPLEX(t)) { int i; printf("("); for (i = 0; i < ARITY(t); i++) { p_term_basic(ARG(t,i)); if (i < ARITY(t)-1) printf(","); } printf(")"); } } fflush(stdout); } /* p_term_basic */ LADR-2009-11A/ladr/sed10000644000175000017500000000002710505425147013521 0ustar mccunemccunes/->container/->data/g LADR-2009-11A/ladr/banner.h0000644000175000017500000000224611151265364014366 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_BANNER_H #define TP_BANNER_H #include "nonport.h" #include "clock.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from banner.c */ void print_separator(FILE *fp, char *str, BOOL initial_newline); void print_banner(int argc, char **argv, char *name, char *version, char *date, BOOL as_comments); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/weight2.h0000644000175000017500000000217411151265364014472 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_WEIGHT2_H #define TP_WEIGHT2_H #include "term.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from weight2.c */ double call_weight(char *func, Term t); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/termorder.h0000644000175000017500000000373211151265363015124 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TERMORDER_H #define TP_TERMORDER_H #include "flatterm.h" /* INTRODUCTION */ /* Public definitions */ /* Term ordering method */ typedef enum { LRPO_METHOD, LPO_METHOD, RPO_METHOD, KBO_METHOD } Order_method; /* End of public definitions */ /* Public function prototypes from termorder.c */ void assign_order_method(Order_method method); Ordertype term_compare_basic(Term t1, Term t2); Ordertype term_compare_ncv(Term t1, Term t2); Ordertype term_compare_vcp(Term t1, Term t2); Ordertype term_compare_vr(Term t1, Term t2); Ordertype flatterm_compare_vr(Flatterm a, Flatterm b); BOOL lrpo_multiset(Term t1, Term t2, BOOL lex_order_vars); BOOL lrpo(Term s, Term t, BOOL lex_order_vars); void init_kbo_weights(Plist weights); int kbo_weight(Term t); BOOL kbo(Term alpha, Term beta, BOOL lex_order_vars); BOOL term_greater(Term alpha, Term beta, BOOL lex_order_vars); Ordertype term_order(Term alpha, Term beta); int flat_kbo_weight(Flatterm f); BOOL flat_lrpo(Flatterm s, Flatterm t, BOOL lex_order_vars); BOOL flat_greater(Flatterm alpha, Flatterm beta, BOOL lex_order_vars); BOOL greater_multiset_current_ordering(Term t1, Term t2); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/discrimb.h0000644000175000017500000000313011167750156014713 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_DISCRIMB_H #define TP_DISCRIMB_H #include "discrim.h" /* INTRODUCTION Discrimination tree indexing in which variables are distinguished in the index and are bound as soon as possible during retrieval. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from discrimb.c */ void fprint_discrimb_mem(FILE *fp, BOOL heading); void p_discrimb_mem(void); void check_discrim_bind_tree(Discrim d, int n); void fprint_discrim_bind_index(FILE *fp, Discrim d); void p_discrim_bind_index(Discrim d); void discrim_bind_update(Term t, Discrim root, void *object, Indexop op); void *discrim_bind_retrieve_first(Term t, Discrim root, Context subst, Discrim_pos *ppos); void *discrim_bind_retrieve_next(Discrim_pos pos); void discrim_bind_cancel(Discrim_pos pos); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/README.char-types0000644000175000017500000000262510450242154015700 0ustar mccunemccuneBOOL end_char(char c) { return (c == '.'); } /* end_char */ BOOL comment_char(char c) { return (c == COMMENT_CHAR); } /* comment_char */ BOOL quote_char(char c) { return (c == '\"'); } /* quote_char */ BOOL punctuation_char(char c) { return (c == ',' || c == ':' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '.'); } /* punctuation_char */ BOOL ordinary_char(char c) { return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$'); } /* ordinary_char */ BOOL special_char(char c) { /* This allows us to have special chars in the list below. */ if (quote_char(c) || end_char(c) || comment_char(c)) return 0; else return (c == '+' || c == '-' || c == '*' || c == '/' || c == '\\' || c == '^' || c == '<' || c == '>' || c == '=' || c == '`' || c == '~' || c == '?' || c == '@' || c == '&' || c == '|' || c == '!' || c == '#' || c == '%' || c == '\'' || c == '\"' || c == '.' || c == ';' ); } /* special_char */ BOOL white_char(char c) { return (c == ' ' || c == '\t' || /* tab */ c == '\n' || /* newline */ c == '\v' || /* vertical tab */ c == '\r' || /* carriage return */ c == '\f'); /* form feed */ } /* white_char */ LADR-2009-11A/ladr/Changelog.old0000644000175000017500000000125510333733560015335 0ustar mccunemccuneLADR Changelog. Most recent changes are at the top. June 3, 2004. Update FPA/Path indexing with chunked fpa lists. May 27, 2004. Submit mace4-2004-D to CASC for testing. May 26, 2004. In formula.c, update the CNF transformation, making it more efficient. Prompted by the May 18, 2004 bug. May 18, 2004. Release ladr-2004-C. May 18, 2004. Soundness bug from Geoff Sutcliffe. CNF transformation. This affects non-clausal input only (formulas(...) in the input). Since this is a serious bug, a new release will be made today. November 17, 2004. Some changes to fastparse. These affect ladr-apps. --- Further changes are listed in the LADR Changelog file (../Changelog). LADR-2009-11A/ladr/dots0000644000175000017500000000024010350035143013622 0ustar mccunemccune/****************************************************************************/ /****************************************************************************/ LADR-2009-11A/ladr/hash.h0000644000175000017500000000267011151265363014044 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_HASH_H #define TP_HASH_H #include "memory.h" typedef struct hashtab * Hashtab; typedef struct hashnode * Hashnode; /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from hash.c */ void fprint_hash_mem(FILE *fp, BOOL heading); void p_hash_mem(); Hashtab hash_init(int size); void hash_insert(void *v, unsigned hashval, Hashtab h); void *hash_lookup(void *v, unsigned hashval, Hashtab h, BOOL (*id_func) (void *, void *)); void hash_delete(void *v, unsigned hashval, Hashtab h, BOOL (*id_func) (void *, void *)); void hash_destroy(Hashtab h); void hash_info(Hashtab h); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clock.c0000644000175000017500000002127710637466321014220 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clock.h" /* Private definitions and types */ struct clock { char *name; /* name of clock */ unsigned accum_msec; /* accumulated time */ unsigned curr_msec; /* time since clock has been turned on */ int level; /* STARTs - STOPs */ }; static BOOL Clocks_enabled = TRUE; /* getrusage can be slow */ static unsigned Clock_starts = 0; /* Keep a count */ static unsigned Wall_start; /* for measuring wall-clock time */ /* Macro to get the number of user CPU milliseconds since the start of the process. Getrusage() can be VERY slow on some systems. So I tried clock() instead (ignoring the rollover problem), but that didn't seem to help on Linux. */ #if 1 #define CPU_TIME(msec) { struct rusage r; getrusage(RUSAGE_SELF, &r);\ msec = r.ru_utime.tv_sec * 1000 + r.ru_utime.tv_usec / 1000; } #else #define CPU_TIME(msec) { msec = clock() / 1000; } #endif /* * memory management */ #define PTRS_CLOCK PTRS(sizeof(struct clock)) static unsigned Clock_gets, Clock_frees; /************* * * Clock get_clock() * *************/ static Clock get_clock(void) { Clock p = get_cmem(PTRS_CLOCK); Clock_gets++; return(p); } /* get_clock */ /************* * * free_clock() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_clock(Clock p) { if (p != NULL) { free_mem(p, PTRS_CLOCK); Clock_frees++; } } /* free_clock */ /* * end of memory management */ /************* * * clock_init() * *************/ /* DOCUMENTATION This routine initializes a clock. You give it a string (which is not copied), representing the name of the new clock, and it returns a Clock to be used for all operations on the clock.

The clock operations are clock_start(), clock_stop(), clock_seconds(), clock_milliseconds(), and clock_reset(). */ /* PUBLIC */ Clock clock_init(char *str) { Clock p = get_clock(); p->name = str; p->level = 0; p->accum_msec = 0; return p; } /* clock_init */ /************* * * clock_start() * *************/ /* DOCUMENTATION This routine starts clock n. It is okay if the clock is already going. */ /* PUBLIC */ void clock_start(Clock p) { if (Clocks_enabled) { p->level++; if (p->level == 1) { CPU_TIME(p->curr_msec); Clock_starts++; } } } /* clock_start */ /************* * * clock_stop() * *************/ /* DOCUMENTATION This routine stops clock n and adds the time to the accumulated total, unless there have been too many starts and not enough stops. See the introduction. */ /* PUBLIC */ void clock_stop(Clock p) { if (Clocks_enabled) { if (p->level <= 0) fprintf(stderr,"WARNING, clock_stop: clock %s not running.\n",p->name); else { p->level--; if (p->level == 0) { unsigned msec; CPU_TIME(msec); p->accum_msec += msec - p->curr_msec; } } } } /* clock_stop */ /************* * * clock_milliseconds() * *************/ /* DOCUMENTATION This routine returns the current value of a clock, in milliseconds. The value is in milliseconds. */ /* PUBLIC */ unsigned clock_milliseconds(Clock p) { if (p == NULL) return 0; else { int i = p->accum_msec; if (p->level == 0) return i; else { int msec; CPU_TIME(msec); return i + (msec - p->curr_msec); } } } /* clock_milliseconds */ /************* * * clock_seconds() * *************/ /* DOCUMENTATION This routine returns the current value of a clock, in seconds. The clock need not be stopped. */ /* PUBLIC */ double clock_seconds(Clock p) { if (p == NULL) return 0.0; else { int i = p->accum_msec; if (p->level == 0) return (i / 1000.0); else { int msec; CPU_TIME(msec); return (i + (msec - p->curr_msec)) / 1000.0; } } } /* clock_seconds */ /************* * * clock_running() * *************/ /* DOCUMENTATION This routine tells you whether or not a clock is running. */ /* PUBLIC */ BOOL clock_running(Clock p) { return p->level > 0; } /* clock_running */ /************* * * clock_reset() * *************/ /* DOCUMENTATION This routine resets a clock, as if it had just been initialized. (You should not need this routine under normal circumstances.) */ /* PUBLIC */ void clock_reset(Clock p) { if (p != NULL) { p->level = 0; p->accum_msec = 0; } } /* clock_reset */ /************* * * fprint_clock() * *************/ /* DOCUMENTATION This routine */ /* PUBLIC */ void fprint_clock(FILE *fp, Clock p) { if (p != NULL) fprintf(fp, "clock %-15s: %6.2f seconds.\n", p->name, clock_seconds(p)); } /* fprint_clock */ /************* * * get_date() * *************/ /* DOCUMENTATION This routine returns a string representation of the current date and time. */ /* PUBLIC */ char * get_date(void) { time_t i = time(NULL); return asctime(localtime(&i)); } /* get_date */ /************* * * user_time() * *************/ /* DOCUMENTATION This routine returns the user CPU time, in milliseconds, that the current process has used so far. */ /* PUBLIC */ unsigned user_time() { struct rusage r; unsigned sec, usec; getrusage(RUSAGE_SELF, &r); sec = r.ru_utime.tv_sec; usec = r.ru_utime.tv_usec; return((sec * 1000) + (usec / 1000)); } /* user_time */ /************* * * user_seconds() * *************/ /* DOCUMENTATION This routine returns the user CPU time, in seconds, that the current process has used so far. */ /* PUBLIC */ double user_seconds() { struct rusage r; unsigned sec, usec; getrusage(RUSAGE_SELF, &r); sec = r.ru_utime.tv_sec; usec = r.ru_utime.tv_usec; return(sec + (usec / 1000000.0)); } /* user_seconds */ /************* * * system_time() * *************/ /* DOCUMENTATION This routine returns the system CPU time, in milliseconds, that has been spent on the current process. (System time measures low-level operations such as system calls, paging, and I/O that the operating systems does on behalf of the process.) */ /* PUBLIC */ unsigned system_time() { struct rusage r; unsigned sec, usec; getrusage(RUSAGE_SELF, &r); sec = r.ru_stime.tv_sec; usec = r.ru_stime.tv_usec; return((sec * 1000) + (usec / 1000)); } /* system_time */ /************* * * system_seconds() * *************/ /* DOCUMENTATION This routine returns the system CPU time, in seconds, that has been spent on the current process. (System time measures low-level operations such as system calls, paging, and I/O that the operating systems does on behalf of the process.) */ /* PUBLIC */ double system_seconds() { struct rusage r; unsigned sec, usec; getrusage(RUSAGE_SELF, &r); sec = r.ru_stime.tv_sec; usec = r.ru_stime.tv_usec; return(sec + (usec / 1000000.0)); } /* system_seconds */ /************* * * absolute_wallclock() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned absolute_wallclock(void) { time_t t = time((time_t *) NULL); return (unsigned) t; } /* absolute_wallclock */ /************* * * init_wallclock() * *************/ /* DOCUMENTATION This routine initializes the wall-clock timer. */ /* PUBLIC */ void init_wallclock() { Wall_start = absolute_wallclock(); } /* init_wallclock */ /************* * * wallclock() * *************/ /* DOCUMENTATION This routine returns the number of wall-clock seconds since init_wallclock() was called. The result is unsigned. */ /* PUBLIC */ unsigned wallclock() { return absolute_wallclock() - Wall_start; } /* wallclock */ /************* * * disable_clocks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void disable_clocks(void) { Clocks_enabled = FALSE; } /* disable_clocks */ /************* * * enable_clocks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void enable_clocks(void) { Clocks_enabled = TRUE; } /* enable_clocks */ /************* * * clocks_enabled() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL clocks_enabled(void) { return Clocks_enabled; } /* clocks_enabled */ LADR-2009-11A/ladr/Makefile~0000644000175000017500000003701511261165115014603 0ustar mccunemccune# LADR/ladr CC = gcc # XFLAGS can be specified on the command line (see XFLAGS below) CFLAGS = $(XFLAGS) -O -Wall # CFLAGS = $(XFLAGS) -O6 -Wall # CFLAGS = $(XFLAGS) -g -O -Wall # CFLAGS = $(XFLAGS) -g -O0 -Wall # CFLAGS = $(XFLAGS) -pg -O -Wall # CFLAGS = $(XFLAGS) -Wall -pedantic BASE_OBJ = order.o clock.o nonport.o\ fatal.o ibuffer.o memory.o hash.o string.o strbuf.o\ glist.o options.o symbols.o avltree.o TERM_OBJ = term.o termflag.o listterm.o tlist.o flatterm.o multiset.o\ termorder.o parse.o accanon.o UNIF_OBJ = unify.o fpalist.o fpa.o discrim.o discrimb.o discrimw.o\ dioph.o btu.o btm.o mindex.o basic.o attrib.o CLAS_OBJ = formula.o definitions.o literals.o topform.o clist.o\ clauseid.o clauses.o\ just.o cnf.o clausify.o parautil.o\ pindex.o compress.o\ maximal.o lindex.o weight.o weight2.o\ int_code.o features.o di_tree.o fastparse.o\ random.o subsume.o clause_misc.o clause_eval.o complex.o INFE_OBJ = dollar.o flatdemod.o demod.o clash.o resolve.o paramod.o\ backdemod.o\ hints.o ac_redun.o xproofs.o ivy.o MODL_OBJ = interp.o MISC_OBJ = std_options.o banner.o ioutil.o tptp_trans.o top_input.o OBJECTS = $(BASE_OBJ) $(TERM_OBJ) $(UNIF_OBJ) $(CLAS_OBJ)\ $(INFE_OBJ) $(MODL_OBJ) $(MISC_OBJ) libladr.a: $(OBJECTS) $(AR) rs libladr.a $(OBJECTS) ############################################################################## lib ladr libladr: $(MAKE) libladr.a dep: util/make_dep $(OBJECTS) clean: /bin/rm -f *.o realclean: /bin/rm -f *.o *.a protos: util/make_protos $(OBJECTS) htmls: util/make_htmls $(OBJECTS) cp index.html.master html/index.html tags: etags *.c dio-solo: $(CC) $(CFLAGS) -DSOLO -o dio dioph.c # The rest of the file is generated automatically by util/make_dep order.o: order.h clock.o: clock.h string.h memory.h fatal.h header.h nonport.o: nonport.h fatal.o: fatal.h header.h ibuffer.o: ibuffer.h fatal.h header.h memory.o: memory.h fatal.h header.h hash.o: hash.h memory.h fatal.h header.h string.o: string.h memory.h fatal.h header.h strbuf.o: strbuf.h string.h memory.h fatal.h header.h glist.o: glist.h order.h string.h memory.h fatal.h header.h options.o: options.h string.h memory.h fatal.h header.h symbols.o: symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h avltree.o: avltree.h memory.h order.h fatal.h header.h term.o: term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termflag.o: termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h listterm.o: listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h tlist.o: tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.o: flatterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h multiset.o: multiset.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termorder.o: termorder.h flatterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h parse.o: parse.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h accanon.o: accanon.h termflag.h termorder.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h unify.o: unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h fpalist.o: fpalist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h fpa.o: fpa.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.o: discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrimb.o: discrimb.h discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrimw.o: discrimw.h discrim.h unify.h index.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h dioph.o: dioph.h btu.o: btu.h dioph.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h btm.o: btm.h unify.h accanon.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h termorder.h flatterm.h mindex.o: mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h basic.o: basic.h unify.h termflag.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h attrib.o: attrib.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h formula.o: formula.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h definitions.o: definitions.h formula.h topform.h clauseid.h just.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h literals.h maximal.h parse.h literals.o: literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.o: topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.o: clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clauseid.o: clauseid.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clauses.o: clauses.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h just.o: just.h clauseid.h parse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h cnf.o: cnf.h formula.h clock.h attrib.h tlist.h termorder.h hash.h unify.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h clausify.o: clausify.h topform.h cnf.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clock.h parautil.o: parautil.h pindex.o: pindex.h clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h compress.o: compress.h parautil.h maximal.o: maximal.h literals.h termorder.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h lindex.o: lindex.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h weight.o: weight.h literals.h unify.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h listterm.h weight2.o: weight2.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h int_code.o: int_code.h just.h ibuffer.h clauseid.h parse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h features.o: features.h literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h di_tree.o: di_tree.h features.h topform.h literals.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h attrib.h formula.h maximal.h unify.h listterm.h termorder.h hash.h flatterm.h fastparse.o: fastparse.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h random.o: random.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h subsume.o: subsume.h parautil.h lindex.h features.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h clause_misc.o: clause_misc.h clist.h mindex.h just.h basic.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h clause_eval.o: clause_eval.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h complex.o: complex.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h dollar.o: dollar.h clist.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h flatdemod.o: flatdemod.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h demod.o: demod.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h clash.o: clash.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h resolve.o: resolve.h clash.h lindex.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h maximal.h topform.h literals.h tlist.h attrib.h formula.h hash.h paramod.o: paramod.h resolve.h basic.h clash.h lindex.h mindex.h parautil.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h maximal.h topform.h literals.h tlist.h attrib.h formula.h hash.h backdemod.o: backdemod.h demod.h clist.h parautil.h mindex.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h topform.h literals.h attrib.h formula.h maximal.h tlist.h hash.h hints.o: hints.h subsume.h clist.h backdemod.h resolve.h parautil.h lindex.h features.h mindex.h maximal.h topform.h fpa.h discrimb.h discrimw.h btu.h btm.h unify.h index.h fpalist.h listterm.h termflag.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h discrim.h dioph.h accanon.h termorder.h flatterm.h literals.h tlist.h attrib.h formula.h hash.h demod.h clash.h ac_redun.o: ac_redun.h parautil.h accanon.h termflag.h termorder.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h flatterm.h xproofs.o: xproofs.h clauses.h clause_misc.h paramod.h subsume.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h resolve.h clash.h lindex.h parautil.h features.h ivy.o: ivy.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h unify.h listterm.h termorder.h hash.h flatterm.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h parse.h resolve.h clash.h lindex.h parautil.h features.h interp.o: interp.h parse.h topform.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h std_options.o: std_options.h options.h symbols.h clock.h string.h memory.h fatal.h header.h strbuf.h glist.h order.h banner.o: banner.h nonport.h clock.h string.h memory.h fatal.h header.h ioutil.o: ioutil.h parse.h fastparse.h ivy.h clausify.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h tptp_trans.o: tptp_trans.h ioutil.h clausify.h parse.h fastparse.h ivy.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h top_input.o: top_input.h ioutil.h std_options.h tptp_trans.h parse.h fastparse.h ivy.h clausify.h listterm.h term.h symbols.h strbuf.h glist.h string.h memory.h fatal.h header.h order.h topform.h literals.h attrib.h formula.h maximal.h termflag.h tlist.h unify.h termorder.h hash.h flatterm.h xproofs.h clauses.h clause_misc.h paramod.h subsume.h clist.h mindex.h just.h basic.h fpa.h discrimb.h discrimw.h btu.h btm.h index.h fpalist.h discrim.h dioph.h accanon.h clauseid.h resolve.h clash.h lindex.h parautil.h features.h cnf.h clock.h options.h LADR-2009-11A/ladr/tptp_trans.c.work0000644000175000017500000004222510755203562016275 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "tptp_trans.h" /* Private definitions and types */ /************* * * declare_tptp_parse_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_tptp_parse_types(void) { /* From Geoff Sutcliffe, Feb 13, 2008: %----These are used in the TPTP and need to exist before the %----transformations and formats are loaded. They are also declared at %----runtime in tptp2X/4. :-op(99,fx,'$'). :-op(100,fx,++). :-op(100,fx,--). %----Postfix for != :-op(100,xf,'!'). %---- .. used for range in tptp2X. Needs to be stronger than : :-op(400,xfx,'..'). %----! and ? are of higher precedence than : so ![X]:p(X) is :(![X],p(X)) %----Otherwise ![X]:![Y]:p(X,Y) cannot be parsed. %----! is fy so Prolog can read !! (blah) as !(!(blah)) and it gets fixed :-op(400,fy,!). :-op(400,fx,?). :-op(400,fx,^). :-op(400,fx,:=). :-op(400,fx,'!!'). :-op(400,fx,'??'). %----= must bind more tightly than : for ! [X] : a = X. = must binder looser %----than quantifiers for otherwise X = ! [Y] : ... is a syntax error (the = %----grabs the quantifier). That means for thf it is necessary to bracket %----formula terms, e.g., a = (! [X] : p(X)) :-op(405,xfx,'='). %---!= not possible because ! is special - see postfix cheat :-op(405,xfx,'!='). :-op(440,xfy,>). %----Type arrow %----Need : stronger than binary connectives for ! [X] : p(X) <=> !Y ... %----Need ~ and : equal and right-assoc for ![X] : ~p and for ~![X] : ... :-op(450,xfy,:). :-op(450,fy,~). :-op(501,yfx,@). :-op(502,xfy,'|'). :-op(502,xfy,'~|'). :-op(502,xfy,'+'). %----Fision for rfof :-op(503,xfy,&). :-op(503,xfy,~&). :-op(503,xfy,'*'). %----Fusion for rfof :-op(504,xfy,=>). :-op(504,xfy,<=). :-op(505,xfy,<=>). :-op(505,xfy,<~>). %----Must be weak to allow any formulae on RHS :-op(550,xfy,:=). */ /* We do not support all of the TPTP operations listed above. */ declare_parse_type(",", 999, INFIX_RIGHT); /* LADR requirement */ declare_parse_type("++", 100, PREFIX_PAREN); declare_parse_type("--", 100, PREFIX_PAREN); declare_parse_type("!", 400, PREFIX_PAREN); declare_parse_type("?", 400, PREFIX_PAREN); declare_parse_type("!=", 405, INFIX); /* added by McCune */ declare_parse_type("=", 405, INFIX); declare_parse_type(":", 450, INFIX_RIGHT); declare_parse_type("~", 410, PREFIX); declare_parse_type("|", 502, INFIX_RIGHT); declare_parse_type("~|", 502, INFIX_RIGHT); declare_parse_type("&", 503, INFIX_RIGHT); declare_parse_type("~&", 503, INFIX_RIGHT); declare_parse_type("=>", 504, INFIX_RIGHT); declare_parse_type("<=", 504, INFIX_RIGHT); declare_parse_type("<=>", 505, INFIX_RIGHT); declare_parse_type("<~>", 505, INFIX_RIGHT); /* Other things */ set_cons_char('\0'); /* Don't recognize list cons */ } /* declare_tptp_parse_types */ /***************************************************************************** This first part is for the TPTP to LADR transformation *****************************************************************************/ /************* * * tptp2_to_ladr_term() * * Take a TPTP "input_clause" transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp2_to_ladr_term(Term t) { Term f = NULL; if (!proper_listterm(t)) { p_term(t); fatal_error("tptp2_to_ladr_term, expected list of literals"); } t = listterm_reverse(t); /* so the result is in the same order */ while (cons_term(t)) { Term a0 = ARG(t,0); Term lit = NULL; if (is_term(a0, "++", 1) || is_term(a0, "--", 1)) { Term atom = ARG(a0, 0); if (is_term(atom, "equal", 2)) { Term tmp = build_binary_term_safe(eq_sym(), ARG(atom,0), ARG(atom,1)); free_term(atom); /* shallow */ atom = tmp; } if (is_term(a0, "++", 1)) lit = atom; else lit = build_unary_term_safe(not_sym(), atom); } else { p_term(a0); fatal_error("tptp2_to_ladr_term, unknown literal"); } if (f == NULL) f = lit; else f = build_binary_term_safe(or_sym(), lit, f); t = ARG(t,1); } return f; } /* tptp2_to_ladr_term */ /************* * * tptp3_to_ladr_term() * * Take a TPTP "cnf" or "fof", and transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp3_to_ladr_term(Term t) { if (is_term(t, "$true", 0)) { free_term(t); return get_rigid_term(true_sym(), 0); } else if (is_term(t, "$false", 0)) { free_term(t); return get_rigid_term(false_sym(), 0); } else if (is_term(t, "~", 1)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term t2 = build_unary_term_safe(not_sym(), a0); free_term(t); return t2; } else if (is_term(t, "|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(imp_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(impby_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "~&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "~|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "<~>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, ":", 2)) { /* Assume it's well formed (don't check for errors). */ Term q = ARG(t,0); Term form = tptp3_to_ladr_term(ARG(t,1)); Term vars = listterm_reverse(ARG(q,0)); if (!proper_listterm(ARG(q,0))) fatal_error("tptp_to_ladr: bad quantified variable(s)"); char *quant = (is_term(q,"!",1) ? all_sym() : exists_sym()); while (cons_term(vars)) { Term v = ARG(vars, 0); Term new = get_rigid_term(quant_sym(), 3); ARG(new,0) = get_rigid_term(quant, 0); ARG(new,1) = copy_term(v); ARG(new,2) = form; form = new; vars = ARG(vars, 1); } zap_term(vars); free_term(t); free_term(q); return form; } else return t; } /* tptp3_to_ladr_term */ /************* * * tptp_input_to_ladr_formula() * * The input Term t is not modified by the call. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula tptp_input_to_ladr_formula(Term t) { char *type = sn_to_str(SYMNUM(t)); Term name = ARG(t,0); Term role = ARG(t,1); Term form = NULL; Term a, b; Formula f; if (str_ident(type, "fof") || str_ident(type, "cnf")) form = tptp3_to_ladr_term(copy_term(ARG(t,2))); else if (str_ident(type, "input_clause")) form = tptp2_to_ladr_term(copy_term(ARG(t,2))); else { p_term(t); fatal_error("tptp_formlua: unknown type"); } a = build_binary_term_safe(attrib_sym(), build_unary_term_safe("label", copy_term(name)), build_unary_term_safe("label", copy_term(role))); b = build_binary_term_safe(attrib_sym(), form, a); f = term_to_formula(b); zap_term(b); return f; } /* tptp_input_to_ladr_formula */ /***************************************************************************** This first part is for the LADR to TPTP transformation *****************************************************************************/ /************* * * rename_vars_to_upper() * *************/ static void rename_vars_to_upper(Formula f) { int i; if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); int sn = fresh_symbol("X", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); free_term(newvar); } for (i = 0; i < f->arity; i++) rename_vars_to_upper(f->kids[i]); } /* rename_vars_to_upper */ /************* * * ladr_term_to_tptp_term() * *************/ static Term ladr_term_to_tptp_term(Term t) { if (is_term(t, true_sym(), 0)) { free_term(t); return get_rigid_term("$true", 0); } else if (is_term(t, false_sym(), 0)) { free_term(t); return get_rigid_term("$false", 0); } else if (is_term(t, not_sym(), 1)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term t2 = build_unary_term_safe("~", a0); free_term(t); return t2; } else if (is_term(t, or_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("|", a0, a1); free_term(t); return t2; } else if (is_term(t, and_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("&", a0, a1); free_term(t); return t2; } else if (is_term(t, imp_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("=>", a0, a1); free_term(t); return t2; } else if (is_term(t, impby_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=", a0, a1); free_term(t); return t2; } else if (is_term(t, iff_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=>", a0, a1); free_term(t); return t2; } else if (is_term(t, quant_sym(), 3)) { Term quant = ARG(t,0); Term var = ARG(t,1); Term form = ladr_term_to_tptp_term(ARG(t,2)); char *q = is_term(quant, "all", 0) ? "!" : "?"; /* build the term :(quant([var]),form) */ Term vlist = listterm_cons(var, get_nil_term()); Term qterm = build_unary_term_safe(q, vlist); Term top = build_binary_term_safe(":", qterm, form); free_term(quant); /* shallow */ return top; } else return t; } /* ladr_term_to_tptp_term */ /************* * * ladr_list_to_tptp_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist ladr_list_to_tptp_list(Plist in, char *name, char *type) { BOOL goal = str_ident(type, "conjecture"); /* goals always become fof */ Plist out = NULL; Plist p; for (p = in; p; p = p->next) { Formula f = p->v; f->attributes = NULL; /* always remove all attributes */ if (clausal_formula(f) && !goal) { Term t, cnf; Topform c = formula_to_clause(f); zap_formula(f); clause_set_variables(c, MAX_VARS); t = ladr_term_to_tptp_term(topform_to_term(c)); zap_topform(c); cnf = get_rigid_term("cnf", 3); ARG(cnf,0) = get_rigid_term(name, 0); ARG(cnf,1) = get_rigid_term(type, 0); ARG(cnf,2) = t; out = plist_prepend(out, cnf); } else { /* f is a non-clausal formula */ Term t, fof; f = universal_closure(f); rename_vars_to_upper(f); t = ladr_term_to_tptp_term(formula_to_term(f)); fof = get_rigid_term("fof", 3); ARG(fof,0) = get_rigid_term(name, 0); ARG(fof,1) = get_rigid_term(type, 0); ARG(fof,2) = t; out = plist_prepend(out, fof); } } return reverse_plist(out); } /* ladr_list_to_tptp_list */ /************* * * syms_in_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist syms_in_form(Term t, BOOL clausal) { if (clausal) { if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), TRUE); else if (is_term(t, "|", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else return fsym_set_in_term(t); } else { /* non-clausal */ if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), FALSE); else if (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else if (is_term(t, ":", 2)) { /* This assumes exactly one universally quantified variable! */ Ilist a = syms_in_form(ARG(t,1), FALSE); a = ilist_removeall(a, SYMNUM(ARG(ARG(ARG(t,0),0),0))); return a; } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else return fsym_set_in_term(t); } } /* syms_in_form */ /************* * * good_tptp_sym() * *************/ static BOOL good_tptp_sym(char *s) { /* [a-z][a-zA-Z0-9_]* */ if (strlen(s) == 0) return FALSE; else { if (!(s[0] >= 'a' && s[0] <= 'z')) return FALSE; else { int i; for (i = 1; i < strlen(s); i++) { char c = s[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) return FALSE; } return TRUE; } } } /* good_tptp_sym */ /************* * * map_for_bad_tptp_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list map_for_bad_tptp_syms(Ilist syms) { if (syms == NULL) return NULL; else { I2list map = map_for_bad_tptp_syms(syms->next); int old_sn = syms->i; char *s = sn_to_str(old_sn); if (!good_tptp_sym(s)) { int new_sn = fresh_symbol("tptp", sn_to_arity(old_sn)); map = i2list_append(map, old_sn, new_sn); } return map; } } /* map_for_bad_tptp_syms */ /************* * * replace_bad_tptp_syms_term() * *************/ static Term replace_bad_tptp_syms_term(Term t, I2list map) { if (VARIABLE(t)) return t; else { int i; int old_sn = SYMNUM(t); int new_sn = assoc(map, old_sn); if (new_sn != INT_MIN) { Term new = get_rigid_term(sn_to_str(new_sn), sn_to_arity(new_sn)); for (i = 0; i < ARITY(t); i++) ARG(new,i) = ARG(t,i); free_term(t); /* shallow */ t = new; } for (i = 0; i < ARITY(t); i++) ARG(t,i) = replace_bad_tptp_syms_term(ARG(t,i), map); return t; } } /* replace_bad_tptp_syms_term */ /************* * * replace_bad_tptp_syms_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term replace_bad_tptp_syms_form(Term t, BOOL clausal, I2list map) { if (is_term(t, "~", 1)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), clausal, map); return t; } else if (clausal && is_term(t, "|", 2)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), TRUE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), TRUE, map); return t; } else if (!clausal && (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2))) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), FALSE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else if (!clausal && is_term(t, ":", 2)) { /* We do not have to worry about quantified variables being replaced---they are disjoint from all other symbols, because they were generted by fresh_symbol(). */ ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else return replace_bad_tptp_syms_term(t, map); } /* replace_bad_tptp_syms_form */ LADR-2009-11A/ladr/termflag.h0000644000175000017500000000253411151265363014721 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TERMFLAG_H #define TP_TERMFLAG_H #include "term.h" /* INTRODUCTION */ /* Public definitions */ #define TP_BIT(bits, flag) (bits & flag) /* End of public definitions */ /* Public function prototypes from termflag.c */ int claim_term_flag(); void release_term_flag(int bit); void term_flag_set(Term t, int flag); void term_flag_clear(Term t, int flag); BOOL term_flag(Term t, int flag); int term_flags(); Term copy_term_with_flags(Term t); Term copy_term_with_flag(Term t, int flag); void term_flag_clear_recursively(Term t, int flag); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/random.c0000644000175000017500000001544410637466322014405 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "random.h" /************* * * random_term() * *************/ /* DOCUMENTATION This routine generates a random term, with depth <= max_depth, and with subterms of arity <= 3. The parameters [v, a0, a1, a2, a3] tells how many variables (named v0,v1,...), constants (named a0,a1,...), unary (named g0,g1,...), binary (named f0,f1,...), ternary (named h0,h1,...), symbols to select from. For example,

random_term(3, 2, 1, 1, 0, 5)
asks for a term, of depth <= 5, with <= 3 variable, <= 2 constant, <= 1 unary, <=1 binary, and 0 ternary symbols. */ /* PUBLIC */ Term random_term(int v, int a0, int a1, int a2, int a3, int max_depth) { int n, arity, j; char *s, symbol[MAX_NAME]; if (max_depth == 0) n = rand() % (v+a0); else n = rand() % (v+a0+a1+a2+a3); if (n < v) { arity = -1; /* variable */ j = n; } else if (n < v+a0) { arity = 0; j = n - v; } else if (n < v+a0+a1) { arity = 1; j = n - (v+a0); } else if (n < v+a0+a1+a2) { arity = 2; j = n - (v+a0+a1); } else { arity = 3; j = n - (v+a0+a1+a2); } if (arity == -1) { return get_variable_term(j); } else { int i; Term t; switch (arity) { case 0: s = "a"; break; case 1: s = "g"; break; case 2: s = "f"; break; case 3: s = "h"; break; default: s = "?"; break; } sprintf(symbol, "%s%d", s, j); t = get_rigid_term(symbol, arity); for (i = 0; i < arity; i++) ARG(t,i) = random_term(v, a0, a1, a2, a3, max_depth-1); return t; } } /* random_term */ /************* * * random_nonvariable_term() * *************/ /* DOCUMENTATION This is like random_term(), except that the returned term will not be a variable. Subterms may be variables. */ /* PUBLIC */ Term random_nonvariable_term(int v, int a0, int a1, int a2, int a3, int max_depth) { Term t = random_term(v, a0, a1, a2, a3, max_depth); /* Let's hope this terminates! */ while (VARIABLE(t)) { zap_term(t); t = random_term(v, a0, a1, a2, a3, max_depth); } return t; } /* random_nonvariable_term */ /************* * * random_complex_term() * *************/ /* DOCUMENTATION This is like random_term(), except that the returned term will not be a variable or a constant. Subterms may be variables or constants. */ /* PUBLIC */ Term random_complex_term(int v, int a0, int a1, int a2, int a3, int max_depth) { Term t = random_term(v, a0, a1, a2, a3, max_depth); /* Let's hope this terminates! */ while (VARIABLE(t)|| CONSTANT(t)) { zap_term(t); t = random_term(v, a0, a1, a2, a3, max_depth); } return t; } /* random_complex_term */ /************* * * random_path() * *************/ /* DOCUMENTATION This routine returns a random-length list of random integers. The range for the length is [1..length_max], and the range for the values is [1..value_max]. */ /* PUBLIC */ Ilist random_path(int length_max, int value_max) { Ilist first, current, new; int length = (rand() % length_max) + 1; /* 1 .. length_max */ int i, value; first = current = NULL; for (i = 0; i < length; i++) { value = (rand() % value_max) + 1; new = get_ilist(); new->i = value; new->next = NULL; if (first == NULL) first = new; else current->next = new; current = new; } return first; } /* random_path */ /************* * * random_permutation() * *************/ /* DOCUMENTATION This routine places a random permtation of [0..size-1] into the array a. (The randomness is not very good.) */ /* PUBLIC */ void random_permutation(int *a, int size) { int n, i, x; for (i = 0; i < size; i++) a[i] = -1; n = 0; while (n < size) { x = rand() % size; if (a[x] == -1) a[x] = n++; else { i = x+1; while (i < size && a[i] != -1) i++; if (i < size) a[i] = n++; else { i = x-1; while (i >= 0 && a[i] != -1) i--; if (i < 0) { fatal_error("random_permutation."); } a[i] = n++; } } } } /* random_permutation */ /************* * * random_clause() * *************/ /* DOCUMENTATION This routin builds and returns a random clause. The arguments are like random_term(), with an extra argument giving the maximum number of literals. */ /* PUBLIC */ Topform random_clause(int v, int a0, int a1, int a2, int a3, int max_depth, int max_lits) { Term t; Topform c; int i, sign; int n = (rand() % max_lits) + 1; /* [1 .. max_lits] */ c = get_topform(); for (i = 0; i < n; i++) { sign = rand() % 2; t = random_complex_term(v, a0, a1, a2, a3, max_depth); c->literals = append_literal(c->literals, new_literal(sign, t)); } return c; } /* random_clause */ /************* * * random_op_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term random_op_term(int depth) { static int initialized = 0; static int symnum[13]; if (!initialized) { symnum[0] = str_to_sn("a", 0); symnum[1] = str_to_sn("->", 2); symnum[2] = str_to_sn("|", 2); symnum[3] = str_to_sn("&", 2); symnum[4] = str_to_sn("~", 1); symnum[5] = str_to_sn("=", 2); symnum[6] = str_to_sn("+", 2); symnum[7] = str_to_sn("*", 2); symnum[8] = str_to_sn("\'", 1); symnum[9] = str_to_sn("$cons", 2); symnum[10] = str_to_sn("$nil", 0); symnum[11] = str_to_sn("$quantified", 1); symnum[12] = str_to_sn("f", 2); initialized = 1; } if (depth == 0) return get_rigid_term("b", 0); else { Term t; int arity, i, sn; sn = symnum[rand() % 13]; arity = sn_to_arity(sn); if (is_symbol(sn, "$quantified", 1)) { Term q = get_rigid_term("$quantified", 1); Term a = get_rigid_term("all", 0); Term x = get_rigid_term("x", 0); Term r = random_op_term(depth-1); Term t = get_nil_term(); t = listterm_cons(r, t); t = listterm_cons(x, t); t = listterm_cons(a, t); ARG(q,0) = t; return q; } else { t = get_rigid_term(sn_to_str(sn), arity); for (i = 0; i < arity; i++) ARG(t,i) = random_op_term(depth-1); return t; } } } /* random_op_term */ LADR-2009-11A/ladr/save/0000755000175000017500000000000011024234737013701 5ustar mccunemccuneLADR-2009-11A/ladr/save/term.c0000644000175000017500000006405610140013503015007 0ustar mccunemccune#include "term.h" /* Sharing Variables. In the original design, no term sharing occurred. This allows compact data structures and simpler algorithms for processiong terms. Then we tried sharing variables only (using the same data structures). In most cases of practical work, nearly all of the leaves in the clause spaces are variables (as opposed to constants). Assuming most function applications are binary, this means that variables take up about half of the term storage. We can save all of this by sharing variables. All terms have a containment field, which points to the containing clause. (If we wished to have terms point to immediate superterms, we could do that instead.) We need containment, because indexing returns terms, and we have to get from those terms to the containing clauses. BUT, we don't index variables, so we can do without containment pointers in variables. Making the change to shared variables was easy. We introduced an array of term pointers, static Term Shared_variables[MAX_VNUM], and changed get_variable_term to return one of those instead of a fresh one. Also, we eliminated the routine set_variable, which changes the variable number of a variable term. If you want to do that now (with shared or with nonshared variables), just free the old one and get a new one. With this code, you can switch back and forth with conditional compilation: #define SHARE_VARIABLES. Things to be careful about: (1) Don't change variable numbers of variable terms. Just use get_variable_term and free_term. (2) Don't use the container field of variables. If you observe those rules, I think everything will be okay; in particular, you should get the same results with and without SHARE_VARIABLES, except for memory usage. January 29, 2003. */ /* Private definitions and types */ #define SHARE_VARIABLES #ifdef SHARE_VARIABLES static Term Shared_variables[MAX_VNUM]; #endif #ifdef TERM_ID_FIELD static int Term_id_count = 0; #endif /* * memory management */ static unsigned Term_gets, Term_frees; #define BYTES_TERM sizeof(struct term) #define PTRS_TERM BYTES_TERM%BPP == 0 ? BYTES_TERM/BPP : BYTES_TERM/BPP + 1 /************* * * Term get_term(arity) * *************/ static Term get_term(int arity) { Term p = get_mem(PTRS_TERM); p->args = get_mem(arity); p->arity = arity; #ifdef TERM_ID_FIELD p->id = ++Term_id_count; #endif Term_gets++; return(p); } /* get_term */ /************* * * free_term() * *************/ /* DOCUMENTATION This routine frees a term node only. If you wish to recursively free all of the subterms as well, call zap_term(t) instead. */ /* PUBLIC */ void free_term(Term p) { #ifdef SHARE_VARIABLES if (VARIABLE(p)) return; /* variables are never freed, because they are shared */ #endif free_mem(p->args, p->arity); free_mem(p, PTRS_TERM); Term_frees++; } /* free_term */ /************* * * fprint_term_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for Terms. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_term_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct term); fprintf(fp, "term (%4d) %11u%11u%11u%9.1f K\n", n, Term_gets, Term_frees, Term_gets - Term_frees, ((Term_gets - Term_frees) * n) / 1024.); /* end of printing for each type */ } /* fprint_term_mem */ /************* * * p_term_mem() * *************/ /* DOCUMENTATION This routine prints memory usage statistics for Terms to stdout. */ /* PUBLIC */ void p_term_mem(void) { fprint_term_mem(stdout, 1); } /* p__mem */ /* * end of memory management */ /************* * * get_variable_term() * *************/ /* DOCUMENTATION This routine returns a term of type VARIABLE. The index of the variable is set to var_num, which should be an integer >= 0. */ /* PUBLIC */ Term get_variable_term(int var_num) { #ifdef SHARE_VARIABLES if (var_num < 0 || var_num > MAX_VNUM) fatal_error("get_variable_term: var_num too big"); if (Shared_variables[var_num] == NULL) { Term t = get_term(0); t->private_symbol = var_num; Shared_variables[var_num] = t; } return Shared_variables[var_num]; #else Term t = get_term(0); if (var_num < 0 || var_num > MAX_VAR) fatal_error("get_variable_term, var_num out of range."); t->private_symbol = var_num; return t; #endif } /* get_variable_term */ /************* * * zap_variables() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_variables(void) { #ifdef SHARE_VARIABLES int i; for (i = 0; i < MAX_VNUM; i++) { Term t = Shared_variables[i]; if (t) { /* Trick free_term into really freeing it by making */ /* it into a constant. */ t->private_symbol = -1; free_term(t); Shared_variables[i] = NULL; } } #endif } /* zap_variables */ /************* * * get_rigid_term_like() * *************/ /* DOCUMENTATION This routine allocates and returns a term node with the same symbol and arity as the given Term t. */ /* PUBLIC */ Term get_rigid_term_like(Term t) { Term t1 = get_term(t->arity); t1->private_symbol = t->private_symbol; return t1; } /* get_rigid_term_like */ /************* * * get_rigid_term() * *************/ /* DOCUMENTATION This routine allocates and returns a term node with the given symbol and arity. If you already have a similar term node, say t, (containing the symbol and arity you need) call get_rigid_term_like(t) instead. */ /* PUBLIC */ Term get_rigid_term(char *sym, int arity) { Term t1 = get_term(arity); t1->private_symbol = -str_to_sn(sym, arity); return t1; } /* get_rigid_term */ /************* * * get_rigid_term_dangerously() * *************/ /* DOCUMENTATION This routine can be used to allocate a term node if all you have is the symbol ID and arity. If the arity is not correct for the symbol ID, terrible things will happen!

If you have a similar term, use get_rigid_term_like() instead. If you can afford the time to access the symbol table, use sn_to_str() and get_rigid_term() instead. */ /* PUBLIC */ Term get_rigid_term_dangerously(int symnum, int arity) { Term t1 = get_term(arity); t1->private_symbol = -symnum; return t1; } /* get_rigid_term_dangerously */ /************* * * zap_term(term) * * Free a term and all of its subterms. * *************/ /* DOCUMENTATION This routine frees a term t and all of its subterms. You should not refer to t after calling zap_term(t). */ /* PUBLIC */ void zap_term(Term t) { int i; for (i = 0; i < t->arity; i++) zap_term(t->args[i]); free_term(t); } /* zap_term */ /************* * * int term_ident(term1, term2) -- Compare two terms. * * If identical return 1); else return 0. The bits * field is not checked. * *************/ /* DOCUMENTATION This function checks if two terms are identical. Only the structure and symbols are checked---any extra fields such as bits or u are NOT checked. */ /* PUBLIC */ BOOL term_ident(Term t1, Term t2) { if (t1->private_symbol != t2->private_symbol) return 0; else { int i; for (i = 0; i < t1->arity; i++) if (!term_ident(t1->args[i], t2->args[i])) return 0; return 1; } } /* term_ident */ /************* * * Term copy_term(term) -- Return a copy of the term. * * The bits field is not copied. * *************/ /* DOCUMENTATION This routine copies a term. Only the symbols and structure are copied---any extra fields such as bits or u are NOT copied. */ /* PUBLIC */ Term copy_term(Term t) { if (VARIABLE(t)) return get_variable_term(VARNUM(t)); else { int i; Term t2 = get_rigid_term_like(t); for (i = 0; i < t->arity; i++) t2->args[i] = copy_term(t->args[i]); return t2; } } /* copy_term */ /************* * * int ground_term(t) -- is a term ground? * *************/ /* DOCUMENTATION This function checks if a term is ground, that is, has no variables. */ /* PUBLIC */ BOOL ground_term(Term t) { if (VARIABLE(t)) return FALSE; else { int i; for (i = 0; i < t->arity; i++) if (!ground_term(t->args[i])) return FALSE; return TRUE; } } /* ground_term */ /************* * * biggest_variable() * *************/ /* DOCUMENTATION This routine returns the greatest variable index of any variable int the given term t. If t is ground, -1 is returned. */ /* PUBLIC */ int biggest_variable(Term t) { if (VARIABLE(t)) return VARNUM(t); else { int i, max, v; for (max = -1, i = 0; i < t->arity; i++) { v = biggest_variable(t->args[i]); max = (v > max ? v : max); } return max; } } /* biggest_variable */ /************* * * symbol_count * *************/ /* DOCUMENTATION This routine returns the total number of symbols (i.e., the number of nodes) in the given term t. */ /* PUBLIC */ int symbol_count(Term t) { int i; int count = 0; for (i = 0; i < ARITY(t); i++) count += symbol_count(ARG(t,i)); return count+1; } /* symbol_count */ /************* * * int occurs_in(t1, t2) -- Does t1 occur in t2 (including t1==t2)? * * term_ident is used to check identity. * *************/ /* DOCUMENTATION This function checks if Term t2 is identical to a subterm of Term t1, including the case term_ident(t1,t2). All identity checks are done with term_ident(), so extra fields such as bits or u are not checked. */ /* PUBLIC */ BOOL occurs_in(Term t1, Term t2) { if (term_ident(t1, t2)) return TRUE; else { int i; for (i = 0; i < t2->arity; i++) if (occurs_in(t1, t2->args[i])) return TRUE; return FALSE; } } /* occurs_in */ /************* * * fprint_term(fp, t) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a term. A newline is NOT printed. */ /* PUBLIC */ void fprint_term(FILE *fp, Term t) { if (VARIABLE(t)) fprintf(fp, "v%d", VARNUM(t)); else { fprint_sym(fp, SYMNUM(t)); if (COMPLEX(t)) { int i; fprintf(fp, "("); for (i = 0; i < ARITY(t); i++) { fprint_term(fp, ARG(t,i)); if (i < ARITY(t)-1) fprintf(fp, ","); } fprintf(fp, ")"); } } fflush(fp); } /* print_term */ /************* * * sprint_term(sb, t) * *************/ /* DOCUMENTATION This (recursive) routine appends the string representation of a term to a String_buf. A newline is not included. */ /* PUBLIC */ void sprint_term(String_buf sb, Term t) { if (VARIABLE(t)) { char s[MAX_NAME]; sprintf(s, "v%d", VARNUM(t)); sb_append(sb, s); } else { sprint_sym(sb, SYMNUM(t)); if (COMPLEX(t)) { int i; sb_append(sb, "("); for (i = 0; i < t->arity; i++) { sprint_term(sb, t->args[i]); if (i < t->arity-1) sb_append(sb, ","); } sb_append(sb, ")"); } } } /* sprint_term */ /************* * * p_term(t) * *************/ /* DOCUMENTATION This routine prints a term, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_term() instead. If you want the term put into a string, use sprint_term() instead. */ /* PUBLIC */ void p_term(Term t) { fprint_term(stdout, t); printf("\n"); fflush(stdout); } /* p_term */ /************* * * all_args_vars(t) * *************/ /* DOCUMENTATION This Boolean routine checks if all argumets of Term t are VARIABLEs. (It is true also if t is a VARIABLE.) */ /* PUBLIC */ BOOL all_args_vars(Term t) { if (VARIABLE(t)) return TRUE; else { int i; for (i = 0; i < t->arity; i++) if (!VARIABLE(t->args[i])) return FALSE; return TRUE; } } /* all_args_vars */ /************* * * build_binary_term() * *************/ /* DOCUMENTATION Build and return a binary term with SYMNUM sn, first term a1, and second term a2.

WARNING: if sn is not a binary symbol, bad things will happen! */ /* PUBLIC */ Term build_binary_term(int sn, Term a1, Term a2) { Term t = get_rigid_term_dangerously(sn, 2); t->args[0] = a1; t->args[1] = a2; return(t); } /* build_binary_term */ /************* * * build_unary_term() * *************/ /* DOCUMENTATION Build and return a unary term with SYMNUM sn and argument term a.

WARNING: if sn is not a unary symbol, bad things will happen! */ /* PUBLIC */ Term build_unary_term(int sn, Term a) { Term t = get_rigid_term_dangerously(sn, 1); t->args[0] = a; return(t); } /* build_unary_term */ /************* * * subst_term() * *************/ /* DOCUMENTATION In term t, replace all occurrences of Term target with copies of Term replacement. Free all of the replaced terms; */ /* PUBLIC */ Term subst_term(Term t, Term target, Term replacement) { if (term_ident(t, target)) { zap_term(t); return copy_term(replacement); } else { int i; for (i = 0; i < t->arity; i++) t->args[i] = subst_term(t->args[i], target, replacement); return t; } } /* subst_term */ /************* * * subst_var_term() * *************/ /* DOCUMENTATION In Term t, replace all CONSTANT terms containing SYMNUM symnum with a variable containing VARNUM varnum. Free the replaced constants and return the result. */ /* PUBLIC */ Term subst_var_term(Term t, int symnum, int varnum) { if (CONSTANT(t) && SYMNUM(t) == symnum) { Term v = get_variable_term(varnum); zap_term(t); return v; } else { int i; for (i = 0; i < t->arity; i++) t->args[i] = subst_var_term(t->args[i], symnum, varnum); return t; } } /* subst_var_term */ /************* * * greatest_variable() * *************/ /* DOCUMENTATION This routine returns the greatest variable index in a term. If the term is ground, -1 is returned. */ /* PUBLIC */ int greatest_variable(Term t) { if (VARIABLE(t)) return VARNUM(t); else { int i, max, v; for (max = -1, i = 0; i < t->arity; i++) { v = greatest_variable(t->args[i]); max = (v > max ? v : max); } return max; } } /* greatest_variable */ /************* * * greatest_symnum_in_term() * *************/ /* DOCUMENTATION This function returns the greatest SYMNUM (of a CONSTANT or COMPLEX term) in the given Term t. If the term is a VARIABLE, return -1. */ /* PUBLIC */ int greatest_symnum_in_term(Term t) { if (VARIABLE(t)) return -1; else { int max = SYMNUM(t); int i; for (i = 0; i < t->arity; i++) { int sm = greatest_symnum_in_term(t->args[i]); max = (sm > max ? sm : max); } return max; } } /* greatest_symnum_in_term */ /************* * * upward_term_links() * *************/ /* DOCUMENTATION In the given Term t, make the "container" field of t and each subterm, except possibly variables, point to (void *) p. (We're experimenting with shared variables.) */ /* PUBLIC */ void upward_term_links(Term t, void *p) { int i; #ifdef SHARE_VARIABLES if (!VARIABLE(t)) t->container = p; #else t->container = p; #endif for (i = 0; i < t->arity; i++) upward_term_links(t->args[i], p); } /* upward_term_links */ /************* * * occurrences() * *************/ /* DOCUMENTATION This function returns the number of occurrences of Term target in Term t. The checks are made with term_ident(). */ /* PUBLIC */ int occurrences(Term t, Term target) { if (term_ident(t, target)) return 1; else { int n = 0; int i; for (i = 0; i < t->arity; i++) n += occurrences(t->args[i], target); return n; } } /* occurrences */ /************* * * trm_set_vars_recurse() * * There might be another (static) copy of this routine in clause.c. * *************/ static Term trm_set_vars_recurse(Term t, char **varnames, int max_vars) { if (CONSTANT(t)) { char *name = sn_to_str(SYMNUM(t)); if (variable_name(name)) { int i = 0; while (i < max_vars && varnames[i] != NULL && varnames[i] != name) i++; if (i == max_vars) fatal_error("trm_set_vars_recurse: max_vars"); else { if (varnames[i] == NULL) varnames[i] = name; free_term(t); t = get_variable_term(i); } } } else { int i; for (i = 0; i < t->arity; i++) t->args[i] = trm_set_vars_recurse(t->args[i], varnames, max_vars); } return t; } /* trm_set_vars_recurse */ /************* * * term_set_variables() * *************/ /* DOCUMENTATION This routine traverses a term and changes the constants that should be variables, into variables. On input, the term should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

If you are dealing with clauses, use clause_set_variables() instead. */ #define VAR_ARRAY_SIZE 100 /* PUBLIC */ void term_set_variables(Term t, int max_vars) { char *a[VAR_ARRAY_SIZE], **vmap; int i; if (max_vars > VAR_ARRAY_SIZE) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; for (i = 0; i < t->arity; i++) t->args[i] = trm_set_vars_recurse(t->args[i], vmap, max_vars); if (max_vars > VAR_ARRAY_SIZE) free(vmap); } /* term_set_variables */ /************* * * nat_to_term() * *************/ /* DOCUMENTATION This routine takes a nonnegative integer and returns a constant Term with the string representation of the integer as the constant symbol. */ /* PUBLIC */ Term nat_to_term(int n) { char s[100]; if (n < 0) fatal_error("nat_to_term: negative term"); itoa(n, s); return get_rigid_term(s, 0); } /* nat_to_term */ /************* * * natural_constant(t) * *************/ /* DOCUMENTATION This routine takes a term, and if the term represents an nonnegative integer, that integer is returned; otherwise, -1 is returned. */ /* PUBLIC */ int natural_constant(Term t) { if (!CONSTANT(t)) return -1; else { int i; if (!str_to_int(sn_to_str(SYMNUM(t)), &i)) return -1; else if (i < 0) return -1; else return i; } } /* natural_constant */ /************* * * arg_position() * *************/ /* DOCUMENTATION If the given terms are in a parent-child relatioship, return the argument position (index) of the child. Otherwise, return -1. */ /* PUBLIC */ int arg_position(Term parent, Term child) { int i; for (i = 0; i < ARITY(parent); i++) { if (ARG(parent,i) == child) return i; } return -1; } /* arg_position */ /************* * * is_term() * *************/ /* DOCUMENTATION Does term t have the the given symbol and arity? */ /* PUBLIC */ BOOL is_term(Term t, char *str, int arity) { return t != NULL && is_symbol(SYMNUM(t), str, arity); } /* is_term */ /************* * * is_constant() * *************/ /* DOCUMENTATION Is term t a specific constant? */ /* PUBLIC */ BOOL is_constant(Term t, char *str) { return is_term(t, str, 0); } /* is_constant */ /************* * * term_symbol() * *************/ /* DOCUMENTATION Return the print string associated with the given nonvariable term. If the term is a variable, return NULL. */ /* PUBLIC */ char *term_symbol(Term t) { return VARIABLE(t) ? NULL : sn_to_str(SYMNUM(t)); } /* term_symbol */ /************* * * term_to_int() * *************/ /* DOCUMENTATION Given a term, see if it represents an integer. If so, set *result to the integer and return TRUE. If not, return FALSE.

The term representation of a negative integer is the function symbol "-" applied to a nonnegative integer. */ /* PUBLIC */ BOOL term_to_int(Term t, int *result) { if (CONSTANT(t)) { return str_to_int(sn_to_str(SYMNUM(t)), result); } else if (is_term(t, "-", 1)) { if (!CONSTANT(ARG(t,0))) return FALSE; else { if (str_to_int(sn_to_str(SYMNUM(ARG(t,0))), result)) { *result = -(*result); return TRUE; } else return FALSE; } } else return FALSE; } /* term_to_int */ /************* * * symbols_in_term() * *************/ /* DOCUMENTATION This routine collects the multiset of nonvariable symbols in a term. An Ilist of symbol IDs (symnums) is returned */ /* PUBLIC */ Ilist symbols_in_term(Term t, Ilist g) { if (!VARIABLE(t)) { int i; g = ilist_prepend(g, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) g = symbols_in_term(ARG(t,i), g); } return g; } /* symbols_in_term */ /************* * * new_term_top() * *************/ /* DOCUMENTATION Replace the top node of a term with a new node. The new node has an address greater than any other term currently in use. The container pointer and private_flags are copied.

If TERM_ID_FIELD is defined, the new node gets a term ID greater than any other currently in use.

The purpose of this routine is to get the term ready for FPA indexing.

Call it like this: x->t = new_term_top(x->t); */ /* PUBLIC */ Term new_term_top(Term t1) { #if 1 return t1; #else if (VARIABLE(t1)) return t1; else { Term t2 = get_new_term(ARITY(t1)); int i; for (i = 0; i < ARITY(t1); i++) ARG(t2,i) = ARG(t1,i); t2->private_symbol = t1->private_symbol; t2->container = t1->container; t2->private_flags = t1->private_flags; free_term(t1); return t2; } #endif } /* new_term_top */ /************* * * entirely_new_term() * *************/ /* DOCUMENTATION The purpose of this routine is to get the term ready for FPA indexing.

Call it like this: x->t = entirely_new_term(x->t); */ /* PUBLIC */ Term entirely_new_term(Term t) { if (VARIABLE(t)) return t; else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = entirely_new_term(ARG(t,i)); return new_term_top(t); } } /* entirely_new_term */ /************* * * renum_vars_recurse() * *************/ /* DOCUMENTATION This routine renumbers the variables of a term. It is assumed that vmap has been filled with -1 on the initial call and that the size of vmap is at least max_vars.

This returns a Term instead of being void, in case the given term is itself a variable. (Recall that variables may be shared, so we can't just change a variable's index. */ /* PUBLIC */ Term renum_vars_recurse(Term t, int vmap[], int max_vars) { if (VARIABLE(t)) { int i = 0; while (i < max_vars && vmap[i] != -1 && vmap[i] != VARNUM(t)) i++; if (i == max_vars) fatal_error("renum_vars_recurse: too many variables"); if (vmap[i] == -1) vmap[i] = VARNUM(t); free_term(t); return get_variable_term(i); } else { int i; for (i = 0; i < t->arity; i++) t->args[i] = renum_vars_recurse(t->args[i], vmap, max_vars); return t; } } /* renum_vars_recurse */ /************* * * set_vars_recurse() * *************/ /* DOCUMENTATION This routine sets the variables of a term. It is assumed that vnames has been filled with NULL on the initial call and that the size of vnames is at least max_vars.

This returns a Term instead of being void, in case the given term is itself becomes a variable. */ /* PUBLIC */ Term set_vars_recurse(Term t, char *vnames[], int max_vars) { if (CONSTANT(t)) { char *name = sn_to_str(SYMNUM(t)); if (variable_name(name)) { int i = 0; while (i < max_vars && vnames[i] != NULL && vnames[i] != name) i++; if (i == max_vars) fatal_error("set_vars_recurse: max_vars"); else { if (vnames[i] == NULL) vnames[i] = name; free_term(t); t = get_variable_term(i); } } } else { int i; for (i = 0; i < t->arity; i++) t->args[i] = set_vars_recurse(t->args[i], vnames, max_vars); } return t; } /* set_vars_recurse */ /************* * * multiset_of_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist multiset_of_vars(Term t, Plist vars) { if (VARIABLE(t)) return plist_prepend(vars, t); else { int i; for (i = 0; i < ARITY(t); i++) vars = multiset_of_vars(ARG(t,i), vars); return vars; } } /* multiset_of_vars */ /************* * * multiset_of_variables() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist multiset_of_variables(Term t) { return multiset_of_vars(t, NULL); } /* multiset_of_variables */ /************* * * variables_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL variables_subset(Term t1, Term t2) { Plist t1_vars = multiset_of_variables(t1); Plist t2_vars = multiset_of_variables(t2); BOOL ok = plist_subset(t1_vars, t2_vars); zap_plist(t1_vars); zap_plist(t2_vars); return ok; } /* variables_subset */ /************* * * term_at_pos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term term_at_pos(Term t, Ilist pos) { if (pos == NULL) return t; else { if (pos->i > ARITY(t)) fatal_error("term_at_pos, position out of range"); return term_at_pos(ARG(t,pos->i - 1), pos->next); } } /* term_at_pos */ /************* * * pos_of_subterm() * *************/ static Ilist pos_of_subterm(Term t, Term subterm) { if (VARIABLE(t)) return NULL; else if (t == subterm) /* We need to let the caller know that we found it, and we also need to return the position vector (NULL). The easiest way I can see to do that is to return a non-NULL position consisting of a "terminator" which will have to be removed later. */ return ilist_prepend(NULL, INT_MAX); /* terminator */ else { int i; Ilist p = NULL; for (i = 0; i < ARITY(t) && p == NULL; i++) p = pos_of_subterm(ARG(t, i), subterm); return p ? ilist_prepend(p, i) : NULL; } } /* pos_of_subterm */ /************* * * position_of_subterm() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist position_of_subterm(Term t, Term subterm) { Ilist pos = pos_of_subterm(t, subterm); if (pos == NULL) return NULL; else { return ilist_remove_last(pos); } } /* position_of_subterm */ /************* * * symbol_occurrences() * *************/ /* DOCUMENTATION Return the number of occurrences of a symbol in a term. */ /* PUBLIC */ int symbol_occurrences(Term t, int symnum) { if (VARIABLE(t)) return 0; else { int n = (SYMNUM(t) == symnum ? 1 : 0); int i; for (i = 0; i < ARITY(t); i++) n += symbol_occurrences(ARG(t,i), symnum); return n; } } /* symbol_occurrences */ LADR-2009-11A/ladr/save/discrim.c0000644000175000017500000011175610140052442015477 0ustar mccunemccune#include "discrim.h" /* Private definitions and types */ typedef struct flat * Flat; struct discrim { /* node in a discrimination tree */ Discrim next; /* sibling */ union { Discrim kids; /* for internal nodes */ Plist data; /* for leaves */ } u; short symbol; /* variable number or symbol number */ char type; /* term type and for ac indexing type */ }; struct flat { /* for building a stack of states for backtracking */ Term t; Flat prev, next, last; Discrim alternatives; int bound; /* (tame) */ int varnum; /* (tame) */ int place_holder; int num_ac_args; /* for AC symbols (wild) */ int num_ac_nv_args; /* for AC symbols (wild) */ int commutative; /* for commutative symbols (wild) */ int flip; /* for commutative symbols (wild) */ }; struct discrim_pos { /* to save position in set of answers */ Context subst; /* substitution */ Plist data; /* identical terms from leaf of discrim tree */ Flat f; /* stack of states for backtracking */ }; #define GO 1 #define BACKTRACK 2 #define SUCCESS 3 #define FAILURE 4 /* type of discrimination tree node */ #define DVARIABLE 1 #define DRIGID 2 #define AC_ARG_TYPE 3 #define AC_NV_ARG_TYPE 4 #define DVAR(d) (d->type == DVARIABLE) /* * memory management */ static unsigned Discrim_gets, Discrim_frees; static unsigned Flat_gets, Flat_frees; static unsigned Discrim_pos_gets, Discrim_pos_frees; #define BYTES_DISCRIM sizeof(struct discrim) #define PTRS_DISCRIM BYTES_DISCRIM%BPP == 0 ? BYTES_DISCRIM/BPP : BYTES_DISCRIM/BPP + 1 #define BYTES_FLAT sizeof(struct flat) #define PTRS_FLAT BYTES_FLAT%BPP == 0 ? BYTES_FLAT/BPP : BYTES_FLAT/BPP + 1 #define BYTES_DISCRIM_POS sizeof(struct discrim_pos) #define PTRS_DISCRIM_POS BYTES_DISCRIM_POS%BPP == 0 ? BYTES_DISCRIM_POS/BPP : BYTES_DISCRIM_POS/BPP + 1 /************* * * Discrim get_discrim() * *************/ static Discrim get_discrim(void) { Discrim p = get_mem(PTRS_DISCRIM); Discrim_gets++; return(p); } /* get_discrim */ /************* * * free_discrim() * *************/ static void free_discrim(Discrim p) { free_mem(p, PTRS_DISCRIM); Discrim_frees++; } /* free_discrim */ /************* * * Flat get_flat() * *************/ static Flat get_flat(void) { Flat p = get_mem(PTRS_FLAT); Flat_gets++; return(p); } /* get_flat */ /************* * * free_flat() * *************/ static void free_flat(Flat p) { free_mem(p, PTRS_FLAT); Flat_frees++; } /* free_flat */ /************* * * Discrim_pos get_discrim_pos() * *************/ static Discrim_pos get_discrim_pos(void) { Discrim_pos p = get_mem(PTRS_DISCRIM_POS); Discrim_pos_gets++; return(p); } /* get_discrim_pos */ /************* * * free_discrim_pos() * *************/ static void free_discrim_pos(Discrim_pos p) { free_mem(p, PTRS_DISCRIM_POS); Discrim_pos_frees++; } /* free_discrim_pos */ /************* * * fprint_discrim_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrim package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_discrim_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_DISCRIM; fprintf(fp, "discrim (%4d) %11u%11u%11u%9.1f K\n", n, Discrim_gets, Discrim_frees, Discrim_gets - Discrim_frees, ((Discrim_gets - Discrim_frees) * n) / 1024.); n = BYTES_FLAT; fprintf(fp, "flat (%4d) %11u%11u%11u%9.1f K\n", n, Flat_gets, Flat_frees, Flat_gets - Flat_frees, ((Flat_gets - Flat_frees) * n) / 1024.); n = BYTES_DISCRIM_POS; fprintf(fp, "discrim_pos (%4d) %11u%11u%11u%9.1f K\n", n, Discrim_pos_gets, Discrim_pos_frees, Discrim_pos_gets - Discrim_pos_frees, ((Discrim_pos_gets - Discrim_pos_frees) * n) / 1024.); } /* fprint_discrim_mem */ /************* * * p_discrim_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the discrim package. */ /* PUBLIC */ void p_discrim_mem() { fprint_discrim_mem(stdout, TRUE); } /* p_discrim_mem */ /* * end of memory management */ /************* * * discrim_init() * *************/ /* DOCUMENTATION This routine allocates and returns an empty discrimination index. It can be used for either wild or tame indexing. */ /* PUBLIC */ Discrim discrim_init(void) { return get_discrim(); } /* discrim_init */ /************* * * discrim_dealloc(d) * *************/ /* DOCUMENTATION This routine frees an empty discrimination index (wild or tame). */ /* PUBLIC */ void discrim_dealloc(Discrim d) { if (d->u.kids) { fatal_error("discrim_dealloc, nonempty index."); } else free_discrim(d); } /* discrim_dealloc */ /************* * * print_discrim_tree(fp, d, n, depth) * *************/ static void print_discrim_tree(FILE *fp, Discrim d, int n, int depth) { int arity, i; for (i = 0; i < depth; i++) printf(" -"); if (depth == 0) fprintf(fp, "\nroot"); else if (DVAR(d)) fprintf(fp, "v%d", d->symbol); else fprintf(fp, "%s", sn_to_str(d->symbol)); fprintf(fp, "(%x)", (unsigned) d); if (n == 0) { Plist p; for (i = 0, p = d->u.data; p; i++, p = p->next); fprintf(fp, ": leaf has %d objects.\n", i); } else { Discrim d1; fprintf(fp, "\n"); for (d1 = d->u.kids; d1 != NULL; d1 = d1->next) { if (DVAR(d1)) arity = 0; else arity = sn_to_arity(d1->symbol); print_discrim_tree(fp, d1, n+arity-1, depth+1); } } } /* print_discrim_tree */ /************* * * fprint_discrim_tame_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a tame discrimination index. */ /* PUBLIC */ void fprint_discrim_tame_index(FILE *fp, Discrim d) { print_discrim_tree(fp, d, 1, 0); } /* print_discrim_tame_index */ /************* * * p_discrim_tame_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) a tame discrimination index. */ /* PUBLIC */ void p_discrim_tame_index(Discrim d) { fprint_discrim_tame_index(stdout, d); } /* p_discrim_tame_index */ /************* * * Discrim discrim_tame_insert_rec(t, d) * * Return node of d corresp. to end of term t. If it does * not exist, add nodes to t so that it does exist. * *************/ static Discrim discrim_tame_insert_rec(Term t, Discrim d) { Discrim d1, d2, prev; int symbol, i; if (VARIABLE(t)) { d1 = d->u.kids; prev = NULL; symbol = VARNUM(t); while (d1 && DVAR(d1) && d1->symbol < symbol) { prev = d1; d1 = d1->next; } if (d1 == NULL || !DVAR(d1) || d1->symbol != symbol) { d2 = get_discrim(); d2->type = DVARIABLE; d2->symbol = VARNUM(t); d2->next = d1; if (prev == NULL) d->u.kids = d2; else prev->next = d2; return d2; } else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; prev = NULL; /* arities fixed: handle both NAME and COMPLEX */ symbol = SYMNUM(t); while (d1 && DVAR(d1)) { /* skip variables */ prev = d1; d1 = d1->next; } while (d1 && d1->symbol < symbol) { prev = d1; d1 = d1->next; } if (d1 == NULL || d1->symbol != symbol) { d2 = get_discrim(); d2->type = DRIGID; d2->symbol = symbol; d2->next = d1; d1 = d2; } else d2 = NULL; /* new node not required at this level */ for (i = 0; i < t->arity; i++) d1 = discrim_tame_insert_rec(t->args[i], d1); if (d2 != NULL) { /* link in new subtree (possibly a leaf) */ if (prev == NULL) d->u.kids = d2; else prev->next = d2; } return d1; /* d1 is leaf corresp. to end of input term */ } } /* discrim_tame_insert_rec */ /************* * * discrim_tame_insert(t, root, object) * *************/ static void discrim_tame_insert(Term t, Discrim root, void *object) { Discrim d; Plist gp1, gp2; d = discrim_tame_insert_rec(t, root); gp1 = get_plist(); gp1->v = object; /* Install at end of list. */ if (d->u.data == NULL) d->u.data = gp1; else { for (gp2 = d->u.data; gp2->next != NULL; gp2 = gp2->next); gp2->next = gp1; } } /* discrim_tame_insert */ /************* * * Discrim discrim_end(t, d, path_p) * * Given a discrimination tree (or a subtree) and a term, return the * node in the tree that corresponds to the last symbol in t (or NULL * if the node doesn't exist). *path_p is a list that is extended by * this routine. It is a list of pointers to the * nodes in path from the parent of the returned node up to imd. * (It is useful for deletions, because nodes do not have pointers to * parents.) * *************/ static Discrim discrim_end(Term t, Discrim d, Plist *path_p) { Discrim d1; Plist dp; int symbol, sym; /* add current node to the front of the path list. */ dp = get_plist(); dp->v = d; dp->next = *path_p; *path_p = dp; if (VARIABLE(t)) { d1 = d->u.kids; symbol = VARNUM(t); while (d1 && DVAR(d1) && d1->symbol < symbol) d1 = d1->next; if (d1 == NULL || !DVAR(d1) || d1->symbol != symbol) return NULL; else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; sym = SYMNUM(t); /* arities fixed: handle both NAME and COMPLEX */ while (d1 && DVAR(d1)) /* skip variables */ d1 = d1->next; while (d1 && d1->symbol < sym) d1 = d1->next; if (d1 == NULL || d1->symbol != sym) return NULL; else { int i; for (i = 0; d1 && i < t->arity; i++) d1 = discrim_end(t->args[i], d1, path_p); return d1; } } } /* discrim_end */ /************* * * discrim_tame_delete(t, root, object) * *************/ static void discrim_tame_delete(Term t, Discrim root, void *object) { Discrim end, d2, d3, parent; Plist tp1, tp2; Plist dp1, path; /* First find the correct leaf. path is used to help with */ /* freeing nodes, because nodes don't have parent pointers. */ path = NULL; end = discrim_end(t, root, &path); if (end == NULL) { fatal_error("discrim_tame_delete, cannot find end."); } /* Free the pointer in the leaf-list */ tp1 = end->u.data; tp2 = NULL; while(tp1 && tp1->v != object) { tp2 = tp1; tp1 = tp1->next; } if (tp1 == NULL) { fatal_error("discrim_tame_delete, cannot find term."); } if (tp2 == NULL) end->u.data = tp1->next; else tp2->next = tp1->next; free_plist(tp1); if (end->u.data == NULL) { /* free tree nodes from bottom up, using path to get parents */ end->u.kids = NULL; /* probably not necessary */ dp1 = path; while (end->u.kids == NULL && end != root) { parent = (Discrim) dp1->v; dp1 = dp1->next; d2 = parent->u.kids; d3 = NULL; while (d2 != end) { d3 = d2; d2 = d2->next; } if (d3 == NULL) parent->u.kids = d2->next; else d3->next = d2->next; free_discrim(d2); end = parent; } } /* free path list */ while (path) { dp1 = path; path = path->next; free_plist(dp1); } } /* discrim_tame_delete */ /************* * * discrim_tame_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a tame discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted. */ /* PUBLIC */ void discrim_tame_update(Term t, Discrim root, void *object, Indexop op) { if (op == INSERT) discrim_tame_insert(t, root, object); else discrim_tame_delete(t, root, object); } /* discrim_tame_update */ /************* * * check_flat * *************/ static Flat check_flat(Flat f) { Flat last; int i, arity; if (f->next != NULL && f->next->prev != f) fprintf(stderr, "check_flat: next-prev error\n"); if (f->place_holder) arity = 0; else arity = ARITY(f->t); last = f; for (i = 0; i < arity; i++) last = check_flat(last->next); if (f->last != last) fprintf(stderr, "check_flat: last is wrong\n"); return last; } /* check_flat */ /************* * * p_flat * *************/ void p_flat(Flat f) { while (f != NULL) { printf("%s", VARIABLE(f->t) ? "*" : sn_to_str(SYMNUM(f->t))); if (f->place_holder) printf("[]"); f = f->next; if (f != NULL) printf("-"); } printf("\n"); } /* p_flat */ /************* * * flip_flat * *************/ static void flip_flat(Flat f) { /* Assume f is binary. */ Flat arg1 = f->next; Flat arg2 = arg1->last->next; Flat after = f->last->next; Flat p; f->next = arg2; arg2->last->next = arg1; arg1->last->next = after; f->last = arg1->last; arg2->prev = f; arg1->prev = arg2->last; if (after != NULL) after->prev = arg1->last; /* arg2->last is the old end of f */ for (p = f->prev; p != NULL; p = p->prev) if (p->last == arg2->last) p->last = f->last; #if 0 for (p = f; p->prev != NULL; p = p->prev); check_flat(p); #endif } /* flip_flat */ /************* * * discrim_retrieve_leaf(t_in, root, subst, ppos) * *************/ static Plist discrim_retrieve_leaf(Term t_in, Discrim root, Context subst, Flat *ppos) { Flat f, f1, f2, f_save; Term t = NULL; Discrim d = NULL; int symbol = 0; int match = 0; int bound = 0; int status = 0; f = *ppos; /* Don't forget to reset before return. */ t = t_in; f_save = NULL; if (t != NULL) { /* if first call */ d = root->u.kids; if (d != NULL) { f = get_flat(); f->t = t; f->last = f; f->prev = NULL; f->place_holder = (COMPLEX(t)); status = GO; } else status = FAILURE; } else status = BACKTRACK; while (status == GO || status == BACKTRACK) { if (status == BACKTRACK) { while (f && !f->alternatives) { /* clean up HERE??? */ if (f->bound) { subst->terms[f->varnum] = NULL; f->bound = 0; } if (f->commutative && f->flip == 2) { /* commutative with no alternative */ flip_flat(f); /* un-flip */ #if 0 printf("AFTER un-flip: "); p_flat(f); #endif f->flip = 0; } f_save = f; f = f->prev; } if (f != NULL) { if (f->bound) { subst->terms[f->varnum] = NULL; f->bound = 0; } if (f->commutative && f->flip == 1) { flip_flat(f); /* flip */ #if 0 printf("AFTER flip: "); p_flat(f); #endif f->flip = 2; } d = f->alternatives; f->alternatives = NULL; status = GO; } else status = FAILURE; } if (status == GO) { match = 0; while (!match && d && DVAR(d)) { symbol = d->symbol; if (subst->terms[symbol]) { /* if already bound */ match = term_ident(subst->terms[symbol], f->t); bound = 0; } else { /* bind variable in discrim tree */ match = 1; subst->terms[symbol] = f->t; bound = 1; } if (!match) d = d->next; } if (match) { /* push alternatives */ f->alternatives = d->next; f->bound = bound; f->varnum = symbol; f = f->last; } else if (VARIABLE(f->t)) status = BACKTRACK; else { symbol = SYMNUM(f->t); while (d && d->symbol < symbol) d = d->next; if (!d || d->symbol != symbol) status = BACKTRACK; else if (f->place_holder) { int i; /* insert skeleton in place_holder */ f1 = get_flat(); f1->t = f->t; f1->prev = f->prev; f1->last = f; f_save = f1; if (f1->prev) f1->prev->next = f1; t = f->t; for (i = 0; i < t->arity; i++) { if (i < t->arity-1) f2 = get_flat(); else f2 = f; f2->place_holder = COMPLEX(t->args[i]); f2->t = t->args[i]; f2->last = f2; f2->prev = f1; f1->next = f2; f1 = f2; } f = f_save; if (is_commutative(SYMNUM(f->t)) && !term_ident(f->t->args[0], f->t->args[1])) f->commutative = 1; } /* if f->place_holder */ if (f->commutative && f->flip == 0) { f->alternatives = d; f->flip = 1; } } if (status == GO) { if (f->next) { f = f->next; d = d->u.kids; } else status = SUCCESS; } } } if (status == SUCCESS) { *ppos = f; return d->u.data; } else { /* Free flats. */ while (f_save) { f1 = f_save; f_save = f_save->next; free_flat(f1); } return NULL; } } /* discrim_retrieve_leaf */ /************* * * discrim_tame_retrieve_first(t, root, subst, ppos) * * Get the first object associated with a term more general than t. * * Remember to call discrim_tame_cancel(*ppos) if you don't want the * whole sequence. * *************/ /* DOCUMENTATION This routine, along with discrim_tame_retrieve_next(), gets answers from a tame discrimination index. This routine retrieves the first object associated with a term, say ft, more general than Term t. (NULL is returned if there is none.) The substitution for variables of ft is placed into Context subst.

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_tame_cancel() to clear the substitution and free memory associated with the Discrim_pos. */ /* PUBLIC */ void *discrim_tame_retrieve_first(Term t, Discrim root, Context subst, Discrim_pos *ppos) { Plist tp; Flat f; Discrim_pos gp; tp = discrim_retrieve_leaf(t, root, subst, &f); if (tp == NULL) return NULL; else { gp = get_discrim_pos(); gp->subst = subst; gp->f = f; gp->data = tp; *ppos = gp; return tp->v; } } /* discrim_tame_retrieve_first */ /************* * * discrim_tame_retrieve_next(ppos) * * Get the next object associated with a term more general than t. * * Remember to call discrim_tame_cancel(*ppos) if you don't want the * whole sequence. * *************/ /* DOCUMENTATION This routine retrieves the next object in the sequence of answers to a query of a tame discrimination tree. You must not explicitly clear the Context you gave to discrim_tame_retrieve_first()---that is handled internally. See discrim_tame_retrieve_first(). */ /* PUBLIC */ void *discrim_tame_retrieve_next(Discrim_pos pos) { Plist tp; tp = pos->data->next; if (tp != NULL) { /* if any more terms in current leaf */ pos->data = tp; return tp->v; } else { /* try for another leaf */ tp = discrim_retrieve_leaf((Term) NULL, (Discrim) NULL, pos->subst, &(pos->f)); if (tp != NULL) { pos->data = tp; return tp->v; } else { free_discrim_pos(pos); return NULL; } } } /* discrim_tame_retrieve_next */ /************* * * discrim_tame_cancel(pos) * *************/ /* DOCUMENTATION This routine must be called if you get some, but not all answers to a tame discrimintaion query. The Context (which was given to the discrim_tame_retrieve_first() call) is cleared, and the memory associated the retrieval state is freed. */ /* PUBLIC */ void discrim_tame_cancel(Discrim_pos pos) { Flat f1, f2; f1 = pos->f; while (f1) { if (f1->bound) pos->subst->terms[f1->varnum] = NULL; f2 = f1; f1 = f1->prev; free_flat(f2); } free_discrim_pos(pos); } /* discrim_tame_cancel */ /* ******************************** WILD **************************** */ /************* * * num_ac_args(t, symbol) * *************/ static int num_ac_args(struct term *t, int symbol) { if (!COMPLEX(t) || SYMNUM(t) != symbol) return 1; else return (num_ac_args(t->args[0], symbol) + num_ac_args(t->args[1], symbol)); } /* num_ac_args */ /************* * * num_ac_nv_args(t, symbol) * *************/ static int num_ac_nv_args(struct term *t, int symbol) { if (!COMPLEX(t) || SYMNUM(t) != symbol) return (VARIABLE(t) ? 0 : 1); else return (num_ac_nv_args(t->args[0], symbol) + num_ac_nv_args(t->args[1], symbol)); } /* num_ac_nv_args */ /************* * * print_discrim_wild_tree() * *************/ static void print_discrim_wild_tree(FILE *fp, Discrim d, int n, int depth) { int arity, i; for (i = 0; i < depth; i++) fprintf(fp, " -"); if (depth == 0) fprintf(fp, "\nroot"); else if (d->type == AC_ARG_TYPE) fprintf(fp, "AC %d args", d->symbol); else if (d->type == AC_NV_ARG_TYPE) fprintf(fp, "AC %d NV args", d->symbol); else if (DVAR(d)) fprintf(fp, "*"); else fprintf(fp, "%s", sn_to_str(d->symbol)); fprintf(fp, " (%x)", (unsigned) d); if (n == 0) { Plist p; for (i = 0, p = d->u.data; p; i++, p = p->next); fprintf(fp, ": leaf has %d objects.\n", i); } else { Discrim d1; fprintf(fp, "\n"); for (d1 = d->u.kids; d1 != NULL; d1 = d1->next) { if (d1->type == AC_ARG_TYPE || d1->type == AC_NV_ARG_TYPE) arity = 0; else if (DVAR(d1)) arity = 0; else arity = sn_to_arity(d1->symbol); print_discrim_wild_tree(fp, d1, n+arity-1, depth+1); } } } /* print_discrim_wild_tree */ /************* * * fprint_discrim_wild_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a wild discrimination index. */ /* PUBLIC */ void fprint_discrim_wild_index(FILE *fp, Discrim d) { print_discrim_wild_tree(fp, d, 1, 0); } /* fprint_discrim_wild_index */ /************* * * p_discrim_wild_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) a wild discrimination index. */ /* PUBLIC */ void p_discrim_wild_index(Discrim d) { fprint_discrim_wild_index(stdout, d); } /* p_discrim_wild_index */ /************* * * discrim_wild_insert_ac(t, d) * *************/ static Discrim discrim_wild_insert_ac(Term t, Discrim d) { int num_args, num_nv_args; Discrim d1, d2, dnew, prev; num_args = num_ac_args(t, SYMNUM(t)); for (d1 = d->u.kids, prev = NULL; d1 && d1->symbol < num_args; prev = d1, d1 = d1->next); if (d1 == NULL || d1->symbol != num_args) { dnew = get_discrim(); dnew->type = AC_ARG_TYPE; dnew->symbol = num_args; dnew->next = d1; if (prev != NULL) prev->next = dnew; else d->u.kids = dnew; d1 = dnew; } num_nv_args = num_ac_nv_args(t, SYMNUM(t)); for (d2 = d1->u.kids, prev = NULL; d2 && d2->symbol < num_nv_args; prev = d2, d2 = d2->next); if (!d2 || d2->symbol != num_nv_args) { dnew = get_discrim(); dnew->type = AC_NV_ARG_TYPE; dnew->symbol = num_nv_args; dnew->next = d2; if (prev != NULL) prev->next = dnew; else d1->u.kids = dnew; d2 = dnew; } return d2; } /* discrim_wild_insert_ac */ /************* * * Discrim discrim_wild_insert_rec(t, d) * *************/ static Discrim discrim_wild_insert_rec(Term t, Discrim d) { Discrim d1, prev, d2; int sym; if (VARIABLE(t)) { d1 = d->u.kids; if (d1 == NULL || !DVAR(d1)) { d2 = get_discrim(); d2->type = DVARIABLE; d2->symbol = 0; /* HERE */ d2->next = d1; d->u.kids = d2; return d2; } else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; prev = NULL; /* arities fixed: handle both NAME and COMPLEX */ sym = SYMNUM(t); if (d1 && DVAR(d1)) { /* skip variable */ prev = d1; d1 = d1->next; } while (d1 && d1->symbol < sym) { prev = d1; d1 = d1->next; } if (d1 == NULL || d1->symbol != sym) { d2 = get_discrim(); d2->type = DRIGID; d2->symbol = sym; d2->next = d1; d1 = d2; } else d2 = NULL; /* new node not required at this level */ if (is_assoc_comm(SYMNUM(t))) { d1 = discrim_wild_insert_ac(t, d1); } else { int i; for (i = 0; i < t->arity; i++) d1 = discrim_wild_insert_rec(t->args[i], d1); } if (d2 != NULL) { /* link in new subtree (possibly a leaf) */ if (prev == NULL) d->u.kids = d2; else prev->next = d2; } return d1; /* d1 is leaf corresp. to end of input term */ } } /* discrim_wild_insert_rec */ /************* * * discrim_wild_insert(t, root, object) * *************/ static void discrim_wild_insert(Term t, Discrim root, void *object) { Discrim d; Plist gp1, gp2; d = discrim_wild_insert_rec(t, root); gp1 = get_plist(); gp1->v = object; /* Install at end of list. */ if (d->u.data == NULL) d->u.data = gp1; else { for (gp2 = d->u.data; gp2->next; gp2 = gp2->next); gp2->next = gp1; } } /* discrim_wild_insert */ /************* * * Discrim discrim_wild_end(t, is, path_p) * * Given a discrimination tree (or a subtree) and a term, return the * node in the tree that corresponds to the last symbol in t (or NULL * if the node doesn't exist). *path_p is a list that is extended by * this routine. It is a list of pointers to the * nodes in path from the parent of the returned node up to imd. * (It is needed for deletions, because nodes do not have pointers to * parents.) * *************/ static Discrim discrim_wild_end(Term t, Discrim d, Plist *path_p) { Discrim d1; Plist p; int sym; /* add current node to the front of the path list. */ p = get_plist(); p->v = d; p->next = *path_p; *path_p = p; if (VARIABLE(t)) { d1 = d->u.kids; if (d1 && DVAR(d1)) return d1; else return NULL; } else { /* constant || complex */ d1 = d->u.kids; sym = SYMNUM(t); if (d1 && DVAR(d1)) /* skip variables */ d1 = d1->next; while (d1 && d1->symbol < sym) d1 = d1->next; if (d1 == NULL || d1->symbol != sym) return NULL; else if (is_assoc_comm(SYMNUM(t))) { int num_args, num_nv_args; Discrim d2, d3; num_args = num_ac_args(t, SYMNUM(t)); num_nv_args = num_ac_nv_args(t, SYMNUM(t)); for (d2 = d1->u.kids; d2 && d2->symbol != num_args; d2 = d2->next); if (d2 == NULL) return NULL; else { for (d3 = d2->u.kids; d3 && d3->symbol != num_nv_args; d3 = d3->next); if (d3 == NULL) return NULL; else { p = get_plist(); p->v = d1; p->next = *path_p; *path_p = p; p = get_plist(); p->v = d2; p->next = *path_p; *path_p = p; return d3; } } } else { int i; for (i = 0; d1 && i < t->arity; i++) d1 = discrim_wild_end(t->args[i], d1, path_p); return d1; } } } /* discrim_wild_end */ /************* * * discrim_wild_delete(t, root, object) * *************/ static void discrim_wild_delete(Term t, Discrim root, void *object) { Discrim end, i2, i3, parent; Plist tp1, tp2; Plist isp1, path; /* First find the correct leaf. path is used to help with */ /* freeing nodes, because nodes don't have parent pointers. */ path = NULL; end = discrim_wild_end(t, root, &path); if (end == NULL) { fatal_error("discrim_wild_delete, cannot find end."); } /* Free the pointer in the leaf-list */ tp1 = end->u.data; tp2 = NULL; while(tp1 && tp1->v != object) { tp2 = tp1; tp1 = tp1->next; } if (tp1 == NULL) { fatal_error("discrim_wild_delete, cannot find term."); } if (tp2 == NULL) end->u.data = tp1->next; else tp2->next = tp1->next; free_plist(tp1); if (!end->u.data) { /* free tree nodes from bottom up, using path to get parents */ end->u.kids = NULL; /* not really necessary */ isp1 = path; while (!end->u.kids && end != root) { parent = (Discrim) isp1->v; isp1 = isp1->next; i2 = parent->u.kids; i3 = NULL; while (i2 != end) { i3 = i2; i2 = i2->next; } if (i3 == NULL) parent->u.kids = i2->next; else i3->next = i2->next; free_discrim(i2); end = parent; } } /* free path list */ while (path) { isp1 = path; path = path->next; free_plist(isp1); } } /* discrim_wild_delete */ /************* * * discrim_wild_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a wild discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted. */ /* PUBLIC */ void discrim_wild_update(Term t, Discrim root, void *object, Indexop op) { if (op == INSERT) discrim_wild_insert(t, root, object); else discrim_wild_delete(t, root, object); } /* discrim_wild_update */ /************* * * discrim_wild_retrieve_leaf(t_in, root, ppos) * *************/ static Plist discrim_wild_retrieve_leaf(Term t_in, Discrim root, Flat *ppos) { Flat f, f1, f2; Flat f_save = NULL; Term t; Discrim d = NULL; int symbol, status; f = *ppos; /* Don't forget to reset before return. */ t = t_in; if (t != NULL) { /* if first call */ d = root->u.kids; if (d != NULL) { f = get_flat(); f->t = t; f->last = f; f->prev = NULL; f->next = NULL; f->place_holder = COMPLEX(t); status = GO; } else status = FAILURE; } else status = BACKTRACK; while (status == GO || status == BACKTRACK) { /* Three things determine the state at this point. * 1. d is the current node in the discrimination tree. * 2. f is the current node in the stack of flats. * 3. status is either GO or BACKTRACK. * * Commutative symbols: * This is more complicated than it needs to be, because * alternatives are handled awkwardly. * flip == 0 means that we haven't descended into the commutative term. * flip == 1 means that we are in the unflipped commutative term, and * flip == 2 means that we are in the flipped commutative term. */ if (status == BACKTRACK) { #if 0 printf("backtracking\n"); #endif /* Back up to a place with an aternate branch. */ while (f != NULL && f->alternatives == NULL) { if (f->commutative && f->flip == 2) { /* commutative with no alternative */ flip_flat(f); /* un-flip */ #if 0 printf("AFTER un-flip: "); p_flat(f); #endif f->flip = 0; } f_save = f; f = f->prev; } if (f != NULL) { #if 0 printf("alternative: (%x)\n", (unsigned) f->alternatives); #endif if (f->commutative && f->flip == 1) { flip_flat(f); /* flip */ #if 0 printf("AFTER flip: "); p_flat(f); #endif f->flip = 2; } d = f->alternatives; f->alternatives = NULL; status = GO; } else { /* Free stack of flats and fail. */ while (f_save != NULL) { f1 = f_save; f_save = f_save->next; free_flat(f1); } status = FAILURE; } } /* backtrack */ if (status == GO) { #if 0 printf("go with (%x) %s\n", (unsigned) d, DVAR(d) ? "*" : sn_to_str(d->symbol)); #endif if (d && d->type == AC_ARG_TYPE) { if (d->symbol <= f->num_ac_args) f->alternatives = d->next; else status = BACKTRACK; } else if (d && d->type == AC_NV_ARG_TYPE) { if (d->symbol <= f->num_ac_nv_args) f->alternatives = d->next; else status = BACKTRACK; } else if (d && DVAR(d)) { /* push alternatives */ f->alternatives = d->next; f = f->last; } else if (VARIABLE(f->t)) status = BACKTRACK; else { symbol = SYMNUM(f->t); while (d && d->symbol < symbol) d = d->next; if (!d || d->symbol != symbol) status = BACKTRACK; else { if (f->place_holder) { /* Insert skeleton in place_holder. This is tricky, because * someone's "last" pointer may be pointing to f. Therefore, * f becomes the last argument of the skeleton. */ if (is_assoc_comm(SYMNUM(f->t))) { /* AC case */ f1 = get_flat(); f1->t = f->t; f1->prev = f->prev; f1->last = f; if (f1->prev) f1->prev->next = f1; f2 = get_flat(); f2->prev = f1; f2->last = f2; f2->next = f; f->prev = f2; f1->next = f2; f->last = f; /* Now, f2 is the AC_ARGS node, and f is the AC_NV_ARGS node. */ f2->num_ac_args = num_ac_args(f1->t, SYMNUM(f1->t)); f->num_ac_nv_args = num_ac_nv_args(f1->t, SYMNUM(f1->t)); f = f1; } else { /* non AC case */ int i; f1 = get_flat(); f1->t = f->t; f1->prev = f->prev; f1->last = f; f_save = f1; if (f1->prev) f1->prev->next = f1; t = f->t; for (i = 0; i < t->arity; i++) { if (i < t->arity-1) f2 = get_flat(); else f2 = f; f2->place_holder = COMPLEX(t->args[i]); f2->t = t->args[i]; f2->last = f2; f2->prev = f1; f1->next = f2; f1 = f2; } f = f_save; if (is_commutative(SYMNUM(f->t)) && !term_ident(f->t->args[0], f->t->args[1])) f->commutative = 1; } /* non-AC */ } /* if f->place_holder */ if (f->commutative && f->flip == 0) { f->alternatives = d; f->flip = 1; } } /* rigid symbols match */ } /* non-variable */ if (status == GO) { if (f->next) { f = f->next; d = d->u.kids; } else status = SUCCESS; } /* if go */ } /* if go */ } /* while go or backtrack */ if (status == SUCCESS) { *ppos = f; return d->u.data; } else return NULL; } /* discrim_wild_retrieve_leaf */ /************* * * discrim_wild_retrieve_first(t, root, ppos) * * Get the first object associated with a term more general than t. * * Remember to call discrim_wild_cancel(pos) if you don't * want the whole sequence. * *************/ /* DOCUMENTATION This routine, along with discrim_wild_retrieve_next(), gets answers from a wild discrimination index. This routine retrieves the first object associated with a term more general than Term t. (NULL is returned if there is none.)

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_wild_cancel() to clear the substitution and free memory associated with the Discrim_pos. */ /* PUBLIC */ void *discrim_wild_retrieve_first(Term t, Discrim root, Discrim_pos *ppos) { Plist tp; Flat f; Discrim_pos gp; tp = discrim_wild_retrieve_leaf(t, root, &f); if (tp == NULL) return NULL; else { gp = get_discrim_pos(); gp->f = f; gp->data = tp; *ppos = gp; return tp->v; } } /* discrim_wild_retrieve_first */ /************* * * discrim_wild_retrieve_next(pos) * * Get the next object associated with a term more general than t. * * Remember to call discrim_wild_cancel(pos) if you don't * want the whole sequence. * *************/ /* DOCUMENTATION This routine retrieves the next object in the sequence of answers to a query of a wild discrimination tree. See discrim_wild_retrieve_first(). */ /* PUBLIC */ void *discrim_wild_retrieve_next(Discrim_pos pos) { Plist tp; tp = pos->data->next; if (tp != NULL) { /* if any more terms in current leaf */ pos->data = tp; return tp->v; } else { /* try for another leaf */ tp = discrim_wild_retrieve_leaf((Term) NULL, (Discrim) NULL, &(pos->f)); if (tp != NULL) { pos->data = tp; return tp->v; } else { free_discrim_pos(pos); return NULL; } } } /* discrim_wild_retrieve_next */ /************* * * discrim_wild_cancel(pos) * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all answers to a wild discrimintaion query. The memory associated the retrieval state is freed. */ /* PUBLIC */ void discrim_wild_cancel(Discrim_pos pos) { Flat f1, f2; f1 = pos->f; while (f1) { f2 = f1; f1 = f1->prev; free_flat(f2); } free_discrim_pos(pos); } /* discrim_wild_cancel */ /************* * * zap_discrim_tree() * *************/ static void zap_discrim_tree(Discrim d, int n) { if (n == 0) { zap_plist(d->u.data); } else { int arity; Discrim k, prev; k = d->u.kids; while (k != NULL) { if (k->type == AC_ARG_TYPE || k->type == AC_NV_ARG_TYPE) arity = 0; else if (DVAR(k)) arity = 0; else arity = sn_to_arity(k->symbol); prev = k; k = k->next; zap_discrim_tree(prev, n+arity-1); } } free_discrim(d); } /* zap_discrim_tree */ /************* * * destroy_discrim_tree() * *************/ /* DOCUMENTATION This routine frees all the memory associated with a discrimination index. It can be used with either wild or tame trees. */ /* PUBLIC */ void destroy_discrim_tree(Discrim d) { zap_discrim_tree(d, 1); } /* destroy_discrim_tree */ /************* * * discrim_empty() * *************/ /* DOCUMENTATION This Boolean function checks if a discrimination index is empty. It can be used with either wild or tame trees. */ /* PUBLIC */ BOOL discrim_empty(Discrim d) { return (d == NULL ? TRUE : (d->u.kids == NULL ? TRUE : FALSE)); } /* discrim_empty */ LADR-2009-11A/ladr/save/clist.c0000644000175000017500000003373310140052517015164 0ustar mccunemccune#include "clist.h" /* Private definitions and types */ /* * memory management */ static unsigned Clist_pos_gets, Clist_pos_frees; static unsigned Clist_gets, Clist_frees; #define BYTES_CLIST_POS sizeof(struct clist_pos) #define PTRS_CLIST_POS BYTES_CLIST_POS%BPP == 0 ? BYTES_CLIST_POS/BPP : BYTES_CLIST_POS/BPP + 1 #define BYTES_CLIST sizeof(struct clist) #define PTRS_CLIST BYTES_CLIST%BPP == 0 ? BYTES_CLIST/BPP : BYTES_CLIST/BPP + 1 /************* * * Clist_pos get_clist_pos() * *************/ static Clist_pos get_clist_pos(void) { Clist_pos p = get_mem(PTRS_CLIST_POS); Clist_pos_gets++; return(p); } /* get_clist_pos */ /************* * * free_clist_pos() * *************/ static void free_clist_pos(Clist_pos p) { free_mem(p, PTRS_CLIST_POS); Clist_pos_frees++; } /* free_clist_pos */ /************* * * Clist get_clist() * *************/ static Clist get_clist(void) { Clist p = get_mem(PTRS_CLIST); Clist_gets++; return(p); } /* get_clist */ /************* * * free_clist() * *************/ static void free_clist(Clist p) { free_mem(p, PTRS_CLIST); Clist_frees++; } /* free_clist */ /************* * * fprint_clist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_clist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_CLIST_POS; fprintf(fp, "clist_pos (%4d) %11u%11u%11u%9.1f K\n", n, Clist_pos_gets, Clist_pos_frees, Clist_pos_gets - Clist_pos_frees, ((Clist_pos_gets - Clist_pos_frees) * n) / 1024.); n = BYTES_CLIST; fprintf(fp, "clist (%4d) %11u%11u%11u%9.1f K\n", n, Clist_gets, Clist_frees, Clist_gets - Clist_frees, ((Clist_gets - Clist_frees) * n) / 1024.); } /* fprint_clist_mem */ /************* * * p_clist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clist package. */ /* PUBLIC */ void p_clist_mem() { fprint_clist_mem(stdout, TRUE); } /* p_clist_mem */ /* * end of memory management */ /************* * * clist_init() * *************/ /* DOCUMENTATION This routine allocates and returns an empty Clist, which is a doubly-linked list of pointers to clauses. You give it a string (any length, which is copied), representing the name of the list. If don't wish to name the list, send NULL. (You can name the list later with name_clist().) */ /* PUBLIC */ Clist clist_init(char *name) { Clist p = get_clist(); if (name == NULL) p->name = NULL; else p->name = new_str_copy(name); return p; } /* clist_init */ /************* * * name_clist() * *************/ /* DOCUMENTATION This routine names or renames a Clist. The string you supply can be any length and is copied. */ /* PUBLIC */ void name_clist(Clist p, char *name) { if (p->name != NULL) free(p->name); if (name == NULL) p->name = NULL; else p->name = new_str_copy(name); } /* name_clist */ /************* * * clist_free() * *************/ /* DOCUMENTATION This routine frees an empty Clist. If the Clist is not empty, nothing happens. */ /* PUBLIC */ void clist_free(Clist p) { if (p->first == NULL) { if (p->name != NULL) { free(p->name); p->name = NULL; } free_clist(p); } } /* clist_free */ /************* * * clist_append() * *************/ /* DOCUMENTATION This routine appends a Clause to a Clist. */ /* PUBLIC */ void clist_append(Clause c, Clist l) { Clist_pos p; p = get_clist_pos(); p->list = l; p->c = c; p->nocc = c->containers; c->containers = p; p->next = NULL; p->prev = l->last; l->last = p; if (p->prev) p->prev->next = p; else l->first = p; l->length++; } /* clist_append */ /************* * * clist_prepend() * *************/ /* DOCUMENTATION This routine inserts a Clause as the first member of a Clist. */ /* PUBLIC */ void clist_prepend(Clause c, Clist l) { Clist_pos p; p = get_clist_pos(); p->list = l; p->c = c; p->nocc = c->containers; c->containers = p; p->prev = NULL; p->next = l->first; l->first = p; if (p->next) p->next->prev = p; else l->last = p; l->length++; } /* clist_prepend */ /************* * * clist_insert_before() * *************/ /* DOCUMENTATION This routine inserts a Clause before a given position in a Clist. */ /* PUBLIC */ void clist_insert_before(Clause c, Clist_pos pos) { Clist_pos p; p = get_clist_pos(); p->list = pos->list; p->c = c; p->nocc = c->containers; c->containers = p; p->next = pos; p->prev = pos->prev; pos->prev = p; if (p->prev) p->prev->next = p; else pos->list->first = p; pos->list->length++; } /* clist_insert_before */ /************* * * clist_insert_after() * *************/ /* DOCUMENTATION This routine inserts a Clause after a given position in a Clist. */ /* PUBLIC */ void clist_insert_after(Clause c, Clist_pos pos) { Clist_pos p; p = get_clist_pos(); p->list = pos->list; p->c = c; p->nocc = c->containers; c->containers = p; p->prev = pos; p->next = pos->next; pos->next = p; if (p->next) p->next->prev = p; else pos->list->last = p; pos->list->length++; } /* clist_insert_after */ /************* * * clist_remove() * *************/ /* DOCUMENTATION This routine removes a clause from a Clist. If the Clause occurs more than once in the Clist, the most recently inserted occurrence is removed. A fatal error occurs if the Clause is not in the Clist. */ /* PUBLIC */ void clist_remove(Clause c, Clist l) { Clist_pos p, prev; /* Find position from containment list of clause. */ for (p = c->containers, prev = NULL; p && p->list != l; prev = p, p = p->nocc); if (!p) fatal_error("clist_remove: clause not in list"); /* First update normal links. */ if (p->prev) p->prev->next = p->next; else p->list->first = p->next; if (p->next) p->next->prev = p->prev; else p->list->last = p->prev; /* Now update containment links. */ if (prev) prev->nocc = p->nocc; else c->containers = p->nocc; free_clist_pos(p); l->length--; } /* clist_remove */ /************* * * clist_remove_all_clauses() * *************/ /* DOCUMENTATION This routine removes all clauses from a clist. The clauses are NOT deleted, even if they occur nowhere else. */ /* PUBLIC */ void clist_remove_all_clauses(Clist l) { while (l->first) { clist_remove(l->first->c, l); } } /* clist_remove_all_clauses */ /************* * * clist_remove_all() * *************/ /* DOCUMENTATION This routine removes a clause from all lists in which it occurs. The number of lists from which it was removed is returned. */ /* PUBLIC */ int clist_remove_all(Clause c) { int i = 0; while (c->containers) { clist_remove(c, c->containers->list); i++; } return i; } /* clist_remove_all */ /************* * * clist_member() * *************/ /* DOCUMENTATION This Boolean routine checks if a Clause is a member of a Clist. */ /* PUBLIC */ int clist_member(Clause c, Clist l) { Clist_pos p; for (p = c->containers; p; p = p->nocc) { if (p->list == l) return TRUE; } return FALSE; } /* clist_member */ /************* * * fprint_clist() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) each clause in a Clist. If the Clist has a non-empty name, say "usable", the string "list(usable).\n" is printed first. The string "end_of_list.\n" is always printed at the end. */ /* PUBLIC */ void fprint_clist(FILE *fp, Clist l) { Clist_pos p; if (l->name != NULL) fprintf(fp, "list(%s).\n", l->name); for(p = l->first; p; p = p->next) fprint_clause(fp, p->c); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fprint_clist */ /************* * * p_clist() * *************/ /* DOCUMENTATION This routine prints (to stdout) each clause in a Clist. See fprint_clist(). */ /* PUBLIC */ void p_clist(Clist l) { fprint_clist(stdout, l); } /* p_clist */ /************* * * clist_copy() * *************/ /* DOCUMENTATION Copy a clist of clauses. Justificatons and attributes are copied, and the clauses get new IDs. */ /* PUBLIC */ Clist clist_copy(Clist a, BOOL assign_ids) { Clist b = clist_init(a->name); Clist_pos p; for(p = a->first; p; p = p->next) { Clause c = copy_clause(p->c); c->justification = copy_justification(p->c->justification); c->attributes = copy_attributes(p->c->attributes); if (assign_ids) assign_clause_id(c); clist_append(c, b); } return b; } /* clist_copy */ /************* * * clist_assign_ids() * *************/ /* DOCUMENTATION Assign clause IDs to the members of a Clist. */ /* PUBLIC */ void clist_assign_ids(Clist a) { Clist_pos p; for(p = a->first; p; p = p->next) assign_clause_id(p->c); } /* clist_assign_ids */ /************* * * clist_zap() * *************/ /* DOCUMENTATION For each Clause (occurrence) in a Clist, remove it, and if it occurs in no other Clist, call zap_clause() to delete the Clause. Then, free the Clist. */ /* PUBLIC */ void clist_zap(Clist l) { Clist_pos p; Clause c; p = l->first; while (p) { c = p->c; p = p->next; clist_remove(c, l); if (c->containers == NULL) zap_clause(c); } clist_free(l); } /* clist_zap */ /************* * * clist_check() * *************/ /* DOCUMENTATION This routine checks the integrity of a Clist. If any errors are found, a message is sent to stdout. This is used for debugging. */ /* PUBLIC */ void clist_check(Clist l) { Clist_pos p; int n = 0; for (p = l->first; p; p = p->next) { n++; if (p->list != l) printf("clist_check error0\n"); if (p->next) { if (p->next->prev != p) printf("clist_check error1\n"); } else if (p != l->last) printf("clist_check error2\n"); if (p->prev) { if (p->prev->next != p) printf("clist_check error3\n"); } else if (p != l->first) printf("clist_check error4\n"); } if (l->length != n) printf("clist_check error5\n"); } /* clist_check */ /************* * * clist_append_all() * *************/ /* DOCUMENTATION Append each member of l2 to l1, then zap l2. Do not refer to l2 after the call. */ /* PUBLIC */ void clist_append_all(Clist l1, Clist l2) { Clist_pos p; for (p = l2->first; p != NULL; p = p->next) clist_append(p->c, l1); clist_zap(l2); /* This doesn't zap clauses, because they now occur in l1. */ } /* clist_append_all */ /************* * * clist_empty() * *************/ /* DOCUMENTATION This function checks if a (non-NULL) Clist is empty. */ /* PUBLIC */ BOOL clist_empty(Clist lst) { return lst->first == NULL; } /* clist_empty */ /************* * * clist_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clist_length(Clist l) { return l->length; } /* clist_length */ /************* * * max_wt_in_clist() * *************/ /* DOCUMENTATION Scan a Clist, and return the maximum clause weight seen. */ /* PUBLIC */ int max_wt_in_clist(Clist l) { int max = INT_MIN; Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (p->c->weight > max) max = p->c->weight; return max; } /* max_wt_in_clist */ /************* * * horn_clist() * *************/ /* DOCUMENTATION Is every clause in the list a Horn clause? */ /* PUBLIC */ BOOL horn_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (!horn_clause(p->c)) return FALSE; return TRUE; } /* horn_clist */ /************* * * unit_clist() * *************/ /* DOCUMENTATION Is every clause in the list a unit clause? */ /* PUBLIC */ BOOL unit_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (!unit_clause(p->c)) return FALSE; return TRUE; } /* unit_clist */ /************* * * equality_in_clist() * *************/ /* DOCUMENTATION Does the list contain a clause with a positive equality literal? */ /* PUBLIC */ BOOL equality_in_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (contains_pos_eq(p->c)) return TRUE; return FALSE; } /* equality_in_clist */ /************* * * neg_nonunit_in_clist() * *************/ /* DOCUMENTATION Does the list contain a negative nonunit clause ? */ /* PUBLIC */ BOOL neg_nonunit_in_clist(Clist l) { Clist_pos p; for (p = l->first; p != NULL; p = p->next) if (negative_clause(p->c) && number_of_literals(p->c) > 1) return TRUE; return FALSE; } /* neg_nonunit_in_clist */ /************* * * clauses_in_clist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist clauses_in_clist(Plist p, Clist l) { Plist q; Plist result = NULL; for (q = p; q; q = q->next) { Clause c = q->v; if (clist_member(c, l)) result = plist_append(result, c); } return result; } /* clauses_in_clist */ /************* * * clist_swap() * *************/ /* DOCUMENTATION Every clause occurs in a set (maybe empty) of Clists. Given clauses A and B, this routine puts A into the lists in which B occurs and vice versa. */ /* PUBLIC */ void clist_swap(Clause a, Clause b) { Clist_pos p; /* Replace refs to a with refs to b. */ for (p = a->containers; p; p = p->nocc) p->c = b; /* Replace refs to b with refs to a. */ for (p = b->containers; p; p = p->nocc) p->c = a; /* Swap the containment lists. */ p = a->containers; a->containers = b->containers; b->containers = p; } /* clist_swap */ /************* * * clist_move_clauses() * *************/ /* DOCUMENTATION Move all clauses from a to the end of b. */ /* PUBLIC */ void clist_move_clauses(Clist a, Clist b) { while (a->first) { Clause c = a->first->c; clist_remove(c, a); clist_append(c, b); } } /* clist_move_clauses */ LADR-2009-11A/ladr/save/weight1.c0000644000175000017500000000437010147175222015417 0ustar mccunemccune#include "weight1.h" /* Private definitions and types */ static int Number_of_weights; static int *Weights; /* This maps symbol numbers to weights. */ static int Variable_weight = 1; static int Not_symnum; /* Cache the negation symbol: it's needed often. */ static int Or_symnum; /* Cache the disjunction symbol: it's needed often. */ /************* * * set_weights_by_arity() * *************/ static void set_weights_by_arity(int arity, int weight) { int i; for (i = 0; i < Number_of_weights; i++) { /* It's OK if symbol i doesn't exist: sn_to_arity will return -1. */ if (sn_to_arity(i) == arity) Weights[i] = weight; } } /* set_weights_by_arity */ /************* * * init_weight1() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_weight1(Plist p, int constant_weight, int variable_weight) { Plist q; int i; Number_of_weights = greatest_symnum() + 1; Weights = malloc(Number_of_weights * sizeof(int)); /* Allocate an array */ for (i = 0; i < Number_of_weights; i++) Weights[i] = 1; /* default weight of each symbol is 1 */ for (q = p; q; q = q->next) { Term t = q->v; int w; if (!is_term(t, "weight", 2) || !term_to_int(ARG(t,1), &w)) fatal_error("init_weight1, bad weight template"); else { Weights[SYMNUM(ARG(t,0))] = w; } } Not_symnum = str_to_sn(NOT_SYM, 1); /* Cache the symnum for neg literals. */ Or_symnum = str_to_sn(OR_SYM, 2); /* Cache the symnum for OR. */ Variable_weight = variable_weight; set_weights_by_arity(0, constant_weight); } /* init_weight1 */ /************* * * term_weight1() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int term_weight1(Term t) { if (VARIABLE(t)) return Variable_weight; else { int w = Weights[SYMNUM(t)]; int i; for (i = 0; i < ARITY(t); i++) w += term_weight1(ARG(t,i)); return w; } } /* term_weight1 */ /************* * * clause_weight1() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clause_weight1(Clause c) { Literal l; int w = 0; for (l = c->literals; l; l = l->next) { if (l->sign == FALSE) w += Weights[Not_symnum]; w += term_weight1(l->atom); if (l->next) w += Weights[Or_symnum]; } return w; } /* clause_weight1 */ LADR-2009-11A/ladr/save/btm.c0000644000175000017500000007634310140053230014625 0ustar mccunemccune#include "btm.h" /* Private definitions and types */ typedef struct ac_match_pos * Ac_match_pos; typedef struct ac_match_free_vars_pos * Ac_match_free_vars_pos; struct btm_state { Btm_state parent, next, prev, first_child, last_child; Term t1, t2; /* terms being matched */ Context c1; /* context for variables of t1*/ int varnum; /* for unbinding when backtracking */ Context cb; /* for unbinding when backtracking */ Unif_alternative alternative; /* type of alternative (position) */ /* for commutative unification */ int flipped; Btm_state position_bt; /* in sequence of alternatives */ /* for AC matching */ Ac_match_pos acm; /* in sequence of AC matchers */ int partial; /* partial match for this pair */ }; struct ac_match_pos { Term t1, t2; /* t1 is pattern, t2 is subject */ Context c1; /* context for variables in t1 */ int n1; /* number of arguments in t1 */ int n2; /* size of set of set of args in t2 */ Term args1[MAX_ACM_ARGS], args2[MAX_ACM_ARGS]; /* the arguments */ /* position in sequence of matches for complex args of args2 */ Btm_state bt1[MAX_ACM_ARGS]; /* flags indicating which of args1 have been matched */ int match1[MAX_ACM_ARGS]; /* integer indicating how many of each of args2 have been matched */ int match2[MAX_ACM_ARGS]; int mults2[MAX_ACM_ARGS]; /* multiplicities for args2 */ /* indicates which of args2 are matched by bound vars in args1 */ int bound_matches[MAX_ACM_ARGS], bound_count; int last_a1_symbol; /* position of last non-variable arg in args1 */ /* list of backtrack positions for free variables of args1 */ Ac_match_free_vars_pos free_first, free_last; /* # args of unmatched term---used for partial match */ int partial_term_size; Ac_match_pos next; /* for avail list only */ }; struct ac_match_free_vars_pos { int varnum; /* the index of the free variable */ int coef; /* # of occurrences of the var in args1 */ int targets[MAX_ACM_ARGS]; /* terms in args2 that can go with variable */ int n; /* number of tragets*/ int combo[MAX_ACM_ARGS]; /* current subset of the targets */ Ac_match_free_vars_pos prev, next; }; /* #define DEBUG */ #define POP 1 #define BACKTRACK 2 #define GO 3 #define SUCCESS 4 #define FAILURE 5 /* Bind a variable, record binding in a bt_node. */ #define BIND_BT(i, c1, t2, c2, bt) { \ c1->terms[i] = t2; c1->contexts[i] = c2; \ bt->varnum = i; bt->cb = c1; } /* The following declaration is due to mutual recursion with match_bt_guts. */ static int match_commute(Term t1, Context c1, Term t2, Btm_state bt); /* * memory management */ static unsigned Ac_match_pos_gets, Ac_match_pos_frees; static unsigned Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees; static unsigned Btm_state_gets, Btm_state_frees; #define BYTES_AC_MATCH_POS sizeof(struct ac_match_pos) #define PTRS_AC_MATCH_POS BYTES_AC_MATCH_POS%BPP == 0 ? BYTES_AC_MATCH_POS/BPP : BYTES_AC_MATCH_POS/BPP + 1 #define BYTES_AC_MATCH_FREE_VARS_POS sizeof(struct ac_match_free_vars_pos) #define PTRS_AC_MATCH_FREE_VARS_POS BYTES_AC_MATCH_FREE_VARS_POS%BPP == 0 ? BYTES_AC_MATCH_FREE_VARS_POS/BPP : BYTES_AC_MATCH_FREE_VARS_POS/BPP + 1 #define BYTES_BTM_STATE sizeof(struct btm_state) #define PTRS_BTM_STATE BYTES_BTM_STATE%BPP == 0 ? BYTES_BTM_STATE/BPP : BYTES_BTM_STATE/BPP + 1 /************* * * Ac_match_pos get_ac_match_pos() * *************/ static Ac_match_pos get_ac_match_pos(void) { Ac_match_pos p = get_mem(PTRS_AC_MATCH_POS); Ac_match_pos_gets++; return(p); } /* get_ac_match_pos */ /************* * * free_ac_match_pos() * *************/ static void free_ac_match_pos(Ac_match_pos p) { free_mem(p, PTRS_AC_MATCH_POS); Ac_match_pos_frees++; } /* free_ac_match_pos */ /************* * * Ac_match_free_vars_pos get_ac_match_free_vars_pos() * *************/ static Ac_match_free_vars_pos get_ac_match_free_vars_pos(void) { Ac_match_free_vars_pos p = get_mem(PTRS_AC_MATCH_FREE_VARS_POS); Ac_match_free_vars_pos_gets++; return(p); } /* get_ac_match_free_vars_pos */ /************* * * free_ac_match_free_vars_pos() * *************/ static void free_ac_match_free_vars_pos(Ac_match_free_vars_pos p) { free_mem(p, PTRS_AC_MATCH_FREE_VARS_POS); Ac_match_free_vars_pos_frees++; } /* free_ac_match_free_vars_pos */ /************* * * Btm_state get_btm_state() * *************/ static Btm_state get_btm_state(void) { Btm_state p = get_mem(PTRS_BTM_STATE); p->varnum = -1; p->alternative = NO_ALT; Btm_state_gets++; return(p); } /* get_btm_state */ /************* * * free_btm_state() * *************/ static void free_btm_state(Btm_state p) { free_mem(p, PTRS_BTM_STATE); Btm_state_frees++; } /* free_btm_state */ /************* * * fprint_btm_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the btm package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_btm_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_AC_MATCH_POS; fprintf(fp, "ac_match_pos (%4d)%11u%11u%11u%9.1f K\n", n, Ac_match_pos_gets, Ac_match_pos_frees, Ac_match_pos_gets - Ac_match_pos_frees, ((Ac_match_pos_gets - Ac_match_pos_frees) * n) / 1024.); n = BYTES_AC_MATCH_FREE_VARS_POS; fprintf(fp, "ac_match_free_vars_pos (%4d)\n %11u%11u%11u%9.1f K\n", n, Ac_match_free_vars_pos_gets, Ac_match_free_vars_pos_frees, Ac_match_free_vars_pos_gets - Ac_match_free_vars_pos_frees, ((Ac_match_free_vars_pos_gets - Ac_match_free_vars_pos_frees) * n) / 1024.); n = BYTES_BTM_STATE; fprintf(fp, "btm_state (%4d) %11u%11u%11u%9.1f K\n", n, Btm_state_gets, Btm_state_frees, Btm_state_gets - Btm_state_frees, ((Btm_state_gets - Btm_state_frees) * n) / 1024.); } /* fprint_btm_mem */ /************* * * p_btm_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the btm package. */ /* PUBLIC */ void p_btm_mem() { fprint_btm_mem(stdout, TRUE); } /* p_btm_mem */ /* * end of memory management */ /************* * * flatten_mult * * Flatten an AC term into an array, collapsing multiple occurrences * into one, filling in a parallel array with multiplicities. * Also return a count of the total number of arguments. * * The index (*ip) must be initialized by the calling routine. * *************/ static void flatten_mult(Term t, Term *a, int *m, int *ip, int *totp, int (*comp_proc) (void *, void *)) { Term t1; int sn, i; sn = SYMNUM(t); for (i = 0; i < ARITY(t); i++) { t1 = t->args[i]; if (SYMNUM(t1) == sn) flatten_mult(t1, a, m, ip, totp, comp_proc); else { (*totp)++; if (*ip > 0 && (*comp_proc)(t1, a[(*ip)-1]) == SAME_AS) m[(*ip)-1]++; else { if (*ip >= MAX_ACM_ARGS) { fprint_term(stdout, t); fatal_error("flatten_mult, too many arguments."); } a[*ip] = t1; m[*ip] = 1; (*ip)++; } } } } /* flatten_mult */ /************* * * macbv_rec -- match (identically) all args of an AC term. * * Called by match_ac_bound_vars. * *************/ static int macbv_rec(int ac_sn, Term t, Term *args2, int *mults2, int *match2, int n2, int *bound_matches, int *bp) { int i, available; if (!COMPLEX(t) || SYMNUM(t) != ac_sn) { for (i = 0; i < n2; i++) { available = mults2[i] - match2[i]; if (available > 0 && term_ident(t, args2[i])) { match2[i]++; bound_matches[(*bp)++] = i; return(1); } } return(0); } else { if (!macbv_rec(ac_sn,t->args[0],args2,mults2,match2,n2, bound_matches,bp)) return(0); else return(macbv_rec(ac_sn,t->args[1],args2,mults2,match2,n2, bound_matches,bp)); } } /* macbv_rec */ /************* * * match_ac_bound_vars -- match (identically) a set of bound variables. * * For each bound variable of args1, find an identical match in args2. * If bound to an AC term t, (with same AC symbol) find an identical * match for each argument of t. Record the positions of the matched * terms in `bound_matches', so that they can be unmached on backtracking. * *************/ static int match_ac_bound_vars(int ac_sn, Term *args1, int n1, Term *args2, int *mults2, int *match2, int n2, int begin, int *bound_matches, int *bp, Context c1) { int i, ok, vn; Term t; for (i=begin, ok=1, *bp=0; i < n1 && ok; i++) { vn = VARNUM(args1[i]); t = c1->terms[vn]; if (t) ok = macbv_rec(ac_sn,t,args2,mults2,match2,n2,bound_matches,bp); } if (!ok) { /* Subtract any matches that were made before failure. */ for (i = 0; i < *bp; i++) match2[bound_matches[i]] -= 1; *bp = 0; /* Not really necessary, but helpful for debugging. */ } return(ok); } /* match_ac_bound_vars */ /************* * * set_up_free_vars * * Build a list of the set of free variables in args1. Each node * contains the number of occurrences (coef) of the variable. * Sort the list---nonincreasing coef. * * Variables are partitioned into `free' and `bound' according to * their state after all nonvariable terms have been matched. * A variable is called `bound' iff it occurs in a nonvariable term. * * Since the partition does not change during backtracking, this * routine needs to be called only once, after all nonvariable * terms have been matched for the first time. * *************/ static void set_up_free_vars(Ac_match_pos ac, Context c1) { Ac_match_free_vars_pos p1, p2; Term t; int i, temp; ac->free_first = NULL; ac->free_last = NULL; for (i = ac->last_a1_symbol+1; i < ac->n1; i++) { t = ac->args1[i]; if (c1->terms[VARNUM(t)] == NULL) { /* We have a free variable. */ for (p1=ac->free_first; p1 && p1->varnum!=VARNUM(t); p1=p1->next); if (p1 != NULL) (p1->coef)++; else { p1 = get_ac_match_free_vars_pos(); p1->varnum = VARNUM(t); p1->coef = 1; p1->next = NULL; p1->prev = ac->free_last; if (ac->free_last) ac->free_last->next = p1; else ac->free_first = p1; ac->free_last = p1; } } } /* Now sort -- nonincreasing coefficients. */ /* There won't be many, so use a quadratic sort. */ p1 = ac->free_first; if (p1) { while (p1->next) { for (p2 = p1->next; p2; p2 = p2->next) { if (p1->coef < p2->coef) { temp = p2->coef; p2->coef = p1->coef; p1->coef = temp; temp = p2->varnum; p2->varnum = p1->varnum; p1->varnum = temp; } } p1 = p1->next; } } } /* set_up_free_vars */ /************* * * unbind_free_var * * This routine takes an `ac match free variable position' and * unbinds the free variable. If the variable is bound to a * compound AC term that was created just for the binding, * then the new parts of the term are deleted. * *************/ static void unbind_free_var(Ac_match_free_vars_pos pos, Context c) { int i, j; Term t, t1; /* Free the temporary substitution term, if necessary. */ /* First count how many nodes have to be deleted. */ for (i = j = 0; i < pos->n; i++) if (pos->combo[i]) j++; t = c->terms[pos->varnum]; for (i = 0; i < j-1; i++) { t1 = t->args[1]; free_term(t); t = t1; } /* unbind variable */ c->terms[pos->varnum] = NULL; } /* unbind_free_var */ /************* * * free_var_match * * Find the first or next match for a free variable. If (match_all) * then all remaining arguments of args2 must be matched. * Otherwise, backtracking will produce matches in all combinations. * *************/ static int free_var_match(Ac_match_free_vars_pos pos, Term *args2, int *mults2, int *match2, int n2, Context c1, int symbol, int match_all) { Term t; int i, j, k, n, ok, go, avail; t = c1->terms[pos->varnum]; if (!t) { /* It is not a continuation, so set up everything. * * Loop through args2, collecting targets, combinations of which * can be substituted for the current variable. * Example: current variable is 2x; terms available for * matching are 4a, 3b, 2c, 1d; targets are a,a,b,c. */ n = 0; for (i = 0; i < n2; i++) { avail = mults2[i] - match2[i]; if (match_all && (avail % pos->coef != 0)) return 0; /* Fail, because there will be unmatched term(s) */ j = avail / pos->coef; /* integer division */ for (k = 0; k < j; k++) pos->targets[n++] = i; } pos->n = n; if (n == 0) return 0; else { for (i = 0; i < n; i++) pos->combo[i] = 1; } } else { /* continutation */ unbind_free_var(pos, c1); /* unmark args2 terms */ for (i = 0; i < pos->n; i++) if (pos->combo[i]) { match2[pos->targets[i]] -= pos->coef; } if (match_all) { for (i = 0; i < pos->n; i++) pos->combo[i] = 0; return 0; } else { go = 1; while (go) { /* subtract 1 from combo */ for (i = (pos->n)-1; i >= 0 && pos->combo[i] == 0; i--) pos->combo[i] = 1; if (i < 0) return(0); else { pos->combo[i] = 0; /* Check redundancy condition. */ for (i = 0, ok = 1; i < (pos->n)-1 && ok; i++) if (pos->targets[i] == pos->targets[i+1] && pos->combo[i] < pos->combo[i+1]) ok = 0; go = !ok; } } /* Now make sure that combo is not empty. */ for (i = 0, ok = 0; i < pos->n && !ok; i++) ok = pos->combo[i]; if (!ok) return 0; } } /* All is well---we have a match for the current variable. */ /* Build a temporary substitution term, if necessary. */ /* Note order in which it is built---this makes it AC canonical. */ t = NULL; for (i = pos->n-1; i >= 0; i--) if (pos->combo[i]) { if (t == NULL) t = args2[pos->targets[i]]; else t = build_binary_term(symbol, args2[pos->targets[i]], t); } /* Bind variable. */ c1->terms[pos->varnum] = t; /* Mark args2 terms matched to the current variable. */ for (i = 0; i < pos->n; i++) if (pos->combo[i]) match2[pos->targets[i]] += pos->coef; return 1; } /* free_var_match */ /************* * * build_partial_term * * When partial match has been found, this routine collects the * unmatched arguments of args2 and builds and returns an AC term. * The size of the new term is stored in the AC position so that * it can easily be freed. * *************/ static Term build_partial_term(Ac_match_pos ac) { int i, j, k, n; Term t; t = NULL; k = 0; for (i = 0; i < ac->n2; i++) { n = ac->mults2[i] - ac->match2[i]; for (j = 0; j < n; j++) { k++; if (!t) t = ac->args2[i]; else t = build_binary_term(SYMNUM(ac->t1), ac->args2[i], t); } } ac->partial_term_size = k; return t; } /* build_partial_term */ /************* * * clear_partial_term * * Remove the partial term from the substitution and free the * appropriate parts fo the partial term. * *************/ static void clear_partial_term(Ac_match_pos ac) { int i; Term t, t1; t = ac->c1->partial_term; ac->c1->partial_term = NULL; for (i = 0; i < ac->partial_term_size - 1; i++) { t1 = t->args[1]; free_term(t); t = t1; } ac->partial_term_size = 0; } /* clear_partial_term */ #define GO_FUNCTORS 1 #define GO_BOUND_VARS 2 #define GO_FREE_VARS 3 #define SUCCESS 4 #define FAILURE 5 /************* * * match_ac -- associative-commutative matching. * * Get the first (bt->alternative == NO_ALT) or next AC matcher. * I intend for this to be called from `match_bt_guts'. * It assumed that the root symbols of the input terms are AC. * * Call match_ac_cancel(ac) if you quit before getting all matchers. * * t1 -- pattern term * c1 -- context (substitution table) for t1 * t2 -- subject term * bt -- backtrack position * *************/ static int match_ac(Term t1, Context c1, Term t2, Btm_state bt) { int status, n1, n2, total2, i, ok, a1_pos, a2_pos; int free_var_forward; Term a1, a2; Ac_match_pos ac; Ac_match_free_vars_pos free_pos, p1, p2; Btm_state bt1 = NULL; a1_pos = a2_pos = free_var_forward = 0; /* to quiet compiler */ free_pos = NULL; /* to quiet compiler */ if (bt->alternative == NO_ALT) { /* initialize, get first matcher */ ac = get_ac_match_pos(); bt->acm = ac; ac->t1 = t1; ac->t2 = t2; ac->c1 = c1; ac->free_first = NULL; ac->partial_term_size = 0; n1 = 0; n2 = 0; total2 = 0; flatten(t1, ac->args1, &n1); flatten_mult(t2, ac->args2, ac->mults2, &n2, &total2, (int (*)(void*,void*)) term_compare_ncv); if (n1 > total2) /* fail if t1 has more arguments */ status = FAILURE; else { /* Assume inputs are ac_canonical, so don't sort. */ /* Don't bother to eliminate common arguments, because */ /* It usually doesn't pay off. */ ac->n1 = n1; ac->n2 = n2; for (i = 0; i < n1; i++) ac->match1[i] = -1; for (i = 0; i < n2; i++) ac->match2[i] = 0; for (i = 0; i < n1 && !VARIABLE(ac->args1[i]); i++); ac->last_a1_symbol = i-1; a1_pos = 0; a2_pos = 0; bt1 = NULL; status = GO_FUNCTORS; } } else { /* continuation, get next matcher */ ac = bt->acm; if (bt->partial) { printf("WARNING: partial match_ac on continuation.\n"); if (c1->partial_term) clear_partial_term(ac); } n1 = ac->n1; n2 = ac->n2; if (n1 == 0 && n2 == 0) /* vacuous success last time */ status = FAILURE; else { free_pos = ac->free_last; free_var_forward = 0; status = GO_FREE_VARS; } } while (status != SUCCESS && status != FAILURE) { while (status == GO_FUNCTORS) { if (a1_pos > ac->last_a1_symbol) status = GO_BOUND_VARS; else if (a1_pos < 0) status = FAILURE; else { if (bt1) { /* remove arrow */ ac->match1[a1_pos] = -1; ac->bt1[a1_pos] = NULL; ac->match2[a2_pos]--; /* Try for another match with this pair. */ bt1 = match_bt_next(bt1); if (!bt1) a2_pos++; } if (!bt1) { /* Look for a match for a1, starting with a2. */ a1 = ac->args1[a1_pos]; while (bt1 == NULL && a2_pos < ac->n2) { a2 = ac->args2[a2_pos]; if (SYMNUM(a1) == SYMNUM(a2) && ac->match2[a2_pos] < ac->mults2[a2_pos]) bt1 = match_bt_first(a1, c1, a2, 0); if (bt1 == NULL) a2_pos++; } } if (bt1) { /* We have a match: a1->a2. */ /* draw arrow */ ac->match1[a1_pos] = a2_pos; ac->bt1[a1_pos] = bt1; ac->match2[a2_pos]++; a1_pos++; a2_pos = 0; bt1 = NULL; } else { /* back up */ a1_pos--; a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } } } /* while GO_FUNCTORS */ if (status == GO_BOUND_VARS) { /* Try to macth (identically) bound variables. */ ok = match_ac_bound_vars(SYMNUM(t1), ac->args1, n1, ac->args2, ac->mults2, ac->match2, n2, ac->last_a1_symbol+1, ac->bound_matches, &(ac->bound_count), c1); if (ok) { free_pos = ac->free_first; free_var_forward = 1; status = GO_FREE_VARS; } else { /* backup */ a1_pos = ac->last_a1_symbol; if (a1_pos >= 0) { a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } status = GO_FUNCTORS; } } else if (status == GO_FREE_VARS) { if (ac->free_first == NULL) { set_up_free_vars(ac, c1); free_pos = ac->free_first; } while (free_pos) { if (free_var_match(free_pos, ac->args2, ac->mults2, ac->match2, ac->n2, c1, SYMNUM(ac->t1), !bt->partial && free_pos->next == NULL)) { free_pos = free_pos->next; free_var_forward = 1; } else { free_pos = free_pos->prev; free_var_forward = 0; } } if (free_var_forward) { /* Check for non-matched a2 terms. */ for (i = 0, ok = 1; i < n2 && ok; i++) ok = ac->mults2[i] == ac->match2[i]; if (!ok) { /* Have at least 1 non-matched a2 term. */ if (bt->partial) { c1->partial_term = build_partial_term(ac); status = SUCCESS; } else status = GO_FUNCTORS; /* set up below */ } else status = SUCCESS; } else status = GO_FUNCTORS; if (status == GO_FUNCTORS) { /* Unmark bound variable matches. */ for (i = 0; i < ac->bound_count; i++) ac->match2[ac->bound_matches[i]] -= 1; a1_pos = ac->last_a1_symbol; if (a1_pos >= 0) { a2_pos = ac->match1[a1_pos]; bt1 = ac->bt1[a1_pos]; } } } /* if GO_FREE_VARS */ } /* while !SUCCESS && !FAILURE */ if (status == SUCCESS) bt->alternative = AC_ALT; else { /* free memory */ p1 = ac->free_first; while (p1) { p2 = p1; p1 = p1->next; free_ac_match_free_vars_pos(p2); } free_ac_match_pos(ac); bt->alternative = NO_ALT; } return(status == SUCCESS); } /* match_ac */ /************* * * match_ac_cancel * * Free an AC match position. This is to be used when you have obtained * one or more AC matchers by calling match_ac, but you do not wish * to backtrack to obtain additional AC matchers. Do not call this * routine if match_ac returned 0. * *************/ static void match_ac_cancel(Ac_match_pos ac) { Ac_match_free_vars_pos p1, p2; int i; for (i = 0; i <= ac->last_a1_symbol; i++) match_bt_cancel(ac->bt1[i]); p1 = ac->free_first; while (p1) { unbind_free_var(p1, ac->c1); p2 = p1; p1 = p1->next; free_ac_match_free_vars_pos(p2); } if (ac->partial_term_size > 0) clear_partial_term(ac); free_ac_match_pos(ac); } /* match_ac_cancel */ /************* * * Btm_state match_bt_backup(bt) * * Back up (freeing nodes) to the most recent node with an alternative. * *************/ static Btm_state match_bt_backup(Btm_state bt1) { Btm_state bt2, bt3; while (bt1 != NULL && bt1->alternative == NO_ALT) { if (bt1->cb) { /* unbind variable */ bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } if (bt1->prev) { bt1 = bt1->prev; while (bt1->last_child) bt1 = bt1->last_child; } else { bt2 = bt1; bt1 = bt1->parent; while (bt2) { bt3 = bt2; bt2 = bt2->next; free_btm_state(bt3); } if (bt1) bt1->first_child = bt1->last_child = NULL; } } return(bt1); } /* match_bt_backup */ /************* * * match_bt_guts * * Main loop for backtracking matching. * *************/ static Btm_state match_bt_guts(Btm_state bt1) { Term t1, t2; Context c1; int vn1, status; Btm_state bt2, bt3; status = GO; while (status == GO) { t1 = bt1->t1; t2 = bt1->t2; c1 = bt1->c1; if (bt1->alternative == COMM_ALT) { if (match_commute(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (bt1->alternative == AC_ALT) { if (match_ac(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (VARIABLE(t1)) { vn1 = VARNUM(t1); if (c1->terms[vn1]) { if (term_ident(c1->terms[vn1], t2)) status = POP; else status = BACKTRACK; } else { BIND_BT(vn1, c1, t2, NULL, bt1) status = POP; } } else if (VARIABLE(t2)) status = BACKTRACK; else if (SYMNUM(t1) != SYMNUM(t2)) status = BACKTRACK; else if (CONSTANT(t1)) status = POP; else { /* both COMPLEX with same symbol (and same arity) */ int arity = ARITY(t1); if (arity == 2 && is_commutative(SYMNUM(t1))) { if (match_commute(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else if (arity == 2 && is_assoc_comm(SYMNUM(t1))) { if (match_ac(t1, c1, t2, bt1)) status = POP; else status = BACKTRACK; } else { int i; /* Set up children corresponding to args of . */ /* Order not important for correctness. */ /* AC kids last for efficiency, but keep in order otherwise. */ bt3 = NULL; for (i = 0; i < arity; i++) { bt2 = get_btm_state(); bt2->t1 = t1->args[i]; bt2->t2 = t2->args[i]; bt2->c1 = c1; bt2->parent = bt1; if (is_assoc_comm(SYMNUM(bt2->t1))) { /* insert at end */ bt2->prev = bt1->last_child; if (bt1->last_child) bt1->last_child->next = bt2; else bt1->first_child = bt2; bt1->last_child = bt2; } else { if (bt3) { /* insert after bt3 */ bt2->next = bt3->next; bt2->prev = bt3; bt3->next = bt2; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; } else { /* insert at beginning */ bt2->next = bt1->first_child; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; bt1->first_child = bt2; } bt3 = bt2; } } bt1 = bt1->first_child; status = GO; } } if (status == POP) { while (!bt1->next && bt1->parent) bt1 = bt1->parent; if (!bt1->next) status = SUCCESS; else { bt1 = bt1->next; status = GO; } } else if (status == BACKTRACK) { bt1 = match_bt_backup(bt1); if (bt1) status = GO; else status = FAILURE; } } return(bt1); } /* match_bt_guts */ /************* * * match_commute() * * There is nothing fancy here. We simply try to unify both ways. * We can get redundant matches if both ways match, for example, * f(a,x) and f(a,a) match twice, both times with the same substitution. * *************/ static int match_commute(Term t1, Context c1, Term t2, Btm_state bt) { Btm_state bt1, bt2; if (bt->alternative == NO_ALT) { /* first call */ bt->alternative = COMM_ALT; bt->flipped = 0; /* Set up 2 subproblems, then match guts. */ bt1 = get_btm_state(); bt2 = get_btm_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt2->c1 = c1; bt1->t1 = t1->args[0]; bt1->t2 = t2->args[0]; bt2->t1 = t1->args[1]; bt2->t2 = t2->args[1]; bt->position_bt = match_bt_guts(bt1); } else /* continuation */ bt->position_bt = match_bt_next(bt->position_bt); if (!bt->position_bt && !bt->flipped) { /* Set up 2 subproblems, with t2 flipped, then match guts. */ bt1 = get_btm_state(); bt2 = get_btm_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt2->c1 = c1; bt1->t1=t1->args[0]; bt1->t2=t2->args[1]; bt2->t1=t1->args[1]; bt2->t2=t2->args[0]; bt->flipped = 1; bt->position_bt = match_bt_guts(bt1); } if (bt->position_bt) return(1); else { bt->alternative = NO_ALT; return(0); } } /* match_commute */ /************* * * p_acm -- print an ac match position. * *************/ static void p_acm(Ac_match_pos ac) { int i; Ac_match_free_vars_pos p; printf("Ac_match_pos %x.\n", (unsigned) ac); printf("t1: "); p_term(ac->t1); printf("t2: "); p_term(ac->t2); for (i = 0; i < ac->n1; i++) { fprint_term(stdout, ac->args1[i]); printf(" %d ",ac->match1[i]); } printf("\n"); for (i = 0; i < ac->n2; i++) { fprint_term(stdout, ac->args2[i]); printf(" <%d,%d> ",ac->mults2[i],ac->match2[i]); } printf("\n"); printf("last_a1_symbol=%d.\n",ac->last_a1_symbol); printf("free vars list :\n"); for (p = ac->free_first; p; p = p->next) { printf("<%d,%d>, ", p->varnum, p->coef); for (i = 0; i < p->n; i++) { fprint_term(stdout,ac->args2[p->targets[i]]); printf(":%d ",p->combo[i]); } printf("\n"); } printf("\n"); } /* p_acm */ /************* * * p_btm_state() * *************/ /* DOCUMENTATION This routine prints (to stdout) a Btm_state. It is not pretty. */ /* PUBLIC */ void p_btm_state(Btm_state bt) { printf("\nBtm node %x.\n", (unsigned) bt); printf("t1: "); p_term(bt->t1); printf("t2: "); p_term(bt->t2); printf("c1: "); p_context(bt->c1); printf("varnum: %d\n", bt->varnum); printf("cb: "); p_context(bt->c1); printf("alternative: %d\n", bt->alternative); printf("flipped: %d\n", bt->alternative); printf("position_bt: %x\n", (unsigned) bt->position_bt); printf("partial: %d\n", bt->partial); p_acm(bt->acm); } /* p_btm_state */ /************* * * match_bt_first * * *************/ /* DOCUMENTATION This is backtracking matching, to be used when there can be more than one unifier. This version handles (any number of) commutative (C) and associative-commutative (AC) function symbols.

The flag `partial' says that if the top level is AC, then not all arguments of t2 have to be matched. The non-matched args are put in c1->partial_term. Partial matches are allowed for the top level only. This is useful for AC rewriting.

If any AC terms are in t1 or t2, then both t1 and t2 should be in `ac_canonical()' form before the call, that is, AC terms are right associated and sorted. C terms are in t1 or t2 need not be c_canonical. (Commutatvie matching is primitive, and you can get duplicate unifiers.)

Get first matching substitution. Return position for match_bt_next() calls. Here is an example. Assume we have terms t1 and t2.

  {
    Context c1 = get_context();
    Btm_state bt = match_bt_first(t1, c1, t2, 0);
    while (bt != NULL) {
        Term t3 = apply(t1, c1);
        zap_term(t3);
        bt = match_bt_next(bt);
        }
    free_context(c1);
  }
If you quit before NULL is returned, call match_bt_cancel(bt) to clear substitutions and free memory. */ /* PUBLIC */ Btm_state match_bt_first(Term t1, Context c1, Term t2, int partial) { Btm_state bt; bt = get_btm_state(); bt->t1 = t1; bt->t2 = t2; bt->c1 = c1; bt->partial = partial; return(match_bt_guts(bt)); } /* match_bt */ /************* * * match_bt_next -- see match_bt_first * * Get next unifier. Return position for subsequent calls. * *************/ /* DOCUMENTATION This routine gets the next matching substitution. See match_bt_first() for details. */ /* PUBLIC */ Btm_state match_bt_next(Btm_state bt1) { /* Go to last node in tree, then back up to a node with an alternative. */ while (bt1->next) bt1 = bt1->next; while (bt1->last_child) bt1 = bt1->last_child; bt1 = match_bt_backup(bt1); if (bt1) return(match_bt_guts(bt1)); else return NULL; } /* match_bt_next */ /************* * * match_bt_cancel * * This routine should be called if the rest of a sequence of * unifiers is not called for. It clears substitutions and * frees memory. * *************/ /* DOCUMENTATION This routine clears any substitution and frees memory associated with a backtrack matching state. This should be called if you get some, but not all, matching substitutions in backtrack matching. See match_bt_first(). */ /* PUBLIC */ void match_bt_cancel(Btm_state bt) { Btm_state bt1, bt2; for (bt1 = bt; bt1 != NULL; ) { match_bt_cancel(bt1->first_child); if (bt1->alternative == COMM_ALT) /* match_bt_guts leaves us at the second child. */ match_bt_cancel(bt1->position_bt->prev); else if (bt1->alternative == AC_ALT) { match_ac_cancel(bt1->acm); } else if (bt1->cb) { bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } bt2 = bt1; bt1 = bt1->next; free_btm_state(bt2); } } /* match_bt_cancel */ LADR-2009-11A/ladr/save/detach.c0000644000175000017500000000402710147212340015267 0ustar mccunemccune#include "detach.h" /* Private definitions and types */ /************* * * detachable() * *************/ static BOOL detachable(Clause c) { return unit_clause(c) && positive_clause(c) && ARITY(c->literals->atom) == 1 && ARITY(ARG(c->literals->atom,0)) == 2; } /* detachable */ /************* * * detach() * *************/ static Clause detach(Clause c1, Clause c2) { /* Assume each is positive unit in unary relation with binary arg. * Condensed detach with major premise c1 and minor premise c2. */ Term major = ARG(c1->literals->atom,0); Term alpha = ARG(major,0); Term beta = ARG(major,1); Term minor = ARG(c2->literals->atom,0); Context s1 = get_context(); Context s2 = get_context(); Trail tr = NULL; Clause result; if (unify(alpha, s1, minor, s2, &tr)) { Term atom = get_rigid_term_like(c2->literals->atom); Literal lit = new_literal(1, atom); ARG(atom,0) = apply(beta, s1); result = get_clause(); append_literal(result, lit); result->justification = cd_just(c1, c2); inherit_attributes(c1, s1, c2, s2, result); undo_subst(tr); upward_clause_links(result); } else result = NULL; free_context(s1); free_context(s2); return result; } /* detach */ /************* * * cond_detach() * *************/ /* DOCUMENTATION Attempt a condensed detachment. */ /* PUBLIC */ void cond_detach(Clause major, Clause minor, void (*proc_proc) (Clause)) { /* First make sure that both are positive units of the form p(i(a,b)), * for any p, i, a, b. */ if (detachable(major) && detachable(minor)) { Clause cd = detach(major, minor); if (cd != NULL) (*proc_proc)(cd); } } /* cond_detach */ /************* * * cond_detach_2() * *************/ /* DOCUMENTATION Attempt two condensed detachments, with each clause as major premise. */ /* PUBLIC */ void cond_detach_2(Clause c1, Clause c2, void (*proc_proc) (Clause)) { cond_detach(c1, c2, proc_proc); if (c1 != c2) cond_detach(c2, c1, proc_proc); } /* cond_detach_2 */ LADR-2009-11A/ladr/save/formula.c0000644000175000017500000010645710140014122015505 0ustar mccunemccune#include "formula.h" /* Private definitions and types */ /* * memory management */ static unsigned Formula_gets, Formula_frees; #define BYTES_FORMULA sizeof(struct formula) #define PTRS_FORMULA BYTES_FORMULA%BPP == 0 ? BYTES_FORMULA/BPP : BYTES_FORMULA/BPP + 1 /************* * * Formula get_formula() * *************/ static Formula get_formula(int arity) { Formula p = get_mem(PTRS_FORMULA); p->kids = get_mem(arity); p->arity = arity; Formula_gets++; return(p); } /* get_formula */ /************* * * free_formula() * *************/ static void free_formula(Formula p) { free_mem(p->kids, p->arity); free_mem(p, PTRS_FORMULA); Formula_frees++; } /* free_formula */ /************* * * fprint_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the formula package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_formula_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_FORMULA; fprintf(fp, "formula (%4d) %11u%11u%11u%9.1f K\n", n, Formula_gets, Formula_frees, Formula_gets - Formula_frees, ((Formula_gets - Formula_frees) * n) / 1024.); } /* fprint_formula_mem */ /************* * * p_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the formula package. */ /* PUBLIC */ void p_formula_mem() { fprint_formula_mem(stdout, TRUE); } /* p_formula_mem */ /* * end of memory management */ /************* * * formula_get() * *************/ static Formula formula_get(int arity, Ftype type) { Formula f = get_formula(arity); f->type = type; return f; } /* formula_get */ /************* * * quant_form() * *************/ static BOOL quant_form(Formula f) { return (f->type == ALL_FORM || f->type == EXISTS_FORM); } /* quant_form */ /************* * * zap_formula() * *************/ /* DOCUMENTATION Free a formula, including all of its subformulas, including its atoms. */ /* PUBLIC */ void zap_formula(Formula f) { if (f == NULL) return; if (f->type == ATOM_FORM) zap_term(f->atom); else { int i; for (i = 0; i < f->arity; i++) zap_formula(f->kids[i]); } free_formula(f); } /* zap_formula */ /************* * * flatten_top() * *************/ static Formula flatten_top(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { BOOL operate = FALSE; int n = 0; /* count new arity */ int i; for (i = 0; i < f->arity; i++) { if (f->type != f->kids[i]->type) n++; else { n += (f->kids[i]->arity); operate = TRUE; } } if (!operate) return f; else { Formula g = formula_get(n, f->type); int i, j; j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]->type != f->type) g->kids[j++] = f->kids[i]; else { int k; for (k = 0; k < f->kids[i]->arity; k++) g->kids[j++] = f->kids[i]->kids[k]; free_formula(f->kids[i]); } } free_formula(f); /* If the new formula has just one argument, return that argument. */ if (g->arity == 1) { Formula h = g->kids[0]; free_formula(g); return h; } else return g; } } } /* flatten_top */ /************* * * formula_flatten() * *************/ /* DOCUMENTATION This routine (recursively) flattens all AND and OR formulas. */ /* PUBLIC */ Formula formula_flatten(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = formula_flatten(f->kids[i]); return flatten_top(f); } /* flatten */ /************* * * term_to_formula() * *************/ /* DOCUMENTATION

Assume that no subterm (of t) representing a formula is a term of type VARIABLE. */ /* PUBLIC */ Formula term_to_formula(Term t) { Formula f; Ftype type; char *str = sn_to_str(SYMNUM(t)); if (ARITY(t) == 1 && str_ident(str, QUANT_SYM)) { /* example: [all,x,exists,y,all,z,form] */ Term l = t->args[0]; int n = listterm_length(l); if (n % 2 != 1) { fatal_error("term_to_formula, bad quantified formula."); } f = term_to_formula(listterm_i(l, n)); for (n = n-2; n > 0; n = n - 2) { Term quant = listterm_i(l, n); Term var = listterm_i(l, n+1); Formula g; Ftype qtype; qtype = (is_symbol(SYMNUM(quant),ALL_SYM,0) ? ALL_FORM : EXISTS_FORM); g = formula_get(1, qtype); g->kids[0] = f; g->qvar = sn_to_str(SYMNUM(var)); f = g; } } else { if (ARITY(t) == 0 && str_ident(str, TRUE_SYM)) type = AND_FORM; else if (ARITY(t) == 0 && str_ident(str, FALSE_SYM)) type = OR_FORM; else if (ARITY(t) == 1 && str_ident(str, NOT_SYM)) type = NOT_FORM; else if (ARITY(t) == 2 && str_ident(str, AND_SYM)) type = AND_FORM; else if (ARITY(t) == 2 && str_ident(str, OR_SYM)) type = OR_FORM; else if (ARITY(t) == 2 && str_ident(str, IFF_SYM)) type = IFF_FORM; else if (ARITY(t) == 2 && str_ident(str, IMP_SYM)) type = IMP_FORM; else if (ARITY(t) == 2 && str_ident(str, IMPBY_SYM)) type = IMPBY_FORM; else type = ATOM_FORM; if (type == ATOM_FORM) { f = formula_get(0, ATOM_FORM); f->atom = copy_term(t); } else if (type == NOT_FORM) { f = formula_get(1, NOT_FORM); f->kids[0] = term_to_formula(t->args[0]); } else if (ARITY(t) == 0) { f = formula_get(0, type); } else { f = formula_get(2, type); f->kids[0] = term_to_formula(t->args[0]); f->kids[1] = term_to_formula(t->args[1]); } } return flatten_top(f); } /* term_to_formula */ /************* * * formula_to_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term formula_to_term(Formula f) { Term t = NULL; switch (f->type) { case ATOM_FORM: t = copy_term(f->atom); break; case NOT_FORM: t = get_rigid_term(NOT_SYM, 1); t->args[0] = formula_to_term(f->kids[0]); break; case IFF_FORM: t = get_rigid_term(IFF_SYM, 2); t->args[0] = formula_to_term(f->kids[0]); t->args[1] = formula_to_term(f->kids[1]); break; case IMP_FORM: t = get_rigid_term(IMP_SYM, 2); t->args[0] = formula_to_term(f->kids[0]); t->args[1] = formula_to_term(f->kids[1]); break; case IMPBY_FORM: t = get_rigid_term(IMPBY_SYM, 2); t->args[0] = formula_to_term(f->kids[0]); t->args[1] = formula_to_term(f->kids[1]); break; case AND_FORM: case OR_FORM: if (f->arity == 0) t = get_rigid_term(f->type == AND_FORM ? TRUE_SYM : FALSE_SYM, 0); else { int i = f->arity-1; t = formula_to_term(f->kids[i]); for (i--; i >= 0; i--) { Term t1 = get_rigid_term(f->type == AND_FORM ? AND_SYM : OR_SYM, 2); t1->args[0] = formula_to_term(f->kids[i]); t1->args[1] = t; t = t1; } } break; case ALL_FORM: case EXISTS_FORM: { Term l = get_nil_term(); Formula g; for (g = f; quant_form(g); g = g->kids[0]) { Term quant, var; quant = get_rigid_term(g->type == ALL_FORM ? ALL_SYM : EXISTS_SYM, 0); var = get_rigid_term(g->qvar, 0); l = listterm_append(l, quant); l = listterm_append(l, var); } l = listterm_append(l, formula_to_term(g)); t = get_rigid_term(QUANT_SYM, 1); t->args[0] = l; } break; } return t; } /* formula_to_term */ /************* * * fprint_formula() * *************/ /* DOCUMENTATION This routine prints a formula to a file. If you wish to have a formula printed without extra parentheses, you can call fprint_formula_term() instead. */ /* PUBLIC */ void fprint_formula(FILE *fp, Formula f) { if (f->type == ATOM_FORM) { // fprintf(fp, "("); fprint_term(fp, f->atom); // fprintf(fp, ")"); } else if (f->type == NOT_FORM) { // fprintf(fp, "(%s ", NOT_SYM); fprintf(fp, "%s", NOT_SYM); fprint_formula(fp, f->kids[0]); // fprintf(fp, ")"); } else if (f->type == IFF_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", IFF_SYM); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMP_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", IMP_SYM); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMPBY_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", IMPBY_SYM); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (quant_form(f)) { fprintf(fp, "(%s %s ", f->type==ALL_FORM ? ALL_SYM : EXISTS_SYM, f->qvar); fprint_formula(fp, f->kids[0]); fprintf(fp, ")"); } else if (f->type == AND_FORM || f->type == OR_FORM) { if (f->arity == 0) fprintf(fp, "%s", f->type == AND_FORM ? TRUE_SYM : FALSE_SYM); else { int i; fprintf(fp, "("); for (i = 0; i < f->arity; i++) { fprint_formula(fp, f->kids[i]); if (i < f->arity-1) fprintf(fp, " %s ", f->type == AND_FORM ? AND_SYM : OR_SYM); } fprintf(fp, ")"); } } } /* fprint_formula */ /************* * * p_formula() * *************/ /* DOCUMENTATION This routine prints a formula, followed by ".\n" and fflush, to stdout. If you wish to have a formula printed without extra parentheses, you can call p_formula_term() instead. If you don't want the newline, use fprint_formula() instead. */ /* PUBLIC */ void p_formula(Formula c) { fprint_formula(stdout, c); printf(".\n"); fflush(stdout); } /* p_formula */ /************* * * formula_ident() * *************/ /* DOCUMENTATION This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality. */ /* PUBLIC */ BOOL formula_ident(Formula f, Formula g) { if (f->type != g->type || f->arity != g->arity) return 0; else if (f->type == ATOM_FORM) return term_ident(f->atom, g->atom); else if (quant_form(f)) return (str_ident(f->qvar,g->qvar) && formula_ident(f->kids[0],g->kids[0])); else { int i; for (i = 0; i < f->arity; i++) if (!formula_ident(f->kids[i], g->kids[i])) return FALSE; return TRUE; } } /* formula_ident */ /************* * * formula_copy() * *************/ /* DOCUMENTATION This function returns a copy of the given formula. All subformulas, including the atoms, are copied. */ /* PUBLIC */ Formula formula_copy(Formula f) { Formula g = formula_get(f->arity, f->type); if (f->type == ATOM_FORM) g->atom = copy_term(f->atom); else { int i; if (quant_form(f)) g->qvar = f->qvar; for (i = 0; i < f->arity; i++) g->kids[i] = formula_copy(f->kids[i]); } return g; } /* formula_copy */ /************* * * dual_type() * *************/ static BOOL dual_type(int op) { switch (op) { case AND_FORM: return OR_FORM; case OR_FORM: return AND_FORM; case ALL_FORM: return EXISTS_FORM; case EXISTS_FORM: return ALL_FORM; default: return op; } } /* dual */ /************* * * dual() * *************/ /* DOCUMENTATION Change a formula into its dual. */ /* PUBLIC */ Formula dual(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = dual(f->kids[i]); f->type = dual_type(f->type); return f; } /* dual */ /************* * * and() * *************/ static Formula and(Formula a, Formula b) { Formula f = formula_get(2, AND_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* and */ /************* * * or() * *************/ static Formula or(Formula a, Formula b) { Formula f = formula_get(2, OR_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* or */ /************* * * imp() * *************/ static Formula imp(Formula a, Formula b) { Formula f = formula_get(2, IMP_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* imp */ /************* * * impby() * *************/ static Formula impby(Formula a, Formula b) { Formula f = formula_get(2, IMPBY_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* impby */ /************* * * not() * *************/ static Formula not(Formula a) { Formula f = formula_get(1, NOT_FORM); f->kids[0] = a; return f; } /* not */ /************* * * negate() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula negate(Formula a) { return not(a); } /* negate */ /************* * * nnf2() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

The argument "pref" should be either CONJUNCTION or DISJUNCTION, and it specifies the preferred form to use when translating IFFs.

Do not refer to the given formula after the call; a good way to call this routine is f = nnf2(f, CONJUNCTION). */ /* PUBLIC */ Formula nnf2(Formula f, Fpref pref) { if (f->type == ATOM_FORM) return f; else if (quant_form(f)) { f->kids[0] = nnf2(f->kids[0], pref); return f; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = nnf2(f->kids[i], pref); return f; } else if (f->type == IMP_FORM) { Formula g = nnf2(or(not(f->kids[0]), f->kids[1]), pref); free_formula(f); return g; } else if (f->type == IMPBY_FORM) { Formula g = nnf2(or(f->kids[0], not(f->kids[1])), pref); free_formula(f); return g; } else if (f->type == IFF_FORM) { Formula g; Formula a = f->kids[0]; Formula b = f->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(imp(a,b), impby(ac,bc)), pref); else g = nnf2(or(and(a,b),and(not(ac),not(bc))), pref); free_formula(f); return g; } /* NOT */ else if (f->type == NOT_FORM) { Formula h = f->kids[0]; if (h->type == ATOM_FORM) return f; else if (h->type == NOT_FORM) { Formula g = nnf2(h->kids[0], pref); free_formula(h); free_formula(f); return g; } else if (quant_form(h)) { Formula g = formula_get(1, dual_type(h->type)); g->qvar = h->qvar; g->kids[0] = nnf2(not(h->kids[0]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == AND_FORM || h->type == OR_FORM) { Formula g = formula_get(h->arity, dual_type(h->type)); int i; for (i = 0; i < h->arity; i++) g->kids[i] = nnf2(not(h->kids[i]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMP_FORM) { Formula g = nnf2(and(h->kids[0], not(h->kids[1])), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMPBY_FORM) { Formula g = nnf2(and(not(h->kids[0]), h->kids[1]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IFF_FORM) { Formula g; Formula a = h->kids[0]; Formula b = h->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(or(a,b),or(not(ac),not(bc))), pref); else g = nnf2(or(and(a,not(b)),and(not(ac),bc)), pref); free_formula(h); free_formula(f); return g; } else return f; } /* NOT */ else return f; } /* nnf2 */ /************* * * nnf() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

Do not refer to the given formula after the call; a good way to call this routine is f = nnf(f). */ /* PUBLIC */ Formula nnf(Formula f) { return nnf2(f, CONJUNCTION); } /* nnf */ /************* * * complementary() * *************/ static BOOL complementary(Formula a, Formula b) { return (a->type == NOT_FORM && formula_ident(a->kids[0], b)) || (b->type == NOT_FORM && formula_ident(a, b->kids[0])); } /* complementary */ /************* * * contains_complements() * * Assume AND_FORM or OR_FORM. * *************/ static BOOL contains_complements(Formula f) { int i, j; for (i = 0; i < f->arity-1; i++) { for (j = i+1; j < f->arity; j++) { if (complementary(f->kids[i], f->kids[j])) return TRUE; } } return FALSE; } /* contains_complements */ /*************************************************************************/ /************* * * prop_member() * *************/ static BOOL prop_member(Formula f, Formula g) { int i; for (i = 0; i < g->arity; i++) if (formula_ident(f, g->kids[i])) return TRUE; return FALSE; } /* prop_member */ /************* * * prop_subset() * *************/ static BOOL prop_subset(Formula f, Formula g) { int i; for (i = 0; i < f->arity; i++) if (!prop_member(f->kids[i], g)) return FALSE; return TRUE; } /* prop_subset */ /************* * * prop_subsume() * * Assume disjunctions, atomic, TRUE, or FALSE * *************/ static BOOL prop_subsume(Formula f, Formula g) { if (FALSE_FORMULA(f)) return TRUE; else if (TRUE_FORMULA(g)) return TRUE; else if (g->type == OR_FORM) { if (f->type == OR_FORM) return prop_subset(f, g); else return prop_member(f, g); } return formula_ident(f, g); } /* prop_subsume */ /************* * * remove_subsumed() * * Assume flat conjunction. Always return conjunction. * *************/ static Formula remove_subsumed(Formula f) { if (f->type != AND_FORM) return f; else { Formula h; int new_arity = f->arity; int i, j; for (i = 0; i < f->arity; i++) { for (j = i+1; j < f->arity; j++) { if (f->kids[i] && f->kids[j] && prop_subsume(f->kids[i], f->kids[j])) { zap_formula(f->kids[j]); f->kids[j] = NULL; new_arity--; } else if (f->kids[i] && f->kids[j] && prop_subsume(f->kids[j], f->kids[i])) { zap_formula(f->kids[i]); f->kids[i] = NULL; new_arity--; } } } h = formula_get(new_arity, AND_FORM); j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]) h->kids[j++] = f->kids[i]; } free_formula(f); return h; } } /* remove_subsumed */ /************* * * make_conjunction() * *************/ static Formula make_conjunction(Formula f) { if (f->type == AND_FORM) return f; else { Formula h = formula_get(1, AND_FORM); h->kids[0] = f; return h; } } /* make_conjunction */ /************* * * make_disjunction() * *************/ static Formula make_disjunction(Formula f) { if (f->type == OR_FORM) return f; else { Formula h = formula_get(1, OR_FORM); h->kids[0] = f; return h; } } /* make_disjunction */ /************* * * disjoin_flatten_simplify(a, b) a OR b * * Remove duplicates; if it contains complements, return TRUE. * *************/ static Formula disjoin_flatten_simplify(Formula a, Formula b) { Formula c; int new_arity, i, j; a = make_disjunction(a); b = make_disjunction(b); new_arity = a->arity + b->arity; for (i = 0; i < a->arity; i++) { for (j = 0; j < b->arity; j++) { if (b->kids[j] != NULL) { if (complementary(a->kids[i], b->kids[j])) { zap_formula(a); zap_formula(b); /* this can handle NULL kids */ return formula_get(0, AND_FORM); /* TRUE formula */ } else if (formula_ident(a->kids[i], b->kids[j])) { /* Note that this makes b non-well-formed. */ zap_formula(b->kids[j]); /* really FALSE */ b->kids[j] = NULL; new_arity--; } } } } c = formula_get(new_arity, OR_FORM); j = 0; for (i = 0; i < a->arity; i++) c->kids[j++] = a->kids[i]; for (i = 0; i < b->arity; i++) if (b->kids[i] != NULL) c->kids[j++] = b->kids[i]; free_formula(a); free_formula(b); return c; } /* disjoin_flatten_simplify */ /************* * * simplify_and() * * Assume flattened conjunction, and all kids are simplified flat * disjunctions (or atomic, TRUE, FALSE). * * *************/ static Formula simplify_and(Formula f) { if (f->type != AND_FORM) return f; else { f = remove_subsumed(f); /* still AND */ if (f->arity == 1) { Formula g = f->kids[0]; free_formula(f); return g; } else if (contains_complements(f)) { zap_formula(f); return formula_get(0, OR_FORM); /* FALSE */ } else return f; } } /* simplify_and */ /************* * * distribute_top() * * Assume it's a binary disjunction. * *************/ static Formula distribute_top(Formula h) { Formula f = h->kids[0]; Formula g = h->kids[1]; int arity, new_arity, i, j, k; Formula a; free_formula(h); /* If not conjunctions, make them so. */ f = make_conjunction(f); g = make_conjunction(g); /* printf("DT: %5d x %5d\n", f->arity, g->arity); fflush(stdout); */ arity = f->arity * g->arity; new_arity = arity; a = formula_get(arity, AND_FORM); k = 0; for (i = 0; i < f->arity; i++) { for (j = 0; j < g->arity; j++) { Formula fi = formula_copy(f->kids[i]); Formula gj = formula_copy(g->kids[j]); a->kids[k++] = disjoin_flatten_simplify(fi, gj); } } zap_formula(f); zap_formula(g); a = simplify_and(a); return a; } /* distribute_top */ /************* * * distribute() * *************/ static Formula distribute(Formula f) { if (f->type != OR_FORM) return f; else { if (f->arity != 2) fatal_error("distribute: not binary"); f->kids[0] = distribute(f->kids[0]); f->kids[1] = distribute(f->kids[1]); f = distribute_top(f); return f; } } /* distribute */ /************* * * rbt() * * Take a flat OR or AND, and make it into a * right-associated binary tree. * *************/ static Formula rbt(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) { fatal_error("rbt: not AND or OR"); return NULL; /* to please the compiler (won't happen) */ } else if (f->arity == 1) { Formula g = f->kids[0]; free_formula(f); return g; } else if (f->arity == 2) return f; else { int arity = f->arity; int i; Formula a = f->kids[arity-1]; /* working formula */ for (i = arity-2; i >= 0; i--) { Formula b = formula_get(2, f->type); b->kids[0] = f->kids[i]; b->kids[1] = a; a = b; } free_formula(f); return a; } } /* rbt */ /************* * * cnf() * * Assume NNF and flattened. * * This does not go below quantifiers; that is, * quantified formulas are treated as atomic. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula cnf(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = cnf(f->kids[i]); if (f->type == AND_FORM) { f = flatten_top(f); f = simplify_and(f); return f; } else { /* OR_FORM */ /* printf("\nkids done: "); p_formula(f); */ f = dual(remove_subsumed(dual(f))); /* printf("simplify: "); p_formula(f); */ f = rbt(f); /* make the top OR-tree binary */ f = distribute(f); /* printf("\ncnf: "); p_formula(f); */ return f; } } } /* cnf */ /************* * * formula_test() * *************/ int formula_test(Term t) { Formula f = term_to_formula(t); printf("\nform: "); p_formula(f); f = nnf(f); printf("\nnnf : "); p_formula(f); f = skolemize(f); printf("\nskol: "); p_formula(f); f = unique_quantified_vars(f); printf("\nunqu: "); p_formula(f); f = remove_universal_quantifiers(f); printf("\nrmqu: "); p_formula(f); f = formula_flatten(f); printf("\nflat: "); p_formula(f); f = cnf(f); printf("\ncnf : "); p_formula(f); zap_formula(f); p_formula_mem(); return 0; } /* formula_test */ /*************************************************************************/ /************* * * dnf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula dnf(Formula f) { return dual(cnf(dual(f))); } /* dnf */ /************* * * subst_free_var() * *************/ static void subst_free_var(Formula f, Term target, Term replacement) { if (f->type == ATOM_FORM) f->atom = subst_term(f->atom, target, replacement); else if (quant_form(f) && str_ident(sn_to_str(SYMNUM(target)), f->qvar)) { ; /* Do nothing, because we have a quantified variable of the same name. */ } else { int i; for (i = 0; i < f->arity; i++) subst_free_var(f->kids[i], target, replacement); } } /* subst_free_var */ /************* * * skolem() * *************/ static Formula skolem(Formula f, Term uvars) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return f; else if (f->type == ALL_FORM) { Term var = get_rigid_term(f->qvar, 0); Term lst; if (listterm_member(var, uvars)) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } lst = listterm_cons(var, uvars); f->kids[0] = skolem(f->kids[0], lst); free_term(var); free_term(lst); return f; } else if (f->type == EXISTS_FORM) { Formula g; int n = listterm_length(uvars); int sn = next_skolem_symbol(n); Term sk = get_rigid_term(sn_to_str(sn), n); Term evar = get_rigid_term(f->qvar, 0); int i; for (i = 0; i < n; i++) sk->args[i] = copy_term(listterm_i(uvars, n-i)); /* uvars is backward */ subst_free_var(f->kids[0], evar, sk); zap_term(sk); zap_term(evar); g = skolem(f->kids[0], uvars); free_formula(f); return g; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) { f->kids[i] = skolem(f->kids[i], uvars); } return f; } else { /* Not in NNF! Let the caller beware! */ return f; } } /* skolem */ /************* * * skolemize() * *************/ /* DOCUMENTATION This routine Skolemizes an NNF formula. The quantified variables need not be named in any particular way. If there are universally quantified variables with the same name, one in the scope of another, the inner variable will be renamed. (Existential nodes are removed.) */ /* PUBLIC */ Formula skolemize(Formula f) { Term uvars = get_nil_term(); f = skolem(f, uvars); free_term(uvars); return f; } /* skolemize */ /************* * * unique_qvars() * *************/ static Term unique_qvars(Formula f, Term vars) { if (f->type == ATOM_FORM) return vars; else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Term lst; if (listterm_member(var, vars)) { /* Rename this variable. */ int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } lst = listterm_cons(var, vars); return unique_qvars(f->kids[0], lst); } else { int i; for (i = 0; i < f->arity; i++) { vars = unique_qvars(f->kids[i], vars); } return vars; } } /* unique_qvars */ /************* * * unique_quantified_vars() * *************/ /* DOCUMENTATION Rename quantified variables, if necessary, so that each is unique. This works for any formula.

If you wish to rename a quantified variable only if it occurs in the scope of of a quantified variable with the same name, you can use the routine eliminate_rebinding() instead.

(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.) */ /* PUBLIC */ Formula unique_quantified_vars(Formula f) { Term uvars = unique_qvars(f, get_nil_term()); zap_term(uvars); return f; } /* unique_quantified_vars */ /************* * * mark_free_vars_formula() * *************/ /* Replace all free occurrences of CONSTANT *varname with * a VARIABLE of index varnum. */ static void mark_free_vars_formula(Formula f, char *varname, int varnum) { if (f->type == ATOM_FORM) f->atom = subst_var_term(f->atom, str_to_sn(varname, 0), varnum); else if (quant_form(f) && str_ident(f->qvar, varname)) return; else { int i; for (i = 0; i < f->arity; i++) mark_free_vars_formula(f->kids[i], varname, varnum); } } /* mark_free_vars_formula */ /************* * * remove_uni_quant() * *************/ static Formula remove_uni_quant(Formula f, int *varnum_ptr) { if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = remove_uni_quant(f->kids[i], varnum_ptr); return f; } else if (f->type == ALL_FORM) { Formula g = f->kids[0]; mark_free_vars_formula(g, f->qvar, *varnum_ptr); *varnum_ptr += 1; free_formula(f); return remove_uni_quant(g, varnum_ptr); } else { /* If not ATOM_FORM, something's probably wrong, * but let the caller beware! */ return f; } } /* remove_uni_quant */ /************* * * remove_universal_quantifiers() * *************/ /* DOCUMENTATION For each universally quantified variable in the given formula, */ /* PUBLIC */ Formula remove_universal_quantifiers(Formula f) { int varnum = 0; return remove_uni_quant(f, &varnum); } /* remove_universal_quantifiers */ /************* * * clausify_prepare() * *************/ /* DOCUMENTATION This routine gets a formula all ready for translation into clauses. The sequence of transformations is

  • change to negation normal form;
  • propositional simplification;
  • skolemize (nothing fancy here);
  • make the universally quantified variables unique;
  • remove universal quantifiers, changing the constants-which-represent-variables into genuine variables;
  • change to conjunctive normal form (with basic propositional simplification).
The caller should not refer to the given formula f after the call; A good way to call is f = clausify_prepare(f) */ /* PUBLIC */ Formula clausify_prepare(Formula f) { f = nnf(f); f = skolemize(f); f = unique_quantified_vars(f); f = remove_universal_quantifiers(f); f = formula_flatten(f); f = cnf(f); return f; } /* clausify_prepare */ /************* * * greatest_qvar() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a quantified variable in Formula f.

Recall that in Formulas, a quantified variable is represented as a constant (which is bound by the quantifier). If the formula has no quantified variables, return -1. */ /* PUBLIC */ int greatest_qvar(Formula f) { if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_qvar(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_qvar(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_qvar */ /************* * * greatest_symnum_in_formula() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a any subterm. This includes quantifed variables that don't occur in any term.

This routine is intended to be used if you need malloc an array for indexing by SYMNUM. */ /* PUBLIC */ int greatest_symnum_in_formula(Formula f) { if (f->type == ATOM_FORM) { return greatest_symnum_in_term(f->atom); } if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_symnum_in_formula(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_symnum_in_formula(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_symnum_in_formula */ /************* * * elim_rebind() * *************/ static Formula elim_rebind(Formula f, Term uvars) { if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Term lst; if (listterm_member(var, uvars)) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = fresh_symbol("y", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } lst = listterm_cons(var, uvars); f->kids[0] = elim_rebind(f->kids[0], lst); free_term(var); free_term(lst); return f; } else { int i; for (i = 0; i < f->arity; i++) { f->kids[i] = elim_rebind(f->kids[i], uvars); } return f; } } /* elim_rebind */ /************* * * eliminate_rebinding() * *************/ /* DOCUMENTATION This routine renames quantified variables so that no quantified variable occurs in the scope of a quantified variable with the same name.

If you wish to rename variables so that each quantifer has a unique variable, you can use the routine unique_quantified_vars() instead.

(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.) */ /* PUBLIC */ Formula eliminate_rebinding(Formula f) { Term uvars = get_nil_term(); f = elim_rebind(f, uvars); free_term(uvars); return f; } /* eliminate_rebinding */ /************* * * free_vars_term() * *************/ static Plist free_vars_term(Term t, Plist vars) { if (VARIABLE(t)) fatal_error("free_vars_term, VARIABLE term"); if (ARITY(t) == 0) { char *name = sn_to_str(SYMNUM(t)); if (variable_name(name)) { Term var = get_rigid_term(name, 0); if (!tlist_member(var, vars)) vars = plist_append(vars, var); } return vars; } else { int i; for (i = 0; i < ARITY(t); i++) { vars = free_vars_term(ARG(t,i), vars); } return vars; } } /* free_vars_term */ /************* * * free_vars() * *************/ static Plist free_vars(Formula f, Plist vars) { if (f->type == ATOM_FORM) vars = free_vars_term(f->atom, vars); else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Plist vars2 = free_vars(f->kids[0], NULL); vars2 = tlist_remove(var, vars2); vars = tlist_union(vars, vars2); zap_term(var); } else { int i; for (i = 0; i < f->arity; i++) vars = free_vars(f->kids[i], vars); } return vars; } /* free_vars */ /************* * * get_quant_form() * *************/ static Formula get_quant_form(Ftype type, char *qvar, Formula subformula) { Formula f = formula_get(1, type); f->qvar = qvar; f->kids[0] = subformula; return f; } /* get_quant_form */ /************* * * uni_close() * *************/ static Formula uni_close(Formula f, Plist vars) { if (vars == NULL) return f; else { Formula g = uni_close(f, vars->next); Term v = vars->v; return get_quant_form(ALL_FORM, sn_to_str(SYMNUM(v)), g); } } /* uni_close */ /************* * * universal_closure() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula universal_closure(Formula f) { Plist vars = free_vars(f, NULL); f = uni_close(f, vars); zap_tlist(vars); return f; } /* universal_closure */ LADR-2009-11A/ladr/save/cnf.c.alarm0000644000175000017500000005413410260041551015704 0ustar mccunemccune#include "cnf.h" #include "hash.h" #include "clock.h" #include /* Yikes! */ #include #include /* The following has an optimization in which formulas are shared. The main benefit of this is that when checking for identical formulas, we can compare pointers instead of traversing the formulas. Another benefit is that when copying formulas (i.e., applying distributivity), we can copy pointers instead of whole formulas. The routine consolidate_formula() causes some subformulas to be shared. It is currently applied to quantifier-free nnf formulas. shared: ATOM, NOT not shared: AND, OR, ALL, EXISTS */ /* Private definitions and types */ static jmp_buf Jump_env; /* for setjmp/longjmp */ static unsigned Fid_call_limit = UINT_MAX; static unsigned Fid_calls = 0; /************* * * share_formula() * *************/ static Formula share_formula(Formula f, Hashtab h) { if (f->type == AND_FORM || f->type == OR_FORM || f->type == ALL_FORM || f->type == EXISTS_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = share_formula(f->kids[i], h); return f; } else { if (f->type == NOT_FORM) f->kids[0] = share_formula(f->kids[0], h); unsigned hashval = hash_formula(f); Formula g = hash_lookup(f, hashval, h, (BOOL (*)(void *, void *)) formula_ident); if (g) { zap_formula(f); g->excess_refs++; return g; } else { hash_insert(f, hashval, h); return f; } } } /* share_formula */ /************* * * consolidate_formula() * *************/ static Formula consolidate_formula(Formula f) { Hashtab h = hash_init(10000); f = share_formula(f, h); /* hash_info(h); */ hash_destroy(h); return f; } /* consolidate_formula */ /************* * * formula_ident_share() * *************/ /* DOCUMENTATION This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality. */ /* PUBLIC */ BOOL formula_ident_share(Formula f, Formula g) { if (++Fid_calls > Fid_call_limit) { printf("\n%% Fid_call limit; jumping home.\n"); longjmp(Jump_env, 1); } if (f->type != g->type || f->arity != g->arity) return FALSE; else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) if (!formula_ident_share(f->kids[i], g->kids[i])) return FALSE; return TRUE; } else if (f->type == ALL_FORM || f->type == EXISTS_FORM) { return str_ident(f->qvar, g->qvar) && formula_ident_share(f->kids[0], g->kids[0]); } else return f == g; } /* formula_ident_share */ /************* * * formula_copy_share() * *************/ /* DOCUMENTATION This function returns a copy of the given formula. All subformulas, including the atoms, are copied. */ /* PUBLIC */ Formula formula_copy_share(Formula f) { if (f->type == AND_FORM || f->type == OR_FORM) { Formula g = formula_get(f->arity, f->type); int i; for (i = 0; i < f->arity; i++) g->kids[i] = formula_copy_share(f->kids[i]); return g; } else if (f->type == ALL_FORM || f->type == EXISTS_FORM) { Formula g = formula_get(1, f->type); g->qvar = f->qvar; g->kids[0] = formula_copy_share(f->kids[0]); return g; } else { f->excess_refs++; return f; } } /* formula_copy_share */ /************* * * complementary_share() * *************/ static BOOL complementary_share(Formula a, Formula b) { return (a->type == NOT_FORM && formula_ident_share(a->kids[0], b)) || (b->type == NOT_FORM && formula_ident_share(a, b->kids[0])); } /* complementary_share */ /************* * * contains_complements_share() * * Assume AND_FORM or OR_FORM. * *************/ static BOOL contains_complements_share(Formula f) { int i, j; for (i = 0; i < f->arity-1; i++) { for (j = i+1; j < f->arity; j++) { if (complementary_share(f->kids[i], f->kids[j])) return TRUE; } } return FALSE; } /* contains_complements_share */ /************* * * prop_member_share() -- is f an argument of g? * *************/ static BOOL prop_member_share(Formula f, Formula g) { int i; for (i = 0; i < g->arity; i++) if (formula_ident_share(f, g->kids[i])) return TRUE; return FALSE; } /* prop_member_share */ /************* * * prop_subset_share() -- are the arguments of f a subset of the arguments of g? * *************/ static BOOL prop_subset_share(Formula f, Formula g) { int i; for (i = 0; i < f->arity; i++) if (!prop_member_share(f->kids[i], g)) return FALSE; return TRUE; } /* prop_subset_share */ /************* * * prop_subsume_share() * * Assume disjunctions, atomic, TRUE, or FALSE * *************/ static BOOL prop_subsume_share(Formula f, Formula g) { if (FALSE_FORMULA(f)) return TRUE; else if (TRUE_FORMULA(g)) return TRUE; else if (g->type == OR_FORM) { if (f->type == OR_FORM) return prop_subset_share(f, g); else return prop_member_share(f, g); } return formula_ident_share(f, g); } /* prop_subsume_share */ /************* * * remove_subsumed_share() * * Assume flat conjunction. Always return conjunction. * *************/ static Formula remove_subsumed_share(Formula f) { if (f->type != AND_FORM) return f; else { Formula h; int new_arity = f->arity; int i, j; for (i = 0; i < f->arity; i++) { for (j = i+1; j < f->arity; j++) { if (f->kids[i] && f->kids[j] && prop_subsume_share(f->kids[i], f->kids[j])) { zap_formula(f->kids[j]); f->kids[j] = NULL; new_arity--; } else if (f->kids[i] && f->kids[j] && prop_subsume_share(f->kids[j], f->kids[i])) { zap_formula(f->kids[i]); f->kids[i] = NULL; new_arity--; } } } h = formula_get(new_arity, AND_FORM); j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]) h->kids[j++] = f->kids[i]; } free_formula(f); return h; } } /* remove_subsumed_share */ /************* * * bbt() * *************/ static Formula bbt(Formula f, int start, int end) { if (start == end) return f->kids[start]; else { int mid = (start + end) / 2; Formula b = formula_get(2, f->type); b->kids[0] = bbt(f, start, mid); b->kids[1] = bbt(f, mid+1, end); return b; } } /* bbt */ /************* * * balanced_binary() * * Take a flat OR or AND, and make it into a balanced binary tree. * *************/ static Formula balanced_binary(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) { fatal_error("balanced_binary: not AND or OR"); return NULL; /* to please the compiler (won't happen) */ } else if (f->arity == 0) return f; else { Formula b = bbt(f, 0, f->arity-1); free_formula(f); return b; } } /* balanced_binary */ /************* * * disjoin_flatten_simplify(a, b) a OR b * * Remove duplicates; if it contains complements, return TRUE. * *************/ static Formula disjoin_flatten_simplify(Formula a, Formula b) { Formula c; int new_arity, i, j; a = make_disjunction(a); b = make_disjunction(b); new_arity = a->arity + b->arity; for (i = 0; i < a->arity; i++) { for (j = 0; j < b->arity; j++) { if (b->kids[j] != NULL) { if (complementary_share(a->kids[i], b->kids[j])) { zap_formula(a); zap_formula(b); /* this can handle NULL kids */ return formula_get(0, AND_FORM); /* TRUE formula */ } else if (formula_ident_share(a->kids[i], b->kids[j])) { /* Note that this makes b non-well-formed. */ zap_formula(b->kids[j]); /* really FALSE */ b->kids[j] = NULL; new_arity--; } } } } c = formula_get(new_arity, OR_FORM); j = 0; for (i = 0; i < a->arity; i++) c->kids[j++] = a->kids[i]; for (i = 0; i < b->arity; i++) if (b->kids[i] != NULL) c->kids[j++] = b->kids[i]; free_formula(a); free_formula(b); return c; } /* disjoin_flatten_simplify */ /************* * * simplify_and_share() * * Assume flattened conjunction, and all kids are simplified flat * disjunctions (or atomic, TRUE, FALSE). * * *************/ static Formula simplify_and_share(Formula f) { if (f->type != AND_FORM) return f; else { f = remove_subsumed_share(f); /* still AND */ if (f->arity == 1) { Formula g = f->kids[0]; free_formula(f); return g; } else if (contains_complements_share(f)) { zap_formula(f); return formula_get(0, OR_FORM); /* FALSE */ } else return f; } } /* simplify_and_share */ /************* * * distribute_top() * * Assume it's a binary disjunction. * *************/ static Formula distribute_top(Formula h) { Formula f = h->kids[0]; Formula g = h->kids[1]; int arity, i, j, k; Formula a; free_formula(h); /* If not conjunctions, make them so. */ f = make_conjunction(f); g = make_conjunction(g); /* printf("DT: %5d x %5d\n", f->arity, g->arity); fflush(stdout); */ arity = f->arity * g->arity; a = formula_get(arity, AND_FORM); k = 0; for (i = 0; i < f->arity; i++) { for (j = 0; j < g->arity; j++) { Formula fi = formula_copy_share(f->kids[i]); Formula gj = formula_copy_share(g->kids[j]); a->kids[k++] = disjoin_flatten_simplify(fi, gj); } } zap_formula(f); zap_formula(g); a = simplify_and_share(a); return a; } /* distribute_top */ /************* * * distribute() * *************/ static Formula distribute(Formula f) { if (f->type != OR_FORM || f->arity == 0) return f; else { if (f->arity != 2) fatal_error("distribute: not binary"); f->kids[0] = distribute(f->kids[0]); f->kids[1] = distribute(f->kids[1]); f = distribute_top(f); return f; } } /* distribute */ /************* * * cnf() * * Assume NNF and flattened. * * This does not go below quantifiers; that is, * quantified formulas are treated as atomic. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula cnf(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = cnf(f->kids[i]); if (f->type == AND_FORM) { f = flatten_top(f); f = simplify_and_share(f); return f; } else { /* OR_FORM */ f = dual(remove_subsumed_share(dual(f))); f = balanced_binary(f); /* make the top OR-tree binary */ f = distribute(f); return f; } } } /* cnf */ /************* * * dnf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula dnf(Formula f) { return dual(cnf(dual(f))); } /* dnf */ /************* * * skolem() * *************/ static Formula skolem(Formula f, Ilist uvars) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return f; else if (f->type == ALL_FORM) { Term var = get_rigid_term(f->qvar, 0); Ilist uvars_plus; if (ilist_member(uvars, SYMNUM(var))) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = gen_new_symbol("x", 0, uvars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } uvars_plus = ilist_prepend(uvars, SYMNUM(var)); f->kids[0] = skolem(f->kids[0], uvars_plus); free_term(var); free_ilist(uvars_plus); /* frees first node only; uvars still good */ return f; } else if (f->type == EXISTS_FORM) { Formula g; int n = ilist_count(uvars); int sn = next_skolem_symbol(n); Term sk = get_rigid_term(sn_to_str(sn), n); Term evar = get_rigid_term(f->qvar, 0); Ilist p; int i; /* uvars is backward */ for (p = uvars, i = n-1; p; p = p->next, i--) ARG(sk,i) = get_rigid_term(sn_to_str(p->i), 0); subst_free_var(f->kids[0], evar, sk); zap_term(sk); zap_term(evar); g = skolem(f->kids[0], uvars); free_formula(f); return g; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) { f->kids[i] = skolem(f->kids[i], uvars); } return f; } else { /* Not in NNF! Let the caller beware! */ return f; } } /* skolem */ /************* * * skolemize() * *************/ /* DOCUMENTATION This routine Skolemizes an NNF formula. The quantified variables need not be named in any particular way. If there are universally quantified variables with the same name, one in the scope of another, the inner variable will be renamed. (Existential nodes are removed.) */ /* PUBLIC */ Formula skolemize(Formula f) { f = skolem(f, NULL); return f; } /* skolemize */ /************* * * unique_qvars() * *************/ static Ilist unique_qvars(Formula f, Ilist vars) { if (f->type == ATOM_FORM) return vars; else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); if (ilist_member(vars, SYMNUM(var))) { /* Rename this variable. */ int sn = gen_new_symbol("x", 0, vars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } vars = ilist_prepend(vars, SYMNUM(var)); return unique_qvars(f->kids[0], vars); } else { int i; for (i = 0; i < f->arity; i++) vars = unique_qvars(f->kids[i], vars); return vars; } } /* unique_qvars */ /************* * * unique_quantified_vars() * *************/ /* DOCUMENTATION Rename quantified variables, if necessary, so that each is unique. This works for any formula.

If you wish to rename a quantified variable only if it occurs in the scope of of a quantified variable with the same name, you can use the routine eliminate_rebinding() instead.

(This could be a void routine, because none of the formula nodes is changed.) */ /* PUBLIC */ Formula unique_quantified_vars(Formula f) { Ilist uvars = unique_qvars(f, NULL); zap_ilist(uvars); return f; } /* unique_quantified_vars */ /************* * * mark_free_vars_formula() * *************/ /* Replace all free occurrences of CONSTANT *varname with * a VARIABLE of index varnum. */ static void mark_free_vars_formula(Formula f, char *varname, int varnum) { if (f->type == ATOM_FORM) f->atom = subst_var_term(f->atom, str_to_sn(varname, 0), varnum); else if (quant_form(f) && str_ident(f->qvar, varname)) return; else { int i; for (i = 0; i < f->arity; i++) mark_free_vars_formula(f->kids[i], varname, varnum); } } /* mark_free_vars_formula */ /************* * * remove_uni_quant() * *************/ static Formula remove_uni_quant(Formula f, int *varnum_ptr) { if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = remove_uni_quant(f->kids[i], varnum_ptr); return f; } else if (f->type == ALL_FORM) { Formula g = f->kids[0]; mark_free_vars_formula(g, f->qvar, *varnum_ptr); *varnum_ptr += 1; free_formula(f); return remove_uni_quant(g, varnum_ptr); } else { /* If not ATOM_FORM, something's probably wrong, * but let the caller beware! */ return f; } } /* remove_uni_quant */ /************* * * remove_universal_quantifiers() * *************/ /* DOCUMENTATION For each universally quantified variable in the given formula, */ /* PUBLIC */ Formula remove_universal_quantifiers(Formula f) { int varnum = 0; return remove_uni_quant(f, &varnum); } /* remove_universal_quantifiers */ /************* * * clausify_prepare() * *************/ /* DOCUMENTATION This routine gets a formula all ready for translation into clauses. The sequence of transformations is

  • change to negation normal form;
  • propositional simplification;
  • skolemize (nothing fancy here);
  • make the universally quantified variables unique;
  • remove universal quantifiers, changing the constants-which-represent-variables into genuine variables;
  • change to conjunctive normal form (with basic propositional simplification).
The caller should not refer to the given formula f after the call; A good way to call is f = clausify_prepare(f) */ /* PUBLIC */ Formula clausify_prepare(Formula f) { formula_canon_eq(f); f = nnf(f); f = skolemize(f); f = unique_quantified_vars(f); f = remove_universal_quantifiers(f); f = formula_flatten(f); f = consolidate_formula(f); /* causes sharing of some subformulas */ #if 0 printf("%% CNF translation, nnf_size=%d, ", formula_size(f)); fflush(stdout); #endif f = cnf(f); #if 0 printf("cnf_size=%d, cnf_clauses=%d\n", formula_size(f), f->type == AND_FORM ? f->arity : 1); fflush(stdout); #endif return f; } /* clausify_prepare */ /************* * * ms_free_vars() * *************/ static Formula ms_free_vars(Formula f) { /* f is ALL_FORM, kids are rms, kids not AND_FORM */ Formula child = f->kids[0]; if (child->type != OR_FORM) { if (free_variable(f->qvar, child)) return f; else { free_formula(f); return child; } } else { Plist free = NULL; /* children with qvar free */ Plist notfree = NULL; /* children without qvar free */ int free_count = 0; /* size of free */ int notfree_count = 0; /* size of notfree */ int i; for (i = child->arity-1; i >= 0; i--) { if (!free_variable(f->qvar, child->kids[i])) { notfree = plist_prepend(notfree, child->kids[i]); notfree_count++; } else { free = plist_prepend(free, child->kids[i]); free_count++; } } if (notfree_count == 0) return f; /* all children have qvar free */ else if (free_count == 0) { free_formula(f); return child; /* no child has qvar free */ } else { Formula or_free = formula_get(free_count , OR_FORM); Formula or_top = formula_get(notfree_count + 1 , OR_FORM); Plist p; for (p = free, i = 0; p; p = p->next, i++) or_free->kids[i] = p->v; for (p = notfree, i = 0; p; p = p->next, i++) or_top->kids[i] = p->v; or_top->kids[i] = f; f->kids[0] = or_free; free_formula(child); return or_top; } } } /* ms_free_vars */ /************* * * miniscope() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula miniscope(Formula f) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return f; if (f->type == AND_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = miniscope(f->kids[i]); f = flatten_top(f); f = simplify_and_share(f); return f; } else if (f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = miniscope(f->kids[i]); f = flatten_top(f); f = dual(remove_subsumed_share(dual(f))); f = balanced_binary(f); /* make the top OR-tree binary */ f = distribute(f); return f; } else if (f->type == EXISTS_FORM) { f = dual(f); f = miniscope(f); f = dual(f); return f; } else if (f->type == ALL_FORM) { f->kids[0] = miniscope(f->kids[0]); if (f->kids[0]->type == AND_FORM) { /* distribute all to children */ int i; Formula and = f->kids[0]; free_formula(f); /* shallow */ for (i = 0; i < and->arity; i++) { Formula g = get_quant_form(ALL_FORM, f->qvar, and->kids[i]); g = ms_free_vars(g); and->kids[i] = g; } return and; /* need to simplify first? */ } else { f = ms_free_vars(f); return f; } } /* ALL */ else { fatal_error("miniscope: formula not in nnf"); return NULL; /* to please the complier */ } } /* miniscope */ /************* * * miniscope_alarm_handler() * *************/ static void miniscope_alarm_handler(int signum) { printf("\n%% Caught miniscope alarm signal; jumping home.\n"); longjmp(Jump_env, 1); } /* miniscope_alarm_handler */ /************* * * miniscope_formula() * *************/ typedef void (*sighandler_t)(int); /* DOCUMENTATION */ /* PUBLIC */ Formula miniscope_formula(Formula f, unsigned seconds_limit) { /* set an alarm, saving any old alarm */ sighandler_t save_handler = signal(SIGALRM, miniscope_alarm_handler); unsigned save_alarm = alarm(seconds_limit); printf("setalarm, save=%u, limit=%u,\n", save_alarm, seconds_limit); int return_code = setjmp(Jump_env); if (return_code != 0) { /* We just landed from longjmp() */ /* I'd like to reclaim the formula memory, but that would take some thought, because the partly transformed formula is not well formed */ /* restore handler and alarm */ signal(SIGALRM, save_handler); alarm(save_alarm - seconds_limit); printf("restoring alarm, save=%u, limit=%u,\n", save_alarm, seconds_limit); printf("mega_mem_calls=%u\n", mega_mem_calls()); return NULL; } else { /* ordinary execution */ Formula f2 = NULL; int wall_start = wallclock(); formula_canon_eq(f); f = nnf(f); f = formula_flatten(f); f = consolidate_formula(f); /* share some subformulas */ f = miniscope(f); /* return a formula without shared subformulas */ f2 = formula_copy(f); zap_formula(f); /* restore handler and alarm */ signal(SIGALRM, save_handler); alarm(save_alarm - (wallclock() - wall_start)); return f2; } } /* miniscope_formula */ /************* * * cnf_max_clauses() * *************/ /* DOCUMENTATION Given an NNF formula, return the maximum number of clauses that it can produce. (The maximum happens if no simplification occurs.) */ /* PUBLIC */ int cnf_max_clauses(Formula f) { if (f->type == ATOM_FORM || f->type == NOT_FORM) return 1; else if (f->type == ALL_FORM || f->type == EXISTS_FORM) return cnf_max_clauses(f->kids[0]); else if (f->type == AND_FORM) { int i; int n = 0; for (i = 0; i < f->arity; i++) n += cnf_max_clauses(f->kids[i]); return n; } else if (f->type == OR_FORM) { int i; int n = 1; for (i = 0; i < f->arity; i++) n *= cnf_max_clauses(f->kids[i]); return n; } else { fatal_error("cnf_max_clauses, formula not NNF"); return -1; /* won't happen */ } } /* cnf_max_clauses */ LADR-2009-11A/ladr/save/lindex.c0000644000175000017500000001162410140052321015315 0ustar mccunemccune#include "lindex.h" /* Private definitions and types */ /* * memory management */ static unsigned Lindex_gets, Lindex_frees; #define BYTES_LINDEX sizeof(struct lindex) #define PTRS_LINDEX BYTES_LINDEX%BPP == 0 ? BYTES_LINDEX/BPP : BYTES_LINDEX/BPP + 1 /************* * * Lindex get_lindex() * *************/ static Lindex get_lindex(void) { Lindex p = get_mem(PTRS_LINDEX); Lindex_gets++; return(p); } /* get_lindex */ /************* * * free_lindex() * *************/ static void free_lindex(Lindex p) { free_mem(p, PTRS_LINDEX); Lindex_frees++; } /* free_lindex */ /************* * * fprint_lindex_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the lindex package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_lindex_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_LINDEX; fprintf(fp, "lindex (%4d) %11u%11u%11u%9.1f K\n", n, Lindex_gets, Lindex_frees, Lindex_gets - Lindex_frees, ((Lindex_gets - Lindex_frees) * n) / 1024.); } /* fprint_lindex_mem */ /************* * * p_lindex_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the lindex package. */ /* PUBLIC */ void p_lindex_mem() { fprint_lindex_mem(stdout, TRUE); } /* p_lindex_mem */ /* * end of memory management */ /************* * * lindex_init() * *************/ /* DOCUMENTATION This routine allocates and returns a literal index (Lindex), which is a pair of Mindexes, one for positive literals, and one for negative literals. The first three parameters are for the positive literal Mindex, and the second three are for the negative.

  • Mindextype: {LINEAR, FPA, DISCRIM, DISCRIM_BIND}
  • Uniftype: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
See the routine mindex_init() for further information. */ /* PUBLIC */ Lindex lindex_init(Mindextype pos_mtype, Uniftype pos_utype, int pos_fpa_depth, Mindextype neg_mtype, Uniftype neg_utype, int neg_fpa_depth) { Lindex ldx = get_lindex(); ldx->pos = mindex_init(pos_mtype, pos_utype, pos_fpa_depth); ldx->neg = mindex_init(neg_mtype, neg_utype, neg_fpa_depth); return ldx; } /* lindex_init */ /************* * * lindex_destroy() * *************/ /* DOCUMENTATION This frees all the memory associated with a Lindex. Do not refer to the Lindex after calling this routine. */ /* PUBLIC */ void lindex_destroy(Lindex ldx) { mindex_destroy(ldx->pos); mindex_destroy(ldx->neg); free_lindex(ldx); } /* lindex_destroy */ /************* * * lindex_update() * *************/ /* DOCUMENTATION This routine indexes (or unindexes) all literals of a clause. */ /* PUBLIC */ void lindex_update(Lindex ldx, Clause c, Indexop op) { Literal lit; for (lit = c->literals; lit != NULL; lit = lit->next) { if (lit->sign) mindex_update(ldx->pos, lit->atom, op); else mindex_update(ldx->neg, lit->atom, op); } } /* lindex_update */ /************* * * lindex_update_maximal() * *************/ /* DOCUMENTATION Positive clauses: index maximal literals.

Nonpositive clauses: index negative literals. */ /* PUBLIC */ void lindex_update_maximal(Lindex ldx, Clause c, Indexop op) { BOOL positive = positive_clause(c); Literal lit; for (lit = c->literals; lit != NULL; lit = lit->next) { if (positive) { if (maximal_literal_check(lit)) mindex_update(ldx->pos, lit->atom, op); } else { if (lit->sign == FALSE) mindex_update(ldx->neg, lit->atom, op); } } } /* lindex_update_maximal */ /************* * * lindex_update_first() * *************/ /* DOCUMENTATION This routine indexes (or unindexes) the first literal of a clause. */ /* PUBLIC */ void lindex_update_first(Lindex ldx, Clause c, Indexop op) { Literal lit = c->literals; if (lit) { if (lit->sign) mindex_update(ldx->pos, lit->atom, op); else mindex_update(ldx->neg, lit->atom, op); } } /* lindex_update_first */ /************* * * lindex_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an Lindex is empty, that is, has no atoms. It must exist (be non-NULL). */ /* PUBLIC */ BOOL lindex_empty(Lindex idx) { return mindex_empty(idx->pos) && mindex_empty(idx->neg); } /* lindex_empty */ /************* * * lindex_backtrack() * *************/ /* DOCUMENTATION This Boolean function checks if either of the Mindex components (pos, neg) uses backtrack unification. */ /* PUBLIC */ BOOL lindex_backtrack(Lindex idx) { return (idx->pos->unif_type == BACKTRACK_UNIF || idx->neg->unif_type == BACKTRACK_UNIF); } /* lindex_backtrack */ LADR-2009-11A/ladr/save/sos.c.old0000644000175000017500000000771310173271364015437 0ustar mccunemccune#else /* not NEW_SOS*/ /****************************************************************************/ /* Private definitions and types */ static Clist Lightest = NULL; /* Lightest clauses in Sos, or empty */ /************* * * clist_lightest_append() * *************/ static void clist_lightest_append(Clause c) { if (Lightest->first == NULL || c->weight > Lightest->first->c->weight) ; /* do nothing */ else if (c->weight == Lightest->first->c->weight) clist_append(c, Lightest); else clist_remove_all_clauses(Lightest); } /* clist_lightest_append */ /************* * * insert_into_sos() * *************/ /* DOCUMENTATION This routine appends a clause to the sos list and updates the (private) index for extracting shortest clauses. */ /* PUBLIC */ void insert_into_sos(Clause c, Clist sos) { if (Lightest == NULL) Lightest = clist_init("lightest"); clist_lightest_append(c); clist_append(c, sos); } /* insert_into_sos */ /************* * * remove_from_sos() * *************/ /* DOCUMENTATION This routine removes a clause from the sos list and updates the index for extracting the lightest clause. */ /* PUBLIC */ void remove_from_sos(Clause c, Clist sos) { clist_remove(c, sos); if (clist_member(c, Lightest)) clist_remove(c, Lightest); } /* remove_from_sos */ /************* * * first_lightest_clause() * *************/ static Clause first_lightest_clause(Clist l) { int min = INT_MAX; Clause lightest = NULL; Clist_pos p; for (p = l->first; p; p = p->next) { int len = p->c->weight; if (len < min) { lightest = p->c; min = len; } } return lightest; } /* first_lightest_clause */ /************* * * first_sos_clause() * *************/ /* DOCUMENTATION Given a nonempty Clist, remove and return the first clause. Also, this may update the index for finding lightest clauses. */ /* PUBLIC */ Clause first_sos_clause(Clist lst) { if (lst->first == NULL) return NULL; else return lst->first->c; } /* first_sos_clause */ /************* * * lightest_sos_clause() * * Get the first, lightest clause in Sos. We use an auxiliary * Clist "Lightest" so that we don't have to scan Sos each time. * At any given time, Lightest is either empty or contains * all of the Sos clauses of minimum weight, in the same order as * in Sos. * * To insert a newly kept clause c into Sos: If c is the same * weight as clauses in Lightest, append it to Lightest as well as * to Sos. If c is heaaver than Lightest, append it to Sos only. * If c is lighter than Lightest, remove all clauses from Lightest, * (leaving Lightest empty), and append c to Sos. * * To get the first, lightest clause: If Lightest is empty, build * a new Lightest list. (This currently requires 2 scans of Sos.) * Now just take the first member of Lightest. * * Good performance of this scheme depends on the assumption that * the Lightest list is farily stable; that is, as we go from * given clause to given clause, the weight of the lightest clauses * doesn't change often. * *************/ /* DOCUMENTATION This routine uses a private index to extract the first shortest clause from the sos list. */ /* PUBLIC */ Clause lightest_sos_clause(Clist sos) { if (sos->first == NULL) return NULL; else { if (Lightest->first == NULL) { /* Build a new "lightest" list. */ int wt = first_lightest_clause(sos)->weight; Clist_pos p; for (p = sos->first; p; p = p->next) { if (p->c->weight == wt) clist_append(p->c, Lightest); } } return Lightest->first->c; } } /* lightest_sos_clause */ /************* * * zap_sos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_sos(void) { if (Lightest != NULL) { clist_remove_all_clauses(Lightest); clist_free(Lightest); Lightest = NULL; } } /* zap_sos */ /****************************************************************************/ #endif /* NEW_SOS */ LADR-2009-11A/ladr/save/commands.c0000644000175000017500000001755310151454663015663 0ustar mccunemccune#include "commands.h" /* Private definitions and types */ Term List_identifier = NULL; /************* * * process_op() * *************/ static void process_op(FILE *fout, Term t, int prec, Term type_term, Term symb_term) { if (ARITY(symb_term) != 0) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("symbols in op command must have no arguments"); } else { Parsetype pt = NOTHING_SPECIAL; if (is_constant(type_term, "infix")) pt = INFIX; else if (is_constant(type_term, "infix_left")) pt = INFIX_LEFT; else if (is_constant(type_term, "infix_right")) pt = INFIX_RIGHT; else if (is_constant(type_term, "prefix")) pt = PREFIX; else if (is_constant(type_term, "prefix_paren")) pt = PREFIX_PAREN; else if (is_constant(type_term, "postfix")) pt = POSTFIX; else if (is_constant(type_term, "postfix_paren")) pt = POSTFIX_PAREN; else if (is_constant(type_term, "clear")) pt = NOTHING_SPECIAL; else { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad parse-type in op command"); } set_parse_type(sn_to_str(SYMNUM(symb_term)), prec, pt); } } /* process_op */ /************* * * flag_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void flag_handler(FILE *fout, Term t, int unknown_action) { int flag = str_to_flag_id(sn_to_str(SYMNUM(ARG(t,0)))); if (flag == -1) { if (unknown_action == KILL_UNKNOWN) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("flag not recognized"); } else if (unknown_action == WARN_UNKNOWN) { bell(stderr); fprintf(fout, "WARNING, flag not recognized: "); fwrite_term_nl(fout, t); fprintf(stderr, "WARNING, flag not recognized: "); fwrite_term_nl(stderr, t); } else if (unknown_action == NOTE_UNKNOWN) { fprintf(fout, "NOTE: flag not recognized: "); fwrite_term_nl(fout, t); } } else update_flag(fout, flag, is_term(t, "set", 1)); } /* flag_handler */ /************* * * parm_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void parm_handler(FILE *fout, Term t, int unknown_action) { int val; BOOL ok = term_to_int(ARG(t,1), &val); if (!ok) { int id = str_to_stringparm_id(sn_to_str(SYMNUM(ARG(t,0)))); if (id == -1) { /* This should take into account unknown_action. */ fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad assign command"); } else { char *s = sn_to_str(SYMNUM(ARG(t,1))); assign_stringparm(id, s); } } else { int parm = str_to_parm_id(sn_to_str(SYMNUM(ARG(t,0)))); if (parm == -1) { if (unknown_action == KILL_UNKNOWN) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("parm not recognized"); } else if (unknown_action == WARN_UNKNOWN) { bell(stderr); fprintf(fout, "WARNING, parm not recognized: "); fwrite_term_nl(fout, t); fprintf(stderr, "WARNING, parm not recognized: "); fwrite_term_nl(stderr, t); } else if (unknown_action == NOTE_UNKNOWN) { fprintf(fout, "NOTE: parm not recognized: "); fwrite_term_nl(fout, t); } } else { assign_parm(parm, val); } } } /* parm_handler */ /************* * * preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void preliminary_precedence(Plist p) { int n = 0; Plist q; reinit_lex_vals(); for (q = p ; q; q = q->next) { Term t = q->v; set_lex_val(SYMNUM(t), ++n); } } /* preliminary_precedence */ /************* * * read_commands_from_file() * *************/ /* DOCUMENTATION

This routine reads commands from a file. Echoing the commands to an output file is optional. Here are examples of the currently supported commands.

  • set(verbose).
  • clear(verbose).
  • assign(max_seconds, 1800).
  • assoc_comm(+).
  • commutative(+).
  • op(400, infix, ^).
  • lex([e, a, b, _*_, _', h(_,_)]).

A term is returned:

  • NULL: commands were read up to EOF.
  • nonNULL term: commands were read up to this unrecognized term; you will probably wish to continue your input processing with this term.

If any error occurs, a message goes to file fout and to stderr, and a fatal_error() occurs. */ /* PUBLIC */ Term read_commands_from_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action) { Term t = read_term(fin, fout); BOOL go = (t != NULL); while (go) { BOOL already_echoed = FALSE; /************************************************************ set, clear */ if (is_term(t, "set", 1) || is_term(t, "clear", 1)) { if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } flag_handler(fout, t, unknown_action); } else if (is_term(t, "assign", 2)) { /************************************************************** assign */ if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } parm_handler(fout, t, unknown_action); } else if (is_term(t, "assoc_comm", 1) || is_term(t, "commutative", 1)) { /************************************************************ AC, etc. */ Term f = ARG(t,0); if (!CONSTANT(f)) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("argument must be symbol only"); } else { if (is_term(t, "assoc_comm", 1)) set_assoc_comm(sn_to_str(SYMNUM(f)), TRUE); else set_commutative(sn_to_str(SYMNUM(f)), TRUE); } } else if (is_term(t, "op", 3)) { /****************************************************************** op */ /* e.g., op(300, infix, +); */ Term prec_term = ARG(t,0); Term type_term = ARG(t,1); Term symb_term = ARG(t,2); int prec; BOOL ok = term_to_int(prec_term, &prec); if (!ok || prec < MIN_PRECEDENCE || prec > MAX_PRECEDENCE) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad precedence in op command"); } else if (proper_listterm(symb_term)) { while (cons_term(symb_term)) { process_op(fout, t, prec, type_term, ARG(symb_term, 0)); symb_term = ARG(symb_term, 1); } } else process_op(fout, t, prec, type_term, symb_term); } else if (is_term(t, "lex", 1)) { /***************************************************************** lex */ Plist p = listterm_to_tlist(ARG(t,0)); if (p == NULL) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("lex command must contain a proper list, e.g., [a,b,c]"); } else { preliminary_precedence(p); zap_plist(p); } } else { /******************************************************** unrecognized */ /* return this unknown term */ go = FALSE; } if (go) { if (echo && !already_echoed) fwrite_term_nl(fout, t); zap_term(t); t = read_term(fin, fout); go = (t != NULL); } } return t; } /* read_commands_from_file */ /************* * * read_commands() * *************/ /* PUBLIC */ void read_commands(int argc, char **argv, FILE *fout, BOOL echo, int unknown_action) { int n = which_string_member("-f", argv, argc); if (n == -1) { List_identifier = read_commands_from_file(stdin,fout,echo,unknown_action); } else { /* Read from the files until we get to a term that is not recognized (which should be a list identifier). Save that term. */ int i; Term t = NULL; for (i = n+1; i < argc && t == NULL; i++) { FILE *fin = fopen(argv[i], "r"); if (fin == NULL) { fprintf(stdout, "File not found: %s\n", argv[i]); fprintf(stderr, "File not found: %s\n", argv[i]); fatal_error("read_commands: file not found"); } t = read_commands_from_file(fin, fout, echo, unknown_action); fclose(fin); List_identifier = t; } } } /* read_commands */ LADR-2009-11A/ladr/save/fpalist.c0000644000175000017500000001472010140052405015477 0ustar mccunemccune#include "fpalist.h" /* Private definitions and types */ /* This if the new code (April 2004) for inserting/deleting/traversing FPA lists. It should function exactly the same as the old code, except that deletions should be much faster, and memory usage will be somewhat different (not much). Instead of a (singly-linked) list of pointers to terms, we have a (singly-linked) list of *arrays* of pointers to terms. As before, the terms are kept in decreasing order. Recall that in practice, terms being inserted will usually be greater than anything already in the list. */ /* The design is determined by the following properties of the application: (1) items will nearly always be inserted in increasing order, (2) the lists will be traversed, and the items must be kept in decreasing order, and (3) deletions will be arbitrary and occasionally extensive. */ /* * memory management */ static unsigned Fpa_chunk_gets, Fpa_chunk_frees; #define BYTES_FPA_CHUNK sizeof(struct fpa_chunk) #define PTRS_FPA_CHUNK BYTES_FPA_CHUNK%BPP == 0 ? BYTES_FPA_CHUNK/BPP : BYTES_FPA_CHUNK/BPP + 1 /************* * * Fpa_chunk get_fpa_chunk() * *************/ static Fpa_chunk get_fpa_chunk(void) { Fpa_chunk p = get_mem(PTRS_FPA_CHUNK); Fpa_chunk_gets++; return(p); } /* get_fpa_chunk */ /************* * * free_fpa_chunk() * *************/ static void free_fpa_chunk(Fpa_chunk p) { free_mem(p, PTRS_FPA_CHUNK); Fpa_chunk_frees++; } /* free_fpa_chunk */ /************* * * fprint_fpalist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpalist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_fpalist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_FPA_CHUNK; fprintf(fp, "fpa_chunk (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_chunk_gets, Fpa_chunk_frees, Fpa_chunk_gets - Fpa_chunk_frees, ((Fpa_chunk_gets - Fpa_chunk_frees) * n) / 1024.); } /* fprint_fpalist_mem */ /************* * * p_fpalist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the fpalist package. */ /* PUBLIC */ void p_fpalist_mem() { fprint_fpalist_mem(stdout, TRUE); } /* p_fpalist_mem */ /* * end of memory management */ /* First and last items in chunk. Items are right-justified. */ #define FLAST(f) (f)->d[FMAX-1] #define FFIRST(f) (f)->d[FMAX-((f)->n)] /************* * * flist_insert() * * If the item is greater than any in the list, insertion should * be constant time. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Fpa_chunk flist_insert(Fpa_chunk f, Term x) { if (f == NULL) { f = get_fpa_chunk(); FLAST(f) = x; f->n = 1; } else if (f->n == FMAX) { if (FLT(x,FLAST(f))) f->next = flist_insert(f->next, x); else if (x == FLAST(f)) fprintf(stderr, "WARNING: flist_insert, item %p already here (1)!\n", x); else if (FGT(x,FFIRST(f))) { /* This special case isn't necessary. It is to improve performance. The application for which I'm writing this inserts items in increasing order (most of the time), and this prevents a lot of half-empty chunks in that case. */ Fpa_chunk f2 = flist_insert(NULL, x); f2->next = f; f = f2; } else { /* split this chunk in half */ Fpa_chunk f2 = get_fpa_chunk(); int move = FMAX / 2; int i, j; for (i = 0, j = FMAX-move; i < move; i++, j++) { f2->d[j] = f->d[i]; f->d[i] = NULL; } f2->n = move; f->n = FMAX - move; f2->next = f; f = flist_insert(f2, x); } } else { if (f->next && FLE(x,FFIRST(f->next))) f->next = flist_insert(f->next, x); else { /* insert into this pa_chunk */ int n = f->n; int i = FMAX - n; while (i < FMAX && FLT(x,f->d[i])) i++; if (i < FMAX && x == f->d[i]) fprintf(stderr, "WARNING: flist_insert, item %p already here (2)!\n", x); else if (i == FMAX - n) { f->d[i-1] = x; f->n = n+1; } else { /* insert at i-1, shifting the rest */ int j; for (j = FMAX-n; j < i; j++) f->d[j-1] = f->d[j]; f->d[i-1] = x; f->n = n+1; } } } return f; } /* flist_insert */ /************* * * consolidate() - try to join f and f->next; not recursive * *************/ static Fpa_chunk consolidate(Fpa_chunk f) { if (f->next && f->n + f->next->n <= FMAX) { Fpa_chunk f2 = f->next; int i; for (i = 0; i < f->n; i++) f2->d[FMAX - (f2->n + i + 1)] = f->d[FMAX - (i+1)]; f2->n = f->n + f2->n; free_fpa_chunk(f); return f2; } else return f; } /* consolidate */ /************* * * flist_delete() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Fpa_chunk flist_delete(Fpa_chunk f, Term x) { if (f == NULL) fprintf(stderr, "WARNING: flist_delete, item %p not found (1)!\n", x); else if (FLT(x,FLAST(f))) f->next = flist_delete(f->next, x); else { int n = f->n; int i = FMAX - n; while (i < FMAX && FLT(x,f->d[i])) i++; if (x != f->d[i]) fprintf(stderr, "WARNING: flist_delete, item %p not found (2)!\n", x); else { /* delete and close the hole */ int j; for (j = i; j > FMAX-n; j--) f->d[j] = f->d[j-1]; f->d[j] = NULL; f->n = n-1; if (f->n == 0) { /* delete this chunk */ Fpa_chunk next = f->next; free_fpa_chunk(f); f = next; } else { /* try to join this chunk with the next */ f = consolidate(f); } } } return f; } /* flist_delete */ /************* * * first_fpos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ struct fposition first_fpos(Fpa_chunk f) { if (f == NULL) return (struct fposition) {NULL, 0}; else return (struct fposition) {f, FMAX - f->n}; } /* first_fpos */ /************* * * next_fpos() * *************/ /* DOCUMENTATION */ /* PUBLIC */ struct fposition next_fpos(struct fposition p) { int i = p.i+1; if (i < FMAX) return (struct fposition) {p.f, i}; else return first_fpos((p.f)->next); } /* next_fpos */ /************* * * zap_fpa_chunks() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_fpa_chunks(Fpa_chunk p) { if (p != NULL) { zap_fpa_chunks(p->next); free_fpa_chunk(p); } } /* zap_fpa_chunks */ LADR-2009-11A/ladr/save/features.c0000644000175000017500000001070710155672347015677 0ustar mccunemccune#include "features.h" /* Private definitions and types */ static Ilist Feature_symbols; /* list of featured symbols (symnums)*/ /* The following are work arrays, indexed by symnum, used for calculating the features of a clause. They are allocated by init_features() and left in place throughout the process. */ static int *Pos_occurrences; static int *Neg_occurrences; static int *Pos_maxdepth; static int *Neg_maxdepth; /************* * * init_features() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void init_features(Ilist fsyms, Ilist rsyms) { Feature_symbols = ilist_cat(ilist_copy(fsyms), ilist_copy(rsyms)); Pos_occurrences = calloc(greatest_symnum() + 1, sizeof(int)); Neg_occurrences = calloc(greatest_symnum() + 1, sizeof(int)); Pos_maxdepth = calloc(greatest_symnum() + 1, sizeof(int)); Neg_maxdepth = calloc(greatest_symnum() + 1, sizeof(int)); } /* init_features */ /************* * * fill_in_arrays() * *************/ static void fill_in_arrays(Term t, BOOL sign, int depth) { if (!VARIABLE(t)) { int i; if (sign) { Pos_occurrences[SYMNUM(t)]++; Pos_maxdepth[SYMNUM(t)] = IMAX(depth, Pos_maxdepth[SYMNUM(t)]); } else { Neg_occurrences[SYMNUM(t)]++; Neg_maxdepth[SYMNUM(t)] = IMAX(depth, Neg_maxdepth[SYMNUM(t)]); } for (i = 0; i < ARITY(t); i++) fill_in_arrays(ARG(t,i), sign, depth+1); } } /* fill_in_arrays */ /************* * * features() * *************/ /* DOCUMENTATION For each symbol in the list of symbols given to init_features(), count positive occurrences, negative occurrences, max depth in a positive literal, and max_depth in a negative literal. Return the Ilist of results. */ /* PUBLIC */ Ilist features(Clause c) { Literal lit; for (lit = c->literals; lit; lit = lit->next) { fill_in_arrays(lit->atom, lit->sign, 0); } { /* Build it backwards, then reverse it. */ Ilist f = NULL; Ilist p; for (p = Feature_symbols; p; p = p->next) { // #define FINTS /* use an int for each feature */ #ifdef FINTS f = ilist_prepend(f, Pos_occurrences[p->i]); f = ilist_prepend(f, Neg_occurrences[p->i]); f = ilist_prepend(f, Pos_maxdepth[p->i]); f = ilist_prepend(f, Neg_maxdepth[p->i]); #else /* put 4 features into each int */ int i1 = IMIN(8,Pos_occurrences[p->i]); int i2 = IMIN(8,Neg_occurrences[p->i]); int i3 = IMIN(8,Pos_maxdepth[p->i]); int i4 = IMIN(8,Neg_maxdepth[p->i]); unsigned char u1 = (1 << i1) - 1; unsigned char u2 = (1 << i2) - 1; unsigned char u3 = (1 << i3) - 1; unsigned char u4 = (1 << i4) - 1; int i = 0; i = (i << 8) | u1; i = (i << 8) | u2; i = (i << 8) | u3; i = (i << 8) | u4; f = ilist_prepend(f, i); #endif Pos_occurrences[p->i] = 0; Neg_occurrences[p->i] = 0; Pos_maxdepth[p->i] = 0; Neg_maxdepth[p->i] = 0; } f = reverse_ilist(f); #if 0 printf("Features for clause "); f_clause(c); p_features(f); #endif return f; } } /* features */ /************* * * feature_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int feature_length(void) { #ifdef FINTS return ilist_count(Feature_symbols) * 4; #else return ilist_count(Feature_symbols); #endif } /* feature_length */ /************* * * features_less_or_equal() * *************/ /* DOCUMENTATION Return TRUE if Ilists c and d are thr same length and each member of c is <= the corresponding member of d. */ /* PUBLIC */ BOOL features_less_or_equal(Ilist c, Ilist d) { #ifdef FINTS while (c && d && c->i <= d->i) { #else while (c && d && ((c->i | d->i) == d->i)) { #endif c = c->next; d = d->next; } return !c && !d; } /* features_less_or_equal */ /************* * * p_features() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_features(Ilist f) { Ilist p; for (p = Feature_symbols; p; p = p->next) { #ifdef FINTS printf(" symbol %s: ", sn_to_str(p->i)); printf("pos_occ=%d, neg_occ=%d, pos_max=%d, neg_max=%d\n", f->i, f->next->i, f->next->next->i, f->next->next->next->i); f = f->next->next->next->next; #else int i = f->i; int i1, i2, i3, i4; i4 = i & 0xFF; i = i >> 8; i3 = i & 0xFF; i = i >> 8; i2 = i & 0xFF; i = i >> 8; i1 = i & 0xFF; printf(" symbol %s: ", sn_to_str(p->i)); printf("pos_occ=%d, neg_occ=%d, pos_max=%d, neg_max=%d. %x\n", i1,i2,i3,i4,f->i); f = f->next; #endif } } /* p_features */ LADR-2009-11A/ladr/save/strbuf.c0000644000175000017500000001620410140052047015343 0ustar mccunemccune#include "strbuf.h" /* * private definitions and types */ struct string_buf { int size; struct chunk *first; struct string_buf *link; }; #define CHUNK 500 struct chunk { char s[CHUNK]; struct chunk *next; }; typedef struct chunk *Chunk; /* * memory management */ static unsigned Chunk_gets, Chunk_frees; static unsigned String_buf_gets, String_buf_frees; #define BYTES_CHUNK sizeof(struct chunk) #define PTRS_CHUNK BYTES_CHUNK%BPP == 0 ? BYTES_CHUNK/BPP : BYTES_CHUNK/BPP + 1 #define BYTES_STRING_BUF sizeof(struct string_buf) #define PTRS_STRING_BUF BYTES_STRING_BUF%BPP == 0 ? BYTES_STRING_BUF/BPP : BYTES_STRING_BUF/BPP + 1 /************* * * Chunk get_chunk() * *************/ static Chunk get_chunk(void) { Chunk p = get_mem(PTRS_CHUNK); Chunk_gets++; return(p); } /* get_chunk */ /************* * * free_chunk() * *************/ static void free_chunk(Chunk p) { free_mem(p, PTRS_CHUNK); Chunk_frees++; } /* free_chunk */ /************* * * String_buf get_string_buf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ String_buf get_string_buf(void) { String_buf p = get_mem(PTRS_STRING_BUF); String_buf_gets++; return(p); } /* get_string_buf */ /************* * * free_string_buf() * *************/ static void free_string_buf(String_buf p) { free_mem(p, PTRS_STRING_BUF); String_buf_frees++; } /* free_string_buf */ /************* * * fprint_strbuf_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the strbuf package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_strbuf_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_CHUNK; fprintf(fp, "chunk (%4d) %11u%11u%11u%9.1f K\n", n, Chunk_gets, Chunk_frees, Chunk_gets - Chunk_frees, ((Chunk_gets - Chunk_frees) * n) / 1024.); n = BYTES_STRING_BUF; fprintf(fp, "string_buf (%4d) %11u%11u%11u%9.1f K\n", n, String_buf_gets, String_buf_frees, String_buf_gets - String_buf_frees, ((String_buf_gets - String_buf_frees) * n) / 1024.); } /* fprint_strbuf_mem */ /************* * * p_strbuf_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the strbuf package. */ /* PUBLIC */ void p_strbuf_mem() { fprint_strbuf_mem(stdout, 1); } /* p_strbuf_mem */ /* * end of memory management */ /************* * * String_buf init_string_buf() * *************/ /* DOCUMENTATION This routine allocates and returns a String_buf, initialized to string s. Don't forget to call zap_string_buf(sb) when finished with it. Also see get_string_buf(). */ /* PUBLIC */ String_buf init_string_buf(char *s) { String_buf p = get_string_buf(); sb_append(p, s); return(p); } /* init_string_buf */ /************* * * fprint_sb() * *************/ /* DOCUMENTATION This routine prints String_buf sb to FILE *fp. */ /* PUBLIC */ void fprint_sb(FILE *fp, String_buf sb) { Chunk h = sb->first; int i = 0; while (i < sb->size) { fprintf(fp, "%c", h->s[i % CHUNK]); i++; if (i % CHUNK == 0) h = h->next; } } /* fprint_sb */ /************* * * p_sb() * *************/ /* DOCUMENTATION This routine prints String_buf sb, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_sb() instead. */ /* PUBLIC */ void p_sb(String_buf sb) { fprint_sb(stdout, sb); printf("\n"); fflush(stdout); } /* p_sb */ /************* * * sb_append() * *************/ /* DOCUMENTATION This routine appends string s to String_buf sb. The NULL character that marks the end of s does not go into the String_buf. */ /* PUBLIC */ void sb_append(String_buf sb, char *s) { int i; int n = sb->size; Chunk last = sb->first; while (last != NULL && last->next != NULL) last = last->next; for (i = 0; s[i] != '\0'; i++) { if (n % CHUNK == 0) { Chunk new = get_chunk(); if (last != NULL) last->next = new; else sb->first = new; last = new; } last->s[n % CHUNK] = s[i]; n++; } sb->size = n; } /* sb_append */ /************* * * sb_append_char() * *************/ /* DOCUMENTATION This routine appends character c to String_buf sb. */ /* PUBLIC */ void sb_append_char(String_buf sb, char c) { char s[2]; s[0] = c; s[1] = '\0'; sb_append(sb, s); } /* sb_append_char */ /************* * * sb_char() * *************/ /* DOCUMENTATION This routine returns the n-th character (counting from 0) of String_buf sb. If index n is out of range, the NULL character '\0' is returned. */ /* PUBLIC */ char sb_char(String_buf sb, int n) { if (n < 0 || n >= sb->size) return '\0'; else { Chunk h = sb->first; int i; for (i = 0; i < n / CHUNK; i++) h = h->next; return h->s[n % CHUNK]; } } /* sb_char */ /************* * * sb_cat_copy() * *************/ /* DOCUMENTATION This routine appends a copy of sb2 to sb1. String_buf sb2 is not changed. You can use sb_cat() instead if you won't be needing sb2. */ /* PUBLIC */ void sb_cat_copy(String_buf sb1, String_buf sb2) { /* Note that this is inefficient if there are many chunks in either sb. */ int i; char c; for (i = 0; (c = sb_char(sb2, i)); i++) sb_append_char(sb1, c); } /* sb_cat_copy */ /************* * * sb_cat() * *************/ /* DOCUMENTATION This routine appends a copy of sb2 to sb1, then deallocates sb2. Do not refer to sb2 after calling this rouine because it won't exist. You can use sb_cat_copy() instead if you need to save sb2. */ /* PUBLIC */ void sb_cat(String_buf sb1, String_buf sb2) { sb_cat_copy(sb1, sb2); zap_string_buf(sb2); } /* sb_cat */ /************* * * zap_string_buf() * *************/ /* DOCUMENTATION This routine deallocates a String_buf and frees all memory associated with it. */ /* PUBLIC */ void zap_string_buf(String_buf sb) { Chunk curr, prev; curr = sb->first; while (curr != NULL) { prev = curr; curr = curr->next; free_chunk(prev); } free_string_buf(sb); } /* zap_string_buf */ /************* * * sb_to_new_string() * *************/ /* DOCUMENTATION This routine returns a new, ordinary C string corresponding to the String_buf argument sb. WARNING: the new string, say s, is dynamically allocated (malloced), so don't forget to call the system routine free(s) when you are finished with the string. (This routine is not intended for printing String_bufs; use fprint_sb() instead.)

String_bufs do not have a NULL character marking the end; instead, they keep a count of the number of characters. */ /* PUBLIC */ char *sb_to_new_string(String_buf sb) { char *s = malloc(sb->size + 1); if (s == NULL) return NULL; else { int i; for (i = 0; i < sb->size; i++) s[i] = sb_char(sb, i); s[sb->size] = '\0'; return s; } } /* sb_to_new_string */ /************* * * sb_size() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int sb_size(String_buf sb) { return sb->size; } /* sb_size */ LADR-2009-11A/ladr/save/printing0000644000175000017500000001056310156414076015464 0ustar mccunemccune/************* * * fwrite_clause_jmap() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void fwrite_clause_jmap(FILE *fp, Clause c, BOOL print_id_just, BOOL justification_last, Ilist map) { Term t = clause_to_term(c); char a[10]; if (t == NULL) fatal_error("fwrite_clause_jmap, clause_to_term returns NULL."); if (!print_id_just) fwrite_term_nl(fp, t); else if (!justification_last) { fprintf(fp, "%d%s ", jmap1(map, c->id), jmap2(map, c->id, a)); fprint_just(fp, c->justification, map); fprintf(fp, " "); fwrite_term_nl(fp, t); } else { fprintf(fp, "%d%s ", jmap1(map, c->id), jmap2(map, c->id, a)); fwrite_term(fp, t); fprintf(fp, ". "); fprint_just(fp, c->justification, map); fprintf(fp, "\n"); } fflush(fp); zap_term(t); } /* fwrite_clause_jmap */ /************* * * fprint_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void fprint_res_just(FILE *fp, Ilist p, Ilist map) { char a[10]; Ilist q; fprintf(fp, "(%d%s", jmap1(map, p->i), jmap2(map, p->i, a)); for (q = p->next; q != NULL; q = q->next->next->next) { int nuc_lit = q->i; int sat_id = q->next->i; int sat_lit = q->next->next->i; fprintf(fp, " %c", itoc(nuc_lit)); if (sat_id == 0) fprintf(fp, " xx"); else { fprintf(fp, " %d%s", jmap1(map, sat_id), jmap2(map, sat_id, a)); if (sat_lit > 0) fprintf(fp, " %c", itoc(sat_lit)); else fprintf(fp, " %c_flip", itoc(-sat_lit)); } } fprintf(fp, ")"); fflush(fp); } /* fprint_res_just */ /************* * * fprint_position() * *************/ static void fprint_position(FILE *fp, Ilist p) { Ilist q; fprintf(fp, "(%c", itoc(p->i)); for (q = p->next; q != NULL; q = q->next) { fprintf(fp, " %d", q->i); } fprintf(fp, ")"); fflush(fp); } /* fprint_position */ /************* * * fprint_just() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void fprint_just(FILE *fp, Just just, Ilist map) { char a[10]; Just g = just; fprintf(fp, "["); while (g != NULL) { Just_type rule = g->type; if (rule == INPUT_JUST || rule == CLAUSIFY_JUST) fprintf(fp, "%s", jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { fprintf(fp, "%s ", jstring(g)); fprint_res_just(fp, g->u.lst, map); } else if (rule == DEMOD_JUST) { fprintf(fp, "%s ", jstring(g)); fprint_ilist(fp, g->u.lst); } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; int n = p->i; int id = p->next->i; if (n < 0) /* flipped equality */ fprintf(fp, "%s (%c_flip %d%s)", jstring(g), itoc(-n), jmap1(map, id), jmap2(map, id, a)); else fprintf(fp, "%s (%c %d%s)", jstring(g), itoc(n), jmap1(map, id), jmap2(map, id, a)); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; fprintf(fp, "%s (%d%s %c %c)", jstring(g), jmap1(map, p->i), jmap2(map, p->i, a), itoc(p->next->i), itoc(p->next->next->i)); } else if (rule == XXRES_JUST) { Ilist p = g->u.lst; fprintf(fp, "%s (%d%s %c)", jstring(g), jmap1(map, p->i), jmap2(map, p->i, a), itoc(p->next->i)); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == COPY_JUST) fprintf(fp, "%s %d%s", jstring(g), jmap1(map, g->u.id), jmap2(map, g->u.id, a)); else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST) fprintf(fp, "%s %c", jstring(g), itoc(g->u.id)); else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; fprintf(fp, "%s (%d%s ", jstring(g), jmap1(map, p->from_id), jmap2(map, p->from_id, a)); fprint_position(fp, p->from_pos); fprintf(fp, " %d%s ", jmap1(map, p->into_id), jmap2(map, p->into_id, a)); fprint_position(fp, p->into_pos); fprintf(fp, ")"); } else { printf("\nunknown rule: %d\n", rule); fatal_error("fprint_just: unknown rule"); } g = g->next; } fprintf(fp, "]"); } /* fprint_just */ LADR-2009-11A/ladr/save/parse.c0000644000175000017500000007505610140316557015173 0ustar mccunemccune#include "parse.h" /* TO DO * 1. term_to_terms should not have to call binary_parse_type and * sn_to_str when backtracking. Store that info in pterm. * 2. less use of strbuf? * 3. DONE. Keep allowing applications without parens? NO * 4. think about check_arity. * 5. reduce some term copying? * 6. less space on output? * 7. more parens on output? * 8. another symbol type for single-character tokens? (comma, single quote) */ /* Private definitions and types */ /* Token types */ typedef enum {TOK_UNKNOWN, /* probably a garbage binary char */ TOK_NAME, /* see name_char() */ TOK_SYMBOL, /* see symbol_char() */ TOK_STRING, /* see quote_char() */ TOK_COMMENT, /* see comment_char() */ TOK_PUNC /* see punctutation_char() */ } Toktype; /* Return codes from read_buf() */ typedef enum {READ_BUF_OK,READ_BUF_EOF, READ_BUF_ERROR,READ_BUF_QUOTE_ERROR} Read_rc; /* A list of tokens */ typedef struct token * Token; struct token { Toktype type; char c; /* for punctuation & unknown tokens */ String_buf sb; /* for other tokens */ int buf_pos; /* position of this token in buffer */ Token next; }; /* A list of terms with some other data. */ typedef struct pterm * Pterm; struct pterm { Term t; int possible_application; /* avoids "a b" being parsed as a(b) */ Pterm prev, next; }; /* Token position */ typedef struct tok_pos *Tok_pos; struct tok_pos { Token tok; char *error_message; }; /* Private variables */ static BOOL Translate_neg_equalities = FALSE; /* * memory management */ static unsigned Token_gets, Token_frees; static unsigned Pterm_gets, Pterm_frees; #define BYTES_TOKEN sizeof(struct token) #define PTRS_TOKEN BYTES_TOKEN%BPP == 0 ? BYTES_TOKEN/BPP : BYTES_TOKEN/BPP + 1 #define BYTES_PTERM sizeof(struct pterm) #define PTRS_PTERM BYTES_PTERM%BPP == 0 ? BYTES_PTERM/BPP : BYTES_PTERM/BPP + 1 /************* * * Token get_token() * *************/ static Token get_token(void) { Token p = get_mem(PTRS_TOKEN); Token_gets++; return(p); } /* get_token */ /************* * * free_token() * *************/ static void free_token(Token p) { free_mem(p, PTRS_TOKEN); Token_frees++; } /* free_token */ /************* * * Pterm get_pterm() * *************/ static Pterm get_pterm(void) { Pterm p = get_mem(PTRS_PTERM); Pterm_gets++; return(p); } /* get_pterm */ /************* * * free_pterm() * *************/ static void free_pterm(Pterm p) { free_mem(p, PTRS_PTERM); Pterm_frees++; } /* free_pterm */ /************* * * fprint_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the parse package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_parse_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_TOKEN; fprintf(fp, "token (%4d) %11u%11u%11u%9.1f K\n", n, Token_gets, Token_frees, Token_gets - Token_frees, ((Token_gets - Token_frees) * n) / 1024.); n = BYTES_PTERM; fprintf(fp, "pterm (%4d) %11u%11u%11u%9.1f K\n", n, Pterm_gets, Pterm_frees, Pterm_gets - Pterm_frees, ((Pterm_gets - Pterm_frees) * n) / 1024.); } /* fprint_parse_mem */ /************* * * p_parse_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the parse package. */ /* PUBLIC */ void p_parse_mem() { fprint_parse_mem(stdout, TRUE); } /* p_parse_mem */ /* * end of memory management */ /************* * * translate_neg_equalities() * *************/ /* DOCUMENTATION This routine sets or clears the flag which tells the parser to automatically translate alpha!=beta to ~(alpha=beta). This happens in read_term(), which is called by read_clause(), read_formula(), and read_term_list(). */ /* PUBLIC */ void translate_neg_equalities(BOOL flag) { Translate_neg_equalities = flag; } /* translate_neg_equalities */ /************* * * translate_neg_eq() * *************/ static Term translate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = translate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), NEQ_SYM, 2)) { Term eq_term = get_rigid_term(EQ_SYM, 2); Term not_term = get_rigid_term(NOT_SYM, 1); ARG(eq_term,0) = ARG(t, 0); ARG(eq_term,1) = ARG(t, 1); ARG(not_term,0) = eq_term; free_term(t); t = not_term; } } return t; } /* translate_neg_eq */ /************* * * untranslate_neg_eq() * *************/ static Term untranslate_neg_eq(Term t) { if (t != NULL && COMPLEX(t)) { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = untranslate_neg_eq(ARG(t,i)); if (is_symbol(SYMNUM(t), NOT_SYM, 1) && is_symbol(SYMNUM(ARG(t,0)), EQ_SYM, 2)) { Term neq_term = get_rigid_term(NEQ_SYM, 2); ARG(neq_term,0) = ARG(ARG(t,0), 0); ARG(neq_term,1) = ARG(ARG(t,0), 1); free_term(ARG(t,0)); free_term(t); t = neq_term; } } return t; } /* untranslate_neg_eq */ /************* * * free_pterm_list() * *************/ static void free_pterm_list(Pterm p) { Pterm p1; while (p != NULL) { if (p->t != NULL) zap_term(p->t); p1 = p; p = p->next; free_pterm(p1); } } /* free_pterm_list */ /************* * * free_token_list() * *************/ static void free_token_list(Token p) { Token p1; while (p != NULL) { p1 = p; p = p->next; if (p1->sb != NULL) zap_string_buf(p1->sb); free_token(p1); } } /* free_token_list */ /************* * * end_char() * *************/ static BOOL end_char(char c) { return (c == '.'); } /* end_char */ /************* * * comment_char() * *************/ static BOOL comment_char(char c) { return (c == '%'); } /* comment_char */ /************* * * quote_char() * *************/ static BOOL quote_char(char c) { return (c == '\"'); } /* quote_char */ /************* * * punctuation_char() * *************/ static BOOL punctuation_char(char c) { return (c == ',' || c == ':' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '.'); } /* punctuation_char */ /************* * * name_char() * *************/ static BOOL name_char(char c) { return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$'); } /* name_char */ /************* * * symbol_char(c) * *************/ static BOOL symbol_char(char c) { /* This allows us to have special chars in the list below. */ if (quote_char(c) || end_char(c) || comment_char(c)) return 0; else return (c == '+' || c == '-' || c == '*' || c == '/' || c == '\\' || c == '^' || c == '<' || c == '>' || c == '=' || c == '`' || c == '~' || c == '?' || c == '@' || c == '&' || c == '|' || c == '!' || c == '#' || c == '%' || c == '\'' || c == '\"' || c == '.' || c == ';' ); } /* symbol_char */ /************* * * white_char() * *************/ static BOOL white_char(char c) { return (c == ' ' || c == '\t' || /* tab */ c == '\n' || /* newline */ c == '\v' || /* vertical tab */ c == '\r' || /* carriage return */ c == '\f'); /* form feed */ } /* white_char */ /************* * * white_or_comment() * *************/ static BOOL white_or_comment(String_buf sb) { int i = 0; BOOL ok = TRUE; int n = sb_size(sb); while (ok && i < n) { char c = sb_char(sb, i); if (white_char(c)) i++; else if (comment_char(c)) { /* skip over comment */ i++; while (i < n && sb_char(sb, i) != '\n') i++; if (i < n) i++; } else ok = FALSE; } return ok; } /* white_or_comment */ /************* * * read_buf() * * Read characters into buffer until one of the following: * 1. END_CHAR is reached (which goes into the buffer) * (except if in quoted string or comment). * 2. EOF is reached (everything still goes into buffer). * * Return: * READ_BUF_OK * READ_BUF_EOF possible white space or comment, then EOF * READ_BUF_ERROR non-white space, noncomment then EOF * READ_BUF_QUOTE_ERROR no end to quoted string (EOF) * *************/ static int read_buf(FILE *fp, String_buf sb) { int c, end, eof, eof_q; end = eof = eof_q = 0; /* stop conditions */ while (!end && !eof && !eof_q) { c = getc(fp); if (c == EOF) eof = 1; else { sb_append_char(sb, c); if (end_char(c)) end = 1; else if (quote_char(c)) { int qc = c; c = getc(fp); while (c != qc && c != EOF) { sb_append_char(sb, c); c = getc(fp); } if (c == EOF) eof_q = 1; else sb_append_char(sb, c); } else if (comment_char(c)) { c = getc(fp); while (c != '\n' && c != EOF) { sb_append_char(sb, c); c = getc(fp); } if (c == EOF) eof = 1; else sb_append_char(sb, c); } } } if (end) return READ_BUF_OK; else if (eof_q) return READ_BUF_QUOTE_ERROR; else { /* eof */ if (white_or_comment(sb)) return READ_BUF_EOF; else return READ_BUF_ERROR; } } /* read_buf */ /************* * * tokenize() * * Break up a string into a sequence of tokens. * *************/ static Token tokenize(String_buf sb) { int i = 0; char c = sb_char(sb, i); Token first, last, tok; first = last = NULL; while (!end_char(c) && c != '\0') { tok = get_token(); /* delete if not needed, i.e., white space */ tok->buf_pos = i; /* Make sure that each case, when finished, sets c to the next char. */ if (white_char(c)) { do { c = sb_char(sb, ++i); } while (white_char(c)); free_token(tok); tok = NULL; } else if (punctuation_char(c)) { tok->type = TOK_PUNC; tok->c = c; c = sb_char(sb, ++i); } else if (name_char(c)) { tok->type = TOK_NAME; tok->sb = get_string_buf(); while (name_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (symbol_char(c)) { tok->type = TOK_SYMBOL; tok->sb = get_string_buf(); while (symbol_char(c)) { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (comment_char(c)) { tok->type = TOK_COMMENT; tok->sb = get_string_buf(); while (c != '\n' && c != '\0') { sb_append_char(tok->sb, c); c = sb_char(sb, ++i); } } else if (quote_char(c)) { char qc = c; tok->type = TOK_STRING; tok->sb = get_string_buf(); sb_append_char(tok->sb, c); do { c = sb_char(sb, ++i); sb_append_char(tok->sb, c); } while (c != qc && c != '\0'); if (c == qc) c = sb_char(sb, ++i); } else { tok->type = TOK_UNKNOWN; tok->c = c; c = sb_char(sb, ++i); } if (tok != NULL) { if (first == NULL) first = tok; else last->next = tok; last = tok; } } /* while */ return first; } /* tokenize */ /************* * * comma_terms() * *************/ static int comma_terms(Term t) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) return 1; else return comma_terms(t->args[0]) + comma_terms(t->args[1]); } /* comma_terms */ /************* * * transfer_comma_term() * *************/ static void transfer_comma_term(Term t, Term dest, int *p) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { dest->args[*p] = copy_term(t); (*p)++; } else { transfer_comma_term(t->args[0], dest, p); transfer_comma_term(t->args[1], dest, p); } } /* transfer_comma_term */ /************* * * quantifier() * *************/ static BOOL quantifier(Term t) { return (is_symbol(SYMNUM(t), ALL_SYM, 0) || is_symbol(SYMNUM(t), EXISTS_SYM, 0)); } /* quantifier */ /* reference for mutual recursion */ static Term terms_to_term(Pterm start, Pterm end, int m); /************* * * terms_to_quant_term() * * Try to build a quantified term from a sequence of terms. * A quantified term is like this $quantified([all,x,all,y,exists,z,term]). * Why the "$quantified"? Because we wish * to recognize it as a special term for printing and transformations. * Note that, different from previous versions, each variable needs * its own quantifier. * *************/ static Term terms_to_quant_term(Pterm start, Pterm end) { Pterm curr = start; int vars_ok = 1; while (curr != NULL && quantifier(curr->t) && vars_ok) { curr = curr->next; if (curr != NULL && ARITY(curr->t) == 0) curr = curr->next; else vars_ok = 0; } if (vars_ok && curr != NULL) { Term formula = terms_to_term(curr, end, 1000); if (formula == NULL) return NULL; else { /* We have a good quantifier prefix and formula. * Build and return the quantified term. */ Pterm p; Term q = get_rigid_term("$quantified", 1); Term t = get_nil_term(); /* build list from the back */ t = listterm_cons(formula, t); for (p = curr->prev; p != NULL; p = p->prev) { t = listterm_cons(copy_term(p->t), t); } q->args[0] = t; return q; } } else return NULL; } /* terms_to_quant_term */ /************* * * terms_to_term() * * This routine attempts to construct a term * starting with start, ending with end, with precedence <= m. * On success, the resulting term is an entirely new copy. * *************/ static Term terms_to_term(Pterm start, Pterm end, int m) { if (start == end) { if (is_symbol(SYMNUM(start->t), ",", 0)) return NULL; /* don't allow commas as constants */ else return copy_term(start->t); } else { int rc, prec; Parsetype type; char *str; /* Try for prefix op; return if successful. */ if (ARITY(start->t) == 0) { str = sn_to_str(SYMNUM(start->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == PREFIX_PAREN || type == PREFIX)) { int p = (type == PREFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start->next, end, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); t->args[0] = t1; return t; } } } /* Try for postfix op; return if successful. */ if (ARITY(end->t) == 0) { str = sn_to_str(SYMNUM(end->t)); rc = unary_parse_type(str, &prec, &type); if (rc && prec <= m && (type == POSTFIX_PAREN || type == POSTFIX)) { int p = (type == POSTFIX_PAREN ? prec-1 : prec); Term t1 = terms_to_term(start, end->prev, p); if (t1 != NULL) { Term t = get_rigid_term(str, 1); t->args[0] = t1; return t; } } } /* Try for an application; return if successful. */ if (start->next == end && end->possible_application && ARITY(start->t) == 0 && !is_symbol(SYMNUM(start->t), ",", 0)) { Term t; int arity = comma_terms(end->t); int argnum = 0; t = get_rigid_term(sn_to_str(SYMNUM(start->t)), arity); transfer_comma_term(end->t, t, &argnum); return t; } /* Try for quantified formula; return if successful. * Allow this only if we are not in a recursive call. */ if (start->next != end && m == 1000) { if (quantifier(start->t)) { Term t = terms_to_quant_term(start, end); if (t != NULL) return t; } } /* Try for infix op; return if successful. */ if (start->next != end) { /* Try each possible infix op, until success or exhausted. */ Pterm op; int backward = 0; /* If we parse a long left-associated expression left-to-right, * it ends up trying all the different associations before finding * the correct one. Therefore, as a heuristic, if the second * symbol is INFIX_LEFT, then we try to parse backward. This * doesn't always work well, for example, with & right and + left, * a&...&a -> a+...+a (symmetric shape) is slow both forward * and backward. To speed things up, the user can include * parentheses, i.e., (a&...&a) -> (a+...+a). */ if (ARITY(start->next->t) == 0) { str = sn_to_str(SYMNUM(start->next->t)); rc = binary_parse_type(str, &prec, &type); backward = (rc && type == INFIX_LEFT); } op = (backward ? end->prev : start->next); while (backward ? op != start : op != end) { if (ARITY(op->t) == 0) { str = sn_to_str(SYMNUM(op->t)); rc = binary_parse_type(str, &prec, &type); if (rc && prec <= m) { Term t1, t2; int p1 = (type == INFIX || type == INFIX_RIGHT ? prec-1 : prec); int p2 = (type == INFIX || type == INFIX_LEFT ? prec-1 : prec); t1 = terms_to_term(start, op->prev, p1); if (t1 != NULL) { t2 = terms_to_term(op->next, end, p2); if (t2 == NULL) zap_term(t1); else { Term t = get_rigid_term(str, 2); t->args[0] = t1; t->args[1] = t2; return t; } } } } /* arity 0 */ op = (backward ? op->prev : op->next); } /* while (binary attempts) */ } /* nothing works */ return NULL; } /* start != end */ } /* terms_to_term */ /************* * * next_token() * * This routine is called when it's time to move to the next token. * The current token (including any sb) is deleted. Don't call this * routine if an error is found; instead, set the error message ane * return NULL (from whereever you are). * *************/ static void next_token(Tok_pos p) { Token tok = p->tok; p->tok = p->tok->next; if (tok->sb != NULL) zap_string_buf(tok->sb); free_token(tok); } /* next_token */ /* reference for mutual recursion */ static Term toks_to_term(Tok_pos p); /************* * * toks_to_set() * *************/ static Term toks_to_set(Tok_pos p) { p->error_message = "set parsing not done"; return NULL; } /* toks_to_set */ /************* * * make_a_list() * * Prepend, to tail, copies of comma-elements in t. * *************/ static Term make_a_list(Term t, Term tail) { if (ARITY(t) == 0 || !is_symbol(SYMNUM(t), ",", 2)) { return listterm_cons(copy_term(t), tail); } else { Term l = make_a_list(t->args[1], tail); return make_a_list(t->args[0], l); } } /* make_a_list */ /************* * * toks_to_list() * * On entry, current token is [. * On successful exit, current token should be ]. * *************/ static Term toks_to_list(Tok_pos p) { /* Assume current token is "[". */ next_token(p); if (p->tok != NULL && p->tok->c == ']') { return get_nil_term(); } else { Term cterm = toks_to_term(p); /* a comma-term */ if (cterm == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || (p->tok->c != ']' && p->tok->c != ':')) { p->error_message = "\']\' or \':\' expected in list"; zap_term(cterm); return NULL; } else if (p->tok->type == TOK_PUNC && p->tok->c == ':') { Term tail; next_token(p); tail = toks_to_term(p); if (tail == NULL) return NULL; else if (p->tok == NULL || p->tok->type != TOK_PUNC || p->tok->c != ']') { p->error_message = "\']\' expected in list"; zap_term(cterm); zap_term(tail); return NULL; } else { Term list = make_a_list(cterm, tail); zap_term(cterm); return list; } } else { /* current token is ']' */ Term list = make_a_list(cterm, get_nil_term()); zap_term(cterm); return list; } } } /* toks_to_list */ /************* * * toks_to_terms() * *************/ static Pterm toks_to_terms(Tok_pos p) { Term t; int done = 0; int error = 0; int possible_application; int comma_constant; Pterm first = NULL; Pterm last = NULL; Pterm new; while (!done && !error) { possible_application = 0; comma_constant = 0; t = NULL; if (p->tok->type == TOK_NAME || p->tok->type == TOK_SYMBOL || p->tok->type == TOK_STRING ) { char *str = sb_to_new_string(p->tok->sb); t = get_rigid_term(str, 0); free(str); } else if (p->tok->type == TOK_PUNC && p->tok->c == ',') { /* Special case: comma is both punctuation and operator. */ t = get_rigid_term(",", 0); comma_constant = 1; } else if (p->tok->type == TOK_PUNC) { if (p->tok->c == '(') { next_token(p); t = toks_to_term(p); if (t == NULL) error = 1; else if (p->tok == NULL || p->tok->c != ')') { p->error_message = "closing parenthesis expected"; zap_term(t); t = NULL; error = 1; } else possible_application = 1; } else if (p->tok->c == '[') { t = toks_to_list(p); error = (t == NULL); } else if (p->tok->c == '{') { t = toks_to_set(p); error = (t == NULL); } else { /* bad punctuation */ p->error_message = "bad punctuation character"; error = 1; } } else if (p->tok->type == TOK_COMMENT) { ; /* do nothing */ } else if (p->tok->type == TOK_UNKNOWN) { p->error_message = "bad character"; error = 1; } if (t != NULL) { /* Add a node to the terms list. */ new = get_pterm(); new->prev = last; if (first == NULL) first = new; else last->next = new; new->t = t; new->possible_application = possible_application; last = new; } if (!error) { /* */ next_token(p); if (p->tok == NULL) done = 1; else if(p->tok->type == TOK_PUNC && (p->tok->c == ')' || p->tok->c == ']' || p->tok->c == '}' || p->tok->c == ':')) done = 1; } } /* while */ if (error) { free_pterm_list(first); return NULL; } else return first; } /* toks_to_terms */ /************* * * toks_to_term() * *************/ static Term toks_to_term(Tok_pos p) { Term t; Pterm terms; terms = toks_to_terms(p); if (terms == NULL) t = NULL; else { Pterm end; for (end = terms; end->next != NULL; end = end->next); t = terms_to_term(terms, end, 1000); free_pterm_list(terms); if (t == NULL) { p->error_message = "terms/ops could not be combined into a term"; } } return t; } /* toks_to_term */ /************* * * fprint_parse_error() * *************/ static void fprint_parse_error(FILE *fp, char *msg, String_buf sb, int position) { int i; int n = sb_size(sb); fprintf(fp, "Error parsing input string, %s:\n", msg); for (i = 0; i < position; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, " **HERE** "); for (i = position; i < n; i++) fprintf(fp, "%c", sb_char(sb, i)); fprintf(fp, "\n"); } /* fprint_parse_error */ /************* * * sread_term() * *************/ /* DOCUMENTATION This routine reads a term (from String_buf *sb). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term sread_term(String_buf sb, FILE *fout) { Token tokens; Term t; struct tok_pos tp; tokens = tokenize(sb); if (tokens == NULL) fatal_error("sread_term, empty term (too many periods?)"); tp.tok = tokens; tp.error_message = ""; t = toks_to_term(&tp); if (t == NULL || tp.tok != NULL) { int pos; if (t != NULL) tp.error_message = "characters after complete term"; pos = (tp.tok != NULL ? tp.tok->buf_pos : sb_size(sb)-1); fprint_parse_error(fout, tp.error_message, sb, pos); free_token_list(tp.tok); fatal_error("sread_term error"); } return t; } /* sread_term */ /************* * * read_term() * *************/ /* DOCUMENTATION This routine reads a term (from FILE *fin). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ Term read_term(FILE *fin, FILE *fout) { Read_rc rc; String_buf sb = get_string_buf(); rc = read_buf(fin, sb); if (rc == READ_BUF_EOF) { zap_string_buf(sb); return NULL; } else if (rc != READ_BUF_OK) { char *msg; switch (rc) { case READ_BUF_ERROR: msg = "EOF found while reading term (missing period?)"; break; case READ_BUF_QUOTE_ERROR: msg = "EOF found while reading quoted string"; break; default: msg = "error reading characters from file"; break; } fprint_parse_error(fout, msg, sb, sb_size(sb)); zap_string_buf(sb); fatal_error("read_term error"); return NULL; /* to please the complier */ } else { Term t = sread_term(sb, fout); zap_string_buf(sb); if (Translate_neg_equalities) t = translate_neg_eq(t); return t; } } /* read_term */ /************* * * quantified_term() * *************/ static BOOL quantified_term(Term t) { return (COMPLEX(t) && is_symbol(SYMNUM(t), "$quantified", 1) && listterm_length(t->args[0]) >= 3); } /* quantified_term */ /************* * * arrange_term() * *************/ static void arrange_term(String_buf sb, Term t, int par_prec) { if (t == NULL) sb_append(sb, "arrange_term gets NULL term"); else if (VARIABLE(t)) { char str[100]; if (variable_style() == INTEGER_STYLE) sprintf(str, "%d", VARNUM(t)); else if (variable_style() == PROLOG_STYLE) { /* A,B,C,D,E,F,V6,V7,V8,... */ if (VARNUM(t) < 6) sprintf(str, "%c", 'A' + VARNUM(t)); else sprintf(str, "V%d", VARNUM(t)); } else { /* x,y,z,u,v,w,v6,v7,v8,... */ if (VARNUM(t) < 3) sprintf(str, "%c", 'x' + VARNUM(t)); else if (VARNUM(t) < 6) sprintf(str, "%c", 'r' + VARNUM(t)); else sprintf(str, "v%d", VARNUM(t)); } sb_append(sb, str); } /* variable */ else if (CONSTANT(t)) { if (nil_term(t)) sb_append(sb, "[]"); else sb_append(sb, sn_to_str(SYMNUM(t))); } /* constant */ else if (quantified_term(t)) { Term t1 = t->args[0]; sb_append(sb, "("); while (cons_term(t1->args[1])) { arrange_term(sb, t1->args[0], 1000); sb_append(sb, " "); t1 = t1->args[1]; } sb_append(sb, "("); arrange_term(sb, t1->args[0], 1000); sb_append(sb, ")"); sb_append(sb, ")"); } /* quantified */ else if (cons_term(t)) { Term t1 = t; sb_append(sb, "["); while (cons_term(t1)) { arrange_term(sb, t1->args[0], 1000); t1 = t1->args[1]; if (cons_term(t1)) sb_append(sb, ","); } if (!nil_term(t1)) { sb_append(sb, ":"); arrange_term(sb, t1, 1000); } sb_append(sb, "]"); } /* cons_term */ else { Parsetype type; int op_prec; if (ARITY(t) == 2 && binary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = (type == INFIX || type == INFIX_RIGHT ? op_prec-1 : op_prec); int p2 = (type == INFIX || type == INFIX_LEFT ? op_prec-1 : op_prec); if (op_prec > par_prec) sb_append(sb, "("); arrange_term(sb, t->args[0], p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, t->args[1], p2); if (op_prec > par_prec) sb_append(sb, ")"); } /* binary infix */ else if (ARITY(t) == 1 && unary_parse_type(sn_to_str(SYMNUM(t)), &op_prec, &type)) { int p1 = (type == PREFIX_PAREN || type == POSTFIX_PAREN ? op_prec-1 : op_prec); if (op_prec > par_prec) sb_append(sb, "("); if (type == PREFIX_PAREN || type == PREFIX) { sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, " "); arrange_term(sb, t->args[0], p1); } /* prefix */ else { arrange_term(sb, t->args[0], p1); sb_append(sb, " "); sb_append(sb, sn_to_str(SYMNUM(t))); } /* postfix */ if (op_prec > par_prec) sb_append(sb, ")"); } /* unary prefix or postfix */ else { /* ordinary application */ int i; sb_append(sb, sn_to_str(SYMNUM(t))); sb_append(sb, "("); for (i = 0; i < ARITY(t); i++) { arrange_term(sb, t->args[i], 1000); if (i < ARITY(t)-1) sb_append(sb, ","); } sb_append(sb, ")"); } /* ordinary application */ } } /* arrange_term */ /************* * * fwrite_term() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term(FILE *fp, Term t) { String_buf sb = get_string_buf(); if (Translate_neg_equalities) { Term temp_term = untranslate_neg_eq(copy_term(t)); arrange_term(sb, temp_term, 1000); zap_term(temp_term); } else arrange_term(sb, t, 1000); fprint_sb(fp, sb); zap_string_buf(sb); } /* fwrite_term */ /************* * * fwrite_term_nl() * *************/ /* DOCUMENTATION This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. Also printed is ".\n".

See the documentation on mixfix terms and the routine set_parse_type(). */ /* PUBLIC */ void fwrite_term_nl(FILE *fp, Term t) { fwrite_term(fp, t); fprintf(fp, ".\n"); } /* fwrite_term_nl */ /************* * * declare_standard_parse_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_standard_parse_types(void) { set_parse_type(",", 999, INFIX_RIGHT); /* essential */ set_parse_type(ATTRIB_SYM, 810, INFIX_RIGHT); set_parse_type(IFF_SYM, 800, INFIX); set_parse_type(IMP_SYM, 800, INFIX); set_parse_type(IMPBY_SYM, 800, INFIX); set_parse_type(OR_SYM, 790, INFIX_RIGHT); set_parse_type(AND_SYM, 780, INFIX_RIGHT); set_parse_type(EQ_SYM, 700, INFIX); set_parse_type(NEQ_SYM, 700, INFIX); set_parse_type("==", 700, INFIX); set_parse_type("<", 700, INFIX); set_parse_type("<=", 700, INFIX); set_parse_type(">", 700, INFIX); set_parse_type(">=", 700, INFIX); set_parse_type("+", 600, INFIX); set_parse_type("*", 500, INFIX); set_parse_type("/", 500, INFIX); set_parse_type("\\", 500, INFIX); set_parse_type("^", 500, INFIX); set_parse_type("v", 500, INFIX); set_parse_type(NOT_SYM, 400, PREFIX); set_parse_type("\'", 300, POSTFIX); } /* declare_standard_parse_types */ LADR-2009-11A/ladr/save/detach.o0000644000175000017500000005271010150667504015317 0ustar mccunemccuneELF\P4( U‰åVS‹]¾ƒì SèüÿÿÿƒÄ…Àt,ƒì SèüÿÿÿƒÄ…Àt‹C‹@€xu‹@‹€xu¾‰ðeø[^]ÉöU‰åWVSƒì ‹U‹B‹@‹@‹‹@‹0‹@‰Eì‹U ‹B‹@‹@‹èüÿÿÿ‰Çèüÿÿÿ‰EèÇEðƒì EðPÿuèSWVèüÿÿÿƒÄ …Àt}ƒì ‹U ‹Bÿpèüÿÿÿ‰ÃƒÄSjèüÿÿÿ‰ÆƒÄWÿuìèüÿÿÿ‹S‰èüÿÿÿ‰ÃƒÄVSèüÿÿÿƒÄÿu ÿuèüÿÿÿ‰C‰$ÿuèÿu WÿuèüÿÿÿƒÄÿuðèüÿÿÿ‰$èüÿÿÿƒÄ뻃ì WèüÿÿÿƒÄÿuèèüÿÿÿ‰Øeô[^_]ÃU‰åVS‹u‹] ƒì Vè˜þÿÿƒÄ…Àt+ƒì SèˆþÿÿƒÄ…ÀtƒìSVèËþÿÿƒÄ…Àt ƒì PÿUƒÄeø[^]ÃvU‰åWVSƒì‹]‹u ‹}WVSèüÿÿÿƒÄ9ótƒìWSVèüÿÿÿƒÄeô[^_]Ã01.01ì6 d%d.<=€g€€°€è€%€v€Ç€ò€!€K€t€Ž€©€Ê€€&€K€u€ž‚§‚®‚¹‚‚ʂтۂä‚í‚õ‚þ‚‚+‚¢D‚¢¢]‚–€Ç¢«‚Å‚¢Ý‚¢€ .€!F€"\€#s€%Œ€&£€1»€2Ô€3ì€4€5€69€8R€9l€;€=§€>¿€?×€@ï€A€B"€C9€DR€Ei€F‚€G›€H¶€IÍ€N8€QQ€Rs€S‹€T§€UÄ€VÝ€Xö€[ €^* €eA €h\ €lw €q‘ €r® €uË €vê €y €z& €}@ €€[ €ƒw €„” €‡® €ŠÉ ‚ê ‚ €¢: €ƒ €# €È €4æ €<7 €Cq €FŽ €S%€Ze€^ƒ€Œ¢¢œ€-¼€7Ò‚ç‚‚¢‚S€i€8¢~‚“‚¢Ì‚¢æ€K¢j€°€#ø‚ ‚¢%‚:‚¢s‚¢¢‚¢Æ€¥€Ü€H€K5€Lf€U™€ZÔ€^ €aE€b}€*€Õ€Ë€D€­¢h€5Þ€7÷€8€9+€:¢F‚€+¢€ª·€€y€J€Ab€X‰€a±€iÖ€l¢ü€P‚¢0‚¢¢J‚`‚¢x‚¢±€bê€j$‚=‚¢U‚¢o€"…€#œ€$±€%Ç€&Ý€'õ€( €-# €19 €=P €Bg €G €L˜ €Q¯ €WÆ €cÝ €hó €m !€s%!€t>!€zU!‚i!‚¢ƒ!€Fš!‚¢´!€RÎ!‚¢è!€^¢"‚¢9"€–N"€—d"€˜x"€¾"€¿¦"€À½"€ÁÔ"€Äí"€Å#€Æ#€Ç8#€ÉR#‚h#‚¢€#‚¢¢›#‚µ#‚¢Í#‚¢ç#‚¢$‚$€:$€¢ƒ$€&›$‚¯$€¢ì$‚%‚¢%€¢]%€1y%€7‘%€JÜ%€Q¢ó%‚¢&€æ*&€êF&€î¢b&€'€š'‚°'‚¢È'‚¢¢(€¨¢/(‚h(‚¤(‚Ý(‚ó(‚¢ )‚*)‚H)‚¢¢¢d)‚¢¢¢¢¢ƒ)‚™)‚¢±)‚¢ê)‚¢*‚!*‚¢7*‚¢Q*‚¢¢¢g*€ƒ*€¢¢—*€¢¢Ã*‚Ì*‚¢Õ*€¢+‚ +‚¢+€|+€¢•+‚+‚¢¦+€ Ì+€þ+€$,€¢U,€È,€'ß,€$-€1=-€r-€8‹-€¿-€>Ø-€.€E1.€[¢[.‚¢c.€@„.€¢¢9/‚D/‚¢¢K/‚T/‚¢]/‚¢d/‚l/‚¢s/€d/€@0€mf0€0€t¢±0€ò0€ 1€"¢>1€ e1€«1€Ð1€¢¢ˆ2€À3€"×3€$4€h4€-z4€¢ì4‚¢ô4‚¢¢ý4$ 5  D DDK5@ $R"5$T05 :5  DD! D"D#D$"D%0D&7D'?D*FD+_D,rD.D/D0—D1¡D2²D3ÄD4ÏD5×D7ÜD9áD:êD;õD<÷D5@!Q5@"^5€#ìÿÿÿi5@$v5@%5€&èÿÿÿ‹5€'ðÿÿÿ•5@(À£5@+¯5@,À_à×à÷$ÿº5$JÎ5 IÛ5 I è5 IDJDO DP+DQ5DR<DSFDTF 6@I6@I$6@PÀ+àF$M.6$bD6 aN6 a X6 aDbDcDdDe!Df/j6@at6@a~6@a$7dÛdetach.c/sandbox/mccune/LADR/ladr/detach.cgcc2_compiled.int:t(0,1)=r(0,1);-2147483648;2147483647;char:t(0,2)=r(0,2);0;127;long int:t(0,3)=r(0,3);-2147483648;2147483647;unsigned int:t(0,4)=r(0,4);0000000000000;0037777777777;long unsigned int:t(0,5)=r(0,5);0000000000000;0037777777777;long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;long long unsigned int:t(0,7)=@s64;r(0,7);0000000000000;01777777777777777777777;short int:t(0,8)=@s16;r(0,8);-32768;32767;short unsigned int:t(0,9)=@s16;r(0,9);0;65535;signed char:t(0,10)=@s8;r(0,10);-128;127;unsigned char:t(0,11)=@s8;r(0,11);0;255;float:t(0,12)=r(0,1);4;0;double:t(0,13)=r(0,1);8;0;long double:t(0,14)=r(0,1);12;0;complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;complex float:t(0,16)=r(0,16);8;0;complex double:t(0,17)=r(0,17);16;0;complex long double:t(0,18)=r(0,18);24;0;__builtin_va_list:t(0,19)=*(0,20)=(0,20)detach.hjust.hclauseid.hclause.htlist.hterm.hsymbols.hstring.hmemory.hfatal.hheader.h/usr/include/stdio.h/usr/include/features.h/usr/include/sys/cdefs.h/usr/include/gnu/stubs.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.hsize_t:t(16,1)=(0,4)/usr/include/bits/types.h/usr/include/features.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h__u_char:t(17,1)=(0,11)__u_short:t(17,2)=(0,9)__u_int:t(17,3)=(0,4)__u_long:t(17,4)=(0,5)__u_quad_t:t(17,5)=(0,7)__quad_t:t(17,6)=(0,6)__int8_t:t(17,7)=(0,10)__uint8_t:t(17,8)=(0,11)__int16_t:t(17,9)=(0,8)__uint16_t:t(17,10)=(0,9)__int32_t:t(17,11)=(0,1)__uint32_t:t(17,12)=(0,4)__int64_t:t(17,13)=(0,6)__uint64_t:t(17,14)=(0,7)__qaddr_t:t(17,15)=(17,16)=*(17,6)__dev_t:t(17,17)=(17,5)__uid_t:t(17,18)=(17,3)__gid_t:t(17,19)=(17,3)__ino_t:t(17,20)=(17,4)__mode_t:t(17,21)=(17,3)__nlink_t:t(17,22)=(17,3)__off_t:t(17,23)=(0,3)__loff_t:t(17,24)=(17,6)__pid_t:t(17,25)=(0,1)__ssize_t:t(17,26)=(0,1)__rlim_t:t(17,27)=(17,4)__rlim64_t:t(17,28)=(17,5)__id_t:t(17,29)=(17,3)__fsid_t:t(17,30)=(17,31)=s8__val:(17,32)=ar(17,33)=r(17,33);0000000000000;0037777777777;;0;1;(0,1),0,64;;__daddr_t:t(17,34)=(0,1)__caddr_t:t(17,35)=(17,36)=*(0,2)__time_t:t(17,37)=(0,3)__useconds_t:t(17,38)=(0,4)__suseconds_t:t(17,39)=(0,3)__swblk_t:t(17,40)=(0,3)__clock_t:t(17,41)=(0,3)__clockid_t:t(17,42)=(0,1)__timer_t:t(17,43)=(0,1)__key_t:t(17,44)=(0,1)__ipc_pid_t:t(17,45)=(0,9)__blksize_t:t(17,46)=(0,3)__blkcnt_t:t(17,47)=(0,3)__blkcnt64_t:t(17,48)=(17,6)__fsblkcnt_t:t(17,49)=(17,4)__fsblkcnt64_t:t(17,50)=(17,5)__fsfilcnt_t:t(17,51)=(17,4)__fsfilcnt64_t:t(17,52)=(17,5)__ino64_t:t(17,53)=(17,5)__off64_t:t(17,54)=(17,24)__t_scalar_t:t(17,55)=(0,3)__t_uscalar_t:t(17,56)=(0,5)__intptr_t:t(17,57)=(0,1)__socklen_t:t(17,58)=(0,4)/usr/include/bits/pthreadtypes.h/usr/include/bits/sched.h__sched_param:T(21,1)=s4__sched_priority:(0,1),0,32;;_pthread_fastlock:T(20,1)=s8__status:(0,3),0,32;__spinlock:(0,1),32,32;;_pthread_descr:t(20,2)=(20,3)=*(20,4)=xs_pthread_descr_struct:__pthread_attr_s:T(20,5)=s36__detachstate:(0,1),0,32;__schedpolicy:(0,1),32,32;__schedparam:(21,1),64,32;__inheritsched:(0,1),96,32;__scope:(0,1),128,32;__guardsize:(16,1),160,32;__stackaddr_set:(0,1),192,32;__stackaddr:(0,19),224,32;__stacksize:(16,1),256,32;;pthread_attr_t:t(20,6)=(20,5)pthread_cond_t:t(20,7)=(20,8)=s12__c_lock:(20,1),0,64;__c_waiting:(20,2),64,32;;pthread_condattr_t:t(20,9)=(20,10)=s4__dummy:(0,1),0,32;;pthread_key_t:t(20,11)=(0,4)pthread_mutex_t:t(20,12)=(20,13)=s24__m_reserved:(0,1),0,32;__m_count:(0,1),32,32;__m_owner:(20,2),64,32;__m_kind:(0,1),96,32;__m_lock:(20,1),128,64;;pthread_mutexattr_t:t(20,14)=(20,15)=s4__mutexkind:(0,1),0,32;;pthread_once_t:t(20,16)=(0,1)pthread_t:t(20,17)=(0,5)FILE:t(12,1)=(12,2)=xs_IO_FILE:__FILE:t(12,3)=(12,2)/usr/include/libio.h/usr/include/_G_config.h/usr/include/bits/types.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.hwchar_t:t(25,1)=(0,3)wint_t:t(25,2)=(0,4)/usr/include/wchar.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h/usr/include/bits/wchar.h__mbstate_t:t(26,1)=(26,2)=s8__count:(0,1),0,32;__value:(26,3)=u4__wch:(25,2),0,32;__wchb:(26,4)=ar(17,33);0;3;(0,2),0,32;;,32,32;;_G_fpos_t:t(23,1)=(23,2)=s12__pos:(17,23),0,32;__state:(26,1),32,64;;_G_fpos64_t:t(23,3)=(23,4)=s16__pos:(17,54),0,64;__state:(26,1),64,64;;/usr/include/gconv.h/usr/include/features.h/usr/include/wchar.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h/usr/include/bits/wchar.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h :T(29,1)=e__GCONV_OK:0,__GCONV_NOCONV:1,__GCONV_NODB:2,__GCONV_NOMEM:3,__GCONV_EMPTY_INPUT:4,__GCONV_FULL_OUTPUT:5,__GCONV_ILLEGAL_INPUT:6,__GCONV_INCOMPLETE_INPUT:7,__GCONV_ILLEGAL_DESCRIPTOR:8,__GCONV_INTERNAL_ERROR:9,; :T(29,2)=e__GCONV_IS_LAST:1,__GCONV_IGNORE_ERRORS:2,;__gconv_fct:t(29,3)=(29,4)=*(29,5)=f(0,1)__gconv_init_fct:t(29,6)=(29,7)=*(29,8)=f(0,1)__gconv_end_fct:t(29,9)=(29,10)=*(29,11)=f(0,20)__gconv_trans_fct:t(29,12)=(29,13)=*(29,14)=f(0,1)__gconv_trans_context_fct:t(29,15)=(29,16)=*(29,17)=f(0,1)__gconv_trans_query_fct:t(29,18)=(29,19)=*(29,20)=f(0,1)__gconv_trans_init_fct:t(29,21)=(29,22)=*(29,23)=f(0,1)__gconv_trans_end_fct:t(29,24)=(29,25)=*(29,26)=f(0,20)__gconv_trans_data:T(29,27)=s20__trans_fct:(29,12),0,32;__trans_context_fct:(29,15),32,32;__trans_end_fct:(29,24),64,32;__data:(0,19),96,32;__next:(29,28)=*(29,27),128,32;;__gconv_step:T(29,29)=s56__shlib_handle:(29,30)=*(29,31)=xs__gconv_loaded_object:,0,32;__modname:(29,32)=*(0,2),32,32;__counter:(0,1),64,32;__from_name:(17,36),96,32;__to_name:(17,36),128,32;__fct:(29,3),160,32;__init_fct:(29,6),192,32;__end_fct:(29,9),224,32;__min_needed_from:(0,1),256,32;__max_needed_from:(0,1),288,32;__min_needed_to:(0,1),320,32;__max_needed_to:(0,1),352,32;__stateful:(0,1),384,32;__data:(0,19),416,32;;__gconv_step_data:T(29,33)=s36__outbuf:(29,34)=*(0,11),0,32;__outbufend:(29,34),32,32;__flags:(0,1),64,32;__invocation_counter:(0,1),96,32;__internal_use:(0,1),128,32;__statep:(29,35)=*(26,1),160,32;__state:(26,1),192,64;__trans:(29,28),256,32;;__gconv_info:T(29,36)=s8__nsteps:(16,1),0,32;__steps:(29,37)=*(29,29),32,32;__data:(29,38)=ar(17,33);0;-1;(29,33),64,0;;__gconv_t:t(29,39)=(29,40)=*(29,36)_G_iconv_t:t(23,5)=(23,6)=u44__cd:(29,36),0,64;__combined:(23,7)=s44__cd:(29,36),0,64;__data:(29,33),64,288;;,0,352;;_G_int16_t:t(23,8)=(0,8)_G_int32_t:t(23,9)=(0,1)_G_uint16_t:t(23,10)=(0,9)_G_uint32_t:t(23,11)=(0,4)/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stdarg.h__gnuc_va_list:t(35,1)=(0,19)_IO_lock_t:t(22,1)=(0,20)_IO_marker:T(22,2)=s12_next:(22,3)=*(22,2),0,32;_sbuf:(22,4)=*(12,2),32,32;_pos:(0,1),64,32;;__codecvt_result:T(22,5)=e__codecvt_ok:0,__codecvt_partial:1,__codecvt_error:2,__codecvt_noconv:3,;_IO_FILE:T(12,2)=s148_flags:(0,1),0,32;_IO_read_ptr:(17,36),32,32;_IO_read_end:(17,36),64,32;_IO_read_base:(17,36),96,32;_IO_write_base:(17,36),128,32;_IO_write_ptr:(17,36),160,32;_IO_write_end:(17,36),192,32;_IO_buf_base:(17,36),224,32;_IO_buf_end:(17,36),256,32;_IO_save_base:(17,36),288,32;_IO_backup_base:(17,36),320,32;_IO_save_end:(17,36),352,32;_markers:(22,3),384,32;_chain:(22,4),416,32;_fileno:(0,1),448,32;_blksize:(0,1),480,32;_old_offset:(17,23),512,32;_cur_column:(0,9),544,16;_vtable_offset:(0,10),560,8;_shortbuf:(22,6)=ar(17,33);0;0;(0,2),568,8;_lock:(22,7)=*(22,1),576,32;_offset:(17,54),608,64;__pad1:(0,19),672,32;__pad2:(0,19),704,32;_mode:(0,1),736,32;_unused2:(22,8)=ar(17,33);0;51;(0,2),768,416;;_IO_FILE:t(22,9)=(12,2)__io_read_fn:t(22,10)=(22,11)=f(17,26)__io_write_fn:t(22,12)=(22,13)=f(17,26)__io_seek_fn:t(22,14)=(22,15)=f(0,1)__io_close_fn:t(22,16)=(22,17)=f(0,1)fpos_t:t(12,4)=(23,1)/usr/include/bits/stdio_lim.h/usr/include/bits/stdio.h/usr/include/stdlib.h/usr/include/features.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.hdiv_t:t(38,1)=(38,2)=s8quot:(0,1),0,32;rem:(0,1),32,32;;ldiv_t:t(38,3)=(38,4)=s8quot:(0,3),0,32;rem:(0,3),32,32;;/usr/include/sys/types.h/usr/include/features.h/usr/include/bits/types.hu_char:t(41,1)=(17,1)u_short:t(41,2)=(17,2)u_int:t(41,3)=(17,3)u_long:t(41,4)=(17,4)quad_t:t(41,5)=(17,6)u_quad_t:t(41,6)=(17,5)fsid_t:t(41,7)=(17,30)loff_t:t(41,8)=(17,24)ino_t:t(41,9)=(17,20)dev_t:t(41,10)=(17,17)gid_t:t(41,11)=(17,19)mode_t:t(41,12)=(17,21)nlink_t:t(41,13)=(17,22)uid_t:t(41,14)=(17,18)off_t:t(41,15)=(17,23)pid_t:t(41,16)=(17,25)id_t:t(41,17)=(17,29)ssize_t:t(41,18)=(17,26)daddr_t:t(41,19)=(17,34)caddr_t:t(41,20)=(17,35)key_t:t(41,21)=(17,44)/usr/include/time.h/usr/include/bits/types.htime_t:t(44,1)=(17,37)/usr/include/bits/types.hclockid_t:t(44,2)=(17,42)/usr/include/bits/types.htimer_t:t(44,3)=(17,43)/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.hulong:t(41,22)=(0,5)ushort:t(41,23)=(0,9)uint:t(41,24)=(0,4)int8_t:t(41,25)=(0,10)int16_t:t(41,26)=(0,8)int32_t:t(41,27)=(0,1)int64_t:t(41,28)=(0,6)u_int8_t:t(41,29)=(0,11)u_int16_t:t(41,30)=(0,9)u_int32_t:t(41,31)=(0,4)u_int64_t:t(41,32)=(0,7)register_t:t(41,33)=(0,1)/usr/include/endian.h/usr/include/features.h/usr/include/bits/endian.h/usr/include/sys/select.h/usr/include/features.h/usr/include/bits/types.h/usr/include/bits/select.h/usr/include/bits/sigset.h__sig_atomic_t:t(56,1)=(0,1)__sigset_t:t(56,2)=(56,3)=s128__val:(56,4)=ar(17,33);0;31;(0,5),0,1024;;sigset_t:t(52,1)=(56,2)/usr/include/time.htimespec:T(57,1)=s8tv_sec:(17,37),0,32;tv_nsec:(0,3),32,32;;/usr/include/bits/time.h/usr/include/bits/types.htimeval:T(58,1)=s8tv_sec:(17,37),0,32;tv_usec:(17,39),32,32;;suseconds_t:t(52,2)=(17,39)__fd_mask:t(52,3)=(0,3)fd_set:t(52,4)=(52,5)=s128__fds_bits:(52,6)=ar(17,33);0;31;(52,3),0,1024;;fd_mask:t(52,7)=(52,3)/usr/include/sys/sysmacros.hblkcnt_t:t(41,34)=(17,47)fsblkcnt_t:t(41,35)=(17,49)fsfilcnt_t:t(41,36)=(17,51)random_data:T(38,5)=s28fptr:(38,6)=*(41,27),0,32;rptr:(38,6),32,32;state:(38,6),64,32;rand_type:(0,1),96,32;rand_deg:(0,1),128,32;rand_sep:(0,1),160,32;end_ptr:(38,6),192,32;;drand48_data:T(38,7)=s24__x:(38,8)=ar(17,33);0;2;(0,9),0,48;__old_x:(38,8),48,48;__c:(0,9),96,16;__init:(0,9),112,16;__a:(0,7),128,64;;/usr/include/alloca.h/usr/include/features.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h__compar_fn_t:t(38,9)=(38,10)=*(38,11)=f(0,1)/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/limits.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/syslimits.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/limits.h/usr/include/limits.h/usr/include/features.h/usr/include/bits/posix1_lim.h/usr/include/bits/local_lim.h/usr/include/linux/limits.h/usr/include/bits/posix2_lim.h/usr/include/string.h/usr/include/features.h/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h/usr/include/bits/string.h/usr/include/bits/string2.h/usr/include/endian.h/usr/include/bits/types.h/usr/include/stdlib.h :T(11,1)=eFALSE:0,TRUE:1,;BOOL:t(11,2)=(11,1) :T(9,1)=eWORKING_MODE:0,PERMANENT_MODE:1,;strbuf.hmemory.hString_buf:t(81,1)=(81,2)=*(81,3)=xsstring_buf:order.hheader.h :T(83,1)=eNOT_COMPARABLE:0,SAME_AS:1,LESS_THAN:2,GREATER_THAN:3,NOT_LESS_THAN:4,NOT_GREATER_THAN:5,;Ordertype:t(83,2)=(83,1)glist.hmemory.hPlist:t(85,1)=(85,2)=*(85,3)=xsplist:plist:T(85,3)=s8v:(0,19),0,32;next:(85,1),32,32;;Ilist:t(85,4)=(85,5)=*(85,6)=xsilist:ilist:T(85,6)=s8i:(0,1),0,32;next:(85,4),32,32;; :T(7,1)=eNOTHING_SPECIAL:0,INFIX:1,INFIX_LEFT:2,INFIX_RIGHT:3,PREFIX_PAREN:4,PREFIX:5,POSTFIX_PAREN:6,POSTFIX:7,;Parsetype:t(7,2)=(7,1) :T(7,3)=eFUNCTION_SYMBOL:0,RELATION_SYMBOL:1,UNSPECIFIED_SYMBOL:2,;Symbol_type:t(7,4)=(7,3) :T(7,5)=eEMPTY_THEORY:0,COMMUTE:1,ASSOC_COMMUTE:2,;Unif_theory:t(7,6)=(7,5) :T(7,7)=eLRPO_LR_STATUS:0,LRPO_MULTISET_STATUS:1,;Lrpo_status:t(7,8)=(7,7) :T(7,9)=eSTANDARD_STYLE:0,PROLOG_STYLE:1,INTEGER_STYLE:2,;Variable_style:t(7,10)=(7,9)Sym_ent:t(7,11)=(7,12)=*(7,13)=xssym_ent:glist.hTerm:t(6,1)=(6,2)=*(6,3)=xsterm:term:T(6,3)=s16private_symbol:(0,8),0,16;arity:(0,11),16,8;private_flags:(0,11),24,8;args:(6,4)=*(6,1),32,32;container:(0,19),64,32;u:(6,5)=u4id:(0,4),0,32;vp:(0,19),0,32;;,96,32;;termflag.hterm.hattrib.hheader.hterm.hunify.hterm.hContext:t(93,1)=(93,2)=*(93,3)=xscontext:context:T(93,3)=s808terms:(93,4)=ar(17,33);0;99;(6,1),0,3200;contexts:(93,5)=ar(17,33);0;99;(93,1),3200,3200;multiplier:(0,1),6400,32;partial_term:(6,1),6432,32;;Trail:t(93,6)=(93,7)=*(93,8)=xstrail: :T(93,9)=eNO_ALT:0,AC_ALT:1,COMM_ALT:2,;Unif_alternative:t(93,10)=(93,9) :T(90,1)=eINT_ATTRIBUTE:0,STRING_ATTRIBUTE:1,TERM_ATTRIBUTE:2,;Attribute_type:t(90,2)=(90,1)Attribute:t(90,3)=(90,4)=*(90,5)=xsattribute:Literal:t(4,1)=(4,2)=*(4,3)=xsliteral:literal:T(4,3)=s12sign:(0,1),0,32;atom:(6,1),32,32;next:(4,1),64,32;;Clause:t(4,4)=(4,5)=*(4,6)=xsclause:clause:T(4,6)=s24id:(0,1),0,32;weight:(0,1),32,32;literals:(4,1),64,32;attributes:(90,3),96,32;justification:(4,7)=*(4,8)=xsjust:,128,32;containers:(4,9)=*(4,10)=xsclist_pos:,160,32;; :T(2,1)=eINPUT_JUST:0,CLAUSIFY_JUST:1,COPY_JUST:2,BACK_DEMOD_JUST:3,BACK_UNIT_DEL_JUST:4,BINARY_RES_JUST:5,HYPER_RES_JUST:6,UR_RES_JUST:7,CD_JUST:8,FACTOR_JUST:9,XXRES_JUST:10,PARA_JUST:11,PARA_FX_JUST:12,PARA_IX_JUST:13,PARA_FX_IX_JUST:14,DEMOD_JUST:15,UNIT_DEL_JUST:16,FLIP_JUST:17,XX_JUST:18,MERGE_JUST:19,;Just_type:t(2,2)=(2,1)Parajust:t(2,3)=(2,4)=*(2,5)=xsparajust:parajust:T(2,5)=s16from_id:(0,1),0,32;into_id:(0,1),32,32;from_pos:(85,4),64,32;into_pos:(85,4),96,32;;Just:t(2,6)=(4,7)just:T(4,8)=s12type:(2,2),0,32;next:(2,6),32,32;u:(2,7)=u4id:(0,1),0,32;lst:(85,4),0,32;para:(2,3),0,32;;,64,32;;unify.hclause.hdetachable:f(11,2)c:p(4,4)c:r(4,4)detach:f(4,4)c1:p(4,4)c2:p(4,4)major:r(6,1)alpha:r(6,1)beta:(6,1)minor:r(6,1)s1:r(93,1)s2:(93,1)tr:(93,6)result:r(4,4)atom:r(6,1)lit:r(4,1)cond_detach:F(0,20)major:p(4,4)minor:p(4,4)proc_proc:p(0,21)=*(0,22)=f(0,20)major:r(4,4)minor:r(4,4)cd:r(4,4)cond_detach_2:F(0,20)c1:p(4,4)c2:p(4,4)proc_proc:p(0,21)c1:r(4,4)c2:r(4,4)proc_proc:r(0,21)GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.3 2.96-110).symtab.strtab.shstrtab.rel.text.data.bss.note.rel.stab.stabstr.comment4Ü U %+0:$ 6 U8 @@6IÐO7PRdR°  Tëñÿ RTÿ (8DJ^jp{Š’¥°ÄÑTMݤ7detach.cdetachabledetachunit_clausepositive_clauseget_contextunifyget_rigid_term_likenew_literalapplyget_clauseappend_literalcd_justinherit_attributesundo_substupward_clause_linksfree_contextcond_detachcond_detach_2 " … Œ ¨ÀÍÛåñÿ':EºÌ d¸°|LADR-2009-11A/ladr/save/str_toupper0000644000175000017500000000075410406636272016223 0ustar mccunemccune/************* * * str_toupper() * *************/ static char *str_toupper(char *source, char *dest) { int i; int n = strlen(source) + 1; for (i = 0; i < n; i++) dest[i] = toupper(source[i]); return dest; } /* str_toupper */ /************* * * str_tolower() * *************/ static char *str_tolower(char *source, char *dest) { int i; int n = strlen(source) + 1; for (i = 0; i < n; i++) dest[i] = tolower(source[i]); return dest; } /* str_tolower */ LADR-2009-11A/ladr/save/detach.h0000644000175000017500000000065010150667353015306 0ustar mccunemccune#ifndef TP_DETACH_H #define TP_DETACH_H #include "just.h" #include "unify.h" #include "clause.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from detach.c */ void cond_detach(Clause major, Clause minor, void (*proc_proc) (Clause)); void cond_detach_2(Clause c1, Clause c2, void (*proc_proc) (Clause)); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/just.c0000644000175000017500000005221410140052332015021 0ustar mccunemccune#include "just.h" /* Private definitions and types */ /* * memory management */ static unsigned Just_gets, Just_frees; static unsigned Parajust_gets, Parajust_frees; #define BYTES_JUST sizeof(struct just) #define PTRS_JUST BYTES_JUST%BPP == 0 ? BYTES_JUST/BPP : BYTES_JUST/BPP + 1 #define BYTES_PARAJUST sizeof(struct parajust) #define PTRS_PARAJUST BYTES_PARAJUST%BPP == 0 ? BYTES_PARAJUST/BPP : BYTES_PARAJUST/BPP + 1 /************* * * Just get_just() * *************/ static Just get_just(void) { Just p = get_mem(PTRS_JUST); Just_gets++; return(p); } /* get_just */ /************* * * free_just() * *************/ static void free_just(Just p) { free_mem(p, PTRS_JUST); Just_frees++; } /* free_just */ /************* * * Parajust get_parajust() * *************/ static Parajust get_parajust(void) { Parajust p = get_mem(PTRS_PARAJUST); Parajust_gets++; return(p); } /* get_parajust */ /************* * * free_parajust() * *************/ static void free_parajust(Parajust p) { free_mem(p, PTRS_PARAJUST); Parajust_frees++; } /* free_parajust */ /************* * * fprint_just_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the just package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_just_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_JUST; fprintf(fp, "just (%4d) %11u%11u%11u%9.1f K\n", n, Just_gets, Just_frees, Just_gets - Just_frees, ((Just_gets - Just_frees) * n) / 1024.); n = BYTES_PARAJUST; fprintf(fp, "parajust (%4d) %11u%11u%11u%9.1f K\n", n, Parajust_gets, Parajust_frees, Parajust_gets - Parajust_frees, ((Parajust_gets - Parajust_frees) * n) / 1024.); } /* fprint_just_mem */ /************* * * p_just_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the just package. */ /* PUBLIC */ void p_just_mem() { fprint_just_mem(stdout, TRUE); } /* p_just_mem */ /* * end of memory management */ /************* * * input_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for input. */ /* PUBLIC */ Just input_just(void) { /* (INPUT_JUST) */ Just j = get_just(); j->type = INPUT_JUST; return j; } /* input_just */ /************* * * clausify_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for clausify. */ /* PUBLIC */ Just clausify_just(void) { /* (CLAUSIFY_JUST) */ Just j = get_just(); j->type = CLAUSIFY_JUST; return j; } /* clausify_just */ /************* * * copy_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for copy. */ /* PUBLIC */ Just copy_just(Clause c) { /* (COPY_JUST parent_id) */ Just j = get_just(); j->type = COPY_JUST; j->u.id = c->id; return j; } /* copy_just */ /************* * * back_demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_demod. */ /* PUBLIC */ Just back_demod_just(Clause c) { /* (BACK_DEMOD_JUST parent_id) */ Just j = get_just(); j->type = BACK_DEMOD_JUST; j->u.id = c->id; return j; } /* back_demod_just */ /************* * * back_unit_deletion_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_unit_deletion. */ /* PUBLIC */ Just back_unit_deletion_just(Clause c) { /* (BACK_UNIT_DEL_JUST parent_id) */ Just j = get_just(); j->type = BACK_UNIT_DEL_JUST; j->u.id = c->id; return j; } /* back_unit_deletion_just */ /************* * * binary_res_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for binary resolution. (Binary res justifications may also be constructed in resolve(), along with hyper and UR.) */ /* PUBLIC */ Just binary_res_just(Clause c1, int n1, Clause c2, int n2) { /* (BINARY_RES_JUST (id1 lit1 id2 lit2) */ Just j = get_just(); j->type = BINARY_RES_JUST; j->u.lst = ilist_append( ilist_append( ilist_append( ilist_append(NULL,c1->id),n1),c2->id),n2); return j; } /* binary_res_just */ /************* * * cd_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just cd_just(Clause major, Clause minor) { /* (CD_JUST (major_id minor_id)) */ Just j = get_just(); j->type = CD_JUST; j->u.lst = ilist_append(ilist_append(NULL, major->id), minor->id); return j; } /* cd_just */ /************* * * factor_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just factor_just(Clause c, int lit1, int lit2) { /* (FACTOR_JUST (clause_id lit1 lit2)) */ Just j = get_just(); j->type = FACTOR_JUST; j->u.lst = ilist_append(ilist_append(ilist_append(NULL,c->id),lit1),lit2); return j; } /* factor_just */ /************* * * resolve_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for resolution rules. This handles binary, hyper, ur, and maybe others. */ /* PUBLIC */ Just resolve_just(Ilist g, Just_type type) { Just j = get_just(); j->type = type; j->u.lst = g; return j; } /* resolve_just */ /************* * * para_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are not copied. */ /* PUBLIC */ Just para_just(Just_type rule, Clause from, Ilist from_vec, Clause into, Ilist into_vec) { Just j = get_just(); j->type = rule; j->u.para = get_parajust(); j->u.para->from_id = from->id; j->u.para->into_id = into->id; j->u.para->from_pos = from_vec; j->u.para->into_pos = into_vec; return j; } /* para_just */ /************* * * para_just_rev_copy() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are copied and reversed. */ /* PUBLIC */ Just para_just_rev_copy(Just_type rule, Clause from, Ilist from_vec, Clause into, Ilist into_vec) { return para_just(rule, from, reverse_ilist(copy_ilist(from_vec)), into, reverse_ilist(copy_ilist(into_vec))); } /* para_just_rev_copy */ /************* * * demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for demodulation. The given ilist is not copied. */ /* PUBLIC */ Just demod_just(Ilist g) { Just j = get_just(); j->type = DEMOD_JUST; j->u.lst = g; return j; } /* demod_just */ /************* * * unit_del_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just unit_del_just(Clause deleter, int literal_num) { /* UNIT_DEL (clause-id literal-num) */ Just j = get_just(); j->type = UNIT_DEL_JUST; j->u.lst = ilist_append(ilist_append(NULL, literal_num), deleter->id); return j; } /* cd_just */ /************* * * flip_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for equality flipping. */ /* PUBLIC */ Just flip_just(int n) { Just j = get_just(); j->type = FLIP_JUST; j->u.id = n; return j; } /* flip_just */ /************* * * xx_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the XX rule, which removes literals that are instances of x!=x. */ /* PUBLIC */ Just xx_just(int n) { Just j = get_just(); j->type = XX_JUST; j->u.id = n; return j; } /* xx_just */ /************* * * merge_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the merging a literal. The n-th literal has been removed because it is identical to another literal. */ /* PUBLIC */ Just merge_just(int n) { Just j = get_just(); j->type = MERGE_JUST; j->u.id = n; return j; } /* merge_just */ /************* * * append_just() * *************/ /* DOCUMENTATION This appends two justifications. No copying occurs. */ /* PUBLIC */ Just append_just(Just j1, Just j2) { if (j1 == NULL) return j2; else { j1->next = append_just(j1->next, j2); return j1; } } /* append_just */ /************* * * copy_justification() * *************/ /* DOCUMENTATION Copy a justification. */ /* PUBLIC */ Just copy_justification(Just j) { if (j == NULL) return NULL; else { Just j2 = get_just(); j2->type = j->type; j2->next = copy_justification(j->next); switch (j->type) { case INPUT_JUST: case CLAUSIFY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: j2->u.id = j->u.id; break; case CD_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case DEMOD_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: j2->u.lst = copy_ilist(j->u.lst); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: j2->u.para = get_parajust(); j2->u.para->from_id = j->u.para->from_id; j2->u.para->into_id = j->u.para->into_id; j2->u.para->from_pos = copy_ilist(j->u.para->from_pos); j2->u.para->into_pos = copy_ilist(j->u.para->into_pos); break; default: fatal_error("copy_justification: unknown type"); } return j2; } } /* copy_justification */ /************* * * fix_input_just() * *************/ /* DOCUMENTATION If the clause's justification is simply a copy, replace the justification with the justification of the parent. This is intended for input clauses for which the pre_processing does nothing. The purpose is simply to prevent duplicate steps when printing proofs. */ /* PUBLIC */ void fix_input_just(Clause c) { Just j = c->justification; if (j && j->type == COPY_JUST && j->next == NULL) { Clause parent = find_clause_by_id(j->u.id); c->justification = copy_justification(parent->justification); zap_just(j); } } /* fix_input_just */ /************* * * jstring() - strings for printing justifications * *************/ static char *jstring(Just j) { switch (j->type) { // primary justifications case INPUT_JUST: return "input"; case CLAUSIFY_JUST: return "clausify"; case COPY_JUST: return "copy"; case BACK_DEMOD_JUST: return "back_demod"; case BACK_UNIT_DEL_JUST: return "back_unit_del"; case BINARY_RES_JUST: return "resolve"; case HYPER_RES_JUST: return "hyper"; case UR_RES_JUST: return "ur"; case CD_JUST: return "cd"; case FACTOR_JUST: return "factor"; case PARA_JUST: return "para"; case PARA_FX_JUST: return "para_fx"; case PARA_IX_JUST: return "para_ix"; case PARA_FX_IX_JUST: return "para_fx_ix"; // secondary justifications need a space case FLIP_JUST: return " flip"; case XX_JUST: return " xx"; case MERGE_JUST: return " merge"; case DEMOD_JUST: return " demod"; case UNIT_DEL_JUST: return " unit_del"; } return "unknown"; } /* jstring */ /************* * * itoc() * *************/ static char itoc(int i) { return 'a' + i - 1; } /* itoc */ /************* * * jmap1() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns the first. If i is not in the map, i is returned. */ /* PUBLIC */ int jmap1(Ilist map, int i) { int id = assoc2a(map, i); return (id == INT_MIN ? i : id); } /* jmap1 */ /************* * * jmap2() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns a string representation of the second. If i is not in the map, or if the int value of is INT_MIN, "" is returned. Starting with 0, the strings are "A" - "Z", "A26", "A27", ... . The argument *a must point to available space for the result. The result is returned. */ /* PUBLIC */ char *jmap2(Ilist map, int i, char *a) { int n = assoc2b(map, i); if (n == INT_MIN) a[0] = '\0'; else if (n >= 0 && n <= 25) { /* "A" -- "Z" */ a[0] = 'A' + n; a[1] = '\0'; } else { /* "A26", ... */ a[0] = 'A'; sprintf(a+1, "%d", n); } return a; } /* jmap2 */ /************* * * fprint_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void fprint_res_just(FILE *fp, Ilist p, Ilist map) { char a[10]; Ilist q; fprintf(fp, "(%d%s", jmap1(map, p->i), jmap2(map, p->i, a)); for (q = p->next; q != NULL; q = q->next->next->next) { fprintf(fp, " %c", itoc(q->i)); fprintf(fp, " %d%s", jmap1(map, q->next->i), jmap2(map, q->next->i, a)); fprintf(fp, " %c", itoc(q->next->next->i)); } fprintf(fp, ")"); fflush(fp); } /* fprint_res_just */ /************* * * fprint_position() * *************/ static void fprint_position(FILE *fp, Ilist p) { Ilist q; fprintf(fp, "(%c", itoc(p->i)); for (q = p->next; q != NULL; q = q->next) { fprintf(fp, " %d", q->i); } fprintf(fp, ")"); fflush(fp); } /* fprint_position */ /************* * * fprint_just() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void fprint_just(FILE *fp, Just just, Ilist map) { char a[10]; Just g = just; fprintf(fp, "["); while (g != NULL) { Just_type rule = g->type; if (rule == INPUT_JUST || rule == CLAUSIFY_JUST) fprintf(fp, "%s", jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { fprintf(fp, "%s ", jstring(g)); fprint_res_just(fp, g->u.lst, map); } else if (rule == DEMOD_JUST || rule == CD_JUST) { fprintf(fp, "%s ", jstring(g)); fprint_ilist(fp, g->u.lst); } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; fprintf(fp, "%s (%c %d%s)", jstring(g), itoc(p->i), jmap1(map, p->next->i), jmap2(map, p->next->i, a)); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; fprintf(fp, "%s (%d%s %c %c)", jstring(g), jmap1(map, p->i), jmap2(map, p->i, a), itoc(p->next->i), itoc(p->next->next->i)); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == COPY_JUST) fprintf(fp, "%s %d%s", jstring(g), jmap1(map, g->u.id), jmap2(map, g->u.id, a)); else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST) fprintf(fp, "%s %c", jstring(g), itoc(g->u.id)); else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; fprintf(fp, "%s (%d%s ", jstring(g), jmap1(map, p->from_id), jmap2(map, p->from_id, a)); fprint_position(fp, p->from_pos); fprintf(fp, " %d%s ", jmap1(map, p->into_id), jmap2(map, p->into_id, a)); fprint_position(fp, p->into_pos); fprintf(fp, ")"); } else { printf("\nunknown rule: %d\n", rule); fatal_error("fprint_just: unknown rule"); } g = g->next; } fprintf(fp, "]"); } /* fprint_just */ /************* * * p_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_just(Just j) { fprint_just(stdout, j, NULL); printf("\n"); } /* p_just */ /************* * * zap_parajust() * *************/ static void zap_parajust(Parajust p) { zap_ilist(p->from_pos); zap_ilist(p->into_pos); free_parajust(p); } /* zap_parajust */ /************* * * zap_just() * *************/ /* DOCUMENTATION This routine frees a justification list, including any sublists. */ /* PUBLIC */ void zap_just(Just just) { if (just != NULL) { zap_just(just->next); switch (just->type) { case INPUT_JUST: case CLAUSIFY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: break; /* nothing to do */ case CD_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case DEMOD_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: zap_ilist(just->u.lst); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: zap_parajust(just->u.para); break; default: fatal_error("zap_just: unknown type"); } free_just(just); } } /* zap_just */ /************* * * get_clanc() * *************/ static Plist get_clanc(int id, Plist anc) { Clause c = find_clause_by_id(id); if (c == NULL) { printf("get_clanc, clause with id=%d not found.\n", id); fatal_error("get_clanc, clause not found."); } if (!plist_member(anc, c)) { Just g = c->justification; anc = insert_clause_into_plist(anc, c, TRUE); while (g != NULL) { Just_type rule = g->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid nuclit sat1id sat1lit nuclit2 sat2id sat2lit ...)] */ Ilist p = g->u.lst; int nuc_id = p->i; anc = get_clanc(nuc_id, anc); p = p->next; while (p != NULL) { int sat_id = p->next->i; anc = get_clanc(sat_id, anc); p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; anc = get_clanc(p->from_id, anc); anc = get_clanc(p->into_id, anc); } else if (rule == FACTOR_JUST) { int parent_id = g->u.lst->i; anc = get_clanc(parent_id, anc); } else if (rule == UNIT_DEL_JUST) { int parent_id = g->u.lst->next->i; anc = get_clanc(parent_id, anc); } else if (rule == CD_JUST) { Ilist p = g->u.lst; int major_id = p->i; int minor_id = p->next->i; anc = get_clanc(major_id, anc); anc = get_clanc(minor_id, anc); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == BACK_UNIT_DEL_JUST) { int parent_id = g->u.id; anc = get_clanc(parent_id, anc); } else if (rule == DEMOD_JUST) { Ilist p; for (p = g->u.lst; p; p = p->next) anc = get_clanc(p->i, anc); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == INPUT_JUST || rule == CLAUSIFY_JUST) ; /* do nothing */ else fatal_error("get_clanc, unknown rule."); g = g->next; } } return anc; } /* get_clanc */ /************* * * get_clause_ancestors() * *************/ /* DOCUMENTATION This routine returns the Plist of clauses that are ancestors of Clause c, including clause c. The result is sorted (increasing) by ID. */ /* PUBLIC */ Plist get_clause_ancestors(Clause c) { Plist ancestors = get_clanc(c->id, NULL); return ancestors; } /* get_clause_ancestors */ /************* * * proof_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int proof_length(Plist proof) { Plist p; int n = 0; for (p = proof; p; p = p->next) { Clause c = p->v; if (c->justification != NULL) n++; } return n; } /* proof_length */ /************* * * map_id() * *************/ static int map_id(Ilist a, int arg) { int val = assoc(a, arg); return val == INT_MIN ? arg : val; } /* map_id */ /************* * * map_just() * *************/ /* DOCUMENTATION Update the clause IDs in a justification according to the map. */ /* PUBLIC */ void map_just(Just just, Ilist map) { Just j; for (j = just; j; j = j->next) { Just_type rule = j->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid n sat1id n n sat2id n ...)] */ Ilist p = j->u.lst; p->i = map_id(map, p->i); /* nucleus */ p = p->next; while (p != NULL) { p->next->i = map_id(map, p->next->i); /* satellite */ p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = j->u.para; p->from_id = map_id(map, p->from_id); p->into_id = map_id(map, p->into_id); } else if (rule == FACTOR_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); } else if (rule == UNIT_DEL_JUST) { Ilist p = j->u.lst; p->next->i = map_id(map, p->next->i); } else if (rule == CD_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); p->next->i = map_id(map, p->next->i); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == BACK_UNIT_DEL_JUST) { j->u.id = map_id(map, j->u.id); } else if (rule == DEMOD_JUST) { Ilist p; for (p = j->u.lst; p; p = p->next) p->i = map_id(map, p->i); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == INPUT_JUST || rule == CLAUSIFY_JUST) ; /* do nothing */ else fatal_error("get_clanc, unknown rule."); } } /* map_just */ LADR-2009-11A/ladr/save/options.c0000644000175000017500000004326410140052302015531 0ustar mccunemccune#include "options.h" #include /* for variable argument lists */ /* Private definitions and types */ /* Dependencies. For now, only flags can have dependencies. */ typedef enum { FLAGT, PARMT, STRINGPARMT } Opttype; /* type of dependent */ typedef struct optdep * Optdep; struct optdep { /* these get attached to flags that have dependents */ BOOL flag_trigger; /* whether set or clear triggers action */ Opttype type; /* type of dependent option */ int id; /* id of dependent option */ int val; /* value for dependent flag or parm */ char *sval; /* value for dependent stringparm */ Optdep next; /* next dependent */ }; struct flag { /* Flags are boolean valued options */ char *name; BOOL val; Optdep dependencies; }; struct parm { /* Parms are integer valued options */ char *name; int val; int min, max; /* minimum and maximum permissible values */ // Optdep dependencies; }; struct stringparm { /* Stringparms are string valued options */ char *name; char *val; /* current valuse: index into array of strings */ int n; /* number of values */ char **range; /* array of possible vales */ // Optdep dependencies; }; static struct flag Flags[MAX_FLAGS]; static struct parm Parms[MAX_PARMS]; static struct stringparm Stringparms[MAX_STRINGPARMS]; /* * memory management */ static unsigned Optdep_gets, Optdep_frees; #define BYTES_OPTDEP sizeof(struct optdep) #define PTRS_OPTDEP BYTES_OPTDEP%BPP == 0 ? BYTES_OPTDEP/BPP : BYTES_OPTDEP/BPP + 1 /************* * * Optdep get_optdep() * *************/ static Optdep get_optdep(void) { Optdep p = get_mem(PTRS_OPTDEP); Optdep_gets++; return(p); } /* get_optdep */ /************* * * free_optdep() * *************/ #if 0 static void free_optdep(Optdep p) { free_mem(p, PTRS_OPTDEP); Optdep_frees++; } /* free_optdep */ #endif /************* * * fprint_options_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the options package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_options_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_OPTDEP; fprintf(fp, "optdep (%4d) %11u%11u%11u%9.1f K\n", n, Optdep_gets, Optdep_frees, Optdep_gets - Optdep_frees, ((Optdep_gets - Optdep_frees) * n) / 1024.); } /* fprint_options_mem */ /************* * * p_options_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the options package. */ /* PUBLIC */ void p_options_mem() { fprint_options_mem(stdout, TRUE); } /* p_options_mem */ /* * end of memory management */ /************* * * next_available_flag_id() * *************/ /* DOCUMENTATION If you're not sure what flag IDs have already been claimed, for example if you're adding options to an existing program, you can use this function to find an available one. Return -1 if none is available. */ /* PUBLIC */ int next_available_flag_id(void) { int i = 0; while (i < MAX_FLAGS && Flags[i].name != NULL) i++; return (i < MAX_FLAGS ? i : -1); } /* next_available_flag_id */ /************* * * next_available_parm_id() * *************/ /* DOCUMENTATION If you're not sure what parm IDs have already been claimed, for example if you're adding options to an existing program, you can use this function to find an available one. Return -1 if none is available. */ /* PUBLIC */ int next_available_parm_id(void) { int i = 0; while (i < MAX_PARMS && Parms[i].name != NULL) i++; return (i < MAX_PARMS ? i : -1); } /* next_available_parm_id */ /************* * * next_available_stringparm_id() * *************/ /* DOCUMENTATION If you're not sure what stringparm IDs have already been claimed, for example if you're adding options to an existing program, you can use this function to find an available one. Return -1 if none is available. */ /* PUBLIC */ int next_available_stringparm_id(void) { int i = 0; while (i < MAX_STRINGPARMS && Stringparms[i].name == NULL) i++; return (i < MAX_STRINGPARMS ? i : -1); } /* next_available_stringparm_id */ /************* * * init_flag() * *************/ /* DOCUMENTATION Initialize a flag (boolean-valued option). You give it an integer identifier (unique among all flags), a name, and a default value. Flags are typically changed by user commands which are parsed by read_commands(). The value of a flag is checked with flag(ID). */ /* PUBLIC */ void init_flag(int flag_id, char *flag_name, BOOL default_value) { if (flag_id < 0 || flag_id >= MAX_FLAGS) fatal_error("init_flag: flag ID out of range"); else if (Flags[flag_id].name != NULL) fatal_error("init_flag: flag ID already in use"); else if (str_to_flag_id(flag_name) != -1) fatal_error("init_flag: flag name already in use"); else { Flags[flag_id].name = flag_name; Flags[flag_id].val = default_value; Flags[flag_id].dependencies = NULL; } } /* init_flag */ /************* * * init_parm() * *************/ /* DOCUMENTATION Initialize a parm (integer-valued option). You give it an integer identifier (unique among all parms), a name, a default value, and min and max values. Parms are typically changed by user commands which are parsed by read_commands(). The value of a parm is checked with parm(ID). */ /* PUBLIC */ void init_parm(int parm_id, char *parm_name, int default_value, int min_value, int max_value) { if (parm_id < 0 || parm_id >= MAX_PARMS) fatal_error("init_parm: parm ID out of range"); else if (Parms[parm_id].name != NULL) fatal_error("init_parm: parm ID already in use"); else if (str_to_parm_id(parm_name) != -1) fatal_error("init_parm: parm name already in use"); else if (default_value < min_value || default_value > max_value) fatal_error("init_parm: default parm value out of range"); else { Parms[parm_id].name = parm_name; Parms[parm_id].val = default_value; Parms[parm_id].min = min_value; Parms[parm_id].max = max_value; } } /* init_parm */ /************* * * init_stringparm() * *************/ /* DOCUMENTATION Initialize a stringparm (string-valued option). You give it an integer identifier (unique among all stringparms), a name, a number n of possible values, and n strings which are the possible values. The first string given is the default value.

Stringparms are typically changed by user commands which are parsed by read_commands(). The value of a stringparm is checked with the Boolean routine stringparm(ID, string). */ /* PUBLIC */ void init_stringparm(int id, char *name, int n, ...) { if (id < 0 || id >= MAX_STRINGPARMS) fatal_error("init_stringparm: ID out of range"); else if (Stringparms[id].name != NULL) fatal_error("init_stringparm: ID already in use"); else if (str_to_stringparm_id(name) != -1) fatal_error("init_stringparm: name already in use"); else { int i; va_list parameters; va_start(parameters, n); Stringparms[id].range = malloc(n * sizeof(char *)); for (i = 0; i < n; i++) Stringparms[id].range[i] = va_arg(parameters, char *); va_end(parameters); Stringparms[id].name = name; Stringparms[id].n = n; /* number of values */ Stringparms[id].val = Stringparms[id].range[0]; /* first is default */ } } /* init_stringparm */ /************* * * fprint_options(fp) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the current values of all of the the options (flags, parms, and stringparms). */ /* PUBLIC */ void fprint_options(FILE *fp) { int i, j; fprintf(fp, "\n--------------- options ---------------\n"); j = 0; for (i = 0; i < MAX_FLAGS; i++) /* print flags */ if (Flags[i].name[0] != '\0') { fprintf(fp, "%s", Flags[i].val ? "set(" : "clear("); fprintf(fp, "%s). ", Flags[i].name); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n\n"); j = 0; for (i = 0; i < MAX_PARMS; i++) /* print parms */ if (Parms[i].name[0] != '\0') { fprintf(fp, "assign("); fprintf(fp, "%s, %d). ", Parms[i].name, Parms[i].val); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } fprintf(fp, "\n\n"); j = 0; for (i = 0; i < MAX_STRINGPARMS; i++) { /* print stringparms */ struct stringparm *sp = &(Stringparms[i]); if (sp->name[0] != '\0') { fprintf(fp, "assign("); fprintf(fp, "%s, %s). ", sp->name, sp->val); fprintf(fp, "%s", (++j % 3 == 0) ? "\n" : ""); } } fprintf(fp, "\n"); fflush(fp); } /* fprint_options */ /************* * * p_options() * *************/ /* DOCUMENTATION This routine prints (to stdout) the current values of the the options (flags, parms, and stringparms). */ /* PUBLIC */ void p_options(void) { fprint_options(stdout); } /* p_options */ /************* * * flag() * *************/ /* DOCUMENTATION This Boolean routine returns the value of a flag. If the Flag index is out of range, bad things can happen. */ /* PUBLIC */ int flag(int flag_id) { return Flags[flag_id].val; } /* flag */ /************* * * parm() * *************/ /* DOCUMENTATION This integer routine returns the value of a parameter. If the parm index is out of range, bad things can happen. */ /* PUBLIC */ int parm(int parm_id) { return Parms[parm_id].val; } /* parm */ /************* * * stringparm() * *************/ /* DOCUMENTATION This routine checks if the current value of a stringparm matches the given string. The ID must be valid. */ /* PUBLIC */ BOOL stringparm(int id, char *s) { return str_ident(Stringparms[id].val, s); } /* stringparm */ /************* * * stringparm1() * *************/ /* DOCUMENTATION This routine returns the current value of a stringparm. The ID must be valid. */ /* PUBLIC */ char *stringparm1(int id) { return Stringparms[id].val; } /* stringparm1 */ /************* * * update_flag() * *************/ /* DOCUMENTATION This performs the role of set_flag() and clear_flag(). In addition, an output file is given for dependency messages. */ /* PUBLIC */ void update_flag(FILE *fout, int id, BOOL val) { if (id < 0 || id >= MAX_FLAGS) { fprintf(fout, "update_flag: flag id %d, is out of range.\n", id); fprintf(stderr, "update_flag: flag id %d, is out of range.\n", id); fatal_error("update_flag, flag out of range"); } else { Optdep p; Flags[id].val = val; for (p = Flags[id].dependencies; p; p = p->next) { if (p->flag_trigger == val) { if (p->type == FLAGT) { fprintf(fout, " %% %s(%s) -> %s(%s).\n", val ? "set" : "clear", Flags[id].name, p->val ? "set" : "clear", Flags[p->id].name); update_flag(fout, p->id, p->val); } else if (p->type == PARMT) { fprintf(fout, " %% %s(%s) -> assign(%s, %d).\n", val ? "set" : "clear", Flags[id].name, Parms[p->id].name, p->val); assign_parm(p->id, p->val); } else { /* assume it's a stringparm */ fprintf(fout, " %% %s(%s) -> assign(%s, %s).\n", val ? "set" : "clear", Flags[id].name, Stringparms[p->id].name, p->sval); assign_stringparm(p->id, p->sval); } } } } } /* update_flag */ /************* * * set_flag() * *************/ /* DOCUMENTATION This routine sets a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs. */ /* PUBLIC */ void set_flag(int id) { update_flag(stdout, id, TRUE); } /* set_flag */ /************* * * clear_flag() * *************/ /* DOCUMENTATION This routine clears a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs. */ /* PUBLIC */ void clear_flag(int id) { update_flag(stdout, id, FALSE); } /* clear_flag */ /************* * * assign_parm() * *************/ /* DOCUMENTATION This routine assigns a value to a parm. The parm is identified by its integer ID (which is available from str_to_parm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs. */ /* PUBLIC */ void assign_parm(int id, int val) { if (id < 0 || id >= MAX_PARMS) { fprintf(stdout, "assign_parm: parm id %d, is out of range.\n", id); fprintf(stderr, "assign_parm: parm id %d, is out of range.\n", id); fatal_error("assign_parm"); } else if (val < Parms[id].min || val > Parms[id].max) { fprintf(stdout, "assign_parm: parm %s, value %d out of range [%d..%d].\n", Parms[id].name, val, Parms[id].min, Parms[id].max); fprintf(stderr, "assign_parm: parm %s, value %d out of range [%d..%d].\n", Parms[id].name, val, Parms[id].min, Parms[id].max); fatal_error("assign_parm"); } else Parms[id].val = val; } /* assign_parm */ /************* * * assign_stringparm() * *************/ /* DOCUMENTATION This routine assigns a value to a stringparm. The stringparm is identified by its integer ID (which is available from str_to_stringparm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs. */ /* PUBLIC */ void assign_stringparm(int id, char *val) { if (id < 0 || id >= MAX_STRINGPARMS) { fprintf(stdout, "assign_stringparm: id %d, is out of range.\n", id); fprintf(stderr, "assign_stringparm: id %d, is out of range.\n", id); fatal_error("assign_stringparm"); } else { struct stringparm *sp = &(Stringparms[id]); int i = 0;; while (i < sp->n && !str_ident(sp->range[i], val)) i++; if (i < sp->n) sp->val = sp->range[i]; else { printf("range of values for stringparm %s:\n", sp->name); for (i = 0; i < sp->n; i++) printf(" %s\n", sp->range[i]); fatal_error("assign_stringparm, value out of range"); } } } /* assign_stringparm */ /************* * * str_to_flag_id() * *************/ /* DOCUMENTATION This routine converts the string name of a flag to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_flag_id(char *name) { int i; for (i = 0; i < MAX_FLAGS; i++) if (Flags[i].name && str_ident(name, Flags[i].name)) return i; return -1; } /* str_to_flag_id */ /************* * * str_to_parm_id() * *************/ /* DOCUMENTATION This routine converts the string name of a parm to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_parm_id(char *name) { int i; for (i = 0; i < MAX_PARMS; i++) if (Parms[i].name && str_ident(name, Parms[i].name)) return i; return -1; } /* str_to_parm_id */ /************* * * str_to_stringparm_id() * *************/ /* DOCUMENTATION This routine converts the string name of a stringparm to its integer ID. If the string name is not valid, -1 is returned. */ /* PUBLIC */ int str_to_stringparm_id(char *name) { int i; for (i = 0; i < MAX_STRINGPARMS; i++) if (Stringparms[i].name && str_ident(name, Stringparms[i].name)) return i; return -1; } /* str_to_stringparm_id */ /************* * * flag_id_to_str() * *************/ /* DOCUMENTATION Given a flag ID, return the corresponding name of the flag. */ /* PUBLIC */ char *flag_id_to_str(int id) { if (id < 0 || id > MAX_FLAGS) fatal_error("flag_id_to_str, bad id"); return Flags[id].name; } /* flag_id_to_str */ /************* * * parm_id_to_str() * *************/ /* DOCUMENTATION Given a parm ID, return the corresponding name of the parm. */ /* PUBLIC */ char *parm_id_to_str(int id) { if (id < 0 || id > MAX_PARMS) fatal_error("parm_id_to_str, bad id"); return Parms[id].name; } /* parm_id_to_str */ /************* * * stringparm_id_to_str() * *************/ /* DOCUMENTATION Given a stringparm ID, return the corresponding name of the stringparm. */ /* PUBLIC */ char *stringparm_id_to_str(int id) { if (id < 0 || id > MAX_STRINGPARMS) fatal_error("stringparm_id_to_str, bad id"); return Stringparms[id].name; } /* stringparm_id_to_str */ /************* * * flag_flag_dependency() * *************/ /* DOCUMENTATION This routine declares that a flag depends on another flag. If flag "id" gets value "val", then flag "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_flag_dependency(int id, BOOL val, int dep_id, BOOL dep_val) { Optdep dep = get_optdep(); dep->type = FLAGT; dep->id = dep_id; dep->val = dep_val; dep->flag_trigger = val; dep->next = Flags[id].dependencies; Flags[id].dependencies = dep; } /* flag_flag_dependency */ /************* * * flag_parm_dependency() * *************/ /* DOCUMENTATION This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_parm_dependency(int id, BOOL val, int dep_id, int dep_val) { Optdep dep = get_optdep(); dep->type = PARMT; dep->id = dep_id; dep->val = dep_val; dep->flag_trigger = val; dep->next = Flags[id].dependencies; Flags[id].dependencies = dep; } /* flag_parm_dependency */ /************* * * flag_stringparm_dependency() * *************/ /* DOCUMENTATION This routine declares that a stringparm depends on a flag. If flag "id" gets value "val", then stringparm "dep_id" is automatically given value "dep_val". */ /* PUBLIC */ void flag_stringparm_dependency(int id, BOOL val, int dep_id, char *dep_val) { Optdep dep = get_optdep(); dep->type = STRINGPARMT; dep->id = dep_id; dep->sval = dep_val; dep->flag_trigger = val; dep->next = Flags[id].dependencies; Flags[id].dependencies = dep; } /* flag_stringparm_dependency */ LADR-2009-11A/ladr/save/fpa.c0000644000175000017500000006577710140244342014630 0ustar mccunemccune#include "fpa.h" /* Private definitions and types */ static unsigned FPA_ID_COUNT = 0; typedef struct fpa_trie * Fpa_trie; struct fpa_trie { Fpa_trie parent, next, kids; int label; Fpa_chunk terms; #ifdef FPA_DEBUG Ilist path; #endif }; struct fpa_index { Fpa_trie root; int depth; Fpa_index next; }; struct fpa_state { int type; Fpa_state left, right; Term left_term, right_term; struct fposition fpos; #ifdef FPA_DEBUG Ilist path; #endif }; /* A path is a sequence of integers. We have to do some operations to the end of a path, and an Ilist is singly-linked; but we can get away with just keeping a pointer to the end of the list. */ struct path { Ilist first; Ilist last; }; enum { LEAF, UNION, INTERSECT }; /* types of fpa_state (node in FPA tree) */ /* for a mutual recursion */ static Fpa_state build_query(Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index); /* * memory management */ static unsigned Fpa_trie_gets, Fpa_trie_frees; static unsigned Fpa_state_gets, Fpa_state_frees; static unsigned Fpa_index_gets, Fpa_index_frees; #define BYTES_FPA_TRIE sizeof(struct fpa_trie) #define PTRS_FPA_TRIE BYTES_FPA_TRIE%BPP == 0 ? BYTES_FPA_TRIE/BPP : BYTES_FPA_TRIE/BPP + 1 #define BYTES_FPA_STATE sizeof(struct fpa_state) #define PTRS_FPA_STATE BYTES_FPA_STATE%BPP == 0 ? BYTES_FPA_STATE/BPP : BYTES_FPA_STATE/BPP + 1 #define BYTES_FPA_INDEX sizeof(struct fpa_index) #define PTRS_FPA_INDEX BYTES_FPA_INDEX%BPP == 0 ? BYTES_FPA_INDEX/BPP : BYTES_FPA_INDEX/BPP + 1 /************* * * Fpa_trie get_fpa_trie() * *************/ static Fpa_trie get_fpa_trie(void) { Fpa_trie p = get_mem(PTRS_FPA_TRIE); p->label = -1; Fpa_trie_gets++; return(p); } /* get_fpa_trie */ /************* * * free_fpa_trie() * *************/ static void free_fpa_trie(Fpa_trie p) { free_mem(p, PTRS_FPA_TRIE); Fpa_trie_frees++; } /* free_fpa_trie */ /************* * * Fpa_state get_fpa_state() * *************/ static Fpa_state get_fpa_state(void) { Fpa_state p = get_mem(PTRS_FPA_STATE); Fpa_state_gets++; return(p); } /* get_fpa_state */ /************* * * free_fpa_state() * *************/ static void free_fpa_state(Fpa_state p) { free_mem(p, PTRS_FPA_STATE); Fpa_state_frees++; } /* free_fpa_state */ /************* * * Fpa_index get_fpa_index() * *************/ static Fpa_index get_fpa_index(void) { Fpa_index p = get_mem(PTRS_FPA_INDEX); p->depth = -1; Fpa_index_gets++; return(p); } /* get_fpa_index */ /************* * * free_fpa_index() * *************/ static void free_fpa_index(Fpa_index p) { free_mem(p, PTRS_FPA_INDEX); Fpa_index_frees++; } /* free_fpa_index */ /************* * * fprint_fpa_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpa package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_fpa_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_FPA_TRIE; fprintf(fp, "fpa_trie (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_trie_gets, Fpa_trie_frees, Fpa_trie_gets - Fpa_trie_frees, ((Fpa_trie_gets - Fpa_trie_frees) * n) / 1024.); n = BYTES_FPA_STATE; fprintf(fp, "fpa_state (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_state_gets, Fpa_state_frees, Fpa_state_gets - Fpa_state_frees, ((Fpa_state_gets - Fpa_state_frees) * n) / 1024.); n = BYTES_FPA_INDEX; fprintf(fp, "fpa_index (%4d) %11u%11u%11u%9.1f K\n", n, Fpa_index_gets, Fpa_index_frees, Fpa_index_gets - Fpa_index_frees, ((Fpa_index_gets - Fpa_index_frees) * n) / 1024.); } /* fprint_fpa_mem */ /************* * * p_fpa_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the fpa package. */ /* PUBLIC */ void p_fpa_mem() { fprint_fpa_mem(stdout, TRUE); } /* p_fpa_mem */ /* * end of memory management */ /************* * * fprint_path() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) an FPA Path. A newline is NOT printed. */ /* PUBLIC */ void fprint_path(FILE *fp, Ilist p) { int i; fprintf(fp, "("); for (i = 0; p != NULL; p = p->next, i++) { if (i%2 == 0) { if (p->i == 0) fprintf(fp, "*"); else fprint_sym(fp, p->i); } else fprintf(fp, "%d", p->i); if (p->next != NULL) fprintf(fp, " "); } fprintf(fp, ")"); } /* fprint_path */ /************* * * p_path() * *************/ /* DOCUMENTATION This routine prints (to stdout) an FPA Path. A newline is NOT printed. */ /* PUBLIC */ void p_path(Ilist p) { fprint_path(stdout, p); fflush(stdout); } /* p_path */ /************* * * fprint_fpa_trie -- Print an FPA trie to stdout. * *************/ static void fprint_fpa_trie(FILE *fp, Fpa_trie p, int depth) { int i; Fpa_trie q; for (i = 0; i < depth; i++) fprintf(fp, " - "); if (depth == 0) fprintf(fp, "root"); else if (depth % 2 == 1) { if (p->label == 0) fprintf(fp, "*"); else fprint_sym(fp, p->label); } else fprintf(fp, "%2d", p->label); if (p->terms != NULL) { #if 0 Plist g; fprintf(fp, " ["); for (g = p->terms; g != NULL; g = g->next) fprintf(fp, "%u%s", (unsigned) FPA_ID(g->v), g->next == NULL ? "" : ","); fprintf(fp, "]"); #endif } #ifdef FPA_DEBUG if (p->path != NULL) fprint_path(fp, p->path); #endif fprintf(fp, "\n"); for (q = p->kids; q != NULL; q = q->next) fprint_fpa_trie(fp, q, depth+1); } /* fprint_fpa_trie */ /************* * * fprint_fpa_index() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first. */ /* PUBLIC */ void fprint_fpa_index(FILE *fp, Fpa_index idx) { fprintf(fp, "FPA/Path index, depth is %d.\n", idx->depth); fprint_fpa_trie(fp, idx->root, 0); } /* fprint_fpa_index */ /************* * * p_fpa_index() * *************/ /* DOCUMENTATION This routine prints (to stdout) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first. */ /* PUBLIC */ void p_fpa_index(Fpa_index idx) { fprint_fpa_index(stdout, idx); } /* p_fpa_index */ /************* * * fpa_trie_member_insert (recursive) -- This routine takes a trie * and a path, and looks for a node in the trie that corresponds * to the path. If such a node does not exist, it is created, and * the trie is updated. * *************/ static Fpa_trie fpa_trie_member_insert(Fpa_trie node, Ilist path) { if (path == NULL) return node; else { /* Find child node that matches first member of path; * if it doesn't exist, create it. Children are in increasing order. */ int val = path->i; Fpa_trie curr = node->kids; Fpa_trie prev = NULL; while (curr != NULL && curr->label < val) { prev = curr; curr = curr->next; } if (curr != NULL && curr->label == val) return fpa_trie_member_insert(curr, path->next); else { /* Get a new node and insert it before curr (which may be NULL). */ Fpa_trie new = get_fpa_trie(); new->parent = node; new->label = val; new->next = curr; if (prev == NULL) node->kids = new; else prev->next = new; return fpa_trie_member_insert(new, path->next); } } } /* fpa_trie_member_insert */ /************* * * fpa_trie_member (recursive) -- This routine looks for a trie * node that corresponds to a given path. * *************/ static Fpa_trie fpa_trie_member(Fpa_trie node, Ilist path) { if (path == NULL) return node; else { /* Find child node that matches first member of path; * Children are in increasing order. */ int val = path->i; Fpa_trie curr = node->kids; while (curr != NULL && curr->label < val) curr = curr->next; if (curr != NULL && curr->label == val) return fpa_trie_member(curr, path->next); else return NULL; } } /* fpa_trie_member */ /************* * * fpa_trie_possible_delete (recursive) -- This routine checks if * a trie node should be deleted. If so, it is deleted, and a * recursive call is made on the parent node. The trie node should * be deleted if (1) it is not the root, (2) there is no FPA list, * and (3) it has no children. * *************/ static void fpa_trie_possible_delete(Fpa_trie node) { if (node->parent != NULL && node->terms == NULL && node->kids == NULL) { if (node->parent->kids == node) node->parent->kids = node->next; else { Fpa_trie p = node->parent->kids; while (p->next != node) p = p->next; p->next = node->next; } fpa_trie_possible_delete(node->parent); free_fpa_trie(node); } } /* fpa_trie_delete */ /************* * * path_insert -- Given (term,path,index), insert a pointer * to the term into the path list of the index. * *************/ static void path_insert(Term t, Ilist path, Fpa_trie index) { Fpa_trie node = fpa_trie_member_insert(index, path); #ifdef FPA_DEBUG if (node->path == NULL) node->path = copy_ilist(path); #endif node->terms = flist_insert(node->terms, t); } /* path_insert */ /************* * * path_delete -- Given (term,path,index), try to delete a pointer * to the term from the path list of the index. * *************/ static void path_delete(Term t, Ilist path, Fpa_trie index) { Fpa_trie node = fpa_trie_member(index, path); if (node == NULL) { fatal_error("path_delete, trie node not found."); } node->terms = flist_delete(node->terms, t); #ifdef FPA_DEBUG if (node->terms == NULL) { zap_ilist(node->path); node->path = NULL; } #endif fpa_trie_possible_delete(node); } /* path_delete */ /************* * * path_push -- append an integer to a path. "save" is used because * we have a pointer to the last member, but the list is singly linked. * *************/ static Ilist path_push(struct path *p, int i) { Ilist new = get_ilist(); Ilist save = p->last; new->i = i; if (p->last == NULL) p->first = new; else p->last->next = new; p->last = new; return save; } /* path_push */ /************* * * path_restore -- pop and throw away the last member of a path. * We assume that "save" points to the next-to-last member. * *************/ static void path_restore(struct path *p, Ilist save) { free_ilist(p->last); p->last = save; if (save != NULL) save->next = NULL; else p->first = NULL; } /* path_restore */ /************* * * fpa_paths (recursive) -- This routine traverses a term, keeping a * path, and either inserts or deletes pointers to the term into/from the * appropriate path lists of an FPA/PATH index. * *************/ static void fpa_paths(Term root, Term t, struct path *p, int bound, Indexop op, Fpa_trie index) { Ilist save1; if (VARIABLE(t)) save1 = path_push(p, 0); else save1 = path_push(p, SYMNUM(t)); if (COMPLEX(t) && bound > 0 && !is_assoc_comm(SYMNUM(t))) { int i; Ilist save2 = path_push(p, 0); for (i = 0; i < t->arity; i++) { p->last->i = i+1; /* Count arguments from 1. */ fpa_paths(root, t->args[i], p, bound-1, op, index); } path_restore(p, save2); } else { /* printf(" "); p_path(p->first); */ if (op == INSERT) path_insert(root, p->first, index); else path_delete(root, p->first, index); } path_restore(p, save1); } /* fpa_paths */ /************* * * fpa_init_index() * *************/ /* DOCUMENTATION This routine allocates and returns an empty FPA/Path index. Parameter depth tells how deep to index the terms. For example, depth=0 means to index on the root symbol only. */ /* PUBLIC */ Fpa_index fpa_init_index(int depth) { Fpa_index f = get_fpa_index(); f->depth = depth; f->root = get_fpa_trie(); return f; } /* fpa_init_index */ /************* * * fpa_update -- Insert/delete a term into/from a FPA-PATH index. * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) a term into an Fpa_index or deletes (op==DELETE) a term from an Fpa_index.

IMPORTANT: FPA indexing owns the FPA_ID field of the term.

A fatal error occurs if you try to delete a term that was not previously inserted. */ /* PUBLIC */ void fpa_update(Term t, Fpa_index idx, Indexop op) { struct path p; if (FPA_ID(t) == 0) { if (op == INSERT) FPA_ID(t) = ++FPA_ID_COUNT; else fatal_error("fpa_update: FPA_ID=0."); } p.first = p.last = NULL; fpa_paths(t, t, &p, idx->depth, op, idx->root); } /* fpa_update */ /************* * * query_leaf_full - for testing only * * Ordinarily, with query_leaf(), if an FPA list doesn't exist, * the query will be simplified. If you wish to get the whole * query tree, with NULL leaves for nonexistant FPA lists, you * can use this instead of query_leaf(). This is useful if you * want to print the query tree. * *************/ #ifdef FPA_DEBUG static Fpa_state query_leaf_full(Ilist path, Fpa_trie index) { Fpa_trie n = fpa_trie_member(index, path); Fpa_state q = get_fpa_state(); q->type = LEAF; q->terms = (n == NULL ? NULL : n->terms); q->path = copy_ilist(path); return q; } /* query_leaf_full */ #endif /************* * * query_leaf * *************/ static Fpa_state query_leaf(Ilist path, Fpa_trie index) { Fpa_trie n; /* return query_leaf_full(path, index); */ n = fpa_trie_member(index, path); if (n == NULL) return NULL; else { Fpa_state q = get_fpa_state(); q->type = LEAF; q->fpos = first_fpos(n->terms); #ifdef FPA_DEBUG q->path = copy_ilist(path); #endif return q; } } /* query_leaf */ /************* * * query_intersect * *************/ static Fpa_state query_intersect(Fpa_state q1, Fpa_state q2) { /* Assume neither is NULL. */ Fpa_state q = get_fpa_state(); q->type = INTERSECT; q->left = q1; q->right = q2; return q; } /* query_intersect */ /************* * * query_union * *************/ static Fpa_state query_union(Fpa_state q1, Fpa_state q2) { if (q1 == NULL) return q2; else if (q2 == NULL) return q1; else { Fpa_state q = get_fpa_state(); q->type = UNION; q->left = q1; q->right = q2; return q; } } /* query_union */ /************* * * query_special (recursive) * *************/ static Fpa_state query_special(Fpa_trie n) { /* There are 2 kinds of nodes: argument position (1,2,3,...) and * symbol (a,b,f,g,h); the two types alternate in a path. The * given node n is a symbol node. What we wish to do is construct * the union of all leaves, excluding those that have an argument * position greater than 1. This should contain all terms that * have a path corresponding to node n. */ if (n->kids == NULL) { Fpa_state q = get_fpa_state(); q->type = LEAF; q->fpos = first_fpos(n->terms); #ifdef FPA_DEBUG q->path = copy_ilist(n->path); #endif return q; } else { Fpa_state q1 = NULL; Fpa_trie pos_child; for (pos_child=n->kids; pos_child!=NULL; pos_child=pos_child->next) { if (pos_child->label == 1) { Fpa_trie sym_child; for (sym_child=pos_child->kids; sym_child!=NULL; sym_child=sym_child->next) { Fpa_state q2 = query_special(sym_child); q1 = query_union(q1, q2); } } } return q1; } } /* query_special */ /************* * * zap_fpa_state (recursive) * * This (recursive) routine frees an Fpa_state. * It should NOT be called if you retrieve all answers to * a query, because the query tree is freed as it is processsed * by fpa_next_answer(). This routine should be called only if * you decide not to get all of the answers. * *************/ static void zap_fpa_state(Fpa_state q) { if (q != NULL) { zap_fpa_state(q->left); zap_fpa_state(q->right); #ifdef FPA_DEBUG zap_ilist(q->path); #endif free_fpa_state(q); } } /* zap_fpa_state */ /************* * * union_commuted() * *************/ static Fpa_state union_commuted(Fpa_state q, Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index) { Fpa_state q1; int empty, i; #if 0 printf("enter union_commuted with\n"); p_fpa_state(q); #endif q1 = NULL; empty = 0; for (i = 0; i < 2 && !empty; i++) { p->last->i = (i == 0 ? 2 : 1); /* Skip this arg if VARIABLE && (UNIFY || INSTANCE). */ if (!VARIABLE(t->args[i]) || type==GENERALIZATION || type==VARIANT || type==IDENTICAL) { Fpa_state q2 = build_query(t->args[i], c, type, p, bound-1, index); if (q2 == NULL) { empty = 1; zap_fpa_state(q1); q1 = NULL; } else if (q1 == NULL) q1 = q2; else q1 = query_intersect(q1, q2); } } if (q1 != NULL) q1 = query_union(q, q1); else q1 = q; #if 0 printf("exit union_commuted with\n"); p_fpa_state(q1); #endif return(q1); } /* union_commuted */ /************* * * var_in_context() * *************/ static BOOL var_in_context(Term t, Context c) { DEREFERENCE(t, c); return VARIABLE(t); } /* var_in_context */ /************* * * all_args_vars_in_context() * *************/ static BOOL all_args_vars_in_context(Term t, Context c) { /* Assume t is not a variable. */ int i = 0; BOOL ok = TRUE; while (i < t->arity && ok) { ok = var_in_context(t->args[i], c); i++; } return ok; } /* all_args_vars_in_context */ /************* * * build_query() * *************/ static Fpa_state build_query(Term t, Context c, Querytype type, struct path *p, int bound, Fpa_trie index) { if (VARIABLE(t)) { int i = VARNUM(t); if (c != NULL && c->terms[i] != NULL) return build_query(c->terms[i], c->contexts[i], type, p, bound, index); else if (type == UNIFY || type == INSTANCE) { fatal_error("build_query, variable."); return NULL; /* to quiet compiler */ } else { Ilist save = path_push(p, 0); Fpa_state q = query_leaf(p->first, index); path_restore(p, save); return q; } } else { /* non-variable */ Fpa_state q1 = NULL; Ilist save1 = path_push(p, SYMNUM(t)); if (CONSTANT(t) || bound <= 0 || is_assoc_comm(SYMNUM(t))) { q1 = query_leaf(p->first, index); } else if ((type == INSTANCE || type == UNIFY) && all_args_vars_in_context(t, c)) { Fpa_trie n = fpa_trie_member(index, p->first); q1 = (n == NULL ? NULL : query_special(n)); } else { Ilist save2 = path_push(p, 0); int empty = 0; int i; for (i = 0; i < t->arity && !empty; i++) { p->last->i = i+1; /* Skip this arg if VARIABLE && (UNIFY || INSTANCE). */ if (!var_in_context(t->args[i],c) || type==GENERALIZATION || type==VARIANT || type==IDENTICAL) { Fpa_state q2 = build_query(t->args[i], c, type, p, bound-1, index); if (q2 == NULL) { empty = 1; zap_fpa_state(q1); q1 = NULL; } else if (q1 == NULL) q1 = q2; else q1 = query_intersect(q1, q2); } } if (is_commutative(SYMNUM(t)) && !term_ident(t->args[0], t->args[1])) q1 = union_commuted(q1, t, c, type, p, bound, index); path_restore(p, save2); } if (type == UNIFY || type == GENERALIZATION) { Fpa_state q2; p->last->i = 0; q2 = query_leaf(p->first, index); q1 = query_union(q1, q2); } path_restore(p, save1); return q1; } } /* build_query */ /************* * * fprint_fpa_state (recursive) * *************/ /* DOCUMENTATION This (recursive) routine prints (to FILE *fp) an Fpa_state tree. The depth parameter should be 0 on the top call. This is an AND/OR tree, with lists of terms (ordered by FPA_ID) at the leaves. If FPA_DEBUG is not defined in fpa.h, the paths corresponding to the leaves are not printed, and the tree is hard to understand without the paths. */ /* PUBLIC */ void fprint_fpa_state(FILE *fp, Fpa_state q, int depth) { int i; for (i = 0; i < depth; i++) fprintf(fp, "- - "); switch (q->type) { case UNION: fprintf(fp, "OR\n"); break; case INTERSECT: fprintf(fp, "AND\n"); break; case LEAF: #ifdef FPA_DEBUG fprint_path(fp, q->path); fprintf(fp, " "); #endif { #if 0 Plist p; fprintf(fp, "["); for (p = q->terms; p != NULL; p = p->next) fprintf(fp, "%u%s", (unsigned) FPA_ID(p->v), p->next == NULL ? "" : ","); fprintf(fp, "]\n"); #endif } break; } fflush(fp); if (q->type == UNION || q->type == INTERSECT) { fprint_fpa_state(fp, q->right, depth+1); fprint_fpa_state(fp, q->left, depth+1); } } /* fprint_fpa_state */ /************* * * p_fpa_state * *************/ /* DOCUMENTATION This routine prints (to stdout) an Fpa_state tree. See the description of fprint_fpa_state(). */ /* PUBLIC */ void p_fpa_state(Fpa_state q) { fprint_fpa_state(stdout, q, 0); } /* fprint_fpa_state */ /************* * * p_fpa_query * *************/ /* DOCUMENTATION This routine constructs an fpa_query tree and prints it to stdout. */ /* PUBLIC */ void p_fpa_query(Term t, Querytype query_type, Fpa_index idx) { Fpa_state q; char *s; struct path p; p.first = p.last = NULL; switch (query_type) { case UNIFY: s = "UNIFY "; break; case INSTANCE: s = "INSTANCE "; break; case GENERALIZATION: s = "GENERALIZATION"; break; case VARIANT: s = "VARIANT "; break; case IDENTICAL: s = "IDENTICAL "; break; default: s = "FPA_?? "; break; } printf("\n%s with term %u: ", s, (unsigned) FPA_ID(t)); p_term(t); fflush(stdout); q = build_query(t, NULL, query_type, &p, idx->depth, idx->root); p_fpa_state(q); zap_fpa_state(q); } /* fprint_fpa_query */ /************* * * next_term() * * Get the first or next term that satisfies a unification condition. * (Unification conditions are provided by build_query.) * `max' should be FPA_ID_MAX on top calls. A return of NULL indicates * that there are none or no more terms that satisfy (and the tree has * been deallocated). If you want to stop getting terms before a NULL * is returned, then please deallocate the tree with zap_fpa_state(tree). * * Warning: a return of NULL means that the tree has been deallocated. * *************/ static Term next_term(Fpa_state q, FPA_ID_TYPE max) { if (q == NULL) return NULL; else if (q->type == LEAF) { Term t = FTERM(q->fpos); while (t != NULL && FPA_ID(t) > max) { q->fpos = next_fpos(q->fpos); t = FTERM(q->fpos); } if (t == NULL) { zap_fpa_state(q); return NULL; } else { q->fpos = next_fpos(q->fpos); return t; } } else if (q->type == INTERSECT) { Term t1, t2; t1 = next_term(q->left, max); if (t1 != NULL) t2 = next_term(q->right, FPA_ID(t1)); else t2 = (Term) &t2; /* anything but NULL */ while (t1 != t2 && t1 != NULL && t2 != NULL) { if (FGT(t1,t2)) t1 = next_term(q->left, FPA_ID(t2)); else t2 = next_term(q->right, FPA_ID(t1)); } if (t1 == NULL || t2 == NULL) { if (t1 == NULL) q->left = NULL; if (t2 == NULL) q->right = NULL; zap_fpa_state(q); return NULL; } else return t1; } else { /* UNION node */ Term t1, t2; /* first get the left term */ t1 = q->left_term; if (t1 == NULL) { /* it must be brought up */ if (q->left) { t1 = next_term(q->left, max); if (t1 == NULL) q->left = NULL; } } else /* it was saved from a previous call */ q->left_term = NULL; /* now do the same for the right side */ t2 = q->right_term; if (t2 == NULL) { if (q->right) { t2 = next_term(q->right, max); if (t2 == NULL) q->right = NULL; } } else q->right_term = NULL; /* At this point, both left_term and right_term are NULL. * Now decide which of t1 and t2 to return. If both are * non-NULL (and different), save the smaller for the next * call, and return the larger. */ if (t1 == NULL) { if (t2 == NULL) { zap_fpa_state(q); return NULL; } else return t2; } else if (t2 == NULL) return t1; else if (t1 == t2) return t1; else if (FGT(t1,t2)) { q->right_term = t2; /* save t2 for next time */ return t1; } else { q->left_term = t1; /* save t1 for next time */ return t2; } } } /* next_term */ /************* * * fpa_next_answer() * *************/ /* DOCUMENTATION This routine extracts and returns the next answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree. */ /* PUBLIC */ Term fpa_next_answer(Fpa_state q) { return next_term(q, FPA_ID_MAX); } /* fpa_next_answer */ /************* * * fpa_first_answer() * *************/ /* DOCUMENTATION This routine extracts and returns the first answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree.

The query types are UNIFY, INSTANCE, GENERALIZATION, VARIANT, and IDENTICAL.

If Context c is not NULL, then the instance of the term (in the context) is used for the query. */ /* PUBLIC */ Term fpa_first_answer(Term t, Context c, Querytype query_type, Fpa_index idx, Fpa_state *ppos) { struct path p; p.first = p.last = NULL; *ppos = build_query(t, c, query_type, &p, idx->depth, idx->root); return fpa_next_answer(*ppos); } /* fpa_first_answer */ /************* * * fpa_cancel * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all answers to an fpa query. See fpa_first_answer() and fpa_next_answer(). */ /* PUBLIC */ void fpa_cancel(Fpa_state q) { zap_fpa_state(q); } /* fpa_cancel */ /************* * * zap_fpa_trie() * *************/ static void zap_fpa_trie(Fpa_trie n) { Fpa_trie k, prev; k = n->kids; while (k != NULL) { prev = k; k = k->next; zap_fpa_trie(prev); } if (n->terms != NULL) zap_fpa_chunks(n->terms); #ifdef FPA_DEBUG zap_ilist(n->path); #endif free_fpa_trie(n); } /* zap_fpa_trie */ /************* * * zap_fpa_index() * *************/ /* DOCUMENTATION This routine removes all the entries from an Fpa_index idx and frees all of the associated memory. */ /* PUBLIC */ void zap_fpa_index(Fpa_index idx) { zap_fpa_trie(idx->root); free_fpa_index(idx); } /* zap_fpa_index */ /************* * * fpa_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an FPA/Path index is empty. */ /* PUBLIC */ BOOL fpa_empty(Fpa_index idx) { return (idx == NULL ? TRUE : idx->root->kids == NULL); } /* fpa_empty */ LADR-2009-11A/ladr/save/sos.h0000644000175000017500000000132310553716771014666 0ustar mccunemccune#ifndef TP_SOS_H #define TP_SOS_H #include "clist.h" /* INTRODUCTION */ /* Public definitions */ enum { BY_AGE, BY_WEIGHT, BY_RATIO }; enum { SOS1, SOS2 }; /* End of public definitions */ /* Public function prototypes from sos.c */ void p_sos_tree(void); void p_sos_dist(void); void index_sos(Topform c, int set); void insert_into_sos(Topform c, Clist sos, int set); void remove_from_sos(Topform c, Clist sos, int set); Topform first_sos_clause(Clist lst); Topform lightest_sos_clause(int set); Topform worst_sos_clause(Clist sos, int method); int wt_of_clause_at(int set, double part); int clauses_of_weight(int wt, int set); void zap_sos_index(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/commands2.c0000644000175000017500000001565210147175222015737 0ustar mccunemccune#include "commands.h" /* Private definitions and types */ /************* * * process_op() * *************/ static void process_op(FILE *fout, Term t, int prec, Term type_term, Term symb_term) { if (ARITY(symb_term) != 0) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("symbols in op command must have no arguments"); } else { Parsetype pt = NOTHING_SPECIAL; if (is_constant(type_term, "infix")) pt = INFIX; else if (is_constant(type_term, "infix_left")) pt = INFIX_LEFT; else if (is_constant(type_term, "infix_right")) pt = INFIX_RIGHT; else if (is_constant(type_term, "prefix")) pt = PREFIX; else if (is_constant(type_term, "prefix_paren")) pt = PREFIX_PAREN; else if (is_constant(type_term, "postfix")) pt = POSTFIX; else if (is_constant(type_term, "postfix_paren")) pt = POSTFIX_PAREN; else if (is_constant(type_term, "clear")) pt = NOTHING_SPECIAL; else { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad parse-type in op command"); } set_parse_type(sn_to_str(SYMNUM(symb_term)), prec, pt); } } /* process_op */ /************* * * flag_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void flag_handler(FILE *fout, Term t, int unknown_action) { int flag = str_to_flag_id(sn_to_str(SYMNUM(ARG(t,0)))); if (flag == -1) { if (unknown_action == KILL_UNKNOWN) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("flag not recognized"); } else if (unknown_action == WARN_UNKNOWN) { bell(stderr); fprintf(fout, "WARNING, flag not recognized: "); fwrite_term_nl(fout, t); fprintf(stderr, "WARNING, flag not recognized: "); fwrite_term_nl(stderr, t); } else if (unknown_action == NOTE_UNKNOWN) { fprintf(fout, "NOTE: flag not recognized: "); fwrite_term_nl(fout, t); } } else update_flag(fout, flag, is_term(t, "set", 1)); } /* flag_handler */ /************* * * parm_handler() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void parm_handler(FILE *fout, Term t, int unknown_action) { int val; BOOL ok = term_to_int(ARG(t,1), &val); if (!ok) { int id = str_to_stringparm_id(sn_to_str(SYMNUM(ARG(t,0)))); if (id == -1) { /* This should take into account unknown_action. */ fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad assign command"); } else { char *s = sn_to_str(SYMNUM(ARG(t,1))); assign_stringparm(id, s); } } else { int parm = str_to_parm_id(sn_to_str(SYMNUM(ARG(t,0)))); if (parm == -1) { if (unknown_action == KILL_UNKNOWN) { fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("parm not recognized"); } else if (unknown_action == WARN_UNKNOWN) { bell(stderr); fprintf(fout, "WARNING, parm not recognized: "); fwrite_term_nl(fout, t); fprintf(stderr, "WARNING, parm not recognized: "); fwrite_term_nl(stderr, t); } else if (unknown_action == NOTE_UNKNOWN) { fprintf(fout, "NOTE: parm not recognized: "); fwrite_term_nl(fout, t); } } else { assign_parm(parm, val); } } } /* parm_handler */ /************* * * preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void preliminary_precedence(Plist p) { int n = 0; Plist q; reinit_lex_vals(); for (q = p ; q; q = q->next) { Term t = q->v; set_lex_val(SYMNUM(t), ++n); } } /* preliminary_precedence */ /************* * * read_commands() * *************/ /* DOCUMENTATION

This routine reads commands from a file. Echoing the commands to an output file is optional. Here are examples of the currently supported commands.

  • set(verbose).
  • clear(verbose).
  • assign(max_seconds, 1800).
  • assoc_comm(+).
  • commutative(+).
  • op(400, infix, ^).
  • lex([e, a, b, _*_, _', h(_,_)]).

A term is returned:

  • NULL: commands were read up to EOF.
  • nonNULL term: commands were read up to this unrecognized term; you will probably wish to continue your input processing with this term.

If any error occurs, a message goes to file fout and to stderr, and a fatal_error() occurs. */ /* PUBLIC */ Term read_commands(FILE *fin, FILE *fout, BOOL echo, int unknown_action) { Term t = read_term(fin, fout); BOOL go = (t != NULL); while (go) { BOOL already_echoed = FALSE; /************************************************************ set, clear */ if (is_term(t, "set", 1) || is_term(t, "clear", 1)) { if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } flag_handler(fout, t, unknown_action); } else if (is_term(t, "assign", 2)) { /************************************************************** assign */ if (echo) { fwrite_term_nl(fout, t); already_echoed = TRUE; } parm_handler(fout, t, unknown_action); } else if (is_term(t, "assoc_comm", 1) || is_term(t, "commutative", 1)) { /************************************************************ AC, etc. */ Term f = ARG(t,0); if (!CONSTANT(f)) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("argument must be symbol only"); } else { if (is_term(t, "assoc_comm", 1)) set_assoc_comm(sn_to_str(SYMNUM(f)), TRUE); else set_commutative(sn_to_str(SYMNUM(f)), TRUE); } } else if (is_term(t, "op", 3)) { /****************************************************************** op */ /* e.g., op(300, infix, +); */ Term prec_term = ARG(t,0); Term type_term = ARG(t,1); Term symb_term = ARG(t,2); int prec; BOOL ok = term_to_int(prec_term, &prec); if (!ok || prec < MIN_PRECEDENCE || prec > MAX_PRECEDENCE) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("bad precedence in op command"); } else if (proper_listterm(symb_term)) { while (cons_term(symb_term)) { process_op(fout, t, prec, type_term, ARG(symb_term, 0)); symb_term = ARG(symb_term, 1); } } else process_op(fout, t, prec, type_term, symb_term); } else if (is_term(t, "lex", 1)) { /***************************************************************** lex */ Plist p = listterm_to_tlist(ARG(t,0)); if (p == NULL) { bell(stderr); fwrite_term_nl(fout, t); fwrite_term_nl(stderr, t); fatal_error("lex command must contain a proper list, e.g., [a,b,c]"); } else { preliminary_precedence(p); zap_plist(p); } } else { /******************************************************** unrecognized */ /* return this unknown term */ go = FALSE; } if (go) { if (echo && !already_echoed) fwrite_term_nl(fout, t); zap_term(t); t = read_term(fin, fout); go = (t != NULL); } } return t; } /* read_commands */ LADR-2009-11A/ladr/save/glist.c0000644000175000017500000003734610140052375015176 0ustar mccunemccune#include "glist.h" /* * memory management */ static unsigned Ilist_gets, Ilist_frees; static unsigned Plist_gets, Plist_frees; #define BYTES_ILIST sizeof(struct ilist) #define PTRS_ILIST BYTES_ILIST%BPP == 0 ? BYTES_ILIST/BPP : BYTES_ILIST/BPP + 1 #define BYTES_PLIST sizeof(struct plist) #define PTRS_PLIST BYTES_PLIST%BPP == 0 ? BYTES_PLIST/BPP : BYTES_PLIST/BPP + 1 /************* * * Ilist get_ilist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist get_ilist(void) { Ilist p = get_mem(PTRS_ILIST); Ilist_gets++; return(p); } /* get_ilist */ /************* * * free_ilist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_ilist(Ilist p) { free_mem(p, PTRS_ILIST); Ilist_frees++; } /* free_ilist */ /************* * * Plist get_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist get_plist(void) { Plist p = get_mem(PTRS_PLIST); Plist_gets++; return(p); } /* get_plist */ /************* * * free_plist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_plist(Plist p) { free_mem(p, PTRS_PLIST); Plist_frees++; } /* free_plist */ /************* * * fprint_glist_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the glist package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_glist_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_ILIST; fprintf(fp, "ilist (%4d) %11u%11u%11u%9.1f K\n", n, Ilist_gets, Ilist_frees, Ilist_gets - Ilist_frees, ((Ilist_gets - Ilist_frees) * n) / 1024.); n = BYTES_PLIST; fprintf(fp, "plist (%4d) %11u%11u%11u%9.1f K\n", n, Plist_gets, Plist_frees, Plist_gets - Plist_frees, ((Plist_gets - Plist_frees) * n) / 1024.); } /* fprint_glist_mem */ /************* * * p_glist_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the glist package. */ /* PUBLIC */ void p_glist_mem() { fprint_glist_mem(stdout, TRUE); } /* p_glist_mem */ /* * end of memory management */ /************* * * ilist_cat() * *************/ /* DOCUMENTATION Concatenate two Ilists and return the result. The result is constructed from the arguments, so not refer to either of the arguments after the call. */ /* PUBLIC */ Ilist ilist_cat(Ilist p1, Ilist p2) { if (p1 == NULL) return p2; else if (p2 == NULL) return p1; else { Ilist p = p1; while (p->next != NULL) p = p->next; p->next = p2; return p1; } } /* ilist_cat */ /************* * * ilist_pop() * *************/ /* DOCUMENTATION This routine takes a nonempty Ilist, removes and frees the first node (ignoring the contents), and returns the remainder of the list. */ /* PUBLIC */ Ilist ilist_pop(Ilist p) { Ilist q = p; p = p->next; free_ilist(q); return p; } /* ilist_pop */ /************* * * ilist_count() * *************/ /* DOCUMENTATION This routine returns the length of a Ilist. */ /* PUBLIC */ int ilist_count(Ilist p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* ilist_count */ /************* * * rev_app_ilist(p1, p2) * *************/ static Ilist rev_app_ilist(Ilist p1, Ilist p2) { Ilist p3; if (p1 == NULL) return(p2); else { p3 = p1->next; p1->next = p2; return(rev_app_ilist(p3, p1)); } } /* rev_app_ilist */ /************* * * reverse_ilist(p1) * *************/ /* DOCUMENTATION This routine reverses a Ilist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:

p = reverse_ilist(p);
*/ /* PUBLIC */ Ilist reverse_ilist(Ilist p) { return rev_app_ilist(p, NULL); } /* reverse_ilist */ /************* * * copy_ilist(p) * *************/ /* DOCUMENTATION This routine copies a Ilist (the whole list) and returns the copy. */ /* PUBLIC */ Ilist copy_ilist(Ilist p) { Ilist start, p1, p2; start = NULL; p2 = NULL; for ( ; p; p = p->next) { p1 = get_ilist(); p1->i = p->i; if (p2) p2->next = p1; else start = p1; p2 = p1; } return(start); } /* copy_ilist */ /************* * * zap_ilist(p) * *************/ /* DOCUMENTATION This routine frees a Ilist (the whole list). If the list contains any pointers, the things to which they point are not freed. */ /* PUBLIC */ void zap_ilist(Ilist p) { Ilist curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_ilist(prev); } } /* zap_ilist */ /************* * * ilist_append() * *************/ /* DOCUMENTATION This routine appends an integer to a Ilist. The updated Ilist is returned. */ /* PUBLIC */ Ilist ilist_append(Ilist lst, int i) { if (lst == NULL) { Ilist g = get_ilist(); g->i = i; return g; } else { lst->next = ilist_append(lst->next, i); return lst; } } /* ilist_append */ /************* * * ilist_prepend() * *************/ /* DOCUMENTATION This routine inserts an integer as the first member of a Ilist. The updated Ilist is returned. */ /* PUBLIC */ Ilist ilist_prepend(Ilist lst, int i) { Ilist g = get_ilist(); g->i = i; g->next = lst; return g; } /* ilist_prepend */ /************* * * ilist_member() * *************/ /* DOCUMENTATION This function checks if an integer is a member of a Ilist. (If a node in the Ilist contains a pointer instead of an integer, the result is undefined.) */ /* PUBLIC */ BOOL ilist_member(Ilist lst, int i) { if (lst == NULL) return FALSE; else if (lst->i == i) return TRUE; else return ilist_member(lst->next, i); } /* ilist_member */ /************* * * ilist_subtract() * *************/ /* DOCUMENTATION Return the members of p1 that are not in p2; */ /* PUBLIC */ Ilist ilist_subtract(Ilist p1, Ilist p2) { if (p1 == NULL) return NULL; else { Ilist r = ilist_subtract(p1->next, p2); if (ilist_member(p2, p1->i)) return r; else return ilist_prepend(r, p1->i); } } /* ilist_subtract */ /************* * * ilist_intersect() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_intersect(Ilist p1, Ilist p2) { if (p1 == NULL) return NULL; else { Ilist r = ilist_intersect(p1->next, p2); if (ilist_member(p2, p1->i)) return ilist_prepend(r, p1->i); else return r; } } /* ilist_intersect */ /************* * * ilist_set() * *************/ /* DOCUMENTATION Take a list of integers and remove duplicates. This creates a new list and leave the old list as it was. Don't make any assumptions about the order of the result. */ /* PUBLIC */ Ilist ilist_set(Ilist m) { if (m == NULL) return NULL; else { Ilist s = ilist_set(m->next); if (ilist_member(s, m->i)) return s; else return ilist_prepend(s, m->i); } } /* ilist_set */ /************* * * ilist_is_set() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ilist_is_set(Ilist a) { if (a == NULL) return TRUE; else if (ilist_member(a->next, a->i)) return FALSE; else return ilist_is_set(a->next); } /* ilist_is_set */ /************* * * ilist_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ilist_subset(Ilist a, Ilist b) { if (a == NULL) return TRUE; else if (!ilist_member(b, a->i)) return FALSE; else return ilist_subset(a->next, b); } /* plist_subset */ /************* * * plist_cat() * *************/ /* DOCUMENTATION Concatenate two Plists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call. */ /* PUBLIC */ Plist plist_cat(Plist p1, Plist p2) { if (p1 == NULL) return p2; else if (p2 == NULL) return p1; else { Plist p = p1; while (p->next != NULL) p = p->next; p->next = p2; return p1; } } /* plist_cat */ /************* * * plist_pop() * *************/ /* DOCUMENTATION This routine takes a nonempty Plist, removes and frees the first node (ignoring the contents), and returns the remainder of the list. */ /* PUBLIC */ Plist plist_pop(Plist p) { Plist q = p; p = p->next; free_plist(q); return p; } /* plist_pop */ /************* * * plist_count() * *************/ /* DOCUMENTATION This routine returns the length of a Plist. */ /* PUBLIC */ int plist_count(Plist p) { int n; for (n = 0; p; p = p->next, n++); return(n); } /* plist_count */ /************* * * rev_app_plist(p1, p2) * *************/ static Plist rev_app_plist(Plist p1, Plist p2) { Plist p3; if (p1 == NULL) return(p2); else { p3 = p1->next; p1->next = p2; return(rev_app_plist(p3, p1)); } } /* rev_app_plist */ /************* * * reverse_plist(p1) * *************/ /* DOCUMENTATION This routine reverses a Plist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:
p = reverse_plist(p);
*/ /* PUBLIC */ Plist reverse_plist(Plist p) { return rev_app_plist(p, NULL); } /* reverse_plist */ /************* * * copy_plist(p) * *************/ /* DOCUMENTATION This routine copies a Plist (the whole list) and returns the copy. */ /* PUBLIC */ Plist copy_plist(Plist p) { Plist start, p1, p2; start = NULL; p2 = NULL; for ( ; p; p = p->next) { p1 = get_plist(); p1->v = p->v; if (p2) p2->next = p1; else start = p1; p2 = p1; } return(start); } /* copy_plist */ /************* * * zap_plist(p) * *************/ /* DOCUMENTATION This routine frees a Plist (the whole list). The things to which the members point are not freed. */ /* PUBLIC */ void zap_plist(Plist p) { Plist curr, prev; curr = p; while (curr != NULL) { prev = curr; curr = curr->next; free_plist(prev); } } /* zap_plist */ /************* * * plist_append() * *************/ /* DOCUMENTATION This routine appends a pointer to a Plist. The updated Plist is returned. */ /* PUBLIC */ Plist plist_append(Plist lst, void *v) { if (lst == NULL) { Plist g = get_plist(); g->v = v; return g; } else { lst->next = plist_append(lst->next, v); return lst; } } /* plist_append */ /************* * * plist_prepend() * *************/ /* DOCUMENTATION This routine inserts a pointer as the first member of a Plist. The updated Plist is returned. */ /* PUBLIC */ Plist plist_prepend(Plist lst, void *v) { Plist g = get_plist(); g->v = v; g->next = lst; return g; } /* plist_prepend */ /************* * * plist_member() * *************/ /* DOCUMENTATION This function checks if a pointer is a member of a Plist. */ /* PUBLIC */ BOOL plist_member(Plist lst, void *v) { if (lst == NULL) return FALSE; else if (lst->v == v) return TRUE; else return plist_member(lst->next, v); } /* plist_member */ /************* * * plist_subset() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL plist_subset(Plist a, Plist b) { if (a == NULL) return TRUE; else if (!plist_member(b, a->v)) return FALSE; else return plist_subset(a->next, b); } /* plist_subset */ /************* * * fprint_ilist() * *************/ /* DOCUMENTATION The list of integers is printed to FILE *fp like this: (4 5 1 3), without a newline. */ /* PUBLIC */ void fprint_ilist(FILE *fp, Ilist p) { fprintf(fp, "("); for (; p != NULL; p = p->next) { fprintf(fp, "%d", p->i); fprintf(fp, "%s", p->next ? " " : ")"); } fflush(fp); } /* fprint_ilist */ /************* * * p_ilist() * *************/ /* DOCUMENTATION The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end. */ /* PUBLIC */ void p_ilist(Ilist p) { fprint_ilist(stdout, p); printf("\n"); fflush(stdout); } /* p_ilist */ /************* * * ilist_copy() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_copy(Ilist p) { if (p == NULL) return NULL; else { Ilist new = get_ilist(); new->i = p->i; new->next = ilist_copy(p->next); return new; } } /* ilist_copy */ /************* * * ilist_remove_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist ilist_remove_last(Ilist p) { if (p == NULL) return NULL; else if (p->next == NULL) { free_ilist(p); return NULL; } else { p->next = ilist_remove_last(p->next); return p; } } /* ilist_remove_last */ /************* * * plist_remove_last() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist plist_remove_last(Plist p) { if (p == NULL) return NULL; else if (p->next == NULL) { free_plist(p); return NULL; } else { p->next = plist_remove_last(p->next); return p; } } /* plist_remove_last */ /************* * * alist_insert() * *************/ /* DOCUMENTATION This is a quick and clean alist (association list) for integers. Insert key/value pairs. With assoc(key), retreive value. If an key has more than one value, the most recent is returned. It an key is not in the alist, INT_MIN is returned. An alist can be freed with zap_ilist(alist). */ /* PUBLIC */ Ilist alist_insert(Ilist p, int key, int val) { return ilist_prepend(ilist_prepend(p, val), key); } /* alist_insert */ /************* * * assoc() * *************/ /* DOCUMENTATION See alist_insert. */ /* PUBLIC */ int assoc(Ilist p, int key) { /* assume an even number of members */ if (p == NULL) return INT_MIN; else if (p->i == key) return p->next->i; else return assoc(p->next->next, key); } /* assoc */ /************* * * alist2_insert() * *************/ /* DOCUMENTATION This is a quick and clean alist2 (association list) for pairs of integers. Insert key/ pairs. With assoc2a(key), retreive value-a. With assoc2b(key), retreive value-b. If a key has more than one value pair, the most recent is returned. It a key is not in the alist2, INT_MIN is returned. An alist2 can be freed with zap_ilist(alist2). */ /* PUBLIC */ Ilist alist2_insert(Ilist p, int key, int a, int b) { return ilist_prepend(ilist_prepend(ilist_prepend(p, b), a), key); } /* alist2_insert */ /************* * * assoc2a() * *************/ /* DOCUMENTATION See alist2_insert. */ /* PUBLIC */ int assoc2a(Ilist p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return INT_MIN; else if (p->i == key) return p->next->i; else return assoc2a(p->next->next->next, key); } /* assoc2a */ /************* * * assoc2b() * *************/ /* DOCUMENTATION See alist2_insert. */ /* PUBLIC */ int assoc2b(Ilist p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return INT_MIN; else if (p->i == key) return p->next->next->i; else return assoc2b(p->next->next->next, key); } /* assoc2a */ /************* * * alist2_remove() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist alist2_remove(Ilist p, int key) { /* assume number of members is multiple of 3 */ if (p == NULL) return NULL; else { p->next->next->next = alist2_remove(p->next->next->next, key); if (p->i == key) { Ilist a = p; p = p->next->next->next; free_ilist(a->next->next); free_ilist(a->next); free_ilist(a); } return p; } } /* alist2_remove */ /************* * * ilist_occurrences() * *************/ /* DOCUMENTATION How many times does an integer occur in an ilist? */ /* PUBLIC */ int ilist_occurrences(Ilist p, int i) { if (p == NULL) return 0; else return ilist_occurrences(p->next, i) + (p->i == i ? 1 : 0); } /* ilist_occurrences */ LADR-2009-11A/ladr/save/weight1.h0000644000175000017500000000215610150462475015427 0ustar mccunemccune#ifndef TP_WEIGHT1_H #define TP_WEIGHT1_H #include "clause.h" /* INTRODUCTION This is a simple weighting package. Each symbol has a weight (default 1). The weight of a term is the sum of the weights of the subterms plus the weight of the root symbol. (There are no multipliers.) In this scheme, the negation symbol on literals is treated like any other symbol. The weight of a clause is the sum of the weights of the literals. (The OR symbols in clauses don't count.) Variables always have weight 1.

You give init_weight_scheme a list of weight assignments, for example,

weight(a, -5).
weight(g(x), 0).
weight(~x, -3).   % This is how to assign a weight to the negation symbol.
For non-constants, you have to include arguments so that the arity is known; those arguments are ignored, and the convention is to use x. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from weight1.c */ void init_weight1(Plist p, int constant_weight, int variable_weight); int term_weight1(Term t); int clause_weight1(Clause c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/detach.h.bak0000644000175000017500000000065010150462476016041 0ustar mccunemccune#ifndef TP_DETACH_H #define TP_DETACH_H #include "just.h" #include "unify.h" #include "clause.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from detach.c */ void cond_detach(Clause major, Clause minor, void (*proc_proc) (Clause)); void cond_detach_2(Clause c1, Clause c2, void (*proc_proc) (Clause)); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/sos.h~0000644000175000017500000000412110500031623015035 0ustar mccunemccune#ifndef TP_SOS_H #define TP_SOS_H #include "clist.h" /* INTRODUCTION This package has routines for efficiently managing selection of the given clause from the Sos list when using the given-clause algorithm.

We use a private index to quickly find the first, shortest clause in Sos. Here are the routines to use under ordinary circumstances.

  • insert_into_sos_lightest(Topform c, Clist sos);
  • remove_from_sos_lightest(Topform c);
  • extract_lightest_clause(Clist sos);
  • extract_first_clause(Clist lst);
Here's how it works (you probably don't need to know this).

We use an auxiliary Clist "Lightest" so that we don't have to scan Sos each time we need a new given clause. At any given time, Lightest is either empty or contains all of the Sos clauses of minimum weight, in the same order as in Sos.

To insert a newly kept clause c into Sos: If c is the same weight as clauses in Lightest, append it to Lightest as well as to Sos. If c is heaaver than Lightest, append it to Sos only. If c is lighter than Lightest, remove all clauses from Lightest, (leaving Lightest empty), and append c to Sos.

To get the first, lightest clause: If Lightest is empty, build a new Lightest list. Now just take the first member of Lightest.

Good performance of this scheme depends on the assumption that the Lightest list is farily stable; that is, as we go from given clause to given clause, the weight of the lightest clauses doesn't change often. */ /* Public definitions */ enum { BY_AGE, BY_WEIGHT, BY_RATIO }; enum { SOS1, SOS2 }; /* End of public definitions */ /* Public function prototypes from sos.c */ void p_sos_tree(void); void p_sos_dist(void); void index_sos(Topform c, int set); void insert_into_sos(Topform c, Clist sos, int set); void remove_from_sos(Topform c, Clist sos, int set); Topform first_sos_clause(Clist lst); Topform lightest_sos_clause(int set); Topform worst_sos_clause(Clist sos, int method); int wt_of_clause_at(int set, double part); int clauses_of_weight(int wt, int set); void zap_sos_index(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/interp.c0000644000175000017500000007720610140052341015345 0ustar mccunemccune#include "interp.h" /* TO DO: 1. Get rid of arity limits. */ /* Private definitions and types */ struct interp { Term t; /* the term representation (not always present) */ int size; /* domain size */ /* Array of pointers to tables, one for each constant, function, * or predicate symbol (indexed by symbol number). The arity and * print symbol can be obtained from the symbol number. */ int num_tables; /* number of tables */ int **tables; int *types; /* type of tables[i]: FUNCTION or RELATION */ int *occurrences; /* number of occurrences of each element */ Interp next; /* for avail list */ }; /* We're using 1D arrays to for higher dimensions. */ #define I2(n,i,j) ((i) * (n) + (j)) #define I3(n,i,j,k) ((i) * (n) * (n) + (j) * (n) + (k)) #define UNDEFINED 0 #define FUNCTION 1 #define RELATION 2 /* statistics */ static long unsigned Iso_checks = 0; static long unsigned Iso_perms = 0; /* * memory management */ static unsigned Interp_gets, Interp_frees; #define BYTES_INTERP sizeof(struct interp) #define PTRS_INTERP BYTES_INTERP%BPP == 0 ? BYTES_INTERP/BPP : BYTES_INTERP/BPP + 1 /************* * * Interp get_interp() * *************/ static Interp get_interp(void) { Interp p = get_mem(PTRS_INTERP); Interp_gets++; return(p); } /* get_interp */ /************* * * free_interp() * *************/ static void free_interp(Interp p) { free_mem(p, PTRS_INTERP); Interp_frees++; } /* free_interp */ /************* * * fprint_interp_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the interp package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_interp_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_INTERP; fprintf(fp, "interp (%4d) %11u%11u%11u%9.1f K\n", n, Interp_gets, Interp_frees, Interp_gets - Interp_frees, ((Interp_gets - Interp_frees) * n) / 1024.); } /* fprint_interp_mem */ /************* * * p_interp_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the interp package. */ /* PUBLIC */ void p_interp_mem() { fprint_interp_mem(stdout, TRUE); } /* p_interp_mem */ /* * end of memory management */ /************* * * int_power() * *************/ static int int_power(int n, int exp) { if (exp <= 0) return 1; else return n * int_power(n, exp-1); } /* int_power */ /************* * * compile_interp() * *************/ /* DOCUMENTATION This routine takes a term representing an interpretation and builds a data structure that allows fast evaluation of clauses and formulas w.r.t. the interpretation. Here is an example of the term form of an interpretation.

   interpretation(3, [
       function(e,      [0]),
       function(*(_,_), [0,1,2,1,2,0,2,0,1]),
       relation(p,      [1])
       relation(q(_),   [1,0,1])
       ])
The given Term t is not changed. */ /* PUBLIC */ Interp compile_interp(Term t) { Interp p; int number_of_ops, domain_size, arity; int i, j, n, symnum, val, max, rc; BOOL function = FALSE; int *table; Term operations, lst; if (t->arity != 2) fatal_error("compile_interp, bad arity."); rc = str_to_int(sn_to_str(SYMNUM(t->args[0])), &domain_size); if (!rc || domain_size < 1) fatal_error("compile_interp, domain size out of range."); operations = t->args[1]; number_of_ops = listterm_length(operations); if (number_of_ops == 0) fatal_error("compile_interp, no operations."); /* Get the largest symnum, so we can get an table array big enough. */ max = 0; for (i = 1; i <= number_of_ops; i++) { Term f = listterm_i(operations, i); if (f->arity != 2 || VARIABLE(f->args[0])) fatal_error("compile_interp, bad operation."); symnum = SYMNUM(f->args[0]); max = symnum > max ? symnum : max; } p = get_interp(); p->t = copy_term(t); p->size = domain_size; p->num_tables = max+1; p->occurrences = malloc(domain_size * sizeof(int)); for (i = 0; i < domain_size; i++) p->occurrences[i] = 0; p->tables = malloc(p->num_tables * sizeof(int *)); p->types = malloc(p->num_tables * sizeof(int)); for (i = 0; i < p->num_tables; i++) { p->tables[i] = NULL; p->types[i] = UNDEFINED; } for (i = 1; i <= number_of_ops; i++) { Term f = listterm_i(operations, i); if (is_symbol(SYMNUM(f), "function", 2)) function = TRUE; else if (is_symbol(SYMNUM(f), "relation", 2) || is_symbol(SYMNUM(f), "predicate", 2)) { function = FALSE; } else fatal_error("compile_interp, bad function/relation"); symnum = SYMNUM(f->args[0]); arity = ARITY(f->args[0]); /* n = domain_size^arity */ for (j = 0, n = 1; j < arity; j++) n = n * domain_size; lst = f->args[1]; if (listterm_length(lst) != n) fatal_error("compile_interp, bad list."); p->types[symnum] = (function ? FUNCTION : RELATION); p->tables[symnum] = malloc(n * sizeof(int)); table = p->tables[symnum]; for (j = 0; j < n; j++, lst = lst->args[1]) { rc = str_to_int(sn_to_str(SYMNUM(lst->args[0])), &val); if (!rc) fatal_error("compile_interp, bad domain elemnt."); else if (function && (val < 0 || val > domain_size-1)) fatal_error("compile_interp, function element out of range."); else if (!function && (val < 0 || val > 1)) fatal_error("compile_interp, relation element out of range."); else { table[j] = val; if (function) p->occurrences[val]++; } } } return p; } /* compile_interp */ /************* * * transpose_binary() * *************/ /* DOCUMENTATION This routine takes a term representing an interpretation and (destructively) transposes all of the binary functions and relations. It is assumed that the interpretation is well-formed. You can check well-formedness first by calling compile_interp(). */ /* PUBLIC */ void transpose_binary(Term t) { int number_of_ops, n; int i, rc; Term operations; rc = str_to_int(sn_to_str(SYMNUM(t->args[0])), &n); operations = t->args[1]; number_of_ops = listterm_length(operations); for (i = 1; i <= number_of_ops; i++) { Term f = listterm_i(operations, i); /* e.g., function(j(_,_), [0,1,1,0]) */ if (f->args[0]->arity == 2) { int j, k; Term lst = f->args[1]; /* e.g., [0,1,1,0] */ for (j = 0; j < n; j++) { for (k = j+1; k < n; k++) { Term t1 = listterm_i(lst, j*n+k+1); Term t2 = listterm_i(lst, k*n+j+1); int tmp = t1->private_symbol; t1->private_symbol = t2->private_symbol; t2->private_symbol = tmp; } } } } } /* transpose_binary */ /************* * * zap_interp() * *************/ /* DOCUMENTATION Free a compiled interpretation. */ /* PUBLIC */ void zap_interp(Interp p) { int i; free(p->occurrences); free(p->types); for (i = 0; i < p->num_tables; i++) if (p->tables[i] != NULL) free(p->tables[i]); free(p->tables); if (p->t != NULL) zap_term(p->t); free_interp(p); } /* zap_interp */ /************* * * fprint_interp_tex() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in a form that might be useful as input to LaTeX. */ /* PUBLIC */ void fprint_interp_tex(FILE *fp, Interp p) { int n = p->size; int i; BOOL first = TRUE; fprintf(fp, "\\begin{table}[H] \\centering %% size %d\n", p->size); for (i = 0; i < p->num_tables; i++) { /* arity 0 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 0) { if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "%s: %d", sn_to_str(i), table[0]); } } for (i = 0; i < p->num_tables; i++) { /* arity 1 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 1) { int j; if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "\\begin{tabular}{r|"); for (j = 0; j < n; j++) fprintf(fp, "r"); fprintf(fp, "}\n"); fprintf(fp, "%s: & ", sn_to_str(i)); for (j = 0; j < n; j++) fprintf(fp, "%d%s", j, j < n-1 ? " & " : "\\\\\n\\hline\n & "); for (j = 0; j < n; j++) fprintf(fp, "%d%s", table[j], j < n-1 ? " & " : "\n"); fprintf(fp, "\\end{tabular}"); } } for (i = 0; i < p->num_tables; i++) { /* arity 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity == 2) { int j, k; if (first) first = FALSE; else fprintf(fp, " \\hspace{.5cm}\n"); fprintf(fp, "\\begin{tabular}{r|"); for (j = 0; j < n; j++) fprintf(fp, "r"); fprintf(fp, "}\n"); fprintf(fp, "%s: & ", sn_to_str(i)); for (j = 0; j < n; j++) fprintf(fp, "%d%s", j, j < n-1 ? " & " : "\\\\\n\\hline\n"); for (j = 0; j < n; j++) { fprintf(fp, " %d & ", j); for (k = 0; k < n; k++) { fprintf(fp, "%d%s", table[(n*j) + k], k < n-1 ? " & " : (j < n-1 ? " \\\\\n" : "\n")); } } fprintf(fp, "\\end{tabular}"); } } for (i = 0; i < p->num_tables; i++) { /* arity > 2 */ int *table = p->tables[i]; int arity = sn_to_arity(i); if (table != NULL && arity > 2) { fprintf(fp, "\n\n%% table for arity %d %s %s not printed.\n\n", arity, p->types[i] == FUNCTION ? "function" : "relation", sn_to_str(i)); } } fprintf(fp, "\n\\caption{ }\n"); fprintf(fp, "\\end{table}\n"); } /* fprint_interp_tex */ /************* * * fprint_interp() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in portable form, with each operation on a separate line. */ /* PUBLIC */ void fprint_interp(FILE *fp, Interp p) { int i; fprintf(fp, "interpretation(%d, [\n", p->size); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; if (table != NULL) { int j, n; int arity = sn_to_arity(i); fprintf(fp," %s(",p->types[i] == FUNCTION ? "function" : "relation"); if (arity == 0) fprintf(fp, "%s, [", sn_to_str(i)); else { fprintf(fp, "%s(", sn_to_str(i)); for (j = 0; j < arity; j++) fprintf(fp, "_%s", j == arity-1 ? "), [" : ","); } for (j = 0, n = 1; j < arity; j++, n = n * p->size); for (j = 0; j < n; j++) fprintf(fp, "%d%s", table[j], j == n-1 ? "])" : ","); /* ugly: decide if there are any more symbols */ for (j = i+1; j < p->num_tables && p->tables[j] == NULL; j++); if (j < p->num_tables && p->tables[j] != NULL) fprintf(fp, ",\n"); else fprintf(fp, "]).\n"); } } } /* fprint_interp */ /************* * * fprint_interp_2() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a compiled interpretation, in portable form, with each operation on a separate line, except that binary operations are printed on multiple lines. */ /* PUBLIC */ void fprint_interp_2(FILE *fp, Interp p) { int i; fprintf(fp, "\ninterpretation(%d, [\n", p->size); for (i = 0; i < p->num_tables; i++) { int *table = p->tables[i]; if (table != NULL) { int j, n; int arity = sn_to_arity(i); BOOL w = (arity == 2 && p->size > 10); fprintf(fp," %s(",p->types[i] == FUNCTION ? "function" : "relation"); if (arity == 0) fprintf(fp, "%s, [", sn_to_str(i)); else { fprintf(fp, "%s(", sn_to_str(i)); for (j = 0; j < arity; j++) fprintf(fp, "_%s", j == arity-1 ? "), " : ","); fprintf(fp, "[%s", arity== 2 ? "\n " : ""); } for (j = 0, n = 1; j < arity; j++, n = n * p->size); for (j = 0; j < n; j++) { fprintf(fp, w ? "%2d%s" : "%d%s", table[j], j == n-1 ? "])" : ","); if (arity == 2 && (j+1) % p->size == 0 && j != n-1) fprintf(fp, "\n "); } /* ugly: decide if there are any more symbols */ for (j = i+1; j < p->num_tables && p->tables[j] == NULL; j++); if (j < p->num_tables && p->tables[j] != NULL) fprintf(fp, ",\n"); else fprintf(fp, "]).\n"); } } } /* fprint_interp_2 */ /************* * * p_interp() * *************/ /* DOCUMENTATION This routine prints (to stdout) a compiled interpretation, in portable form, with each operation on a separate line. */ /* PUBLIC */ void p_interp(Interp p) { fprint_interp(stdout, p); } /* p_interp */ /************* * * fprint_interp_tabular() * *************/ /* DOCUMENTATION This routine pretty prints (to FILE *fp) an interpretation in tabular (not easily parsable). Arities > 2 are not pretty. */ /* PUBLIC */ void fprint_interp_tabular(FILE *fp, Interp p) { int f, i, j; for (f = 0; f < p->num_tables; f++) { int *table = p->tables[f]; if (table != NULL) { int n = p->size; int arity = sn_to_arity(f); fprintf(fp, "\n %s : ", sn_to_str(f)); if (arity == 0) fprintf(fp, "%d\n", table[0]); else if (arity == 1) { fprintf(fp, "\n "); for (i = 0; i < n; i++) fprintf(fp, "%2d", i); fprintf(fp, "\n ----"); for (i = 0; i < n; i++) fprintf(fp, "--"); fprintf(fp, "\n "); for (i = 0; i < n; i++) fprintf(fp, "%2d", table[i]); fprintf(fp, "\n"); } else if (arity == 2) { fprintf(fp, "\n |"); for (i = 0; i < n; i++) fprintf(fp, "%2d", i); fprintf(fp, "\n ---+"); for (i = 0; i < n; i++) fprintf(fp, "--"); for (i = 0; i < n; i++) { fprintf(fp, "\n %2d |", i); for (j = 0; j < n; j++) fprintf(fp, "%2d", table[I2(n,i,j)]); } fprintf(fp, "\n"); } else { int m = int_power(n, arity); fprintf(fp, "["); for (i = 0; i < m; i++) fprintf(fp, "%d%s", table[i], i == m-1 ? "]\n" : ","); } } } /* for each function or relation */ } /* fprint_interp_tabular */ /************* * * eval_term_ground() * * This version is for clauses, where variables are represented as VARIABLEs. * It works for terms and atoms. All natural numbers are interpreted as * domain values, and if any are out of range, a fatal error occurs. * *************/ static int eval_term_ground(Term t, Interp p, int *vals) { if (VARIABLE(t)) return vals[VARNUM(t)]; else { int n = p->size; int sn = SYMNUM(t); int domain_element; if (CONSTANT(t) && term_to_int(t, &domain_element)) { if (domain_element < 0 || domain_element >= n) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_term_ground, domain element out of range"); } return domain_element; } else { int *table; int i, j, mult; if (sn >= p->num_tables || p->tables[sn] == NULL) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_term_ground, symbol not in interpretation"); } table = p->tables[sn]; j = 0; /* we'll build up the index with j */ mult = 1; for (i = t->arity-1; i >= 0; i--) { int v = eval_term_ground(t->args[i], p, vals); j += v * mult; mult = mult * n; } return table[j]; } } } /* eval_term_ground */ /************* * * eval_clause_ground() * * Given a ground clause and an interpretation, * return "at least one literal is true in the interpretation". * *************/ static BOOL eval_clause_ground(Clause c, Interp p, int *vals) { Literal lit; BOOL atom_val, true_literal; true_literal = FALSE; for (lit = c->literals; lit && !true_literal; lit = lit->next) { if (is_eq_symbol(SYMNUM(lit->atom))) atom_val = (eval_term_ground(lit->atom->args[0], p, vals) == eval_term_ground(lit->atom->args[1], p, vals)); else atom_val = eval_term_ground(lit->atom, p, vals); true_literal = (lit->sign ? atom_val : !atom_val); } return true_literal; } /* eval_clause_ground */ /************* * * all_recurse() * *************/ static BOOL all_recurse(Clause c, Interp p, int *vals, int nextvar, int nvars) { if (nextvar == nvars) { return eval_clause_ground(c, p, vals); } else { int i, rc; for (i = 0; i < p->size; i++) { vals[nextvar] = i; rc = all_recurse(c, p, vals, nextvar+1, nvars); if (!rc) return FALSE; } return TRUE; } } /* all_recurse */ /************* * * eval_clause() * *************/ #define MAX_VARS_EVAL 100 /* DOCUMENTATION This routine evaluates a clause in an interpretation. If all instances (over the domain of the interpretation) of the clause are true in the interpretaion, TRUE is returned. If any instance is false, FALSE is returned.

Note that if the interpretation has d elements and the clause has v variables, it takes d^v evaluations to verify the clause.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the clause (other than EQ_SYM, which is always built in) is absent from the interpetation. */ /* PUBLIC */ BOOL eval_clause(Clause c, Interp p) { int a[MAX_VARS_EVAL], *vals; int nvars; BOOL rc; nvars = greatest_variable_in_clause(c) + 1; if (nvars > MAX_VARS_EVAL) vals = malloc((nvars * sizeof(int))); else vals = a; rc = all_recurse(c, p, vals, 0, nvars); if (nvars > MAX_VARS_EVAL) free(vals); return rc; } /* eval_clause */ /************* * * all_recurse2() * *************/ static int all_recurse2(Clause c, Interp p, int *vals, int nextvar, int nvars) { if (nextvar == nvars) { return eval_clause_ground(c, p, vals) ? 0 : 1; } else { int i; int false_instances = 0; for (i = 0; i < p->size; i++) { vals[nextvar] = i; false_instances += all_recurse2(c, p, vals, nextvar+1, nvars); } return false_instances; } } /* all_recurse2 */ /************* * * eval_clause_false_instances() * *************/ /* DOCUMENTATION This routine evaluates a clause in an interpretation. The number of false instances is returned. */ /* PUBLIC */ int eval_clause_false_instances(Clause c, Interp p) { int a[MAX_VARS_EVAL], *vals; int nvars; int false_instances; nvars = greatest_variable_in_clause(c) + 1; if (nvars > MAX_VARS_EVAL) vals = malloc((nvars * sizeof(int))); else vals = a; false_instances = all_recurse2(c, p, vals, 0, nvars); if (nvars > MAX_VARS_EVAL) free(vals); return false_instances; } /* eval_clause_false_instances */ /************* * * eval_fterm_ground() * * This version is for formulas, where variables are * represented as CONSTANTs. * It works for terms and atoms. * *************/ static int eval_fterm_ground(Term t, Interp p, int *vals) { if (VARIABLE(t)) fatal_error("eval_fterm_ground, VARIABLE encountered."); if (vals[SYMNUM(t)] != -1) return vals[SYMNUM(t)]; else { int n = p->size; int sn = SYMNUM(t); int domain_element; if (CONSTANT(t) && term_to_int(t, &domain_element)) { if (domain_element < 0 || domain_element >= n) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_fterm_ground, domain element out of range"); } return domain_element; } else { int *table; int i, j, mult; if (sn >= p->num_tables || p->tables[sn] == NULL) { printf("ready to abort, bad term: "); p_term(t); fatal_error("eval_fterm_ground, symbol not in interpretation"); } table = p->tables[sn]; j = 0; /* we'll build up the index with j */ mult = 1; for (i = t->arity-1; i >= 0; i--) { int v = eval_term_ground(t->args[i], p, vals); j += v * mult; mult = mult * n; } return table[j]; } } } /* eval_fterm_ground */ /************* * * eval_form() * *************/ static BOOL eval_form(Formula f, Interp p, int vals[]) { if (f->type == ATOM_FORM) { if (is_eq_symbol(SYMNUM(f->atom))) return (eval_fterm_ground(f->atom->args[0], p, vals) == eval_fterm_ground(f->atom->args[1], p, vals)); else return eval_fterm_ground(f->atom, p, vals); } else if (f->type == ALL_FORM) { /* ok if true for every element of domain */ int i; BOOL ok = TRUE; int sn = str_to_sn(f->qvar, 0); if (vals[sn] != -1) fatal_error("eval_form, variable conflict."); for (i = 0; i < p->size && ok; i++) { vals[sn] = i; if (!eval_form(f->kids[0], p, vals)) ok = FALSE; } vals[sn] = -1; return ok; } else if (f->type == EXISTS_FORM) { /* ok if true for any element of domain */ int i; BOOL ok = FALSE; int sn = str_to_sn(f->qvar, 0); if (vals[sn] != -1) fatal_error("eval_form, variable conflict."); for (i = 0; i < p->size && !ok; i++) { vals[sn] = i; if (eval_form(f->kids[0], p, vals)) ok = TRUE; } vals[sn] = -1; return ok; } else if (f->type == AND_FORM) { int i; BOOL ok = TRUE; for (i = 0; i < f->arity && ok; i++) if (!eval_form(f->kids[i], p, vals)) ok = FALSE; return ok; } else if (f->type == OR_FORM) { int i; BOOL ok = FALSE; for (i = 0; i < f->arity && !ok; i++) if (eval_form(f->kids[i], p, vals)) ok = TRUE; return ok; } else if (f->type == NOT_FORM) { return !eval_form(f->kids[0], p, vals); } else if (f->type == IFF_FORM) { return (eval_form(f->kids[0], p, vals) == eval_form(f->kids[1], p, vals)); } else if (f->type == IMP_FORM) { return (!eval_form(f->kids[0], p, vals) || eval_form(f->kids[1], p, vals)); } else if (f->type == IMPBY_FORM) { return (eval_form(f->kids[0], p, vals) || !eval_form(f->kids[1], p, vals)); } else { fatal_error("eval_form, bad formula."); return 0; /* to please the compiler */ } } /* eval_form */ /************* * * eval_formula() * *************/ /* DOCUMENTATION This routine evaluates a formula in an interpretation. There is no restriction on the structure of the formula. However, quantified variables must be named in such a way that when a quantifier binds a variable, say (all x F), then no quantifier in F can rebind x. The routine eliminate_rebinding() can be called to transform a formula, if necessary, so that it satisfies the rule.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the formula (other than EQ_SYM, which is always built in) is absent from the interpetation. */ /* PUBLIC */ BOOL eval_formula(Formula f, Interp p) { int a[MAX_VARS_EVAL], *vals; int nsyms, i; BOOL rc; nsyms = greatest_symnum_in_formula(f) + 1; if (nsyms > MAX_VARS_EVAL) vals = malloc((nsyms * sizeof(int))); else vals = a; for (i = 0; i < nsyms; i++) vals[i] = -1; rc = eval_form(f, p, vals); if (nsyms > MAX_VARS_EVAL) free(vals); #if 0 if (rc) printf("Formula is TRUE in this interpretation.\n"); else { printf("Formula is FALSE in this interpretation.\n"); } #endif return rc; } /* eval_formula */ /************* * * copy_interp() * *************/ /* DOCUMENTATION This routine copies an interpretation. We don't check for errors. */ /* PUBLIC */ Interp copy_interp(Interp p) { int i; Interp q = get_interp(); q->t = copy_term(p->t); q->size = p->size; q->num_tables = p->num_tables; q->occurrences = malloc(q->size * sizeof(int)); for (i = 0; i < q->size; i++) q->occurrences[i] = p->occurrences[i]; q->types = malloc(q->num_tables * sizeof(int)); for (i = 0; i < q->num_tables; i++) q->types[i] = p->types[i]; q->tables = malloc(q->num_tables * sizeof(int *)); for (i = 0; i < q->num_tables; i++) q->tables[i] = NULL; for (i = 0; i < q->num_tables; i++) if (p->tables[i] != NULL) { int arity = sn_to_arity(i); int n = 1; int *ptable, *qtable, j; for (j = 0; j < arity; j++) n = n * p->size; q->tables[i] = malloc(n * sizeof(int)); ptable = p->tables[i]; qtable = q->tables[i]; for (j = 0; j < n; j++) qtable[j] = ptable[j]; } return q; } /* copy_interp */ /************* * * permute_interp() * *************/ /* DOCUMENTATION This routine returns a permutation of an interpretation. The permuted interpretation does not contain the term representation (because it would be nontrivial to construct it). */ /* PUBLIC */ Interp permute_interp(Interp source, int *p) { Interp dest = copy_interp(source); int n = source->size; int f; for (f = 0; f < source->num_tables; f++) { if (source->tables[f] != NULL) { int *st = source->tables[f]; int *dt = dest->tables[f]; int arity = sn_to_arity(f); BOOL function = (source->types[f] == FUNCTION); if (arity == 0) dt[0] = (function ? p[st[0]] : st[0]); else if (arity == 1) { int i; for (i = 0; i < n; i++) dt[p[i]] = (function ? p[st[i]] : st[i]); } else if (arity == 2) { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) dt[I2(n,p[i],p[j])] = (function ? p[st[I2(n,i,j)]] : st[I2(n,i,j)]); } else if (arity == 3) { int i, j, k; for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) dt[I3(n,p[i],p[j],p[k])] = (function ? p[st[I3(n,i,j,k)]] : st[I3(n,i,j,k)]); } else fatal_error("permute_interp: arity > 3"); } } { int i; for (i = 0; i < n; i++) dest->occurrences[p[i]] = source->occurrences[i]; } /* The term representation is no longer correct. */ zap_term(dest->t); dest->t = NULL; return dest; } /* permute_interp */ /************* * * ident_interp_perm() * *************/ /* DOCUMENTATION Is interpretation B identical to a given permutation of interpretation A? If so, then A and B are isomorphic. It is assumed that A and B are the same size and have the same symbols. */ /* PUBLIC */ BOOL ident_interp_perm(Interp a, Interp b, int *p) { int n = a->size; int f; for (f = 0; f < a->num_tables; f++) { if (a->tables[f] != NULL) { int *at = a->tables[f]; int *bt = b->tables[f]; int arity = sn_to_arity(f); BOOL function = (a->types[f] == FUNCTION); if (arity == 0) { if (bt[0] != (function ? p[at[0]] : at[0])) return FALSE; } else if (arity == 1) { int i; for (i = 0; i < n; i++) { if (bt[p[i]] != (function ? p[at[i]] : at[i])) return FALSE; } } else if (arity == 2) { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { if (bt[I2(n,p[i],p[j])] != (function ? p[at[I2(n,i,j)]] : at[I2(n,i,j)])) return FALSE; } } else if (arity == 3) { int i, j, k; for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) { if (bt[I3(n,p[i],p[j],p[k])] != (function ? p[at[I3(n,i,j,k)]] : at[I3(n,i,j,k)])) return FALSE; } } else fatal_error("ident_interp_perm: arity > 3"); } } return TRUE; } /* ident_interp_perm */ /************* * * canon_interp() * *************/ /* DOCUMENTATION This routine returns a canonicalized copy of an interpretation. Canonical interpretations are used to speed up isomorphism checking.

Consider, in all of the function tables, the number of occurrences of each element. If we have a size-4 interpretation with a binary function, a unary function, and a constant, the occurrence array might be something like [7,6,4,4], meaning that there are 7 occurrences of 0, 6, occurrences of 1, 4 occurrences of 2, and 4 occurrences of 3. If the occurrence array is nonincreasing, the interpretation is in a canonical form. (Canonical forms are not unique; otherwise, isomorphism checking would be trivial.)

If 2 canonical interpretations have different occurrence arrays, they cannot be isomorphic. That's the first check we make.

When checking whether two interpretations are isomorphic, we look at permutations of one of the interpretations, and we can use occurrence array to eliminate some of the permutations. Examples: with occurrence array [7,6,4,4], we look at only 2 permutations: (0,1,2,3) and (0,1,3,2); with occurrence array [4,4,4,3,3], we'd look at 12 (6*2) permutations instead of 120 (5!). */ /* PUBLIC */ Interp canon_interp(Interp a) { int i; int *occ = malloc(sizeof(int) * a->size); /* remember to free this */ int *perm = malloc(sizeof(int) * a->size); /* remember to free this */ int size = a->size; Interp can; /* Determine the permutation we'll use to canonicalize the interpretation. */ for (i = 0; i < size; i++) occ[i] = a->occurrences[i]; for (i = 0; i < size; i++) { int max = -1; int index_of_max = -1; int j; for (j = 0; j < size; j++) { if (occ[j] > max) { index_of_max = j; max = occ[j]; } } perm[index_of_max] = i; occ[index_of_max] = -1; } free(occ); /* This is now useless (all members are -1). */ /* Apply the permutation to the interpretation. */ can = permute_interp(a, perm); free(perm); return can; } /* canon_interp */ /************* * * iso_interp_recurse() * *************/ #define ISWAP(x,y) {int t = x; x = y; y = t;} static BOOL iso_interp_recurse(int *p, int k, int n, Interp a, Interp b, BOOL canon) { int i; if (k == n) { /* We have a permutation. */ Iso_perms++; return ident_interp_perm(a, b, p); } else { /* Continue building permutations. */ if (iso_interp_recurse(p, k+1, n, a, b, canon)) return TRUE; for (i = k+1; i < n; i++) { /* If canonical, and if i and k have different number of occurrences, don't swap them. */ if (!canon || a->occurrences[i] == a->occurrences[k]) { ISWAP(p[k], p[i]); if (iso_interp_recurse(p, k+1, n, a, b, canon)) return TRUE; ISWAP(p[k], p[i]); } } return FALSE; } } /* iso_interp_recurse */ /************* * * isomorphic_canon_interps() * *************/ /* DOCUMENTATION Are interpretations A and B isomorphic? We assume they are compatible (same operations/arities). If the flag canon is set, it is assumed that both interps were produced by canon_interp(); this allows some optimization. */ /* PUBLIC */ BOOL isomorphic_interps(Interp a, Interp b, BOOL canon) { int i; BOOL isomorphic; int *perm; if (a->size != b->size) return FALSE; /* If canonical, make sure the interps have the same occurrence-type. */ if (canon) { for (i = 0; i < a->size; i++) if (a->occurrences[i] != b->occurrences[i]) return FALSE; } Iso_checks++; perm = malloc(sizeof(int) * a->size); /* remember to free this */ /* Initialize perm to the trivial permutation. */ for (i = 0; i < a->size; i++) perm[i] = i; isomorphic = iso_interp_recurse(perm, 0, a->size, a, b, canon); free(perm); return isomorphic; } /* isomorphic_canon_interps */ /************* * * interp_size() * *************/ /* DOCUMENTATION Return the domain size of an interpretation. */ /* PUBLIC */ int interp_size(Interp a) { return a->size; } /* interp_size */ /************* * * interp_table() * *************/ /* DOCUMENTATION Given a symbol and arity, return the corresponding table.xc */ /* PUBLIC */ int *interp_table(Interp p, char *sym, int arity) { int f; for (f = 0; f < p->num_tables; f++) if (is_symbol(f, sym, arity)) return p->tables[f]; return NULL; } /* interp_table */ /************* * * iso_checks() * *************/ /* DOCUMENTATION Return the number of isomorphism checks. For canonical checks, ones where the occurrence-types don't match are not counted. */ /* PUBLIC */ long unsigned iso_checks(void) { return Iso_checks; } /* iso_checks */ /************* * * iso_perms() * *************/ /* DOCUMENTATION Return the number of permutations seen during isomorphism checks. */ /* PUBLIC */ long unsigned iso_perms(void) { return Iso_perms; } /* iso_perms */ LADR-2009-11A/ladr/save/sos.c0000644000175000017500000003112210462714251014647 0ustar mccunemccune#include "sos.h" /****************************************************************************/ /* Private definitions and types */ /* Stree is a simple binary search tree organized by Topform->weight. Each node has a Clist of clauses (ordered by ID) with that weight. This structure will be used to order clasues first by weight, then by ID. In a typical search there aren't very many different weights, so it doesn't seem important to balance the tree; that can be added later if necessary. */ typedef struct stree * Stree; struct stree { int weight; /* weight of clauses in this node */ Clist clauses; /* clauses (ordered by increasing ID) in this node */ int n; /* number of clauses in this subtree (node and children) */ int greatest_id; /* greatest ID in this subtree */ Stree left; Stree right; }; /* * memory management */ #define PTRS_STREE PTRS(sizeof(struct stree)) /* #define PTRS_STREE PTRS(sizeof(struct stree)) */ static unsigned Stree_gets, Stree_frees; /************* * * Stree get_stree() * *************/ static Stree get_stree(void) { Stree p = get_cmem(PTRS_STREE); Stree_gets++; return(p); } /* get_stree */ /************* * * free_stree() * *************/ static void free_stree(Stree p) { free_mem(p, PTRS_STREE); Stree_frees++; } /* free_stree */ /************* * * p_stree() * *************/ static void p_stree(Stree s) { if (s == NULL) printf("Slist NULL\n"); else { p_stree(s->left); printf("\nWeight=%d.\n", s->weight); fprint_clause_clist(stdout, s->clauses); p_stree(s->right); } } /* p_stree */ /************* * * p_dist() * *************/ static void p_dist(Stree s) { if (s != NULL) { p_dist(s->left); printf("Weight=%d, clauses=%d.\n", s->weight, s->clauses->length); p_dist(s->right); } } /* p_dist */ /************* * * stree_insert() * *************/ static Stree stree_insert(Stree s, Topform c) { if (s == NULL) { s = get_stree(); s->weight = c->weight; s->clauses = clist_init("clauses_by_weight"); clist_append(c, s->clauses); } else if (c->weight == s->weight) { clist_append(c, s->clauses); } else if (c->weight < s->weight) s->left = stree_insert(s->left, c); else s->right = stree_insert(s->right, c); s->greatest_id = c->id; /* clauses always inserted with increasing IDs */ s->n++; return s; } /* stree_insert */ /************* * * stree_remove() * *************/ static Stree stree_remove(Stree s, Topform c) { if (s == NULL) fatal_error("stree_remove, clause not found"); else if (c->weight == s->weight) { clist_remove(c, s->clauses); if (clist_empty(s->clauses) && s->left == NULL && s->right == NULL) { clist_free(s->clauses); free_stree(s); return NULL; } else if (clist_empty(s->clauses)) s->greatest_id = 0; else s->greatest_id = s->clauses->last->c->id; } else if (c->weight < s->weight) s->left = stree_remove(s->left, c); else s->right = stree_remove(s->right, c); { int a = s->left ? s->left->greatest_id : 0; int b = clist_empty(s->clauses) ? 0 : s->clauses->last->c->id; int c = s->right ? s->right->greatest_id : 0; int d = IMAX(b,c); s->greatest_id = IMAX(a,d); } s->n--; return s; } /* stree_remove */ /************* * * stree_of_weight() * *************/ static Stree stree_of_weight(Stree s, int weight) { if (s == NULL) return NULL; else if (weight == s->weight) return s; else if (weight < s->weight) return stree_of_weight(s->left, weight); else return stree_of_weight(s->right, weight); } /* stree_of_weight */ /************* * * stree_first_lightest() * *************/ static Topform stree_first_lightest(Stree s) { if (s == NULL) return NULL; else { Topform c; c = stree_first_lightest(s->left); if (c == NULL) c = clist_empty(s->clauses) ? NULL : s->clauses->first->c; if (c == NULL) c = stree_first_lightest(s->right); return c; } } /* stree_first_lightest */ /************* * * stree_last_heaviest() * *************/ static Topform stree_last_heaviest(Stree s) { if (s == NULL) return NULL; else { Topform c; c = stree_last_heaviest(s->right); if (c == NULL) c = clist_empty(s->clauses) ? NULL : s->clauses->last->c; if (c == NULL) c = stree_last_heaviest(s->left); return c; } } /* stree_last_heaviest */ /************* * * stree_last_heaviest_greater_than() * * Find the last heaviest clause that whose ID is greater than the given id. * *************/ static Topform stree_last_heaviest_greater_than(Stree s, int id) { if (s == NULL) return NULL; else if (s->greatest_id <= id) return NULL; else { Topform c; c = stree_last_heaviest_greater_than(s->right, id); if (c == NULL) { if (!clist_empty(s->clauses) && s->clauses->last->c->id > id) c = s->clauses->last->c; } if (c == NULL) c = stree_last_heaviest_greater_than(s->left, id); return c; } } /* stree_last_heaviest_greater_than */ /************* * * greatest_check() * *************/ /* #define GREATEST_CHECK */ #ifdef GREATEST_CHECK static void greatest_check(Stree s) { if (s == NULL) return; else { int a = s->left ? s->left->greatest_id : 0; int b = clist_empty(s->clauses) ? 0 : s->clauses->last->c->id; int c = s->right ? s->right->greatest_id : 0; int d = IMAX(b,c); int e = IMAX(a,d); if (e != s->greatest_id) fatal_error("greatest_check, stree corrupt"); } } /* greatest_check */ #endif /************* * * zap_stree() * *************/ static void zap_stree(Stree s) { if (s != NULL) { zap_stree(s->left); zap_stree(s->right); clist_zap(s->clauses); /* clauses not zapped, because occur elsewhere */ free_stree(s); } } /* zap_stree */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /* Sos is ordered by clause ID, and it is divided into halves by a clause (the center mark). Clauses left of (older than) the center are protected from being "worst" clauses, because they might be useful for the breadth-first part of the search. The center is adjusted lazily. */ static Clist_pos Center; static int Cl_before_center; /************* * * init_sos_center() * *************/ static void init_sos_center(Clist sos, int method) { if (method == BY_WEIGHT || method == BY_AGE) Center = NULL; else { int n = sos->length / 2; int i; Clist_pos p = sos->first; for (i = 0; i < n; i++) p = p->next; Center = p; Cl_before_center = n-1; } } /* init_sos_center */ /************* * * adjust_sos_center() * *************/ static void adjust_sos_center(int size) { int new_clauses_before_center = (size / 2) -1; int n = 0; int i; if (Cl_before_center < new_clauses_before_center) { /* move mark right */ n = new_clauses_before_center - Cl_before_center; for (i = 0; i < n; i++) { Center = Center->next; Cl_before_center++; } } else if (Cl_before_center > new_clauses_before_center) { /* move mark left */ n = Cl_before_center - new_clauses_before_center; for (i = 0; i < n; i++) { Center = Center->prev; Cl_before_center--; } } } /* adjust_sos_center */ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ Stree Sos1; Stree Sos2; /************* * * p_sos_tree() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_sos_tree(void) { p_stree(Sos1); } /* p_sos_tree */ /************* * * p_sos_dist() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_sos_dist(void) { p_dist(Sos1); } /* p_sos_dist */ /************* * * index_sos() * *************/ /* DOCUMENTATION This routine updates the (private) index for extracting sos clauses. */ /* PUBLIC */ void index_sos(Topform c, int set) { if (set == SOS1) Sos1 = stree_insert(Sos1, c); else Sos2 = stree_insert(Sos2, c); } /* index_sos */ /************* * * insert_into_sos() * *************/ /* DOCUMENTATION This routine appends a clause to the sos list and updates the (private) index for extracting sos clauses. */ /* PUBLIC */ void insert_into_sos(Topform c, Clist sos, int set) { clist_append(c, sos); index_sos(c, set); } /* insert_into_sos */ /************* * * remove_from_sos() * *************/ /* DOCUMENTATION This routine removes a clause from the sos list and updates the index for extracting the lightest and heaviest clauses. */ /* PUBLIC */ void remove_from_sos(Topform c, Clist sos, int set) { if (set == SOS1) Sos1 = stree_remove(Sos1, c); else Sos2 = stree_remove(Sos2, c); if (Center) { if (c == Center->c) Center = Center->next; else if (c->id < Center->c->id) Cl_before_center--; } clist_remove(c, sos); } /* remove_from_sos */ /************* * * first_sos_clause() * *************/ /* DOCUMENTATION Given a nonempty Clist, return the first clause. This does not remove the clause from any lists. (Call remove_from_sos(Topform) to do that.) */ /* PUBLIC */ Topform first_sos_clause(Clist lst) { return lst->first ? lst->first->c : NULL; } /* first_sos_clause */ /************* * * lightest_sos_clause() * *************/ /* DOCUMENTATION Return the first (oldest) of the lightest sos clauses. This does not remove the clause from any lists. (Call remove_from_sos(Topform, Clist) to do that.) */ /* PUBLIC */ Topform lightest_sos_clause(int set) { Topform c; if (set == SOS1) { c = stree_first_lightest(Sos1); if (c == NULL) c = stree_first_lightest(Sos2); } else { c = stree_first_lightest(Sos2); if (c == NULL) c = stree_first_lightest(Sos1); } return c; } /* lightest_sos_clause */ /************* * * worst_sos_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform worst_sos_clause(Clist sos, int method) { /* get larger of the two sets */ int n1 = Sos1 ? Sos1->n : 0; int n2 = Sos2 ? Sos2->n : 0; Stree s = n1 > n2 ? Sos1 : Sos2; if (method == BY_WEIGHT) return stree_last_heaviest(s); else if (method == BY_AGE) return (sos->last ? sos->last->c : NULL); else { if (Center == NULL) init_sos_center(sos, method); else adjust_sos_center(sos->length); /* from larger of 2 sets, get the heaviest clause with ID > Center */ { Topform c; c = stree_last_heaviest_greater_than(s, Center ? Center->c->id : 0); if (c == NULL) c = stree_last_heaviest(s); if (c == NULL) { printf("worst_sos_clause NULL, n1=%d, n2=%d\n",n1,n2); } return c; } } } /* worst_sos_clause */ /************* * * wt_of_nth_clause() * * Consider sos, ordered by weight. * Return the weight of the n-th clause. * *************/ static int wt_of_nth_clause(Stree s, int n) { int n1, n2; if (n < 1) n = 1; else if (n > s->n) n = s->n; n1 = s->left ? s->left->n : 0; n2 = s->clauses ? s->clauses->length : 0; if (n <= n1) return wt_of_nth_clause(s->left, n); else if (n - n1 <= n2) return s->weight; else return wt_of_nth_clause(s->right, n - (n1 + n2)); } /* wt_of_nth_clause */ /************* * * wt_of_clause_at() * *************/ /* DOCUMENTATION Consider sos, ordered by weight. Assume 0 <= part <= 1; if not, we make it so. Return the weight of the clause at the part. If sos is empty, return INT_MAX. */ /* PUBLIC */ int wt_of_clause_at(int set, double part) { Stree st = (set == SOS1 ? Sos1 : Sos2); if (st == NULL || st->n == 0) return INT_MAX; else { int n; if (part < 0) part = 0; else if (part > 1) part = 1; n = st->n * part; return wt_of_nth_clause(st, n); } } /* wt_of_clause_at */ /************* * * clauses_of_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int clauses_of_weight(int wt, int set) { Stree st = (set == SOS1 ? Sos1 : Sos2); st = stree_of_weight(st, wt); if (st == NULL) return 0; else return st->clauses->length; } /* clauses_of_weight */ /************* * * zap_sos_index() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_sos_index(void) { zap_stree(Sos1); zap_stree(Sos2); Sos1 = NULL; Sos2 = NULL; Center = NULL; Cl_before_center = 0; } /* zap_sos_index */ LADR-2009-11A/ladr/save/clause.c0000644000175000017500000005611710140052525015322 0ustar mccunemccune#include "clause.h" #include "memory2.h" /* Private definitions and types */ #define VAR_ARRAY_SIZE 100 /* for renumbering variables */ /* * memory management */ static unsigned Literal_gets, Literal_frees; static unsigned Clause_gets, Clause_frees; #define BYTES_LITERAL sizeof(struct literal) #define PTRS_LITERAL BYTES_LITERAL%BPP == 0 ? BYTES_LITERAL/BPP : BYTES_LITERAL/BPP + 1 #define BYTES_CLAUSE sizeof(struct clause) #define PTRS_CLAUSE BYTES_CLAUSE%BPP == 0 ? BYTES_CLAUSE/BPP : BYTES_CLAUSE/BPP + 1 /************* * * Literal get_literal() * *************/ static Literal get_literal(void) { Literal p = get_mem(PTRS_LITERAL); Literal_gets++; return(p); } /* get_literal */ /************* * * free_literal() * *************/ static void free_literal(Literal p) { free_mem(p, PTRS_LITERAL); Literal_frees++; } /* free_literal */ /************* * * Clause get_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Clause get_clause(void) { Clause p = get_mem(PTRS_CLAUSE); Clause_gets++; return(p); } /* get_clause */ /************* * * free_clause() * *************/ static void free_clause(Clause p) { free_mem(p, PTRS_CLAUSE); Clause_frees++; } /* free_clause */ /************* * * fprint_clause_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clause package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_clause_mem(FILE *fp, int heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_LITERAL; fprintf(fp, "literal (%4d) %11u%11u%11u%9.1f K\n", n, Literal_gets, Literal_frees, Literal_gets - Literal_frees, ((Literal_gets - Literal_frees) * n) / 1024.); n = BYTES_CLAUSE; fprintf(fp, "clause (%4d) %11u%11u%11u%9.1f K\n", n, Clause_gets, Clause_frees, Clause_gets - Clause_frees, ((Clause_gets - Clause_frees) * n) / 1024.); } /* fprint_clause_mem */ /************* * * p_clause_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clause package. */ /* PUBLIC */ void p_clause_mem() { fprint_clause_mem(stdout, 1); } /* p_clause_mem */ /* * end of memory management */ /************* * * zap_literal(c) * *************/ /* DOCUMENTATION This routine frees a list of literal. */ /* PUBLIC */ void zap_literal(Literal l) { zap_term(l->atom); free_literal(l); } /* zap_clause */ /************* * * zap_literals(c) * *************/ /* DOCUMENTATION This routine frees a list of literals. */ /* PUBLIC */ void zap_literals(Literal l) { if (l) { zap_literals(l->next); zap_literal(l); } } /* zap_clause */ /************* * * zap_clause(c) * *************/ /* DOCUMENTATION This routine frees a clause (but not any justification list or attributes). The caller should make sure that nothing (e.g., indexes) refer to the clause or any of its subterms.

If the clause has a justification or an ID, use the higher-level routine delete_clause(c) instead. */ /* PUBLIC */ void zap_clause(Clause c) { zap_literals(c->literals); zap_attributes(c->attributes); free_clause(c); } /* zap_clause */ /************* * * fprint_clause() * *************/ /* DOCUMENTATION This routine prints a clause to a file. */ /* PUBLIC */ void fprint_clause(FILE *fp, Clause c) { Literal lit; if (c->id > 0) fprintf(fp, "%d: ", c->id); if (c->literals == NULL) fprintf(fp, "%s", FALSE_SYM); else { for (lit = c->literals; lit != NULL; lit = lit->next) { if (!lit->sign) fprintf(fp, "%s", NOT_SYM); fprint_term(fp, lit->atom); #if 0 if (maximal_literal_check(lit)) fprintf(fp, "[max]"); #endif if (lit->next != NULL) fprintf(fp, " %s ", OR_SYM); } } fprintf(fp, ".\n"); fflush(fp); } /* fprint_clause */ /************* * * p_clause() * *************/ /* DOCUMENTATION This routine prints a clause to stdout. */ /* PUBLIC */ void p_clause(Clause c) { fprint_clause(stdout, c); } /* p_clause */ /************* * * new_literal() * *************/ /* DOCUMENTATION This routine takes a sign (Boolean) and a Term atom, and returns a literal. The atom is not copied. */ /* PUBLIC */ Literal new_literal(int sign, Term atom) { Literal lit = get_literal(); lit->sign = sign; lit->atom = atom; return lit; } /* new_literal */ /************* * * append_literal() * *************/ /* DOCUMENTATION This routine appends a literal to a clause. */ /* PUBLIC */ void append_literal(Clause c, Literal lit) { Literal l = c->literals; if (l == NULL) { c->literals = lit; } else { while (l->next != NULL) l = l->next; l->next = lit; } lit->next = NULL; } /* append_literal */ /************* * * clause_length() * *************/ /* DOCUMENTATION This routine returns the length of a clause, which is the sum of the lengths of its atoms. */ /* PUBLIC */ int clause_length(Clause c) { int n = 0; Literal lit; for (lit = c->literals; lit != NULL; lit = lit->next) n += symbol_count(lit->atom); return n; } /* clause_length */ /************* * * term_to_literals() * *************/ static Literal term_to_literals(Term t, Literal lits) { Literal l; if (COMPLEX(t) && is_term(t, OR_SYM, 2)) { /* Traverse term right-to-left and add to the * front of the clause, so order is preserved. */ l = term_to_literals(t->args[1], lits); l = term_to_literals(t->args[0], l); } else { l = get_literal(); l->next = lits; l->sign = !(COMPLEX(t) && is_term(t, NOT_SYM, 1)); if (l->sign) l->atom = copy_term(t); else l->atom = copy_term(t->args[0]); } return(l); } /* term_to_literals */ /************* * * term_to_clause() * *************/ /* DOCUMENTATION This routine takes a Term t (presumably a disjunction with binary symbol OR_SYM), and constructs a Clause. The Clause is entirely new.

The main use of this routine is intended to be as follows: a Term representing a clause is parsed (using mixfix notation) from the input, then here it is copied translated into a Clause data structure. */ /* PUBLIC */ Clause term_to_clause(Term t) { Clause c = get_clause(); Term t_start; if (COMPLEX(t) && is_term(t, ATTRIB_SYM, 2)) { c->attributes = term_to_attributes(ARG(t,1), ATTRIB_SYM); t_start = ARG(t,0); } else t_start = t; c->literals = term_to_literals(t_start, NULL); return(c); } /* term_to_clause */ /************* * * literals_to_term() * *************/ static Term literals_to_term(Literal l) { Term t; if (l->sign) t = copy_term(l->atom); else { t = get_rigid_term(NOT_SYM, 1); t->args[0] = copy_term(l->atom); } if (l->next) { Term d = get_rigid_term(OR_SYM, 2); d->args[0] = t; d->args[1] = literals_to_term(l->next); return d; } else return t; } /* literals_to_term */ /************* * * clause_to_term() * *************/ /* DOCUMENTATION This routine takes a Clause and returns an entirely new Term which represents the clause. The disjunction symbol for the term is binary OR_SYM, and the negation symbols is NOT_SYM. */ /* PUBLIC */ Term clause_to_term(Clause c) { Term lits; if (c->literals == NULL) lits = get_rigid_term(FALSE_SYM, 0); else lits = literals_to_term(c->literals); if (c->attributes == NULL) return lits; else return build_binary_term(str_to_sn(ATTRIB_SYM, 2), lits, attributes_to_term(c->attributes, ATTRIB_SYM)); } /* clause_to_term */ /************* * * literals_to_term_x() * *************/ static Term literals_to_term_x(Literal l) { Term t; if (l->sign) t = l->atom; else { t = get_rigid_term(NOT_SYM, 1); t->args[0] = l->atom; } if (l->next) { Term d = get_rigid_term(OR_SYM, 2); d->args[0] = t; d->args[1] = literals_to_term_x(l->next); t = d; } free_literal(l); return t; } /* literals_to_term_x */ /************* * * clause_to_term_x() * *************/ /* DOCUMENTATION This routine takes a Clause and returns its Term form. The disjunction symbol for the term is binary OR_SYM, and the negation symbols is NOT_SYM.

This version destroys the clause. */ /* PUBLIC */ Term clause_to_term_x(Clause c) { Term t; if (c->literals != NULL) t = literals_to_term_x(c->literals); else t = get_rigid_term(FALSE_SYM, 0); free_clause(c); /* literals are already freed */ return t; } /* clause_to_term_x */ /************* * * clause_set_variables() * *************/ /* DOCUMENTATION This routine traverses a clause and changes the constants that should be variables, into variables. On input, the clause should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input clauses that are built without regard to variable/constant distinction. */ /* PUBLIC */ void clause_set_variables(Clause c, int max_vars) { char *a[VAR_ARRAY_SIZE], **vmap; int i; Literal lit; if (max_vars > VAR_ARRAY_SIZE) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; for (lit = c->literals; lit != NULL; lit = lit->next) { Term a = lit->atom; for (i = 0; i < a->arity; i++) a->args[i] = set_vars_recurse(a->args[i], vmap, max_vars); } /* Now do any answer literals (with the same vmap). */ set_vars_attributes(c->attributes, vmap, max_vars); if (max_vars > VAR_ARRAY_SIZE) free(vmap); } /* clause_set_variables */ /************* * * renumber_variables() * *************/ /* DOCUMENTATION This routine renumbers the variables of a clause. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

The intended is use is for inferred clauses that may contain variable indexes greater than max_vars. */ /* PUBLIC */ void renumber_variables(Clause c, int max_vars) { int a[VAR_ARRAY_SIZE], *vmap; int i; Literal lit; if (max_vars > VAR_ARRAY_SIZE) vmap = malloc((max_vars * sizeof(int))); else vmap = a; for (i = 0; i < max_vars; i++) a[i] = -1; for (lit = c->literals; lit != NULL; lit = lit->next) lit->atom = renum_vars_recurse(lit->atom, vmap, max_vars); /* Now do any inheritable attributes (with the same vmap). */ renumber_vars_attributes(c->attributes, vmap, max_vars); if (max_vars > VAR_ARRAY_SIZE) free(vmap); } /* renumber_variables */ /************* * * term_renumber_variables() * *************/ /* DOCUMENTATION This routine renumbers the variables of a term. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

Do not use this to renumber variables of a clause (see renumber_variables). */ /* PUBLIC */ void term_renumber_variables(Term t, int max_vars) { int a[VAR_ARRAY_SIZE], *vmap; int i; if (max_vars > VAR_ARRAY_SIZE) vmap = malloc((max_vars * sizeof(int))); else vmap = a; for (i = 0; i < max_vars; i++) a[i] = -1; t = renum_vars_recurse(t, vmap, max_vars); if (max_vars > VAR_ARRAY_SIZE) free(vmap); } /* term_renumber_variables */ /************* * * positive_literals() * *************/ /* DOCUMENTATION This function returns the number of positive literals in a clause. */ /* PUBLIC */ int positive_literals(Clause c) { Literal lit; int n = 0; for (lit = c->literals; lit != NULL; lit = lit->next) if (lit->sign) n++; return n; } /* positive_literals */ /************* * * negative_literals() * *************/ /* DOCUMENTATION This function returns the number of negative literals in a clause. */ /* PUBLIC */ int negative_literals(Clause c) { Literal lit; int n = 0; for (lit = c->literals; lit != NULL; lit = lit->next) if (!lit->sign) n++; return n; } /* negative_literals */ /************* * * positive_clause() * *************/ /* DOCUMENTATION This function checks if all of the literals of a clause are positive. */ /* PUBLIC */ BOOL positive_clause(Clause c) { return negative_literals(c) == 0; } /* positive_clause */ /************* * * any_clause() * *************/ /* DOCUMENTATION This function is always TRUE. (It it intended to be used as an argument.) */ /* PUBLIC */ BOOL any_clause(Clause c) { return TRUE; } /* positive_clause */ /************* * * negative_clause() * *************/ /* DOCUMENTATION This function checks if all of the literals of a clause are negative. */ /* PUBLIC */ BOOL negative_clause(Clause c) { return positive_literals(c) == 0; } /* negative_clause */ /************* * * mixed_clause() * *************/ /* DOCUMENTATION This function checks if a clause has at least one positive and at least one negative literal. */ /* PUBLIC */ BOOL mixed_clause(Clause c) { return (positive_literals(c) >= 1 && negative_literals(c) >= 1); } /* mixed_clause */ /************* * * number_of_literals() * *************/ /* DOCUMENTATION This function returns the number of literals in a clause. */ /* PUBLIC */ int number_of_literals(Clause c) { return positive_literals(c) + negative_literals(c); } /* number_of_literals */ /************* * * unit_clause() * *************/ /* DOCUMENTATION This function checks if a clause has exactly one literal. */ /* PUBLIC */ BOOL unit_clause(Clause c) { return c->literals != NULL && c->literals->next == NULL; } /* unit_clause */ /************* * * horn_clause() * *************/ /* DOCUMENTATION This function checks if a clause has at most one positive literal. */ /* PUBLIC */ BOOL horn_clause(Clause c) { return positive_literals(c) <= 1; } /* horn_clause */ /************* * * definite_clause() * *************/ /* DOCUMENTATION This Boolean function checks if a clause has exactly one positive literal. */ /* PUBLIC */ BOOL definite_clause(Clause c) { return positive_literals(c) == 1; } /* definite_clause */ /************* * * greatest_variable_in_clause(c) * *************/ /* DOCUMENTATION This routine returns the greatest variable index in a clause. If the clause is ground, -1 is returned. */ /* PUBLIC */ int greatest_variable_in_clause(Clause c) { Literal lit; int max, v; for (max = -1, lit = c->literals; lit != NULL; lit = lit->next) { v = greatest_variable(lit->atom); max = (v > max ? v : max); } return(max); } /* greatest_variable_in_clause */ /************* * * upward_clause_links() * *************/ /* DOCUMENTATION In the given Clause c, make the "container" field of each subterm point to c. */ /* PUBLIC */ void upward_clause_links(Clause c) { Literal lit; for (lit = c->literals; lit != NULL; lit = lit->next) upward_term_links(lit->atom, c); } /* upward_clause_links */ /************* * * copy_clause() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The container field of each nonvariable subterm points to the clause. */ /* PUBLIC */ Clause copy_clause(Clause c) { Literal l; Clause c2 = get_clause(); for (l = c->literals; l != NULL; l = l->next) { Literal l2 = get_literal(); l2->sign = l->sign; l2->atom = copy_term(l->atom); append_literal(c2, l2); } upward_clause_links(c2); return c2; } /* copy_clause */ /************* * * copy_clause_with_flags() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. All termflags are copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Clause copy_clause_with_flags(Clause c) { Literal l; Clause c2 = get_clause(); for (l = c->literals; l != NULL; l = l->next) { Literal l2 = get_literal(); l2->sign = l->sign; l2->atom = copy_term_with_flags(l->atom); append_literal(c2, l2); } upward_clause_links(c2); return c2; } /* copy_clause_with_flags */ /************* * * copy_clause_with_flag() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The given termflag is copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Clause copy_clause_with_flag(Clause c, int flag) { Literal l; Clause c2 = get_clause(); for (l = c->literals; l != NULL; l = l->next) { Literal l2 = get_literal(); l2->sign = l->sign; l2->atom = copy_term_with_flag(l->atom, flag); append_literal(c2, l2); } upward_clause_links(c2); return c2; } /* copy_clause_with_flag */ /************* * * literal_number() * *************/ /* DOCUMENTATION Given a clause and a literal, return the position of the literal (counting from 1) in the clause. The check is by pointer only. If the literal does not occur in the clause, 0 is returned. */ /* PUBLIC */ int literal_number(Clause c, Literal l) { int n = 1; Literal lit = c->literals; while (lit != NULL && lit != l) { n++; lit = lit->next; } return (lit == NULL ? 0 : n); } /* literal_number */ /************* * * atom_number() * *************/ /* DOCUMENTATION Given a clause and an atom, return the position of the atom (counting from 1) in the clause. The check is by pointer only. If the atom does not occur in the clause, 0 is returned. */ /* PUBLIC */ int atom_number(Clause c, Term atom) { int n = 1; Literal lit = c->literals; while (lit != NULL && lit->atom != atom) { n++; lit = lit->next; } return (lit == NULL ? 0 : n); } /* atom_number */ /************* * * ith_literal() * *************/ /* DOCUMENTATION Return the i-th literal of a clause, counting from 1. Return NULL if i is out of range. */ /* PUBLIC */ Literal ith_literal(Clause c, int i) { Literal lit = c->literals; int n = 1; while (lit != NULL && n < i) { lit = lit->next; n++; } return lit; } /* ith_literal */ /************* * * true_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL true_term(Term t) { return is_term(t, TRUE_SYM, 0); } /* true_term */ /************* * * false_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL false_term(Term t) { return is_term(t, FALSE_SYM, 0); } /* false_term */ /************* * * tautology() * *************/ /* DOCUMENTATION This routine returns TRUE if the clause has complementary literals or if it has any literals of the form $T, -$F. */ /* PUBLIC */ BOOL tautology(Clause c) { Literal l1; for (l1 = c->literals; l1; l1 = l1->next) { BOOL sign = l1->sign; Term a = l1->atom; if (sign && true_term(a)) return TRUE; else if (!sign && false_term(a)) return TRUE; else { /* Check for a complementary occurring after this literal. */ Literal l2; for (l2 = l1->next; l2; l2 = l2->next) { if (sign != l2->sign && term_ident(a, l2->atom)) return TRUE; } } } return FALSE; } /* tautology */ /************* * * inherit_attributes() * *************/ /* DOCUMENTATION This takes two parent clauses and their associated substitutions, and a child clause. All inheritable attributes on the parents are instantiated and appended to the child's attributes. */ /* PUBLIC */ void inherit_attributes(Clause parent1, Context subst1, Clause parent2, Context subst2, Clause child) { Attribute a1 = inheritable_att_instances(parent1->attributes, subst1); Attribute a2 = inheritable_att_instances(parent2->attributes, subst2); child->attributes = cat_att(child->attributes, cat_att(a1, a2)); } /* inherit_attributes */ /************* * * function_symbols_in_clause() * *************/ /* DOCUMENTATION Collect the multiset of function symbols in a clause. */ /* PUBLIC */ Ilist function_symbols_in_clause(Clause c, Ilist g) { Literal lit; for (lit = c->literals; lit; lit = lit->next) { int i; for (i = 0; i < ARITY(lit->atom); i++) { g = symbols_in_term(ARG(lit->atom,i), g); } } return g; } /* function_symbols_in_clause */ /************* * * relation_symbols_in_clause() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols in a clause. */ /* PUBLIC */ Ilist relation_symbols_in_clause(Clause c, Ilist g) { Literal lit; for (lit = c->literals; lit; lit = lit->next) g = ilist_prepend(g, SYMNUM(lit->atom)); return g; } /* relation_symbols_in_clause */ /************* * * symbol_occurrences_in_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int symbol_occurrences_in_clause(Clause c, int symnum) { int n = 0; Literal lit; for (lit = c->literals; lit; lit = lit->next) n += symbol_occurrences(lit->atom, symnum); return n; } /* symbol_occurrences_in_clause */ /************* * * remove_null_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literal remove_null_literals(Literal l) { if (l == NULL) return NULL; else { l->next = remove_null_literals(l->next); if (l->atom != NULL) return l; else { Literal m = l->next; free_literal(l); return m; } } } /* remove_null_literals */ /************* * * new_atom_nodes() * *************/ /* DOCUMENTATION Replace the atom nodes in a clause. The new atom nodes have the property that they are greater in the FPA ordering than any other terms currently in use. */ /* PUBLIC */ void new_atom_nodes(Clause c) { Literal l; for (l = c->literals; l; l = l->next) l->atom = new_term_top(l->atom); } /* new_atom_nodes */ /************* * * new_atoms() * *************/ /* DOCUMENTATION Replace the atoms and all subterms in a clause. The new terms have the property that they are greater in the FPA ordering than any other terms currently in use. Also, all of the new subterms are contiguous in memory. */ /* PUBLIC */ void new_atoms(Clause c) { Literal l; for (l = c->literals; l; l = l->next) l->atom = entirely_new_term(l->atom); } /* new_atoms */ /************* * * first_negative_literal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literal first_negative_literal(Clause c) { Literal lit = c->literals; while (lit && lit->sign) lit = lit->next; return lit; } /* first_negative_literal */ /************* * * constants_in_clause() * *************/ /* DOCUMENTATION Given a clause, return the set of constants therein. */ /* PUBLIC */ Plist constants_in_clause(Clause c) { Plist p = NULL; Literal lit; for (lit = c->literals; lit; lit = lit->next) p = constants_in_term(lit->atom, p); return p; } /* constants_in_clause */ /************* * * clause_ident() * *************/ /* DOCUMENTATION Identical clauses, including order of literals and variable numbering. */ /* PUBLIC */ BOOL clause_ident(Clause c1, Clause c2) { Literal l1, l2; for (l1 = c1->literals, l2 = c2->literals; l1 && l2; l1 = l1->next, l2 = l2->next) { if (l1->sign != l2->sign || !term_ident(l1->atom, l2->atom)) { return FALSE; } } return (l1 == NULL && l2 == NULL); } /* clause_ident */ LADR-2009-11A/ladr/save/lex_compare0000644000175000017500000001016610143735562016131 0ustar mccunemccune/************* * * lex_compare_1() * * 1. constants < arity-2 < arity-3 < ... < arity-infinity < arity-1 * 2. within arity, use strcmp. * *************/ static Ordertype lex_compare_1(Sym_ent s1, Sym_ent s2) { if (s1 == NULL) return LESS_THAN; else if (s2 == NULL) return GREATER_THAN; else if (s1->arity == s2->arity) { int i = strcmp(s1->name, s2->name); if (i < 0) return LESS_THAN; else if (i > 0) return GREATER_THAN; else return SAME_AS; } else if (s1->arity == 1) return GREATER_THAN; else if (s2->arity == 1) return LESS_THAN; else if (s1->arity < s2->arity) return LESS_THAN; else return GREATER_THAN; } /* lex_compare_1 */ /************* * * lex_order_1() * *************/ /* DOCUMENTATION This routine imposes a default total ordering on symbols.
The primary order is

constants < arity-2 < arity-3 < ... < arity-infinity < arity-1
Within arity, the order is determined by the C library function
strcmp, which is (usually) lexicographic ASCII order.
*/

/* PUBLIC */
void lex_order_1(void)
{
  int n = greatest_symnum() + 1;
  Sym_ent *a = malloc(n * sizeof(void *));
  int i;
  for (i = 0; i < n; i++)
    a[i] = sn_to_node(i);

  merge_sort((void **) a, n,
	     (Ordertype (*)(void*, void*)) lex_compare_1);

  for (i = 0; i < n; i++) {
    if (a[i]) {
      a[i]->lex_val = i;
#if 0
      printf("symbol %s/%d, lex_val=%d.\n",
	     a[i]->name, a[i]->arity, a[i]->lex_val);
#endif
    }
  }
  free(a);
}  /* lex_order_1 */

/*************
 *
 *   lex_compare_2()
 *
 *   1. functions < relations < unspecified
 *   2. existing lex_val  (default is INT_MAX)
 *   3. function: constants < arity-2 < ... < arity-infinity < arity-1
 *   4. relations & unspecified: constants < arity-1 < ... < arity-infinity < =
 *   5. = is greatest
 *   6. strcmp
 *
 *************/

static
Ordertype lex_compare_2(Sym_ent s1, Sym_ent s2)
{
  if (s1 == s2)
    return SAME_AS;
  else if (s1 == NULL)
    return LESS_THAN;
  else if (s2 == NULL)
    return GREATER_THAN;

  else if (s1->type == FUNCTION_SYMBOL && s2->type != FUNCTION_SYMBOL)
    return LESS_THAN;
  else if (s1->type != FUNCTION_SYMBOL && s2->type == FUNCTION_SYMBOL)
    return GREATER_THAN;

  else if (s1->type == RELATION_SYMBOL && s2->type != RELATION_SYMBOL)
    return LESS_THAN;
  else if (s1->type != RELATION_SYMBOL && s2->type == RELATION_SYMBOL)
    return GREATER_THAN;

  /* now they have the same type */

  else if (s1->lex_val < s2->lex_val)
    return LESS_THAN;
  else if (s1->lex_val > s2->lex_val)
    return GREATER_THAN;

  else if (s1->type == RELATION_SYMBOL && is_eq_symbol(s2->sym_num))
    return LESS_THAN;
  else if (s1->type == RELATION_SYMBOL && is_eq_symbol(s1->sym_num))
    return GREATER_THAN;

  else if (s1->arity == s2->arity) {
    if (!is_eq_symbol(s1->sym_num) && is_eq_symbol(s2->sym_num))
      return LESS_THAN;
    else if (is_eq_symbol(s1->sym_num) && !is_eq_symbol(s2->sym_num))
      return GREATER_THAN;
    else {
      int i = strcmp(s1->name, s2->name);
      if (i < 0)
	return LESS_THAN;
      else if (i > 0)
	return GREATER_THAN;
      else
	return SAME_AS;
    }
  }
  else if (s1->type == FUNCTION_SYMBOL && s1->arity == 1)
    return GREATER_THAN;
  else if (s1->type == FUNCTION_SYMBOL && s2->arity == 1)
    return LESS_THAN;
  else if (s1->arity < s2->arity)
    return LESS_THAN;
  else
    return GREATER_THAN;
}  /* lex_compare_2 */

/*************
 *
 *   lex_order_2()
 *
 *************/

/* DOCUMENTATION
Assign a total order on lex_vals of (fsyms U rsyms).
If any of the symbols already have lex_vals, they
are considered, but overwritten by this rouine.
For the rules, see lex_compare_2.
*/

/* PUBLIC */
void lex_order_2(Ilist fsyms, Ilist rsyms)
{
  int n = ilist_count(fsyms) + ilist_count(rsyms);
  Sym_ent *a = malloc(n * sizeof(void *));
  Ilist p;
  int i = 0;
  for (p = fsyms; p; p = p->next)
    a[i++] = sn_to_node(p->i);
  for (p = rsyms; p; p = p->next)
    a[i++] = sn_to_node(p->i);
  
  merge_sort((void **) a, n,
	     (Ordertype (*)(void*, void*)) lex_compare_2);
  
  for (i = 0; i < n; i++)
    a[i]->lex_val = i;
  free(a);
}  /* lex_order_2 */

LADR-2009-11A/ladr/save/mindex.c0000644000175000017500000004414410140052314015323 0ustar  mccunemccune#include "mindex.h"

/* Private definitions and types */

struct mindex_pos {

  Mindex     index;
  Querytype  query_type;
  Term       query_term;
  Term       found_term;
  Context    query_subst;
  Context    found_subst;
  Trail      tr;
  Btu_state  btu_position;  /* backtrack unification */
  Btm_state  btm_position;  /* backtrack matching */
  BOOL       partial_match;

  /* FPA */
  Fpa_state  fpa_position;

  /* LINEAR */
  Plist   linear_position;
  
  /* DISCRIM */
  /* DISCRIM_BIND */
  Discrim_pos  discrim_position;

  Mindex_pos next;  /* for avail list */
};

/*
 * memory management
 */

static unsigned Mindex_gets, Mindex_frees;
static unsigned Mindex_pos_gets, Mindex_pos_frees;

#define BYTES_MINDEX sizeof(struct mindex)
#define PTRS_MINDEX BYTES_MINDEX%BPP == 0 ? BYTES_MINDEX/BPP : BYTES_MINDEX/BPP + 1

#define BYTES_MINDEX_POS sizeof(struct mindex_pos)
#define PTRS_MINDEX_POS BYTES_MINDEX_POS%BPP == 0 ? BYTES_MINDEX_POS/BPP : BYTES_MINDEX_POS/BPP + 1

/*************
 *
 *   Mindex get_mindex()
 *
 *************/

static
Mindex get_mindex(void)
{
  Mindex p = get_mem(PTRS_MINDEX);
  p->index_type = -1;
  p->unif_type = -1;
  Mindex_gets++;
  return(p);
}  /* get_mindex */

/*************
 *
 *    free_mindex()
 *
 *************/

static
void free_mindex(Mindex p)
{
  free_mem(p, PTRS_MINDEX);
  Mindex_frees++;
}  /* free_mindex */

/*************
 *
 *   Mindex_pos get_mindex_pos()
 *
 *************/

static
Mindex_pos get_mindex_pos(void)
{
  Mindex_pos p = get_mem(PTRS_MINDEX_POS);
  p->query_type = -1;
  Mindex_pos_gets++;
  return(p);
}  /* get_mindex_pos */

/*************
 *
 *    free_mindex_pos()
 *
 *************/

static
void free_mindex_pos(Mindex_pos p)
{
  free_mem(p, PTRS_MINDEX_POS);
  Mindex_pos_frees++;
}  /* free_mindex_pos */

/*************
 *
 *   fprint_mindex_mem()
 *
 *************/

/* DOCUMENTATION
This routine prints (to FILE *fp) memory usage statistics for data types
associated with the mindex package.
The Boolean argument heading tells whether to print a heading on the table.
*/

/* PUBLIC */
void fprint_mindex_mem(FILE *fp, BOOL heading)
{
  int n;
  if (heading)
    fprintf(fp, "  type (bytes each)        gets      frees     in use      bytes\n");

  n = BYTES_MINDEX;
  fprintf(fp, "mindex (%4d)       %11u%11u%11u%9.1f K\n",
          n, Mindex_gets, Mindex_frees,
          Mindex_gets - Mindex_frees,
          ((Mindex_gets - Mindex_frees) * n) / 1024.);

  n = BYTES_MINDEX_POS;
  fprintf(fp, "mindex_pos (%4d)   %11u%11u%11u%9.1f K\n",
          n, Mindex_pos_gets, Mindex_pos_frees,
          Mindex_pos_gets - Mindex_pos_frees,
          ((Mindex_pos_gets - Mindex_pos_frees) * n) / 1024.);

}  /* fprint_mindex_mem */

/*************
 *
 *   p_mindex_mem()
 *
 *************/

/* DOCUMENTATION
This routine prints (to stdout) memory usage statistics for data types
associated with the mindex package.
*/

/* PUBLIC */
void p_mindex_mem()
{
  fprint_mindex_mem(stdout, TRUE);
}  /* p_mindex_mem */

/*
 *  end of memory management
 */
/*************
 *
 *   mindex_init()
 *
 *************/

/* DOCUMENTATION
This routine allocates and returns an (empty) Mindex, which is
used to retrieve unifiable terms.
  • index_type: {LINEAR, FPA, DISCRIM, DISCRIM_BIND}
  • unif_type: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
Types of retrieval. LINEAR and FPA indexes support all types of retrieval (FPA is slow for GENERALIZATION). DISCRIM and DISCRIM_BIND indexes support GENERALIZATION retrieval only. See mindex_retrieve_first().

Associative-commutative (AC) and commutative/symmetric (C) symbols. DISCRIM_BIND does not support AC symbols. All other combinations are okay. If you have any AC or C symbols, you must specify unif_type BACKTRACK_UNIF. (BACKTRACK_UNIF is also okay with no AC or C symbols, but it is a little bit slower than ORDINARY_UNIF.)

AC symbols must be declared (with set_assoc_comm()) before calling mindex_update(). C symbols need not be declared before mindex_update(), but they must be declared (with set_commutative()) before calling mindex_retrieve_first(). */ /* PUBLIC */ Mindex mindex_init(Mindextype mtype, Uniftype utype, int fpa_depth) { Mindex mdx = get_mindex(); mdx->index_type = mtype; mdx->unif_type = utype; switch(mtype) { case LINEAR: mdx->linear_first = mdx->linear_last = NULL; break; case FPA: mdx->fpa = fpa_init_index(fpa_depth); break; case DISCRIM: mdx->discrim_tree = discrim_init(); break; case DISCRIM_BIND: mdx->discrim_tree = discrim_init(); break; default: free_mindex(mdx); mdx = NULL; } return mdx; } /* mindex_init */ /************* * * mindex_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an Mindex is empty, that is, has no terms. It must exist (be non-NULL). */ /* PUBLIC */ BOOL mindex_empty(Mindex mdx) { switch (mdx->index_type) { case FPA: return fpa_empty(mdx->fpa); break; case LINEAR: return mdx->linear_first == NULL; break; case DISCRIM: case DISCRIM_BIND: return discrim_empty(mdx->discrim_tree); break; } return FALSE; } /* mindex_empty */ /************* * * mindex_free() * *************/ /* DOCUMENTATION This routine frees an empty Mindex. (If the Mindex is not empty, nothing happens.) */ /* PUBLIC */ void mindex_free(Mindex mdx) { if (!mindex_empty(mdx)) fprintf(stderr, "WARNING, mindex_free called with nonempty mindex.\n"); else { switch (mdx->index_type) { case FPA: zap_fpa_index(mdx->fpa); break; case LINEAR: break; case DISCRIM: case DISCRIM_BIND: discrim_dealloc(mdx->discrim_tree); break; } free_mindex(mdx); } } /* mindex_free */ /************* * * mindex_destroy() * *************/ /* DOCUMENTATION This frees all the memory associated with an Mindex. Do not refer to the Mindex after calling this routine. */ /* PUBLIC */ void mindex_destroy(Mindex mdx) { if (!mindex_empty(mdx)) { fprintf(stdout, "\nWARNING: destroying nonempty mindex.\n\n"); fprintf(stderr, "\nWARNING: destroying nonempty mindex.\n\n"); } switch (mdx->index_type) { case FPA: zap_fpa_index(mdx->fpa); break; case LINEAR: zap_plist(mdx->linear_first); break; case DISCRIM: case DISCRIM_BIND: destroy_discrim_tree(mdx->discrim_tree); break; } free_mindex(mdx); } /* mindex_destroy */ /************* * * linear_insert() * *************/ static void linear_insert(Mindex mdx, Term t) { Plist p = get_plist(); p->v = t; if (mdx->linear_last != NULL) mdx->linear_last->next = p; else mdx->linear_first = p; mdx->linear_last = p; } /* linear_insert */ /************* * * linear_delete() * *************/ static void linear_delete(Mindex mdx, Term t) { Plist curr, prev; prev = NULL; curr = mdx->linear_first; while (curr != NULL && curr->v != t) { prev = curr; curr = curr->next; } if (curr == NULL) { fprint_term(stderr, t); fprintf(stderr, "\n"); fatal_error("mindex_delete (linear), term not found."); } else { if (prev != NULL) prev->next = curr->next; else mdx->linear_first = curr->next; if (curr == mdx->linear_last) mdx->linear_last = prev; free_plist(curr); } } /* linear_delete */ /************* * * linear_update() * *************/ static void linear_update(Mindex mdx, Term t, Indexop op) { if (op == INSERT) linear_insert(mdx, t); else linear_delete(mdx, t); } /* linear_update */ /************* * * mindex_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) a Term t into/from an Mindex mdx.

It is your responsibility to remember that t is in the index, because we don't currently have a routine "mindex_member()". */ /* PUBLIC */ void mindex_update(Mindex mdx, Term t, Indexop op) { if (mdx->index_type == FPA) fpa_update(t, mdx->fpa, op); else if (mdx->index_type == LINEAR) linear_update(mdx, t, op); else if (mdx->index_type == DISCRIM) discrim_wild_update(t, mdx->discrim_tree, t, op); else if (mdx->index_type == DISCRIM_BIND) discrim_tame_update(t, mdx->discrim_tree, t, op); else { fatal_error("ERROR, mindex_update: bad mindex type."); } } /* mindex_update */ /************* * * mindex_retrieve_first * *************/ /* DOCUMENTATION This routine finds and returns the first answer to a query (returning NULL if there are no answers).

  • Term t: the query term;
  • Mindex mdx: the Mindex;
  • int query_type: UNIFY, INSTANCE, GENERALIZATION, VARIANT, or IDENTICAL;
  • Context query_subst: subsitution for variables in query term t; this can be NULL for GENERALIZATION, and IDENTICAL;
  • Context found_subst: subsitution for variables in the answer term; this can be NULL for INSTANCE, VARIANT, and IDENTICAL;
  • BOOL partial_match: If TRUE, then for GENERALIZATION, with BACKTRACK_UNIF, when t has an AC symbol at the root, allow the retrieved term to match only part of t, with the remainder of the retrieved term placed in fond_subst->partial_term. This is used for AC rewriting, for example, to let x+x=x rewrite a+a+b.
  • Mindex_pos *ppos (output parameter): If an answer is returned, this address is set to a pointer to a structure that holds the position so you can get the rest of the answers.
If you ask for a type of retrieval not supported by the Mindex mdx, you will get no answers (and no error message).

Here is an example of how to retrieve all answers. Assume we have Term t and Mindex mdx.

{
  Mindex_pos pos;
  Term t2;
  Context cq = get_context();
  Context cf = get_context();
  int n = 0;
  
  t2 = mindex_retrieve_first(t, mdx, UNIFY, cq, cf, FALSE, &pos);
  while (t2 != NULL) {
    t2 = mindex_retrieve_next(pos);
    n++;
  }
  free_context(cq);
  free_context(cf);
  printf("there are %d mates\n", n);
}
*/ /* PUBLIC */ Term mindex_retrieve_first(Term t, Mindex mdx, Querytype qtype, Context query_subst, Context found_subst, BOOL partial_match, Mindex_pos *ppos) { Mindex_pos pos; if ((mdx->index_type == DISCRIM || mdx->index_type == DISCRIM_BIND) && qtype != GENERALIZATION) return NULL; else { pos = get_mindex_pos(); pos->index = mdx; pos->query_type = qtype; pos->query_term = t; pos->query_subst = query_subst; pos->found_term = NULL; pos->found_subst = found_subst; pos->tr = NULL; pos->btu_position = NULL; pos->btm_position = NULL; pos->partial_match = partial_match; if (mdx->index_type == FPA) pos->fpa_position = NULL; else if (mdx->index_type == DISCRIM) pos->discrim_position = NULL; else if (mdx->index_type == DISCRIM_BIND) pos->discrim_position = NULL; else if (mdx->index_type == LINEAR) pos->linear_position = mdx->linear_first; *ppos = pos; return mindex_retrieve_next(pos); } } /* mindex_retrieve_first */ /************* * * next_candidate() * *************/ static Term next_candidate(Mindex_pos pos) { Term tf; if (pos->index->index_type == FPA) { if (pos->fpa_position == NULL) { tf = fpa_first_answer(pos->query_term, pos->query_subst, pos->query_type, pos->index->fpa, &(pos->fpa_position)); } else tf = fpa_next_answer(pos->fpa_position); } else if (pos->index->index_type == DISCRIM) { if (pos->discrim_position == NULL) tf = discrim_wild_retrieve_first(pos->query_term, pos->index->discrim_tree, &(pos->discrim_position)); else tf = discrim_wild_retrieve_next(pos->discrim_position); } else if (pos->index->index_type == DISCRIM_BIND) { if (pos->discrim_position == NULL) tf = discrim_tame_retrieve_first(pos->query_term, pos->index->discrim_tree, pos->found_subst, &(pos->discrim_position)); else tf = discrim_tame_retrieve_next(pos->discrim_position); } else if (pos->index->index_type == LINEAR) { if (pos->linear_position == NULL) tf = NULL; else { tf = pos->linear_position->v; pos->linear_position = pos->linear_position->next; } } else tf = NULL; return tf; } /* next_candidate */ /************* * * retrieve_next_backtrack() * *************/ static Term retrieve_next_backtrack(Mindex_pos pos) { Term tq = pos->query_term; Term tf = pos->found_term; Context cq = pos->query_subst; Context cf = pos->found_subst; if (pos->query_type == UNIFY) { /* We already have a found_term from a previous call; * try for another unifier. */ if (pos->btu_position != NULL) { pos->btu_position = unify_bt_next(pos->btu_position); if (pos->btu_position == NULL) tf = NULL; } if (pos->btu_position == NULL) { /* This is either the first call for the query, or there are * no more unifiers for the previous found_term. */ tf = next_candidate(pos); while (tf != NULL && pos->btu_position == NULL) { pos->btu_position = unify_bt_first(tq, cq, tf, cf); if (pos->btu_position == NULL) tf = next_candidate(pos); } } } /* UNIFY */ else if (pos->query_type == INSTANCE || pos->query_type == GENERALIZATION) { if (pos->btm_position != NULL) { pos->btm_position = match_bt_next(pos->btm_position); if (pos->btm_position == NULL) tf = NULL; } if (pos->btm_position == NULL) { tf = next_candidate(pos); while (tf != NULL && pos->btm_position == NULL) { if (pos->query_type == INSTANCE) pos->btm_position = match_bt_first(tq, cq, tf, pos->partial_match); else pos->btm_position = match_bt_first(tf, cf, tq, pos->partial_match); if (pos->btm_position == NULL) tf = next_candidate(pos); } } } /* INSTANCE || GENERALIZATION */ else if (pos->query_type == VARIANT) { fatal_error("retrieve_next_backtrack, VARIANT not supported."); } /* VARIANT */ else if (pos->query_type == IDENTICAL) { fatal_error("retrieve_next_backtrack, IDENTICAL not supported."); } /* IDENTICAL */ if (tf == NULL) { free_mindex_pos(pos); return NULL; } else { pos->found_term = tf; return tf; } } /* retrieve_next_backtrack */ /************* * * mindex_retrieve_next * *************/ /* DOCUMENTATION This routine finds and returns the next answer to a query. See mindex_retrieve_first() for an explanation. */ /* PUBLIC */ Term mindex_retrieve_next(Mindex_pos pos) { if (pos->index->unif_type == BACKTRACK_UNIF) return retrieve_next_backtrack(pos); else { Term tq, tf; Context cq, cf; Trail tr; BOOL ok; tq = pos->query_term; cq = pos->query_subst; cf = pos->found_subst; undo_subst(pos->tr); /* ok if NULL or not used */ pos->tr = NULL; tf = next_candidate(pos); if (tf != NULL && pos->index->index_type == DISCRIM_BIND) ok = TRUE; else ok = FALSE; while (tf && !ok) { #if 0 printf("potential mate, %d: ", tf->INDEX_ID); p_term(tf); #endif tr = NULL; switch (pos->query_type) { case UNIFY: ok = unify(tq, cq, tf, cf, &(pos->tr)); break; case GENERALIZATION: ok = match(tf, cf, tq, &(pos->tr)); break; case INSTANCE: ok = match(tq, cq, tf, &(pos->tr)); break; case VARIANT: ok = variant(tq, cq, tf, &(pos->tr)); break; case IDENTICAL: ok = term_ident(tq, tf); break; default: ok = FALSE; break; } if (!ok) tf = next_candidate(pos); } if (ok) { #if 0 printf(" MATE, %d: ", tf->INDEX_ID); p_term(tf); #endif return tf; } else { free_mindex_pos(pos); return NULL; } } } /* mindex_retrieve_next */ /************* * * mindex_retrieve_cancel * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all, answers to a query. For example, if you need only one answer you can do something like the following:
{
  Mindex_pos pos;
  Term t2;
  Context cf = get_context();
  
  t2 = mindex_retrieve_first(t, mdx, GENERALIZATION, (Context) NULL, cf, &pos);
  if (t2 != NULL) {
    printf("we found a mate!\n");
    mindex_retrieve_cancel(pos);
  }
  else
    printf("no answer\n");
  free_context(cf);
}
If you fail to call this routine, then the memory associated with an Mindex_pos will be forever lost, that is, you will have a memory leak. */ /* PUBLIC */ void mindex_retrieve_cancel(Mindex_pos pos) { /* Clean up the unification states. The Mindex_pos doesn't know * what kind of unification applies, so try them all. */ if (pos->tr != NULL) undo_subst(pos->tr); else if (pos->btm_position != NULL) match_bt_cancel(pos->btm_position); else if (pos->btu_position != NULL) unify_bt_cancel(pos->btu_position); if (pos->index->index_type == FPA) fpa_cancel(pos->fpa_position); else if (pos->index->index_type == LINEAR) ; /* do nothing */ else if (pos->index->index_type == DISCRIM) discrim_wild_cancel(pos->discrim_position); else if (pos->index->index_type == DISCRIM_BIND) discrim_tame_cancel(pos->discrim_position); free_mindex_pos(pos); } /* mindex_retrieve_cancel */ /************* * * fprint_linear_index() * *************/ static void fprint_linear_index(FILE *fp, Plist first) { Plist p; for (p = first; p != NULL; p = p->next) { Term t = p->v; fprintf(fp, "FPA_ID=%u: ", (unsigned) FPA_ID(t)); fprint_term(fp, t); fprintf(fp, "\n"); } } /* fprint_linear_index */ /************* * * fprint_mindex() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) Mindex mdx. */ /* PUBLIC */ void fprint_mindex(FILE *fp, Mindex mdx) { switch (mdx->index_type) { case LINEAR: fprintf(fp, "\nThis is an Mindex of type LINEAR.\n"); fprint_linear_index(fp, mdx->linear_first); break; case FPA: fprintf(fp, "\nThis is an Mindex of type FPA.\n"); fprint_fpa_index(fp, mdx->fpa); break; case DISCRIM: fprintf(fp, "\nThis is an Mindex of type DISCRIM.\n"); fprint_discrim_wild_index(fp, mdx->discrim_tree); break; case DISCRIM_BIND: fprintf(fp, "\nThis is an Mindex of type DISCRIM_BIND.\n"); fprint_discrim_tame_index(fp, mdx->discrim_tree); break; } } /* fprint_mindex */ LADR-2009-11A/ladr/save/attrib.c0000644000175000017500000004234110140052627015330 0ustar mccunemccune#include "attrib.h" /* Private definitions and types */ /* Attribute: a list of these can be attached to clauses. */ struct attribute { /* to form lists of attributes */ int id; /* attribute ID (index into Attribute_names array) */ union { /* attribute value */ int i; char *s; Term t; } u; Attribute next; }; /* Attribute_names: data about types of attributes. */ #define MAX_ATTRIBUTE_NAMES 50 static struct { /* array, indexed by attribute id */ char *name; /* name of attribute, e.g., label, answer */ Attribute_type type; /* INT_ATTRIBUTE STRING_ATTRIBUTE TERM_ATTRIBUTE etc */ BOOL inheritable; /* child gets instance (for term attributes only) */ } Attribute_names[MAX_ATTRIBUTE_NAMES]; /* * memory management */ static unsigned Attribute_gets, Attribute_frees; #define BYTES_ATTRIBUTE sizeof(struct attribute) #define PTRS_ATTRIBUTE BYTES_ATTRIBUTE%BPP == 0 ? BYTES_ATTRIBUTE/BPP : BYTES_ATTRIBUTE/BPP + 1 /************* * * Attribute get_attribute() * *************/ static Attribute get_attribute(void) { Attribute p = get_mem(PTRS_ATTRIBUTE); Attribute_gets++; return(p); } /* get_attribute */ /************* * * free_attribute() * *************/ static void free_attribute(Attribute p) { free_mem(p, PTRS_ATTRIBUTE); Attribute_frees++; } /* free_attribute */ /************* * * fprint_attrib_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the attrib package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_attrib_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_ATTRIBUTE; fprintf(fp, "attribute (%4d) %11u%11u%11u%9.1f K\n", n, Attribute_gets, Attribute_frees, Attribute_gets - Attribute_frees, ((Attribute_gets - Attribute_frees) * n) / 1024.); } /* fprint_attrib_mem */ /************* * * p_attrib_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the attrib package. */ /* PUBLIC */ void p_attrib_mem() { fprint_attrib_mem(stdout, TRUE); } /* p_attrib_mem */ /* * end of memory management */ /************* * * register_attribute() * *************/ /* DOCUMENTATION This routine associates an attribute name and attribute type with an integer ID to be used with the attribute operations (set, get, etc). */ /* PUBLIC */ void register_attribute(int id, char *name, Attribute_type type) { if (id < 0 || id >= MAX_ATTRIBUTE_NAMES) fatal_error("register_attribute: id out of range"); else if (Attribute_names[id].name != NULL) fatal_error("register_attribute: id already in use"); else { Attribute_names[id].name = new_str_copy(name); Attribute_names[id].type = type; } } /* register_attribute */ /************* * * declare_term_attribute_inheritable() * *************/ /* DOCUMENTATION This routine makes a term attribute (which has already been registered) inheritable. This usually means that when the clause to which the attribute is attached begets a child, the child gets a copy of the instantiated attribute. This was designed for answer literals and ordering constraints. */ /* PUBLIC */ void declare_term_attribute_inheritable(int id) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("declare_term_attribute_inheritable, bad id"); Attribute_names[id].inheritable = TRUE; } /* declare_term_attribute_inheritable */ /************* * * inheritable() * *************/ static BOOL inheritable(Attribute a) { return Attribute_names[a->id].inheritable; } /* inheritable */ /************* * * set_int_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes.

A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_int_attribute(Attribute a, int id, int val) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("set_int_attribute, bad id"); if (a == NULL) { Attribute b = get_attribute(); b->id = id; b->u.i = val; return b; } else { a->next = set_int_attribute(a->next, id, val); return a; } } /* set_int_attribute */ /************* * * get_int_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, INT_MAX is returned.

A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute). */ /* PUBLIC */ int get_int_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("get_int_attribute, bad id"); if (a == NULL) return INT_MAX; else if (a->id == id && n == 1) return a->u.i; else if (a->id == id) return get_int_attribute(a->next, id, n-1); else return get_int_attribute(a->next, id, n); } /* get_int_attribute */ /************* * * exists_attribute() * *************/ /* DOCUMENTATION This routine checks if there are any attributes of the given type. */ /* PUBLIC */ BOOL exists_attribute(Attribute a, int id) { if (a == NULL) return FALSE; else if (a->id == id) return TRUE; else return exists_attribute(a->next, id); } /* exists_attribute */ /************* * * set_term_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes. The term is not copied.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_term_attribute(Attribute a, int id, Term val) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("set_term_attribute, bad ID"); if (a == NULL) { Attribute b = get_attribute(); b->id = id; b->u.t = val; return b; } else { a->next = set_term_attribute(a->next, id, val); return a; } } /* set_term_attribute */ /************* * * replace_term_attribute() * *************/ /* DOCUMENTATION This routine replaces that n-th term attribute for given ID. The term that is already there is zapped, and the new term is NOT copied.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute), or if there are not n attributes identified by ID. */ /* PUBLIC */ void replace_term_attribute(Attribute a, int id, Term val, int n) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("replace_term_attribute, bad ID"); if (a == NULL) fatal_error("replace_term_attribute, attribute not found"); else if (a->id == id && n == 1) { zap_term(a->u.t); a->u.t = val; } else if (a->id == id) replace_term_attribute(a->next, id, val, n-1); else replace_term_attribute(a->next, id, val, n); } /* replace_term_attribute */ /************* * * replace_int_attribute() * *************/ /* DOCUMENTATION This routine replaces that n-th int attribute for given attribute ID.

A fatal error occurs if the ID does not refer to an int type attribute (see register_attribute), or if there are not n attributes identified by ID. */ /* PUBLIC */ void replace_int_attribute(Attribute a, int id, int val, int n) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("replace_int_attribute, bad ID"); if (a == NULL) fatal_error("replace_int_attribute, attribute not found"); else if (a->id == id && n == 1) { a->u.i = val; } else if (a->id == id) replace_int_attribute(a->next, id, val, n-1); else replace_int_attribute(a->next, id, val, n); } /* replace_int_attribute */ /************* * * get_term_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute). */ /* PUBLIC */ Term get_term_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("get_term_attribute, bad ID"); if (a == NULL) return NULL; else if (a->id == id && n == 1) return a->u.t; else if (a->id == id) return get_term_attribute(a->next, id, n-1); else return get_term_attribute(a->next, id, n); } /* get_term_attribute */ /************* * * set_string_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes. The string is not copied.

A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_string_attribute(Attribute a, int id, char *val) { if (Attribute_names[id].type != STRING_ATTRIBUTE) fatal_error("set_string_attribute, bad ID"); if (a == NULL) { Attribute b = get_attribute(); b->id = id; b->u.s = val; return b; } else { a->next = set_string_attribute(a->next, id, val); return a; } } /* set_string_attribute */ /************* * * get_string_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute). */ /* PUBLIC */ char *get_string_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != STRING_ATTRIBUTE) fatal_error("get_string_attribute, bad ID"); if (a == NULL) return NULL; else if (a->id == id && n == 1) return a->u.s; else if (a->id == id) return get_string_attribute(a->next, id, n-1); else return get_string_attribute(a->next, id, n); } /* get_string_attribute */ /************* * * zap_attributes() * *************/ /* DOCUMENTATION This routine frees a list of attributes and any associated memory. In particular, the terms in term attributes are zapped. */ /* PUBLIC */ void zap_attributes(Attribute a) { if (a != NULL) { zap_attributes(a->next); /* If there is any memory associted with the attribure, free it here. */ if (Attribute_names[a->id].type == TERM_ATTRIBUTE) zap_term(a->u.t); free_attribute(a); } } /* zap_attributes */ /************* * * delete_attributes() * *************/ /* DOCUMENTATION This routine frees all attributes of the given type. */ /* PUBLIC */ Attribute delete_attributes(Attribute a, int id) { if (a == NULL) return NULL; else { a->next = delete_attributes(a->next, id); if (a->id == id) { Attribute b = a->next; /* If there is any memory associted with the attribure, free it here. */ if (Attribute_names[a->id].type == TERM_ATTRIBUTE) zap_term(a->u.t); free_attribute(a); return b; } else return a; } } /* delete_attributes */ /************* * * cat_att() * *************/ /* DOCUMENTATION Concatenate two lists of attributes. Return the result. */ /* PUBLIC */ Attribute cat_att(Attribute a, Attribute b) { if (a == NULL) return b; else { a->next = cat_att(a->next, b); return a; } } /* cat_att */ /************* * * build_attr_term() * *************/ /* DOCUMENTATION Given an attribute, build (and return) a term representation of it. The name of the attribute will be the (unary) function symbol, and the value will be the argument.

This is typically used for printing attributes. */ /* PUBLIC */ Term build_attr_term(Attribute a) { char *name = Attribute_names[a->id].name; Attribute_type type = Attribute_names[a->id].type; Term t = get_rigid_term(name, 1); /* e.g., label(cl_32), answer(assoc) */ switch (type) { case INT_ATTRIBUTE: { char s[50]; if (a->u.i < 0) { ARG(t,0) = get_rigid_term("-", 1); itoa(-(a->u.i), s); ARG(ARG(t,0),0) = get_rigid_term(s, 0); } else { itoa(a->u.i, s); ARG(t,0) = get_rigid_term(s, 0); } break; } case STRING_ATTRIBUTE: ARG(t,0) = get_rigid_term(a->u.s, 0); break; case TERM_ATTRIBUTE: ARG(t,0) = copy_term(a->u.t); break; default: fatal_error("build_attr_term: bad attribute type"); } return t; } /* build_attr_term */ /************* * * attributes_to_term() * *************/ /* DOCUMENTATION This routine takes a list of attributes and constructs a term representation. It is a right-associated binary tree with Term forms of the attributes at the leaves. */ /* PUBLIC */ Term attributes_to_term(Attribute a, char *operator) { if (a == NULL) return NULL; /* should happen only on top call */ else if (a->next == NULL) return build_attr_term(a); else { return build_binary_term(str_to_sn(operator, 2), build_attr_term(a), attributes_to_term(a->next, operator)); } } /* attributes_to_term */ /************* * * cat_attributes() * *************/ static Attribute cat_attributes(Attribute a0, Attribute a1) { if (a0 == NULL) return a1; else { a0->next = cat_attributes(a0->next, a1); return a0; } } /* cat_attributes */ /************* * * attribute_name_to_id() * *************/ /* DOCUMENTATION Given an attribute name, return the attribute ID which is used for the "get" and "set" operations. Return -1 if the name has not been registered with "register_attribute". */ /* PUBLIC */ int attribute_name_to_id(char *name) { int i; for (i = 0; i < MAX_ATTRIBUTE_NAMES; i++) { if (Attribute_names[i].name != NULL && str_ident(Attribute_names[i].name, name)) return i; } return -1; } /* attribute_name_to_id */ /************* * * term_to_attributes() * *************/ /* DOCUMENTATION This routine takes a term representing a list of attributes and builds list of attributes. The input term form is a binary term, constructed with the given operator, with the attributes at the leaves. For example,

    label("hi there!") # answer(XGK(x,y,z)) # hint_wt(32)
If anuthing goes wrong, a fatal error occurs. */ /* PUBLIC */ Attribute term_to_attributes(Term t, char *operator) { if (is_term(t, operator, 2)) { Attribute a0 = term_to_attributes(ARG(t,0), operator); Attribute a1 = term_to_attributes(ARG(t,1), operator); return cat_attributes(a0, a1); } else { int id; Attribute a; if (ARITY(t) != 1) fatal_error("term_to_attributes, arity not 1"); id = attribute_name_to_id(sn_to_str(SYMNUM(t))); if (id == -1) fatal_error("term_to_attributes, attribute name not found"); a = get_attribute(); a->id = id; switch (Attribute_names[id].type) { case INT_ATTRIBUTE: if (!CONSTANT(ARG(t,0))) fatal_error("term_to_attributes, bad intger"); else { int i; if (!term_to_int(ARG(t,0), &i)) fatal_error("term_to_attributes, bad integer"); a->u.i = i; } break; case STRING_ATTRIBUTE: if (!CONSTANT(ARG(t,0))) fatal_error("term_to_attributes, bad string"); else a->u.s = sn_to_str(SYMNUM(ARG(t,0))); break; case TERM_ATTRIBUTE: a->u.t = copy_term(ARG(t,0)); break; } return a; } } /* term_to_attributes */ /************* * * inheritable_att_instances() * *************/ /* DOCUMENTATION Given a list of attributes, this routine copies, instantiates, and returns the the inheritable attributes. The Context can be NULL. */ /* PUBLIC */ Attribute inheritable_att_instances(Attribute a, Context subst) { if (a == NULL) return NULL; else if (!inheritable(a)) return inheritable_att_instances(a->next, subst); else { Attribute new = get_attribute(); new->id = a->id; new->u.t = subst ? apply(a->u.t, subst) : copy_term(a->u.t); new->next = inheritable_att_instances(a->next, subst); return new; } } /* inheritable_att_instances */ /************* * * copy_attributes() * *************/ /* DOCUMENTATION This routine copies a list of attributes. */ /* PUBLIC */ Attribute copy_attributes(Attribute a) { if (a == NULL) return NULL; else { Attribute new = get_attribute(); new->id = a->id; switch (Attribute_names[a->id].type) { case INT_ATTRIBUTE: new->u.i = a->u.i; break; case STRING_ATTRIBUTE: new->u.s = a->u.s; break; case TERM_ATTRIBUTE: new->u.t = copy_term(a->u.t); break; default: fatal_error("copy_attribute: unknown attribute"); } new->next = copy_attributes(a->next); return new; } } /* copy_attributes */ /************* * * renumber_vars_attributes() * *************/ /* DOCUMENTATION This routine renumbers the variables in the inheritable attribute terms. */ /* PUBLIC */ void renumber_vars_attributes(Attribute attrs, int vmap[], int max_vars) { Attribute a; for (a = attrs; a; a = a->next) { if (inheritable(a)) { a->u.t = renum_vars_recurse(a->u.t, vmap, max_vars); } } } /* renumber_vars_attributes */ /************* * * set_vars_attributes() * *************/ /* DOCUMENTATION This routine sets the variables in the inheritable attribute terms. */ /* PUBLIC */ void set_vars_attributes(Attribute attrs, char *vnames[], int max_vars) { Attribute a; for (a = attrs; a; a = a->next) { if (inheritable(a)) { a->u.t = set_vars_recurse(a->u.t, vnames, max_vars); } } } /* set_vars_attributes */ LADR-2009-11A/ladr/save/fsyms_clist0000644000175000017500000000515410240455061016162 0ustar mccunemccune/************* * * function_symbols_in_clist() * *************/ /* DOCUMENTATION Collect the multiset of function symbols (including constants) in a Clist. An Ilist of SYMNUMs is returned. */ /* PUBLIC */ Ilist function_symbols_in_clist(Clist lst, Ilist syms) { Clist_pos p; for (p = lst->first; p; p = p->next) syms = function_symbols_in_clause(p->c, syms); return syms; } /* function_symbols_in_clist */ /************* * * function_symbols_in_clists() * *************/ /* DOCUMENTATION Collect the multiset of function symbols (including constants) in a Plist of Clists. An Ilist of SYMNUMs is returned. */ /* PUBLIC */ Ilist function_symbols_in_clists(Plist clists, Ilist syms) { Plist p; for (p = clists; p; p = p->next) syms = function_symbols_in_clist(p->v, syms); return syms; } /* function_symbols_in_clists */ /************* * * relation_symbols_in_clist() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols in a Clist. An Ilist of SYMNUMs is returned. */ /* PUBLIC */ Ilist relation_symbols_in_clist(Clist lst, Ilist syms) { Clist_pos p; for (p = lst->first; p; p = p->next) syms = relation_symbols_in_clause(p->c, syms); return syms; } /* relation_symbols_in_clist */ /************* * * relation_symbols_in_clists() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols in a Plist of Clists. An Ilist of SYMNUMs is returned. */ /* PUBLIC */ Ilist relation_symbols_in_clists(Plist clists, Ilist syms) { Plist p; for (p = clists; p; p = p->next) syms = relation_symbols_in_clist(p->v, syms); return syms; } /* relation_symbols_in_clists */ /************* * * function_lex_check() * *************/ /* DOCUMENTATION Given a Plist of Clists, check that each function symbol has a lex_val. If the check fails, argument "fatal" says whether it should be a fatal error or just a WARNING. */ /* PUBLIC */ void function_lex_check(Plist clists, BOOL fatal) { Ilist function_syms = function_symbols_in_clists(clists, NULL); Ilist lex_syms = syms_with_lex_val(); Ilist diff_syms = ilist_subtract(function_syms, lex_syms); if (diff_syms) { Ilist g; bell(stderr); fprintf(stderr, "\nWARNING: function symbols without lex_val" " (see stdout).\n\n "); printf("\nWARNING: function symbols without lex_val:"); for (g = diff_syms; g; g = g->next) printf(" %s/%d", sn_to_str(g->i), sn_to_arity(g->i)); printf(".\n"); zap_ilist(diff_syms); if (fatal) fatal_error("function symbols without lex_val"); } zap_ilist(function_syms); zap_ilist(lex_syms); } /* function_lex_check */ LADR-2009-11A/ladr/save/commands.h0000644000175000017500000000172310150732761015655 0ustar mccunemccune#ifndef TP_COMMANDS_H #define TP_COMMANDS_H #include "options.h" #include "ioutil.h" /* INTRODUCTION This package has some high-level routines for reading a sequence of commands from an input stream. The commands do things like set options and give properties to symbols.

This is intended to be used to read the prologue to the input. */ /* Public definitions */ /* What shall we do if we read an unknown flag or parameter? */ enum { IGNORE_UNKNOWN, NOTE_UNKNOWN, WARN_UNKNOWN, KILL_UNKNOWN }; /* End of public definitions */ /* Public function prototypes from commands.c */ void flag_handler(FILE *fout, Term t, int unknown_action); void parm_handler(FILE *fout, Term t, int unknown_action); void preliminary_precedence(Plist p); Term read_commands_from_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action); void read_commands(int argc, char **argv, FILE *fout, BOOL echo, int unknown_action); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/save/btu.c0000644000175000017500000010456210140053062014633 0ustar mccunemccune#include "btu.h" /* Private definitions and types */ #define MAX_ACU_ARGS 500 typedef struct ac_position * Ac_position; struct ac_position { int m, n, num_basis; /* # of coefficients and size of basis */ int basis[MAX_BASIS][MAX_COEF]; int constraints[MAX_COEF]; /* 0 for vars, else symbol number */ Term args[MAX_COEF]; Context arg_contexts[MAX_COEF]; Term new_terms[MAX_COEF]; /* substitution terms */ int combo[MAX_BASIS]; /* current subset of basis solutions */ int sum[MAX_COEF]; /* solution corresponding to combo */ Term basis_terms[MAX_BASIS][MAX_COEF]; Context c3; /* table for new variables */ Btu_state sub_position; /* position in sub-unification problem */ int superset_limit; /* for superset-restricted AC unif. */ int combos[MAX_COMBOS][MAX_BASIS];/* for superset-restricted AC unif. */ int combos_remaining; /* for superset-restricted AC unif. */ Ac_position next; /* for avail list only */ }; struct btu_state { Btu_state parent, next, prev, first_child, last_child; Term t1, t2; /* terms being unified or matched */ Context c1, c2; /* respective contexts for variables */ int varnum; /* for unbinding when backtracking */ Context cb; /* for unbinding when backtracking */ Unif_alternative alternative; /* type of alternative (position) */ /* for commutative unification */ int flipped; Btu_state position_bt; /* in sequence of alternatives */ /* for AC unification */ Ac_position ac; /* in sequence of AC unifiers */ }; /* #define DEBUG */ #define GO 1 #define SUCCESS 2 #define EXHAUSTED 4 #define FAILURE 3 #define POP 5 #define BACKTRACK 6 /******** bind a variable, record binding in a bt_node ********/ #define BIND_BT(i, c1, t2, c2, bt) { \ c1->terms[i] = t2; c1->contexts[i] = c2; \ bt->varnum = i; bt->cb = c1; } /* reference for mutual recursion */ static Btu_state unify_bt_guts(Btu_state bt1); /* * memory management */ static unsigned Btu_state_gets, Btu_state_frees; static unsigned Ac_position_gets, Ac_position_frees; #define BYTES_BTU_STATE sizeof(struct btu_state) #define PTRS_BTU_STATE BYTES_BTU_STATE%BPP == 0 ? BYTES_BTU_STATE/BPP : BYTES_BTU_STATE/BPP + 1 #define BYTES_AC_POSITION sizeof(struct ac_position) #define PTRS_AC_POSITION BYTES_AC_POSITION%BPP == 0 ? BYTES_AC_POSITION/BPP : BYTES_AC_POSITION/BPP + 1 /************* * * Btu_state get_btu_state() * *************/ static Btu_state get_btu_state(void) { Btu_state p = get_mem(PTRS_BTU_STATE); p->varnum = -1; Btu_state_gets++; return(p); } /* get_btu_state */ /************* * * free_btu_state() * *************/ static void free_btu_state(Btu_state p) { free_mem(p, PTRS_BTU_STATE); Btu_state_frees++; } /* free_btu_state */ /************* * * Ac_position get_ac_position() * *************/ static Ac_position get_ac_position(void) { Ac_position p = get_mem(PTRS_AC_POSITION); Ac_position_gets++; return(p); } /* get_ac_position */ /************* * * free_ac_position() * *************/ static void free_ac_position(Ac_position p) { free_mem(p, PTRS_AC_POSITION); Ac_position_frees++; } /* free_ac_position */ /************* * * fprint_btu_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the btu package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_btu_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_BTU_STATE; fprintf(fp, "btu_state (%4d) %11u%11u%11u%9.1f K\n", n, Btu_state_gets, Btu_state_frees, Btu_state_gets - Btu_state_frees, ((Btu_state_gets - Btu_state_frees) * n) / 1024.); n = BYTES_AC_POSITION; fprintf(fp, "ac_position (%4d)%11u%11u%11u%9.1f K\n", n, Ac_position_gets, Ac_position_frees, Ac_position_gets - Ac_position_frees, ((Ac_position_gets - Ac_position_frees) * n) / 1024.); } /* fprint_btu_mem */ /************* * * p_btu_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the btu package. */ /* PUBLIC */ void p_btu_mem() { fprint_btu_mem(stdout, TRUE); } /* p_btu_mem */ /* * end of memory management */ /************* * * p_binding() * *************/ #if 0 static void p_binding(int vnum, Context vc, Term t, Context tc) { Term vt, ti; vt = get_variable_term(vnum); ti = apply(vt, vc); printf("["); fprint_term(stdout,vt); printf(",0x%x:%d] -> [", (unsigned) vc, vc->multiplier); fprint_term(stdout,t); printf(",0x%x:%d] (", (unsigned) tc, tc->multiplier); fprint_term(stdout,ti); printf(")\n"); free_term(vt); free_term(ti); } /* p_binding */ #endif /************* * * flatten_deref * * Given a term (t) with AC symbol and a context (tc), fill in an * array (a) with the flattened arguments. Variable arguments are * dereferenced, and a second array (ac) is filled in with the * corresponding contexts. The given term is not changed. * The index (*ip) must be initialized by the calling routine. * * Note: the objects being manipulated are pairs , * where the context determines the values of the variables in the term. * If context is NULL, the variables are treated as constants. * *************/ static void flatten_deref(Term t, Context tc, Term *a, Context *ac, int *ip) { Term t1; Context c1; int sn, i; sn = SYMNUM(t); for (i = 0; i < t->arity; i++) { t1 = t->args[i]; c1 = tc; DEREFERENCE(t1, c1); if (SYMNUM(t1) == sn) flatten_deref(t1, c1, a, ac, ip); else { if (*ip >= MAX_ACU_ARGS) { p_term(t1); fatal_error("flatten_deref, too many arguments."); } else { a[*ip] = t1; ac[*ip] = c1; } (*ip)++; } } } /* flatten_deref(t) */ /************* * * compare_ncv_context -- compare terms, taking context into account. * * Compare terms. NAME < COPMLEX < VARIABLE. * Constants by symbol; complex lexicographically; vars by (context,varnum) * Ignore AC symbols. * * Return LESS_THAN, SAME_AS, or GREATER_THAN. * *************/ static int compare_ncv_context(Term t1, Term t2, Context c1, Context c2) { int rc, m1, m2; if (CONSTANT(t1) && !CONSTANT(t2)) rc = LESS_THAN; else if (!CONSTANT(t1) && CONSTANT(t2)) rc = GREATER_THAN; else if (COMPLEX(t1) && VARIABLE(t2)) rc = LESS_THAN; else if (VARIABLE(t1) && COMPLEX(t2)) rc = GREATER_THAN; /* Now we know they are the same type. */ else if VARIABLE(t1) { /* both variables */ m1 = (c1 ? c1->multiplier : INT_MIN); m2 = (c2 ? c2->multiplier : INT_MIN); if (m1 < m2) rc = LESS_THAN; else if (m1 > m2) rc = GREATER_THAN; else if (VARNUM(t1) < VARNUM(t2)) rc = LESS_THAN; else if (VARNUM(t1) > VARNUM(t2)) rc = GREATER_THAN; else rc = SAME_AS; } else { if (SYMNUM(t1) < SYMNUM(t2)) rc = LESS_THAN; else if (SYMNUM(t1) > SYMNUM(t2)) rc = GREATER_THAN; else { int i; for (i = 0, rc = SAME_AS; i < t1->arity && rc == SAME_AS; i++) rc = compare_ncv_context(t1->args[i], t2->args[i], c1, c2); } } return(rc); } /* compare_ncv_context */ /************* * * sort_ac(a, c, n) * * Sort an array of terms and their associated contexts. * I intend for the number of terms to be small, so this is * a quadratic sort. * *************/ static void sort_ac(Term *a, Context *c, int n) { int i, j, min_i; Term min_t; Context min_c; for (i = 0; i < n-1; i++) { min_t = a[i]; min_c = c[i]; min_i = i; for (j = i+1; j < n; j++) { if (compare_ncv_context(a[j], min_t, c[j], min_c) == LESS_THAN) { min_t = a[j]; min_c = c[j]; min_i = j; } } if (min_i != i) { a[min_i] = a[i]; a[i] = min_t; c[min_i] = c[i]; c[i] = min_c; } } } /* sort_ac */ /************* * * void elim_con_context * * Eliminate common terms, taking context into account. * Eliminated terms are just set to NULL. * *************/ static void elim_con_context(Term *a1, Term *a2, Context *c1, Context *c2, int n1, int n2) { int i1, i2, rc; i1 = i2 = 0; while (i1 < n1 && i2 < n2) { rc = compare_ncv_context(a1[i1], a2[i2], c1[i1], c2[i2]); if (rc == SAME_AS) { a1[i1] = NULL; c1[i1] = NULL; i1++; a2[i2] = NULL; c2[i2] = NULL; i2++; } else if (rc == LESS_THAN) i1++; else i2++; } } /* elim_con_context */ /************* * * void ac_mult_context * * With an array of terms, eliminate NULL positions, and collapse * duplicates into one, building a corresponding array of multiplicities. * *************/ static void ac_mult_context(Term *a, Context *c, int *mults, int *np) { int it, im, i, m, j, n; n = *np; im = 0; it = 0; while (it < n) { if (!a[it]) it++; else { i = it+1; m = 1; while (i < n && a[i] && compare_ncv_context(a[it], a[i], c[it], c[i]) == SAME_AS) { a[i] = NULL; c[i] = NULL; m++; i++; } mults[im++] = m; it = i; } } for (i = n-1; i >= 0; i--) { if (!a[i]) { for (j = i; j < n-1; j++) { a[j] = a[j+1]; c[j] = c[j+1]; } n--; } } if (n != im) { fatal_error("in ac_mult_context, n!=im."); } *np = n; } /* ac_mult_context */ /************* * * ac_prepare * * Final preparation for diophantine solver. Fill in the arrays: * * ab - coefficients for both terms * constraints - 0 for variable with context * -(varnum+1) for variable w/o context (unbindable) * else symbol number * terms the arguments * contexts contexts for arguments * *************/ static void ac_prepare(Term *a1, Term *a2, Context *c1, Context *c2, int *mults1, int *mults2, int n1, int n2, int *ab, int *constraints, Term *terms, Context *contexts) { int i; if (n1+n2 > MAX_COEF) { fatal_error("ac_prepare, too many arguments."); } for (i = 0; i < n1; i++) { ab[i] = mults1[i]; if (VARIABLE(a1[i])) constraints[i] = (c1[i] ? 0 : (-VARNUM(a1[i])) - 1); else constraints[i] = SYMNUM(a1[i]); terms[i] = a1[i]; contexts[i] = c1[i]; } for (i = 0; i < n2; i++) { ab[i+n1] = mults2[i]; if (VARIABLE(a2[i])) constraints[i+n1] = (c2[i] ? 0 : (-VARNUM(a2[i])) - 1); else constraints[i+n1] = SYMNUM(a2[i]); terms[i+n1] = a2[i]; contexts[i+n1] = c2[i]; } } /* ac_prepare */ /************* * * set_up_basis_terms * * Given the basis solutions, fill in a corresponding array of * partial terms to be used for building substitutions. * This is done once for the basis, to avoid rebuilding the terms * for each subset. * * NOTE: the terms are not well-formed. Each has form f(ti,NULL), * so that it's quick to make, e.g., f(t1,f(t2,f(t3,t4))). * *************/ static void set_up_basis_terms(int sn, int (*basis)[MAX_COEF], int num_basis, int length, Term (*basis_terms)[MAX_COEF]) { Term t1, t2, t3; int i, j, k; for (i = 0; i < num_basis; i++) for (j = 0; j < length; j++) { if (basis[i][j] == 0) basis_terms[i][j] = NULL; else { t1 = get_variable_term(i); for (k = 2; k <= basis[i][j]; k++) { t2 = get_variable_term(i); t3 = get_rigid_term_dangerously(sn, 2); t3->args[0] = t2; t3->args[1] = t1; t1 = t3; } t2 = get_rigid_term_dangerously(sn, 2); t2->args[0] = t1; t2->args[1] = NULL; basis_terms[i][j] = t2; } } } /* set_up_basis_terms */ /************* * * unify_ac * * Associative-commutative Unification. t1 and t2 have the same ac symbol. * (t1, c1, t2, c2, are dereferenced terms from bt.) * * If c1 and c2 are different they must have different multipliers!!! * *************/ /* DOCUMENTATION This routine gets the first or next AC unifier for a pair of terms. This is mutually recursive with unify_bt_guts() and unify_bt_next() for sub-unification problems. The top calls are made to the backtrack unification routines unify_bt_first(), and unify_bt_next(). */ static int unify_ac(Term t1, Context c1, Term t2, Context c2, struct btu_state *bt) { Term t3, t4, ti; Btu_state sub_problems, bt2, bt3; Ac_position ac; Term a1[MAX_ACU_ARGS], a2[MAX_ACU_ARGS]; Context ac1[MAX_ACU_ARGS], ac2[MAX_ACU_ARGS], ci; int mults1[MAX_ACU_ARGS], mults2[MAX_ACU_ARGS]; int ab[MAX_COEF], num_basis, n1, n2; int i, j, length, vn, ok, status; Unif_alternative continuation; num_basis = length = 0; /* to quiet compiler */ continuation = bt->alternative; if (continuation == NO_ALT) { /* If first call, set up dioph eq and solve. */ /* Stats[AC_INITIATIONS]++; */ bt->alternative = AC_ALT; ac = get_ac_position(); bt->ac = ac; ac->c3 = get_context(); ac->superset_limit = -1; /* Parms[AC_SUPERSET_LIMIT].val; */ #ifdef DEBUG printf("\nunify_ac, new problem:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); #endif n1 = 0; flatten_deref(t1,c1,a1,ac1,&n1); /* put args in a1, incl. deref */ sort_ac(a1, ac1, n1); /* sort args */ n2 = 0; flatten_deref(t2,c2,a2,ac2,&n2); sort_ac(a2, ac2, n2); elim_con_context(a1, a2, ac1, ac2, n1, n2); /* elim. common terms */ ac_mult_context(a1, ac1, mults1, &n1); /* get multiplicity */ ac_mult_context(a2, ac2, mults2, &n2); if (n1 == 0 && n2 == 0) { /* Input terms are identical modulo AC. */ /* Succeed with no alternatives. */ free_context(ac->c3); free_ac_position(bt->ac); bt->ac = NULL; bt->alternative = NO_ALT; status = SUCCESS; } else { ac_prepare(a1, a2, ac1, ac2, mults1, mults2, n1, n2, ab, ac->constraints, ac->args, ac->arg_contexts); ok = dio(ab,n1,n2,ac->constraints,ac->basis,&(ac->num_basis)); num_basis = ac->num_basis; length = n1 + n2; if (ok == 1 && num_basis > 0) { /* if solutions, store data in ac_position */ ac->m = n1; ac->n = n2; /* prepare for combination search */ set_up_basis_terms(SYMNUM(t1), ac->basis, num_basis, n1+n2, ac->basis_terms); status = GO; } else { status = FAILURE; if (ok == -1) { printf("basis too big for %d %d.\n", n1, n2); #if 0 fprint_term(stdout, t1); printf(" "); fprint_term(stdout, t2); printf("\n"); p_ac_basis(ac->basis, ac->num_basis, n1, n2); /* print out args2 */ for (i = 0; i < n2; i++) fprint_term(stdout, a2[i]); exit(34); #endif } } } } else { /* continuation */ /* Stats[AC_CONTINUATIONS]++; */ ac = bt->ac; #ifdef DEBUG printf("\nunify_ac, continuation:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); #endif if (ac->sub_position) { /* if subproblems pending */ ac->sub_position = unify_bt_next(ac->sub_position); status = (ac->sub_position ? SUCCESS : GO); } else status = GO; num_basis = ac->num_basis; length = ac->m + ac->n; } while (status == GO) { if (continuation) { /* Undo bindings from previous combination. */ for (i = length-1; i >= 0; i--) { ti = ac->args[i]; ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ti); #ifdef DEBUG printf("<-<-<- clearing (ci) "); fflush(stdout); p_binding(vn, ci, ci->terms[vn], ci->contexts[vn]); #endif ci->terms[vn] = NULL; ci->contexts[vn] = NULL; } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { #ifdef DEBUG printf("<-<-<- clearing (c3)"); fprint_term(stdout, ac->new_terms[i]); p_binding(SYMNUM(ac->new_terms[i]), ac->c3, ac->c3->terms[VARNUM(ac->new_terms[i])], ac->c3->contexts[VARNUM(ac->new_terms[i])]); #endif ac->c3->terms[VARNUM(ac->new_terms[i])] = NULL; ac->c3->contexts[VARNUM(ac->new_terms[i])] = NULL; } } } /* Get first or next relevant subset of the basis solutions. * A parameter limits the number of combinations (and makes AC * unification incomplete). -1 means that there is no limit. * 0 means that no supsersets are allowed, 1 means that supersets * with one additional element are allowed, etc.. Also, if there * is a limit, then at most MAX_COMBOS combinations will be returned. */ if (ac->superset_limit < 0) ok = next_combo_a(length, ac->basis, num_basis, ac->constraints, ac->combo, ac->sum, !continuation); else ok = next_combo_ss(length, ac->basis, num_basis, ac->constraints, ac->combo, ac->sum, !continuation, ac->combos, &(ac->combos_remaining), ac->superset_limit); #ifdef DEBUG printf(" ----Combination? %s\n", ok ? "YES" : "NO"); #endif if (ok) { /* We now have a potential unifier. It's not guaranteed, * because it may have subterms to be unified. */ sub_problems = bt3 = NULL; /* A variable is associated with each row of the basis. * ac->combo is the current subst of the rows. * * Loop through columns, building a term (t4) for each. */ for (i = 0; i < length; i++) { t4 = NULL; /* Loop through rows, building t4. */ for (j = 0; j < num_basis; j++) { if (ac->combo[j]) { t3 = ac->basis_terms[j][i]; if (t3) { if (!t4) t4 = t3->args[0]; else { t3->args[1] = t4; t4 = t3; } } } } ac->new_terms[i] = t4; #ifdef DEBUG printf(" ---- arg %d goes with ", i); p_term(t4); #endif /* t4 must now be unified with args[i]. * switch args[i] * variable: just bind it. * constant: bind t4 (which is a variable in this case). * complex: add t4=args[i] to the set of subproblems. */ ti = ac->args[i]; ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ti); ci->terms[vn] = t4; ci->contexts[vn] = ac->c3; #ifdef DEBUG printf("->->->-> binding (ci) "); p_binding(vn, ci, t4, ac->c3); #endif } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { ac->c3->terms[VARNUM(t4)] = ti; ac->c3->contexts[VARNUM(t4)] = ci; #ifdef DEBUG printf("->->->-> binding (c3)"); p_binding(VARNUM(t4), ac->c3, ti, ci); #endif } else { bt2 = get_btu_state(); bt2->prev = bt3; if (bt3) bt3->next = bt2; else sub_problems = bt2; bt2->t1 = t4; bt2->c1 = ac->c3; bt2->t2 = ti; bt2->c2 = ci; bt3 = bt2; #ifdef DEBUG printf("->->->-> subproblem ["); fprint_term(stdout,t4); printf(",0x%x:%d] :: [", (unsigned) ac->c3, ac->c3->multiplier); fprint_term(stdout,ti); printf(",0x%x:%d]\n", (unsigned) ci, ci->multiplier); #endif } } /* for each arg */ if (sub_problems) { ac->sub_position = unify_bt_guts(sub_problems); if (ac->sub_position) status = SUCCESS; else { #ifdef DEBUG printf(" subproblems failed; continuing\n"); #endif continuation = 1; status = GO; } } else { ac->sub_position = NULL; status = SUCCESS; } } /* if (ok) */ else /* There are no more combinations, so stop. */ status = EXHAUSTED; } /* while (STATUS == go) */ if (status == SUCCESS) { #ifdef DEBUG printf("\nunify_ac, success:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); { Term s1, s2; s1 = apply(t1, c1); s2 = apply(t2, c2); printf(" t1 instance: "); fprint_term_nl(stdout, s1); printf(" t2 instance: "); fprint_term_nl(stdout, s2); zap_term(s1); zap_term(s2); } #endif return(1); } else { /* Free memory, clean up, and fail. */ #ifdef DEBUG printf("\nunify_ac, %s:\n", status == EXHAUSTED ? "finished" : "fail"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x]\n", (unsigned) ac->c3); #endif if (status == EXHAUSTED) { /* Delete all terms in basis_terms. */ for (i = 0; i < num_basis; i++) for (j = 0; j < length; j++) if (ac->basis_terms[i][j]) { t2 = ac->basis_terms[i][j]; zap_term(t2->args[0]); free_term(t2); } } free_context(ac->c3); free_ac_position(bt->ac); bt->ac = NULL; bt->alternative = NO_ALT; return(0); } } /* unify_ac */ /************* * * unify_ac_cancel * *************/ /* DOCUMENTATION This routine should be called if the rest of a sequence of AC unifiers is not called for. It clears substitutions as well frees memory. */ static void unify_ac_cancel(Ac_position ac) { int i, j, length, vn; Context ci; Term t2, ti; Btu_state bt; length = ac->m + ac->n; /* Undo bindings from previous combination. */ for (i = 0; i < length; i++) { ti = ac->args[i]; ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ac->args[i]); ci->terms[vn] = NULL; ci->contexts[vn] = NULL; } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { ac->c3->terms[VARNUM(ac->new_terms[i])] = NULL; ac->c3->contexts[VARNUM(ac->new_terms[i])] = NULL; } } /* Delete all terms in basis_terms. */ for (i = 0; i < ac->num_basis; i++) for (j = 0; j < length; j++) if (ac->basis_terms[i][j]) { t2 = ac->basis_terms[i][j]; zap_term(t2->args[0]); free_term(t2); } if (ac->sub_position) { /* unity_bt leaves you at the end of the list, so get to the start. */ for (bt = ac->sub_position; bt->prev; bt = bt->prev); unify_bt_cancel(bt); } free_context(ac->c3); free_ac_position(ac); } /* unify_ac_cancel */ /************* * * p_ac_position() - print ac_position * *************/ /* DOCUMENTATION This routine prints (to stdout) some of the data in an Ac_position. */ static void p_ac_position(Ac_position ac, int n) { if (!ac) printf("\nac_position is NULL.\n"); else { printf("\nac_position, context c3:\n"); p_context(ac->c3); printf("\nSub problems:\n"); if (!ac->sub_position) printf("none.\n"); else { Btu_state bt; /* Get to the beginning of the list of subproblems. */ for (bt = ac->sub_position; bt->prev; bt = bt->prev); for (; bt; bt = bt->next) p_bt_tree(bt, n); } printf("end of ac_position, context c3:\n"); } } /* p_ac_position */ /************* * * Btu_state unify_bt_backup(bt) * * Back up (freeing nodes) to the most recent node with an alternative. * *************/ static Btu_state unify_bt_backup(Btu_state bt1) { Btu_state bt2, bt3; while (bt1 != NULL && bt1->alternative == NO_ALT) { if (bt1->cb) { /* unbind variable */ #ifdef DEBUG printf("CLEAR: v%d, c%d\n", bt1->varnum, bt1->cb->multiplier); fflush(stdout); #endif bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; bt1->cb = NULL; } if (bt1->prev) { bt1 = bt1->prev; while (bt1->last_child) bt1 = bt1->last_child; } else { bt2 = bt1; bt1 = bt1->parent; while (bt2) { bt3 = bt2; bt2 = bt2->next; free_btu_state(bt3); } if (bt1) bt1->first_child = bt1->last_child = NULL; } } return(bt1); } /* unify_bt_backup */ /************* * * unify_commute() * * Commutative unification. t1 and t2 have the same commutative symbol. * t1, c1, t2, c2, are dereferenced terms from bt. * * This simply tries to unify both ways. * We can get redundant unifiers if both ways unify, for example, * f(a,x) and f(a,a) unify twice, both times with the same substitution. * *************/ static int unify_commute(Term t1, Context c1, Term t2, Context c2, Btu_state bt) { Btu_state bt1, bt2; if (bt->alternative == NO_ALT) { /* first call */ bt->alternative = COMM_ALT; bt->flipped = 0; /* Set up 2 subproblems, then unify guts. */ bt1 = get_btu_state(); bt2 = get_btu_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt1->c2 = c2; bt2->c1 = c1; bt2->c2 = c2; bt1->t1=t1->args[0]; bt1->t2=t2->args[0]; bt2->t1=t1->args[1]; bt2->t2=t2->args[1]; bt->position_bt = unify_bt_guts(bt1); } else /* continuation */ bt->position_bt = unify_bt_next(bt->position_bt); if (!bt->position_bt && !bt->flipped) { /* Set up 2 subproblems, with t2 flipped, then unify guts. */ bt1 = get_btu_state(); bt2 = get_btu_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt1->c2 = c2; bt2->c1 = c1; bt2->c2 = c2; bt1->t1=t1->args[0]; bt1->t2=t2->args[1]; bt2->t1=t1->args[1]; bt2->t2=t2->args[0]; bt->flipped = 1; bt->position_bt = unify_bt_guts(bt1); } if (bt->position_bt) return(1); else { bt->alternative = NO_ALT; return(0); } } /* unify_commute */ /************* * * unify_bt_first * * This is backtracking unification, to be used when there * can be more than one unifier. This version handles (any number of) * commutative and associative-commutative function symbols. * * Get first unifier. Return position for unify_bt_next calls. * This procedure can also be used for matching, because a NULL * context causes the corresponding term to be treated as ground. * * Here is an example of its use: * * c1 = get_context(); * c2 = get_context(); * bt = unify_bt_first(t1, c1, t2, c2); * while (bt) { * t3 = apply(t1, c1); * t4 = apply(t2, c2); * zap_term(t3); * zap_term(t4); * bt = unify_bt_next(bt); * } * free_context(c1); * free_context(c2); * *************/ /* DOCUMENTATION This routine gets the first unifier for a pair of terms and returns a Btu_state (or NULL if there are no unifiers) to be used for calls to unify_bt_next() to get the rest of the unifiers. This unification handles associative-commutative (AC) and commutative (C) symbols, so there can be more than one unifier. (Commutatvie unification is primitive, and you can get duplicate unifiers.)

This is called "backtrack unification", because the unifiers are constructed incrementally, as needed. Here is an example of how to do it. Assume we have Terms t1 and t2.

  {
    Context c1 = get_context();
    Context c2 = get_context();
    bt = unify_bt_first(t1, c1, t2, c2);
    while (bt != NULL) {
      t3 = apply(t1, c1);
      t4 = apply(t2, c2);
      
      zap_term(t4);
      bt = unify_bt_next(bt);
      }
    free_context(c1);
    free_context(c2);
  }
The routine unify_bt_next() takes care of clearing the substitutions before getting the next unifier. If you decide not to get all of the unifiers, you should call unify_bt_cancel() to free the memory used by the Btu_state.

If there are no AC or C symbols, it is a little bit faster to use unify() (ordinary unification) instead of backtrack unification. */ /* PUBLIC */ Btu_state unify_bt_first(Term t1, Context c1, Term t2, Context c2) { Btu_state bt = get_btu_state(); bt->t1 = t1; bt->t2 = t2; bt->c1 = c1; bt->c2 = c2; /* p_term(t1); p_term(t2); printf("\n"); */ return(unify_bt_guts(bt)); } /* unify_bt */ /************* * * unify_bt_next * * Get next unifier. Return position for subsequent calls. * *************/ /* DOCUMENTATION This routine gets the next unifier for "backtrack unification". See unify_bt_first() for an explanation. */ /* PUBLIC */ Btu_state unify_bt_next(Btu_state bt1) { /* Go to last node in tree, then back up to a node with an alternative. */ while (bt1->next != NULL) bt1 = bt1->next; while (bt1->last_child != NULL) bt1 = bt1->last_child; bt1 = unify_bt_backup(bt1); if (bt1 != NULL) return(unify_bt_guts(bt1)); else return(NULL); } /* unify_bt_next */ /************* * * unify_bt_cancel * * This routine should be called if the rest of a sequence of * unifiers is not called for. It clears substitutions as well * frees memory. * *************/ /* DOCUMENTATION This routine frees the memory associated with a state in backtrack unification. This should be called if you decide to get some, but not all, unifiers from unify_bt_first() and unify_bt_next(). */ /* PUBLIC */ void unify_bt_cancel(Btu_state bt) { Btu_state bt1, bt2; for (bt1 = bt; bt1 != NULL; ) { unify_bt_cancel(bt1->first_child); if (bt1->alternative == COMM_ALT) unify_bt_cancel(bt1->position_bt); else if (bt1->alternative == AC_ALT) { unify_ac_cancel(bt1->ac); } else if (bt1->cb != NULL) { bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } bt2 = bt1; bt1 = bt1->next; free_btu_state(bt2); } } /* unify_bt_cancel */ /************* * * unify_bt_guts * * Main loop for backtracking unification. * *************/ /* DOCUMENTATION This routine (mutually recursive with unify_ac()), does the important work of backtrack unification. It is called bt unify_bt_first() and unify_bt_next(). */ static Btu_state unify_bt_guts(Btu_state bt1) { Term t1, t2; Context c1, c2; int vn1, vn2, status; Btu_state bt2, bt3; status = GO; while (status == GO) { t1 = bt1->t1; t2 = bt1->t2; c1 = bt1->c1; c2 = bt1->c2; DEREFERENCE(t1, c1) DEREFERENCE(t2, c2) #ifdef DEBUG printf("guts loop (derefed) "); fprint_term(stdout, t1); printf(" %d ", c1 ? c1->multiplier : -2); fprint_term(stdout, t2); printf(" %d \n", c2 ? c2->multiplier : -2); #endif if (bt1->alternative == COMM_ALT) { if (unify_commute(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (bt1->alternative == AC_ALT) { if (unify_ac(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (c1 && VARIABLE(t1)) { vn1 = VARNUM(t1); if (VARIABLE(t2)) { if (vn1 == VARNUM(t2) && c1 == c2) status = POP; else { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn1, c1->multiplier); fflush(stdout); #endif BIND_BT(vn1, c1, t2, c2, bt1) status = POP; } } else { /* t1 variable, t2 not variable */ /* Stats[BT_OCCUR_CHECKS]++; */ if (occur_check(vn1, c1, t2, c2)) { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn1, c1->multiplier); fflush(stdout); #endif BIND_BT(vn1, c1, t2, c2, bt1) status = POP; } else status = BACKTRACK; } } else if (c2 && VARIABLE(t2)) { /* t2 variable, t1 not variable */ vn2 = VARNUM(t2); /* Stats[BT_OCCUR_CHECKS]++; */ if (occur_check(vn2, c2, t1, c1)) { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn2, c2->multiplier); fflush(stdout); #endif BIND_BT(vn2, c2, t1, c1, bt1) status = POP; } else status = BACKTRACK; } else if (SYMNUM(t1) != SYMNUM(t2)) status = BACKTRACK; else if (CONSTANT(t1)) status = POP; else { /* both COMPLEX with same symbol (and same arity) */ if (is_commutative(SYMNUM(t1))) { if (unify_commute(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (is_assoc_comm(SYMNUM(t1))) { if (unify_ac(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else { /* Set up children corresponding to args of . * Order not important for correctness. * AC kids last for efficiency, but keep in order otherwise. */ int i; bt3 = NULL; for (i = 0; i < t1->arity; i++) { bt2 = get_btu_state(); bt2->t1 = t1->args[i]; bt2->t2 = t2->args[i]; bt2->c1 = c1; bt2->c2 = c2; bt2->parent = bt1; if (is_assoc_comm(SYMNUM(t1->args[i]))) { /* insert at end */ bt2->prev = bt1->last_child; if (bt1->last_child) bt1->last_child->next = bt2; else bt1->first_child = bt2; bt1->last_child = bt2; } else { if (bt3) { /* insert after bt3 */ bt2->next = bt3->next; bt2->prev = bt3; bt3->next = bt2; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; } else { /* insert at beginning */ bt2->next = bt1->first_child; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; bt1->first_child = bt2; } bt3 = bt2; } } bt1 = bt1->first_child; status = GO; } } if (status == POP) { while (!bt1->next && bt1->parent) bt1 = bt1->parent; if (!bt1->next) status = SUCCESS; else { bt1 = bt1->next; status = GO; } } else if (status == BACKTRACK) { bt1 = unify_bt_backup(bt1); if (bt1) status = GO; else status = FAILURE; } } return(bt1); } /* unify_bt_guts */ /************* * * p_bt_tree -- print a bt tree (This could be improved!) * *************/ /* DOCUMENTATION This (recursive) routine prints (to stdout) a backtrack unification state. Parameter n should be 0 on the top call. */ /* PUBLIC */ void p_bt_tree(Btu_state bt, int n) { int i; Btu_state curr, prev; if (bt == NULL) printf("bt tree NULL.\n"); else { printf("\n" ); for (i = 0; i < n%100; i++) printf("----"); printf(" bt_tree: %d\n", n); fprint_term(stdout, bt->t1); printf(" [ 0x%x ]\n", (unsigned) bt->c1); fprint_term(stdout, bt->t2); printf(" [ 0x%x ]\n", (unsigned) bt->c2); p_context(bt->c1); p_context(bt->c2); if (bt->alternative == AC_ALT) { p_ac_position(bt->ac, n+100); } prev = NULL; for (curr = bt->first_child; curr; curr = curr->next) { if (curr->parent != bt) printf("parent error\n"); if (curr->prev != prev) printf("prev error\n"); p_bt_tree(curr, n+1); prev = curr; } if (bt->last_child != prev) printf("last error\n"); printf(" end of bt_tree: %d\n", n); } } /* p_bt_tree */ LADR-2009-11A/ladr/save/goals_to_denials0000644000175000017500000000204310357562332017134 0ustar mccunemccune/************* * * goals_to_denials() * *************/ /* DOCUMENTATION This takes a list of clauses and a list of formulas. The clauses are converted to universally quantified formulas. Then everything is conjoined, negated, and clausified.

In this scheme, if there are multiple goals, a proof will be produced only if all goals are proved. */ /* PUBLIC */ Plist goals_to_denials(Plist clauses, Plist formulas) { Plist p1, p2; Formula f1, f2, f; Plist p; // do clauses p1 = NULL; for (p = clauses; p; p = p->next) { Clause c = p->v; Formula f = clause_to_formula(c); // deep f = universal_closure(f); p1 = plist_append(p1, f); } f1 = formulas_to_conjunction(p1); // shallow zap_plist(p1); // shallow // do formulas p2 = copy_plist_of_formulas(formulas); // deep f2 = formulas_to_conjunction(p2); // shallow zap_plist(p2); // shallow // conjoin, negate, clausify f = and(f1,f2); f = negate(f); p = clausify_formula(f); // deep zap_formula(f); return p; } /* goals_to_denials */ LADR-2009-11A/ladr/save/unify.c0000644000175000017500000004034410140052243015170 0ustar mccunemccune#include "unify.h" /* Private definitions and types */ /* A Trail records substitutions so that they can be easily undone. * Whenever a variable is instantiated (by making in entry in a * Context), one of these nodes is prepended to the current trail. */ struct trail { int varnum; /* index of instantiated variable */ Context context; /* context of instanteated variable */ Trail next; /* next (earlier) member of trail */ }; /* bind a variable, record binding in a trail */ #define BIND_TR(i, c1, t2, c2, trp) { struct trail *tr; \ c1->terms[i] = t2; c1->contexts[i] = c2; \ tr = get_trail(); tr->varnum = i; tr->context = c1; \ tr->next = *trp; *trp = tr; } #define MAX_MULTIPLIERS 500 /* Private variables */ static BOOL Multipliers[MAX_MULTIPLIERS]; /* (m[i]==FALSE) => i is available */ /************* * * next_available_multiplier() * *************/ static int next_available_multiplier() { int i; for (i = 0; i < MAX_MULTIPLIERS; i++) if (!Multipliers[i]) { Multipliers[i] = TRUE; return i; } fatal_error("next_available_multiplier, none avaiable (infinite loop?)."); return -1; /* to quiet compiler */ } /* next_available_multiplier */ /* * memory management */ static unsigned Context_gets, Context_frees; static unsigned Trail_gets, Trail_frees; #define BYTES_CONTEXT sizeof(struct context) #define PTRS_CONTEXT BYTES_CONTEXT%BPP == 0 ? BYTES_CONTEXT/BPP : BYTES_CONTEXT/BPP + 1 #define BYTES_TRAIL sizeof(struct trail) #define PTRS_TRAIL BYTES_TRAIL%BPP == 0 ? BYTES_TRAIL/BPP : BYTES_TRAIL/BPP + 1 /************* * * Context get_context() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Context get_context(void) { Context p = get_mem(PTRS_CONTEXT); p->multiplier = next_available_multiplier(); Context_gets++; return(p); } /* get_context */ /************* * * free_context() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_context(Context p) { Multipliers[p->multiplier] = FALSE; free_mem(p, PTRS_CONTEXT); Context_frees++; } /* free_context */ /************* * * Trail get_trail() * *************/ static Trail get_trail(void) { Trail p = get_mem(PTRS_TRAIL); Trail_gets++; return(p); } /* get_trail */ /************* * * free_trail() * *************/ static void free_trail(Trail p) { free_mem(p, PTRS_TRAIL); Trail_frees++; } /* free_trail */ /************* * * fprint_unify_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the unify package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_unify_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_CONTEXT; fprintf(fp, "context (%4d) %11u%11u%11u%9.1f K\n", n, Context_gets, Context_frees, Context_gets - Context_frees, ((Context_gets - Context_frees) * n) / 1024.); n = BYTES_TRAIL; fprintf(fp, "trail (%4d) %11u%11u%11u%9.1f K\n", n, Trail_gets, Trail_frees, Trail_gets - Trail_frees, ((Trail_gets - Trail_frees) * n) / 1024.); } /* fprint_unify_mem */ /************* * * p_unify_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the unify package. */ /* PUBLIC */ void p_unify_mem() { fprint_unify_mem(stdout, 1); } /* p_unify_mem */ /* * end of memory management */ /************* * * unify() * *************/ /* DOCUMENTATION This routine tries to unify two terms in their respective contexts. Trail * trp is the address of a Trail. If successful, the trail is extended (at its front) with substitutions that were made, and trp is updated to point to the new beginning of the trail. If unify fails, the Contexts and the Trail * are not changed.

You must make sure, before calling unify(), that no variable v in t1 or t2 has VARNUM(v) >= MAXVARS. This is usually accomplished by calling a routine that renames variables.

Here is an example how to use unify(), apply(), and undo_subst(). Assume we have terms t1 and t2. (Terms t1 and t2 may share variables, but we "separate" the variables by using different contexts. That is, variable v1 in context c1 is different from variable v1 in context c2.)

    {
        Context c1 = get_context();
        Context c2 = get_context();
        Trail tr = NULL;
        if (unify(t1, c1, t2, c2, &tr)) {
            Term t3 = apply(t1, c1);
            Term t4 = apply(t2, c2);
            if (term_ident(t3, t4))
                printf("everything is OK\n");
            else
                printf("something is broken\n");
            undo_subst(tr);
            zap_term(t3);
            zap_term(t4);
        }
        else
            printf("unify fails\n");
        free_context(c1);
        free_context(c2);
    }
*/ /* PUBLIC */ BOOL unify(Term t1, Context c1, Term t2, Context c2, Trail *trp) { Trail tpos, tp, t3; int vn1, vn2; DEREFERENCE(t1, c1) /* dereference macro */ DEREFERENCE(t2, c2) /* dereference macro */ /* Now, neither t1 nor t2 is a bound variable. */ if (VARIABLE(t1)) { vn1 = VARNUM(t1); if (VARIABLE(t2)) { /* both t1 and t2 are variables */ if (vn1 == VARNUM(t2) && c1 == c2) return TRUE; /* identical */ else { BIND_TR(vn1, c1, t2, c2, trp) return TRUE; } } else { /* t1 variable, t2 not variable */ if (occur_check(vn1, c1, t2, c2)) { BIND_TR(vn1, c1, t2, c2, trp) return TRUE; } else return FALSE; /* failed occur_check */ } } else if (VARIABLE(t2)) { /* t2 variable, t1 not variable */ vn2 = VARNUM(t2); if (occur_check(vn2, c2, t1, c1)) { BIND_TR(vn2, c2, t1, c1, trp) return TRUE; } else return FALSE; /* failed occur_check */ } else if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else if (t1->arity == 0) return TRUE; else { /* both complex with same symbol */ int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = t1->arity; while (i < arity && unify(t1->args[i], c1, t2->args[i], c2, trp)) i++; if (i == arity) return TRUE; else { /* restore trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; tp->context->contexts[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } /* unify */ /************* * * int variant(t1, c1, t2, trail_address) * *************/ /* DOCUMENTATION This routine checks if Term t1 (in Context c1) and Term t2 (without a Context) are variants, that is, if each is an instance of the other. If successful, the unifying substitution is in Context c1. The calling sequence and the use of Contexts and Trails is the same as for unify(). */ /* PUBLIC */ BOOL variant(Term t1, Context c1, Term t2, Trail *trp) { /* If this gets used a lot, it should be recoded so that it won't * traverse the terms twice. */ BOOL ok; Trail tr = NULL; Context c2 = get_context(); if (match(t2, c2, t1, &tr)) { undo_subst(tr); ok = match(t1, c1, t2, trp); } else ok = 0; free_context(c2); return ok; } /* variant */ /************* * * int occur_check(varnum, var_context, term, term_context) * * Return 0 iff variable occurs in term under substitution * (including var==term). * *************/ /* DOCUMENTATION This function checks if a variable with index vn (in Context vc) occurs in Term t (in Context c), including the top case, where t is the variable in question. */ /* PUBLIC */ BOOL occur_check(int vn, Context vc, Term t, Context c) { if (!c) return TRUE; else if (VARIABLE(t)) { /* variable */ int tvn; tvn = VARNUM(t); if (tvn == vn && c == vc) return FALSE; /* fail occur_check here */ else if (c->terms[tvn] == NULL) return TRUE; /* uninstantiated variable */ else return occur_check(vn, vc, c->terms[tvn], c->contexts[tvn]); } else { /* constant or complex */ int i; for (i = 0; i < t->arity; i++) if (!occur_check(vn, vc, t->args[i], c)) return FALSE; return TRUE; } } /* occur_check */ /************* * * int match(t1, c1, t2, trail_address) -- one-way unification. * * Match returns 1 if t2 is an instance of {t1 in context c1}. * This is not a very general version, but it is useful for * demodulation and subsumption. It assumes that the variables * of t1 and t2 are separate, that none of the variables in t2 * have been instantiated, and that none of those t2's variables * will be instantiatied. Hence, there is no context for t2, * no need to dereference more than one level, and no need for * an occur_check. * * The use of the trail is the same as in `unify'. * *************/ /* DOCUMENTATION This routine checks if Term t2 (without a Context) is an instance of Term t1 (in Context c1). If successful, Context c1 and Trail * trp are updated. The calling sequence and the use of Contexts and Trails is similar to those for unify(). */ /* PUBLIC */ BOOL match(Term t1, Context c1, Term t2, Trail *trp) { int vn; if (VARIABLE(t1)) { vn = VARNUM(t1); if (c1->terms[vn] == NULL) { BIND_TR(vn, c1, t2, NULL, trp) return TRUE; } else return term_ident(c1->terms[vn], t2); } else if (VARIABLE(t2)) return FALSE; else { /* neither term is a variable */ if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else { Trail tpos, tp, t3; int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = t1->arity; while (i < arity && match(t1->args[i], c1, t2->args[i], trp)) i++; if (i == arity) return TRUE; else { /* restore from trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } } /* match */ /************* * * Term apply(term, context) -- Apply a substitution to a term. * * Apply always succeeds and returns a pointer to the * instantiated term. * *************/ /* DOCUMENTATION This routine applies the substitution in Context c to Term t. See the explanation of unify() for an example of the use of apply(). */ /* PUBLIC */ Term apply(Term t, Context c) { DEREFERENCE(t, c) /* A NULL context is ok. It happens when c is built by match. */ /* If the context is NULL, then apply just copies the term. */ if (VARIABLE(t)) { if (!c) return get_variable_term(VARNUM(t)); else return get_variable_term(c->multiplier * MAX_VARS + VARNUM(t)); } else { /* constant or complex term */ Term t2 = get_rigid_term_like(t); int i; for (i = 0; i < t->arity; i++) t2->args[i] = apply(t->args[i], c); return t2; } } /* apply */ /************* * * apply_substitute() * *************/ /* DOCUMENTATION This routine is like apply(), but when it reaches a particular subterm (into_term) of the source term (t), it continues with another source term (beta). This routine is intended to be used for paramodulation, to avoid unnecessary work. For example, when paramodulating alpha=beta into p[into_term], where alpha unifies with into_term, we construct the appropriate instance of p[beta] in one step by using this routine. */ /* PUBLIC */ Term apply_substitute(Term t, Term beta, Context c_from, Term into_term, Context c_into) { if (t == into_term) return apply(beta, c_from); else if (VARIABLE(t)) return apply(t, c_into); else { Term t2 = get_rigid_term_like(t); int i; for (i = 0; i < t->arity; i++) t2->args[i] = apply_substitute(t->args[i], beta, c_from, into_term, c_into); return t2; } } /* apply_substitute */ /************* * * undo_subst(trail_1) -- Clear a substitution. * *************/ /* DOCUMENTATION This routine clears substitution entries recoded in Trail tr, and frees the corresponding Trail nodes. */ /* PUBLIC */ void undo_subst(Trail tr) { Trail t3; while (tr != NULL) { tr->context->terms[tr->varnum] = NULL; tr->context->contexts[tr->varnum] = NULL; t3 = tr; tr = tr->next; free_trail(t3); } } /* undo_subst */ /************* * * undo_subst_2(trail_1, trail_2) -- Clear part of a substitution. * * It is assumed that trail_2 (possibly NULL) is a subtrail * of trail_1. This routine clears entries starting at trail_1, * up to (but not including) trail_2. * *************/ /* DOCUMENTATION It is assumed that Trail sub_tr is a subtrail of Trail tr. This routine clears part (maybe all) of a substitution, by clearing the entries from tr up to, but not including sub_tr. The corresponding Trail nodes are deallocated, so the caller should no longer refer to tr. (This is useful for inference rules like hyperresolution, which backtrack, undoing parts of substitutions.) */ /* PUBLIC */ void undo_subst_2(Trail tr, Trail sub_tr) { Trail t3; while (tr != sub_tr) { tr->context->terms[tr->varnum] = NULL; tr->context->contexts[tr->varnum] = NULL; t3 = tr; tr = tr->next; free_trail(t3); } } /* undo_subst_2 */ /************* * * fprint_context(file_ptr, context) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Context. */ /* PUBLIC */ void fprint_context(FILE *fp, Context c) { int i; if (c == NULL) fprintf(fp, "Substitution NULL.\n"); else { fprintf(fp, "Substitution, multiplier %d\n", c->multiplier); for (i=0; i< MAX_VARS; i++) { if (c->terms[i] != NULL) { Term t = get_variable_term(i); fprint_term(fp, t); free_term(t); fprintf(fp, " [0x%x] -> ", (unsigned) c); fprint_term(fp, c->terms[i]); if (c->contexts[i] == NULL) fprintf(fp, " (NULL context)\n"); else fprintf(fp, " [0x%x:%d]\n", (unsigned) c->contexts[i], c->contexts[i]->multiplier); } } #if 0 if (c->partial_term) { printf("partial_term: "); print_term(fp, c->partial_term); printf("\n"); } #endif } } /* fprint_context */ /************* * * p_context(context) * *************/ /* DOCUMENTATION This routine prints (to stdout) a Context. */ /* PUBLIC */ void p_context(Context c) { fprint_context(stdout, c); } /* p_context */ /************* * * fprint_trail(file_ptr, context) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Trail. The whole list is printed. */ /* PUBLIC */ void fprint_trail(FILE *fp, Trail t) { Trail t2; fprintf(fp, "Trail:"); t2 = t; while (t2 != NULL) { fprintf(fp, " <%d,%x>", t2->varnum, (unsigned) t2->context); t2 = t2->next; } fprintf(fp, ".\n"); } /* fprint_trail */ /************* * * p_trail(context) * *************/ /* DOCUMENTATION This routine prints (to stdout) a Trail. The whole list is printed. */ /* PUBLIC */ void p_trail(Trail t) { fprint_trail(stdout, t); } /* p_trail */ /************* * * match_weight2() * *************/ /* DOCUMENTATION Special-purpose match for weighting. */ /* PUBLIC */ BOOL match_weight2(Term t1, Context c1, Term t2, Trail *trp, int var_sn) { if (SYMNUM(t1) == var_sn) { return VARIABLE(t2); } else if (VARIABLE(t1)) { int vn = VARNUM(t1); if (c1->terms[vn] == NULL) { BIND_TR(vn, c1, t2, NULL, trp) return TRUE; } else return term_ident(c1->terms[vn], t2); } else if (VARIABLE(t2)) return FALSE; else { /* neither term is a variable */ if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else { Trail tpos, tp, t3; int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = t1->arity; while (i < arity && match_weight2(t1->args[i], c1, t2->args[i], trp, var_sn)) i++; if (i == arity) return TRUE; else { /* restore from trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } } /* match_weight2 */ LADR-2009-11A/ladr/save/hash.c0000644000175000017500000001171010140052347014761 0ustar mccunemccune#include "hash.h" /* Private definitions and types */ struct hashtab { int size; Hashnode *table; Hashtab next; /* for avail list only */ }; struct hashnode { int id; void *v; Hashnode next; }; static unsigned Hashtab_gets, Hashtab_frees; static unsigned Hashnode_gets, Hashnode_frees; #define BYTES_HASHTAB sizeof(struct hashtab) #define PTRS_HASHTAB BYTES_HASHTAB%BPP == 0 ? BYTES_HASHTAB/BPP : BYTES_HASHTAB/BPP + 1 #define BYTES_HASHNODE sizeof(struct hashnode) #define PTRS_HASHNODE BYTES_HASHNODE%BPP == 0 ? BYTES_HASHNODE/BPP : BYTES_HASHNODE/BPP + 1 /************* * * Hashtab get_hashtab() * *************/ static Hashtab get_hashtab(void) { Hashtab p = get_mem(PTRS_HASHTAB); Hashtab_gets++; return(p); } /* get_hashtab */ /************* * * free_hashtab() * *************/ static void free_hashtab(Hashtab p) { free_mem(p, PTRS_HASHTAB); Hashtab_frees++; } /* free_hashtab */ /************* * * Hashnode get_hashnode() * *************/ static Hashnode get_hashnode(void) { Hashnode p = get_mem(PTRS_HASHNODE); Hashnode_gets++; return(p); } /* get_hashnode */ /************* * * free_hashnode() * *************/ static void free_hashnode(Hashnode p) { free_mem(p, PTRS_HASHNODE); Hashnode_frees++; } /* free_hashnode */ /************* * * fprint_hash_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the hash package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_hash_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_HASHTAB; fprintf(fp, "hashtab (%4d) %11u%11u%11u%9.1f K\n", n, Hashtab_gets, Hashtab_frees, Hashtab_gets - Hashtab_frees, ((Hashtab_gets - Hashtab_frees) * n) / 1024.); n = BYTES_HASHNODE; fprintf(fp, "hashnode (%4d) %11u%11u%11u%9.1f K\n", n, Hashnode_gets, Hashnode_frees, Hashnode_gets - Hashnode_frees, ((Hashnode_gets - Hashnode_frees) * n) / 1024.); } /* fprint_hash_mem */ /************* * * p_hash_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the hash package. */ /* PUBLIC */ void p_hash_mem() { fprint_hash_mem(stdout, TRUE); } /* p_hash_mem */ /* * end of memory management */ /************* * * hash_init() * *************/ /* DOCUMENTATION Allocate and initialize a hash table of the given size. */ /* PUBLIC */ Hashtab hash_init(int size) { Hashtab p = get_hashtab(); int i; p->size = size; p->table = malloc(size * sizeof(Hashnode)); for (i = 0; i < size; i++) { p->table[i] = NULL; } return p; } /* hash_init */ /************* * * hash_insert() * *************/ /* DOCUMENTATION Insert a pair (integer, void *) into a hash table. If the integer is already there, a fatal error occurs. */ /* PUBLIC */ void hash_insert(int id, void *v, Hashtab h) { Hashnode p, prev, new; int i = id % h->size; p = h->table[i]; prev = NULL; while (p != NULL && p->id < id) { prev = p; p = p->next; } if (p != NULL && p->id == id) fatal_error("hash_insert, id already there."); else { new = get_hashnode(); new->id = id; new->v = v; new->next = p; if (prev != NULL) prev->next = new; else h->table[i] = new; } } /* hash_insert */ /************* * * hash_lookup() * *************/ /* DOCUMENTATION Find and return the pointer associated with the given integer ID. If the ID is not in the table, NULL is returned. */ /* PUBLIC */ void * hash_lookup(int id, Hashtab h) { Hashnode p = h->table[id % h->size]; while (p != NULL && p->id < id) p = p->next; if (p != NULL && p->id == id) return p->v; else return NULL; } /* hash_lookup */ /************* * * hash_delete() * *************/ /* DOCUMENTATION Delete the pair (ID, void *) for the given integer ID. If the ID is not in the table, nothing happens. */ /* PUBLIC */ void hash_delete(int id, Hashtab h) { Hashnode p, prev; int i = id % h->size; p = h->table[i]; prev = NULL; while (p != NULL && p->id < id) { prev = p; p = p->next; } if (p != NULL && p->id == id) { if (prev == NULL) h->table[i] = p->next; else prev->next = p->next; free_hashnode(p); } } /* hash_delete */ /************* * * hash_destroy() * *************/ /* DOCUMENTATION Free all of the memory used by the given hash table. Do not refer to the table after calling this routine. The hash table need not be empty; */ /* PUBLIC */ void hash_destroy(Hashtab h) { int i; for (i = 0; i < h->size; i++) { Hashnode p = h->table[i]; while (p != NULL) { Hashnode p2 = p; p = p->next; free_hashnode(p2); } } free(h->table); free_hashtab(h); } /* hash_destroy */ LADR-2009-11A/ladr/save/clash.c0000644000175000017500000001375310140052535015140 0ustar mccunemccune#include "clash.h" /* Private definitions and types */ /* * memory management */ static unsigned Clash_gets, Clash_frees; #define BYTES_CLASH sizeof(struct clash) #define PTRS_CLASH BYTES_CLASH%BPP == 0 ? BYTES_CLASH/BPP : BYTES_CLASH/BPP + 1 /************* * * Clash get_clash() * *************/ static Clash get_clash(void) { Clash p = get_mem(PTRS_CLASH); Clash_gets++; return(p); } /* get_clash */ /************* * * free_clash() * *************/ static void free_clash(Clash p) { free_mem(p, PTRS_CLASH); Clash_frees++; } /* free_clash */ /************* * * fprint_clash_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clash package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_clash_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_CLASH; fprintf(fp, "clash (%4d) %11u%11u%11u%9.1f K\n", n, Clash_gets, Clash_frees, Clash_gets - Clash_frees, ((Clash_gets - Clash_frees) * n) / 1024.); } /* fprint_clash_mem */ /************* * * p_clash_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clash package. */ /* PUBLIC */ void p_clash_mem() { fprint_clash_mem(stdout, TRUE); } /* p_clash_mem */ /* * end of memory management */ /************* * * append_clash() * *************/ /* DOCUMENTATION This routine simply allocates a new clash node, links it in after the given node, and returns the new node. */ /* PUBLIC */ Clash append_clash(Clash p) { Clash q = get_clash(); if (p != NULL) p->next = q; return q; } /* append_clash */ /************* * * zap_clash() * *************/ /* DOCUMENTATION Free a clash list. Contexts in clashable nodes (which are assumed to exist and be empty) are freed as well. */ /* PUBLIC */ void zap_clash(Clash p) { while (p != NULL) { Clash q = p; p = p->next; if (q->clashable && !q->clashed) free_context(q->sat_subst); free_clash(q); } } /* zap_clash */ /************* * * atom_to_literal() * *************/ /* DOCUMENTATION This routine takes an atom and returns its parent literal. */ /* PUBLIC */ Literal atom_to_literal(Term atom) { Clause c = atom->container; Literal lit = (c == NULL ? NULL : c->literals); while (lit != NULL && lit->atom != atom) lit = lit->next; return lit; } /* atom_to_literal */ /************* * * apply_lit() * *************/ /* DOCUMENTATION This routine applies a substitution to a literal and returns the instance. The given literal is not changed. */ /* PUBLIC */ Literal apply_lit(Literal lit, Context c) { return new_literal(lit->sign, apply(lit->atom, c)); } /* apply_lit */ /************* * * lit_position() * *************/ static int lit_position(Clause c, Literal lit) { int i = 1; Literal l = c->literals; while (l != NULL && l != lit) { i++; l = l->next; } if (l == lit) return i; else return -1; } /* lit_position */ /************* * * resolve() * *************/ static Clause resolve(Clash first, Just_type rule) { Clause r = get_clause(); Clause nuc = first->nuc_lit->atom->container; Ilist j = ilist_append(NULL, nuc->id); Clash p; int n; /* First, include literals in the nucleus. */ for (p = first; p != NULL; p = p->next, n++) { if (!p->clashed) append_literal(r, apply_lit(p->nuc_lit, p->nuc_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(nuc->attributes, first->nuc_subst)); /* Next, include literals in the satellites. */ n = 1; /* n-th nucleus literal, starting with 1 */ for (p = first; p != NULL; p = p->next, n++) { if (p->clashed) { Literal lit; Clause sat = p->sat_lit->atom->container; j = ilist_append(j, n); j = ilist_append(j, sat->id); j = ilist_append(j, lit_position(sat, p->sat_lit)); for (lit = sat->literals; lit != NULL; lit = lit->next) { if (lit != p->sat_lit) append_literal(r, apply_lit(lit, p->sat_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(sat->attributes, p->sat_subst)); } } r->justification = resolve_just(j, rule); upward_clause_links(r); return r; } /* resolve */ /************* * * clash_recurse() * *************/ static void clash_recurse(Clash first, Clash p, BOOL (*sat_test) (Literal), Just_type rule, void (*proc_proc) (Clause)) { if (p == NULL) { Clause resolvent = resolve(first, rule); (*proc_proc)(resolvent); } else if (!p->clashable | p->clashed) clash_recurse(first, p->next, sat_test, rule, proc_proc); else { Term fnd_atom; fnd_atom = mindex_retrieve_first(p->nuc_lit->atom, p->mate_index, UNIFY, p->nuc_subst, p->sat_subst, FALSE, &(p->mate_pos)); while (fnd_atom != NULL) { Literal slit = atom_to_literal(fnd_atom); if ((*sat_test)(slit)) { p->sat_lit = slit; p->clashed = TRUE; clash_recurse(first, p->next, sat_test, rule, proc_proc); p->clashed = FALSE; } fnd_atom = mindex_retrieve_next(p->mate_pos); } } } /* clash_recurse */ /************* * * clash() * *************/ /* DOCUMENTATION This routine takes a complete clash list and computes the resolvents.
  • clash -- a complete clash list corresponding to the nucleus.
  • sat_test -- a Boolean function on clauses which identifies potential satellites (e.g., positive clauses for hyperresolution).
  • rule -- the name of the inference rule for the justification list (see just.h).
  • proc_proc -- procedure for processing resolvents.
*/ /* PUBLIC */ void clash(Clash c, BOOL (*sat_test) (Literal), Just_type rule, void (*proc_proc) (Clause)) { clash_recurse(c, c, sat_test, rule, proc_proc); } /* clash */ LADR-2009-11A/ladr/save/pindex.c0000644000175000017500000003616410140052254015334 0ustar mccunemccune#include "pindex.h" /* Private definitions and types */ struct pair_index { int finished; /* set if nothing to retrieve */ int n; /* number of lists */ int i, j; /* working pair */ int min; /* smallest wt of inserted clause */ int new_min; /* smallest inserted wt since previous retrieval */ Clist *lists; /* lists */ Clist_pos *top; Clist_pos *curr; struct pair_index *next; /* for avail list */ }; #define INT_LARGE INT_MAX / 2 /* It can be doubled without overflow. */ #define IN_RANGE(i, min, max) (i < min ? min : (i > max ? max : i)) /* * memory management */ static unsigned Pair_index_gets, Pair_index_frees; #define BYTES_PAIR_INDEX sizeof(struct pair_index) #define PTRS_PAIR_INDEX BYTES_PAIR_INDEX%BPP == 0 ? BYTES_PAIR_INDEX/BPP : BYTES_PAIR_INDEX/BPP + 1 /************* * * Pair_index get_pair_index() * *************/ static Pair_index get_pair_index(void) { Pair_index p = get_mem(PTRS_PAIR_INDEX); p->min = INT_LARGE; p->new_min = INT_LARGE; Pair_index_gets++; return(p); } /* get_pair_index */ /************* * * free_pair_index() * *************/ static void free_pair_index(Pair_index p) { free_mem(p, PTRS_PAIR_INDEX); Pair_index_frees++; } /* free_pair_index */ /************* * * fprint_pindex_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the pindex package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_pindex_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = BYTES_PAIR_INDEX; fprintf(fp, "pair_index (%4d) %11u%11u%11u%9.1f K\n", n, Pair_index_gets, Pair_index_frees, Pair_index_gets - Pair_index_frees, ((Pair_index_gets - Pair_index_frees) * n) / 1024.); } /* fprint_pindex_mem */ /************* * * p_pindex_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the pindex package. */ /* PUBLIC */ void p_pindex_mem() { fprint_pindex_mem(stdout, TRUE); } /* p_pindex_mem */ /* * end of memory management */ /************* * * init_pair_index() * * *************/ /* DOCUMENTATION This routine allocates and initializes a Pair_index. Parameter n specifies the range 0 .. n-1 of weights that will be used. If a clause is inserted with weight outside of that range, the effective weight for pair indexing will be set to 0 or n-1. */ /* PUBLIC */ Pair_index init_pair_index(int n) { Pair_index p; int i, j; p = get_pair_index(); p->finished = 1; p->n = n; p->i = 0; p->j = 0; p->min = INT_LARGE; p->new_min = INT_LARGE; p->lists = malloc(n * sizeof(Clist)); p->top = malloc(n * n * sizeof(Clist_pos)); p->curr = malloc(n * n * sizeof(Clist_pos)); /* top and curr will be indexed as top[i*n+j]. */ for (i = 0; i < n; i++) p->lists[i] = clist_init(""); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { p->top[i*p->n+j] = NULL; p->curr[i*p->n+j] = NULL; } return p; } /* init_pair_index */ /************* * * zap_pair_index() * * *************/ /* DOCUMENTATION This routine frees a pair index. It need not be empty. */ /* PUBLIC */ void zap_pair_index(Pair_index p) { int i; for (i = 0; i < p->n; i++) { clist_zap(p->lists[i]); } free(p->lists); free(p->top); free(p->curr); free_pair_index(p); } /* zap_pair_index */ /************* * * pairs_exhausted() * *************/ /* DOCUMENTATION This routine is TRUE if the previous call to retrieve_pair() returned nothing and no more pairs have been inserted since then. (Also, TRUE is returned if no pairs were ever inserted.)

Note that FALSE may be returned when there really no pairs available. */ /* PUBLIC */ int pairs_exhausted(Pair_index p) { return p->finished; } /* pairs_exhausted */ /************* * * init_pair() * * Initialize top and curr for lists i and j. * *************/ static void init_pair(int i, int j, Pair_index p) { int n = p->n; Clist_pos lp_i = p->lists[i]->first; Clist_pos lp_j = p->lists[j]->first; if (lp_i && lp_j) { if (i == j) { p->top[i*n+i] = lp_i; p->curr[i*n+i] = NULL; } else { p->top[i*n+j] = lp_i; p->top[j*n+i] = lp_j; /* It doesn't matter which curr gets set to NULL. */ p->curr[i*n+j] = lp_i; p->curr[j*n+i] = NULL; } } else { p->top[i*n+j] = NULL; p->top[j*n+i] = NULL; p->curr[i*n+j] = NULL; p->curr[j*n+i] = NULL; } } /* init_pair */ /************* * * insert_pair_index() * *************/ /* DOCUMENTATION This routine inserts a clause into a Pair_index. If the given weight is out of range [0 ... n-1] (where n is the parameter given to init_pair_index()), weight 0 or n-1 will be used instead. */ /* PUBLIC */ void insert_pair_index(Clause c, int wt, Pair_index p) { /* If the new clause will be the only one in its list, then * for each nonempty list, set the top and curr. */ int i, j, n; n = p->n; j = IN_RANGE(wt, 0, n-1); if (p->lists[j]->first == NULL) { clist_append(c, p->lists[j]); for (i = 0; i < p->n; i++) init_pair(i, j, p); } else clist_append(c, p->lists[j]); p->finished = 0; if (wt < p->new_min) p->new_min = wt; if (wt < p->min) p->min = wt; } /* insert_pair_index */ /************* * * delete_pair_index() * *************/ /* DOCUMENTATION This routine removes a clause from a Pair_index. The parameter wt must be the same as when the clause was inserted. A fatal error may occur if the clause was not previously inserted or if it was inserted with a different weight. */ /* PUBLIC */ void delete_pair_index(Clause c, int wt, Pair_index p) { int i, j; int n = p->n; Clist_pos lp; j = IN_RANGE(wt, 0, n-1); for (lp = p->lists[j]->first; lp && lp->c != c; lp = lp->next); if (!lp) { fatal_error("delete_pair_index, clause not found."); } /* We are deleting a clause from list j. For each list i, consider the * pair [i,j]. Top[i,j] and curr[i,j] (say t1 and c1) point into list i, * and top[j,i] and curr[j,i] (say t2 anc c2) point into list j. */ for (i = 0; i < n; i++) { Clist_pos t1 = p->top[i*n+j]; Clist_pos c1 = p->curr[i*n+j]; Clist_pos t2 = p->top[j*n+i]; Clist_pos c2 = p->curr[j*n+i]; if (i == j) { if (t2 == lp) { /* printf("HERE: i == j\n"); */ /* This handles t2=c2, c2==NULL, c2 != NULL, singleton list. */ if (t2->next) { p->top[i*n+i] = t2->next; p->curr[i*n+i] = NULL; } else { p->top[i*n+i] = t2->prev; p->curr[i*n+i] = t2->prev; } } else if (c2 == lp) { p->curr[i*n+i] = c2->prev; } } else { /* i != j */ if (lp == t2) { /* printf("HERE: i != j (B)\n"); */ if (t2 == c2) { if (t2->next) { t2 = t2->next; c2 = c2->next; c1 = NULL; } else if (t2->prev) { t2 = t2->prev; c2 = c2->prev; c1 = t1; } else t1 = c1 = t2 = c2 = NULL; } else if (t2->prev) t2 = t2->prev; else if (t2->next) { t2 = t2->next; c2 = NULL; t1 = c1 = p->lists[i]->first; } else t1 = c1 = t2 = c2 = NULL; } else if (lp == c2) { /* printf("HERE: i != j (D)\n"); */ c2 = c2->prev; } p->top[i*n+j] = t1; p->curr[i*n+j] = c1; p->top[j*n+i] = t2; p->curr[j*n+i] = c2; } } clist_remove(c, p->lists[j]); } /* delete_pair_index */ /************* * * retrieve_pair() * *************/ /* DOCUMENTATION This routine retrieves the next pair from a Pair_index. The caller gives addresses of clauses which are filled in with the answer. If no pair is available, NULLs are filled in. */ /* PUBLIC */ void retrieve_pair(Pair_index p, Clause *cp1, Clause *cp2) { int i, j, k, max_k, found, n; /* First, find i and j, the smallest pair of weights that * have clauses available. p->i and p->j are from the * previous retrieval, and if no clauses have been inserted * since then, start with them. Otherwise, use new_min * (the smallest weight inserted since the previous retrieval) * and min (the smallest weight in the index) to decide * where to start looking. */ if (p->min + p->new_min < p->i + p->j) { i = p->min; j = p->new_min; } else { i = p->i; j = p->j; } n = p->n; k = i+j; max_k = (n + n) - 2; found = 0; while (k <= max_k && !found) { i = k / 2; j = k - i; while (i >= 0 && j < n && !found) { /* This test works if (i==j). */ found = (p->top[i*n+j] != p->curr[i*n+j] || p->top[j*n+i] != p->curr[j*n+i] || (p->top[i*n+j] && p->top[i*n+j]->next) || (p->top[j*n+i] && p->top[j*n+i]->next)); if (!found) { i--; j++; } } if (!found) k++; } if (!found) { *cp1 = NULL; *cp2 = NULL; p->finished = 1; } else { /* OK, there should be a pair in (i,j). */ /* Recall that if top[i,j]=curr[i,j] and top[j,i]=top[j,i], * then all pairs up to those positions have been returned. */ Clist_pos t1 = p->top[i*n+j]; Clist_pos c1 = p->curr[i*n+j]; Clist_pos t2 = p->top[j*n+i]; Clist_pos c2 = p->curr[j*n+i]; if (i == j) { if (t1 == c1) { p->top[i*n+i] = t1 = t1->next; p->curr[i*n+i] = c1 = NULL; } *cp1 = t1->c; p->curr[i*n+i] = c1 = (c1 ? c1->next : p->lists[i]->first); *cp2 = c1->c; } else { /* i != j */ if (t1 == c1 && t2 == c2) { /* Both tops equal their currs, so pick a top to increment. */ if (t1->next && (t1->c->id < t2->c->id || !t2->next)) { p->top[i*n+j] = t1 = t1->next; p->curr[i*n+j] = c1 = c1->next; p->curr[j*n+i] = c2 = NULL; } else { p->top[j*n+i] = t2 = t2->next; p->curr[j*n+i] = c2 = c2->next; p->curr[i*n+j] = c1 = NULL; } } if (t1 == c1) { *cp1 = t1->c; p->curr[j*n+i] = c2 = (c2 ? c2->next : p->lists[j]->first); *cp2 = c2->c; } else if (t2 == c2) { *cp1 = t2->c; p->curr[i*n+j] = c1 = (c1 ? c1->next : p->lists[i]->first); *cp2 = c1->c; } else { fatal_error("retrieve_pair, bad state."); } } /* Save the "working pair" for next time. */ p->i = i; p->j = j; p->new_min = INT_LARGE; } } /* retrieve_pair */ /************* * * p_pair_index() * * Print a pair index. It is printed in detail, so it should be * called only for small test indexes. * *************/ void p_pair_index(Pair_index p) { int i, j, n; Clist_pos x; n = p->n; for (i = 0; i < n; i++) { printf("Clist %d: ", i); for (x = p->lists[i]->first; x; x = x->next) printf(" %3d", x->c->id); printf(".\n"); } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { printf(" ["); if (p->top[i*n+j]) printf("%2d",p->top[i*n+j]->c->id); else printf("--"); printf(","); if (p->curr[i*n+j]) printf("%2d",p->curr[i*n+j]->c->id); else printf("--"); printf("] "); fflush(stdout); } printf("\n"); } } /* p_pair_index */ /************* * * pair_already_used() * *************/ /* DOCUMENTATION This Boolean routine checks if a pair of clauses (with corresponding weights) has already been retrieved. */ /* PUBLIC */ int pair_already_used(Clause c1, int weight1, Clause c2, int weight2, Pair_index p) { int i, j, id1, id2; int rc = 0; int n = p->n; Clist_pos top1, curr1, top2, curr2; id1 = c1->id; id2 = c2->id; i = IN_RANGE(weight1, 0, n-1); j = IN_RANGE(weight2, 0, n-1); top1 = p->top[i*n+j]; curr1 = p->curr[i*n+j]; top2 = p->top[j*n+i]; curr2 = p->curr[j*n+i]; if (!top1 || !top2) { /* One of the lists is empty. If this happens, something is probably wrong: why would we be trying to use c1 and c2? */ fatal_error("pair_already_used, bad state (1)."); } else if (i == j) { /* Let id2 be the greater one. */ if (id1 > id2) { int tmp = id1; id1 = id2; id2 = tmp; } rc = ((id2 < top1->c->id) || (id2 == top1->c->id && curr1 && id1 <= curr1->c->id)); } else { /* i != j */ if (top1 == curr1) { rc = ((id1 < top1->c->id && id2 <= top2->c->id) || (id1 == top1->c->id && curr2 && id2 <= curr2->c->id)); } else if (top2 == curr2) { rc = ((id2 < top2->c->id && id1 <= top1->c->id) || (id2 == top2->c->id && curr1 && id1 <= curr1->c->id)); } else { fatal_error("pair_already_used, bad state (2)."); } } return rc; } /* pair_already_used */ /* * This file has code for indexing clauses that are to be retrieved in * pairs. When a clause is inserted, its weight is given. Retrieval * is by sum of the weights of the pair -- lowest first. Say we have * clauses with weights 0--4. Then pairs will be returned in this order: * * (0,0) * (0,1) * (1,1) (0,2) * (1,2) (0,3) * (2,2) (1,3) (0,4) * (2,3) (1,4) * (3,3) (2,4) * (3,4) * (4,4) * * Objects can be inserted after retrieval has begun; the smallest * available pair will always be returned. When the index is * initialized, the caller supplies a parameter N, and the actual * weight range for indexing will be 0..N-1. If an inserted clause has * weight outside of this range, the weight will be changed to 0 or N-1. * * This is intended to be used for binary inference rules such as * paramodulation and resolution. * * We keep a list of clauses with each weight 0..N-1. When the index * is initialized, we allocate two N x N arrays (top and curr) * to keep track of the positions in the pairs of lists. * (Since the size of the array is not known at compile time, * we access elements as a[i*N+j] instead of a[i][j].) * * For a pair of weights i and j, we use top[i,j] and curr[i,j] to * point to positions in list i w.r.t. list j. And vice versa. * Roughly, it goes like this: Lists grow upward, and clauses above * "top" have not yet been considered. Increment top[i,j], then return * top[i,j] with each member of list j up to top[j,i]. (Curr[j,i] * marks the position between retrievals.) Now all pairs up to the two * tops have been returned. Now pick the top with the smallest clause * ID, increment it, and continue. If at any point a new clause C is * inserted into the index, and C goes with other clasues to make * smaller pairs, those smaller pairs are returned before continuing * with i and j. * * Valid states of an index. * Case 1: i == j. * (a) top and curr are both NULL; this occurs if the list is empty. * (b) top and top=curr; done up through top. * (c) top and !curr; done up through top-1. * (d) top and curr and top > curr; done up through . * Case 2: i != j. * (a) !t1 and !t2; one or both lists empty. * (b) t1 and t2 and t1=c1 and t2=c2; done up through tops. * (c) t1 and t2 and t1=c1 and c2=NULL; done up through . * (d) t1 and t2 and t1=c1 and c2; * also through . * (e) same as c,d, but vice versa. * * This is similar to the method in "A Theorem-Proving Language * for Experimentation" by Henschen, Overbeek, Wos, CACM 17(6), 1974. * */ LADR-2009-11A/ladr/save/call_weight.c0000644000175000017500000000115711024234737016333 0ustar mccunemccune/************* * * call_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int call_weight(char *program, Term t) { FILE *fp; int result; char *prog_quote_free = process_quoted_symbol(program); String_buf sb = get_string_buf(); sprint_term(sb, t); /* printf("calling %s with ", prog_quote_free); p_sb(sb); */ fflush(stdout); fp = popen(prog_quote_free, "w"); fprint_sb(fp, sb); fprintf(fp, "\n"); fflush(fp); /* fscanf(fp, "%d", &result); */ result = pclose(fp); printf("returning %d: ", result); p_term(t); zap_string_buf(sb); return result; } /* call_weight */ LADR-2009-11A/ladr/save/interp_remove_skolems0000644000175000017500000000170210537273572020247 0ustar mccunemccune#if 0 /************* * * interp_remove_skolems_recurse() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all symbols that start with "$". THIS IS OBSOLETE, BECAUSE SKOLEM SYMBOLS NO LONGER START WITH $. */ /* PUBLIC */ Term interp_remove_skolems_recurse(Term ops) { if (nil_term(ops)) return ops; else { char *sym = sn_to_str(SYMNUM(ARG(ARG(ops,0),0))); if (*sym == '$') { zap_term(ARG(ops,0)); return interp_remove_skolems_recurse(ARG(ops,1)); } else { ARG(ops,1) = interp_remove_skolems_recurse(ARG(ops,1)); return ops; } } } /* interp_remove_skolems_recurse */ /************* * * interp_remove_skolems() * *************/ /* DOCUMENTATION In a non-compiled interpretation, remove all symbols that start with "$". */ /* PUBLIC */ void interp_remove_skolems(Term t) { ARG(t,2) = interp_remove_skolems_recurse(ARG(t,2)); } /* interp_remove_skolems */ #endif LADR-2009-11A/ladr/save/read_tptp_file.c0000644000175000017500000000340110576060260017023 0ustar mccunemccune/************* * * read_tptp_file() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void read_tptp_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action) { Term t; Readlist assumps, goals; assumps = readlist_member(Input_lists, "assumptions", FORMULAS); if (assumps == NULL) assumps = readlist_member_wild(Input_lists, FORMULAS); if (assumps == NULL) fatal_error("read_tptp_file: assumptions/wild list not found"); goals = readlist_member(Input_lists, "goals", FORMULAS); if (goals == NULL) fatal_error("read_tptp_file: goals list not found"); t = read_term(fin, fout); while (t != NULL) { if (echo) fwrite_term_nl(fout, t); if (is_term(t, "include", 1) || is_term(t, "include", 2)) { char *fname = new_str_copy(sn_to_str(SYMNUM(ARG(t,0)))); char *fname2 = fname; if (*fname2 == '\'' || *fname2 == '"') { fname2[strlen(fname2)-1] = '\0'; fname2++; } FILE *fin2 = fopen(fname2, "r"); if (fin2 == NULL) { char s[100]; sprintf(s, "read_tptp_file, file %s not found", fname2); fatal_error(s); } if (echo) printf("\n%% Including file %s\n\n", fname2); read_tptp_file(fin2, fout, echo, unknown_action); if (echo) printf("\n%% Finished including file %s\n\n", fname2); free(fname); } else if (is_term(t, "cnf", 3) || is_term(t, "cnf", 4) || is_term(t, "fof", 3) || is_term(t, "fof", 4)) { Formula form = tptp_formula(t); if (is_term(ARG(t,1), "conjecture", 0)) *(goals->p) = plist_append(*(goals->p), form); else *(assumps->p) = plist_append(*(assumps->p), form); } else { p_term(t); fatal_error("read_tptp_file: unknown term"); } zap_term(t); t = read_term(fin, fout); } } /* read_tptp_file */ LADR-2009-11A/ladr/clause_eval.h0000644000175000017500000000233311151265364015401 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSE_EVAL_H #define TP_CLAUSE_EVAL_H #include "topform.h" /* INTRODUCTION */ /* Public definitions */ typedef struct clause_eval *Clause_eval; /* End of public definitions */ /* Public function prototypes from clause_eval.c */ void zap_clause_eval_rule(Clause_eval p); Clause_eval compile_clause_eval_rule(Term t); BOOL eval_clause_in_rule(Topform c, Clause_eval p); BOOL rule_contains_semantics(Clause_eval p); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/di_tree.c0000644000175000017500000002200210637466321014523 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "di_tree.h" /* Private definitions and types */ static int Nonunit_fsub_tests; static int Nonunit_bsub_tests; static unsigned Sub_calls = 0; static unsigned Sub_calls_overflows = 0; #define BUMP_SUB_CALLS {Sub_calls++; if (Sub_calls == 0) Sub_calls_overflows++;} /************* * * nonunit_fsub_tests(void) * *************/ /* DOCUMENTATION */ /* PUBLIC */ int nonunit_fsub_tests(void) { return Nonunit_fsub_tests; } /* nonunit_fsub_tests */ /************* * * nonunit_bsub_tests(void) * *************/ /* DOCUMENTATION */ /* PUBLIC */ int nonunit_bsub_tests(void) { return Nonunit_bsub_tests; } /* nonunit_bsub_tests */ /* * memory management */ #define PTRS_DI_TREE PTRS(sizeof(struct di_tree)) static unsigned Di_tree_gets, Di_tree_frees; /************* * * Di_tree get_di_tree() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Di_tree get_di_tree(void) { Di_tree p = get_cmem(PTRS_DI_TREE); Di_tree_gets++; return(p); } /* get_di_tree */ /************* * * free_di_tree() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_di_tree(Di_tree p) { free_mem(p, PTRS_DI_TREE); Di_tree_frees++; } /* free_di_tree */ /************* * * fprint_di_tree_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the di_tree package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_di_tree_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct di_tree); fprintf(fp, "di_tree (%4d) %11u%11u%11u%9.1f K\n", n, Di_tree_gets, Di_tree_frees, Di_tree_gets - Di_tree_frees, ((Di_tree_gets - Di_tree_frees) * n) / 1024.); } /* fprint_di_tree_mem */ /************* * * p_di_tree_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the di_tree package. */ /* PUBLIC */ void p_di_tree_mem(void) { fprint_di_tree_mem(stdout, TRUE); } /* p_di_tree_mem */ /* * end of memory management */ /************* * * init_di_tree() * *************/ /* DOCUMENTATION This routine allocates and returns an empty integer-vector discrimination index. */ /* PUBLIC */ Di_tree init_di_tree(void) { return get_di_tree(); } /* init_di_tree */ /************* * * di_tree_insert() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void di_tree_insert(Ilist vec, Di_tree node, void *datum) { if (vec == NULL) { Plist p = get_plist(); p->v = datum; p->next = node->u.data; node->u.data = p; } else { Di_tree prev = NULL; Di_tree curr = node->u.kids; /* kids are in increasing order */ while (curr && vec->i > curr->label) { prev = curr; curr = curr->next; } if (curr == NULL || vec->i != curr->label) { Di_tree new = get_di_tree(); new->label = vec->i; new->next = curr; if (prev) prev->next = new; else node->u.kids = new; curr = new; } di_tree_insert(vec->next, curr, datum); } } /* di_tree_insert */ /************* * * di_tree_delete() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL di_tree_delete(Ilist vec, Di_tree node, void *datum) { if (vec == NULL) { node->u.data = plist_remove(node->u.data, datum); return node->u.data != NULL; /* tells parent whether to keep node */ } else { BOOL keep; Di_tree prev = NULL; Di_tree curr = node->u.kids; /* kids are in increasing order */ while (curr && vec->i > curr->label) { prev = curr; curr = curr->next; } if (curr == NULL || vec->i != curr->label) fatal_error("di_tree_delete, node not found"); keep = di_tree_delete(vec->next, curr, datum); if (keep) return TRUE; else { if (prev) prev->next = curr->next; else node->u.kids = curr->next; free_di_tree(curr); return node->u.kids != NULL; } } } /* di_tree_delete */ /************* * * zap_di_tree() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void zap_di_tree(Di_tree node, int depth) { if (depth == 0) zap_plist(node->u.data); else { Di_tree kid = node->u.kids; while (kid) { Di_tree tmp = kid; kid = kid->next; zap_di_tree(tmp, depth-1); } } free_di_tree(node); } /* zap_di_tree */ /************* * * p_di_tree() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_di_tree(Ilist vec, Di_tree node, int depth) { int i; for (i = 0; i < depth; i++) printf(" "); if (vec == NULL) { Plist p = node->u.data; printf("IDs:"); while (p) { Topform c = p->v; printf(" %d", c->id); p = p->next; } printf("\n"); } else { Di_tree kid; printf("%d\n", node->label); for (kid = node->u.kids; kid; kid = kid->next) p_di_tree(vec->next, kid, depth+1); } } /* p_di_tree */ /************* * * subsume_di_literals() * *************/ static BOOL subsume_di_literals(Literals clit, Context subst, Literals d, Trail *trp) { BOOL subsumed = FALSE; Literals dlit; BUMP_SUB_CALLS; if (clit == NULL) return TRUE; else { for (dlit = d; !subsumed && dlit != NULL; dlit = dlit->next) { if (clit->sign == dlit->sign) { Trail mark = *trp; if (match(clit->atom, subst, dlit->atom, trp)) { if (subsume_di_literals(clit->next, subst, d, trp)) subsumed = TRUE; else { undo_subst_2(*trp, mark); *trp = mark; } } } } return subsumed; } } /* subsume_di_literals */ /************* * * subsumes_di() * *************/ static BOOL subsumes_di(Literals c, Literals d, Context subst) { Trail tr = NULL; BOOL subsumed = subsume_di_literals(c, subst, d, &tr); if (subsumed) undo_subst(tr); return subsumed; } /* subsumes_di */ /************* * * di_tree_forward() * *************/ static Topform di_tree_forward(Ilist vec, Di_tree node, Literals dlits, Context subst) { BUMP_SUB_CALLS; if (vec == NULL) { Plist p = node->u.data; while (p) { Topform c = p->v; Nonunit_fsub_tests++; if (subsumes_di(c->literals, dlits, subst)) return p->v; p = p->next; } return NULL; } else { void *datum = NULL; Di_tree kid = node->u.kids; /* kids are in increasing order; look at those <= vec->i */ while (!datum && kid && kid->label <= vec->i) { datum = di_tree_forward(vec->next, kid, dlits, subst); kid = kid->next; } return datum; } } /* di_tree_forward */ /************* * * forward_feature_subsume() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform forward_feature_subsume(Topform d, Di_tree root) { Ilist f = features(d->literals); Context subst = get_context(); Topform c = di_tree_forward(f, root, d->literals, subst); free_context(subst); zap_ilist(f); return c; } /* forward_feature_subsume */ /************* * * di_tree_back() * *************/ static void di_tree_back(Ilist vec, Di_tree node, Literals clits, Context subst, Plist *subsumees) { BUMP_SUB_CALLS; if (vec == NULL) { Plist p = node->u.data; while (p) { Topform d = p->v; Nonunit_bsub_tests++; if (clits != d->literals && subsumes_di(clits, d->literals, subst)) *subsumees = plist_prepend(*subsumees, d); p = p->next; } } else { Di_tree kid = node->u.kids; /* kids are in increasing order; look at those >= vec->i */ while (kid && kid->label < vec->i) kid = kid->next; while (kid) { di_tree_back(vec->next, kid, clits, subst, subsumees); kid = kid->next; } } } /* di_tree_back */ /************* * * back_feature_subsume() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist back_feature_subsume(Topform c, Di_tree root) { Ilist f = features(c->literals); Context subst = get_context(); Plist subsumees = NULL; di_tree_back(f, root, c->literals, subst, &subsumees); free_context(subst); zap_ilist(f); return subsumees; } /* back_feature_subsume */ /************* * * mega_sub_calls() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned mega_sub_calls(void) { return (Sub_calls / 1000000) + ((UINT_MAX / 1000000) * Sub_calls_overflows); } /* mega_sub_calls */ LADR-2009-11A/ladr/kol.py0000755000175000017500000000263011024305144014075 0ustar mccunemccune#!/usr/bin/python import sys # print "Hello, world!" MIN = 2 def kolmogorov(string): print "string=%s" % string total = 0 length = len(string) - 2 index = MIN print "Will check from index %d to %d." % (index,length) print "Length of string is %d." % length while index <= length: # index of where the search begins maxlook = (length - index) + 2 # don't check for occurences longer than head of string if maxlook > index: maxlook = index print "Checking at index: %d." % index print "Will check strings of length %d through %d." % (MIN,maxlook) flen = 0 # length of found redundancy # index of length of lookahead to check for window in range(MIN, maxlook+1): # note: range(2,5) is [2,3,4] tocheck = string[ index : index+window ] # note: "abcde"[1:3] is "bc" print "Want to know if %s occurs in pos 0 until %d." % (tocheck,index) ind = string.find(tocheck) if ind < index: flen = window if flen == 0: index += 1 else: index += flen total += flen print "total=%d, index=%d, length=%d, MIN=%d" % (total,index,length,MIN) print "DONE."; print "TOTAL REDUNDANCY: %d" % total return float(total) / (length-1) while 1: string = sys.stdin.readline() if not string: break; print str(kolmogorov(string)) LADR-2009-11A/ladr/ibuffer.c0000644000175000017500000001116710637466322014545 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "ibuffer.h" #include /* Private definitions and types */ /* * memory management (nonstandard) */ /************* * * ibuf_init() * *************/ /* DOCUMENTATION Allocate and initialize an Ibuffer. */ /* PUBLIC */ Ibuffer ibuf_init(void) { Ibuffer ibuf = malloc(sizeof(struct ibuffer)); ibuf->buf = malloc(IBUF_INIT_SIZE * sizeof(int)); ibuf->size = IBUF_INIT_SIZE; ibuf->write_position = 0; ibuf->read_position = 0; return ibuf; } /* ibuf_init */ /************* * * ibuf_free() * *************/ /* DOCUMENTATION Free an Ibuffer. */ /* PUBLIC */ void ibuf_free(Ibuffer ibuf) { free(ibuf->buf); free(ibuf); } /* ibuf_free */ /************* * * ibuf_write() * *************/ /* DOCUMENTATION Write an integer to an Ibuffer. */ /* PUBLIC */ void ibuf_write(Ibuffer ibuf, int i) { if (ibuf->write_position >= ibuf->size) { int size2 = ibuf->size * 2; int *buf2, i; printf("ibuf_write, increasing buf size from %d to %d\n", ibuf->size, size2); buf2 = malloc(size2 * sizeof(int)); for (i = 0; i < ibuf->size; i++) buf2[i] = ibuf->buf[i]; free(ibuf->buf); ibuf->buf = buf2; ibuf->size = size2; } ibuf->buf[ibuf->write_position] = i; ibuf->write_position++; } /* ibuf_write */ /************* * * ibuf_write_block() * *************/ /* DOCUMENTATION Write an array of integers to an Ibuffer. */ /* PUBLIC */ void ibuf_write_block(Ibuffer ibuf, int *a, int n) { int i; for (i = 0; i < n; i++) ibuf_write(ibuf, a[i]); } /* ibuf_write_block */ /************* * * ibuf_rewind() * *************/ /* DOCUMENTATION Reset an Ibuffer for reading. */ /* PUBLIC */ void ibuf_rewind(Ibuffer ibuf) { ibuf->read_position = 0; } /* ibuf_rewind */ /************* * * ibuf_read() * *************/ /* DOCUMENTATION Get the next integer from an Ibuffer. This version returns IBUF_EOF (INT_MIN) if there is nothing to read. */ /* PUBLIC */ int ibuf_read(Ibuffer ibuf) { if (ibuf->read_position >= ibuf->write_position) return IBUF_EOF; else { int i = ibuf->buf[ibuf->read_position]; ibuf->read_position++; return i; } } /* ibuf_read */ /************* * * ibuf_xread() * *************/ /* DOCUMENTATION Get the next integer from an Ibuffer. This version assumes there is an integer to read; if it is at the end IBUF_EOF, a fatal error occurs. */ /* PUBLIC */ int ibuf_xread(Ibuffer ibuf) { int i; if (ibuf->read_position >= ibuf->write_position) fatal_error("ibuf_xread: end of buffer"); i = ibuf->buf[ibuf->read_position]; ibuf->read_position++; return i; } /* ibuf_xread */ /************* * * ibuf_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int ibuf_length(Ibuffer ibuf) { return ibuf->write_position; } /* ibuf_length */ /************* * * ibuf_buffer() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int *ibuf_buffer(Ibuffer ibuf) { return ibuf->buf; } /* ibuf_buffer */ /************* * * fd_read_to_ibuf() * *************/ #define ISIZE 100 /* DOCUMENTATION */ /* PUBLIC */ Ibuffer fd_read_to_ibuf(int fd) { Ibuffer ibuf = ibuf_init(); int csize = ISIZE * sizeof(int); int tibuf[ISIZE]; int rc; do { rc = read(fd, tibuf, csize); if (rc == -1) { perror(""); fatal_error("fd_read_to_ibuf, read error"); } else if (rc == 0) ; /* we're done */ else if (rc % sizeof(int) != 0) fatal_error("fd_read_to_ibuf, bad number of chars read"); else { ibuf_write_block(ibuf, tibuf, rc / sizeof(int)); } } while (rc > 0); return ibuf; } /* fd_read_to_ibuf */ /************* * * p_ibuf() * *************/ /* DOCUMENTATION Print a an Ibuffer to a stdout. This is mainly for debugging. */ /* PUBLIC */ void p_ibuf(Ibuffer ibuf) { int i = ibuf_read(ibuf); while (i != IBUF_EOF) { printf("%d ", i); i = ibuf_read(ibuf); } printf("\n"); } /* p_ibuf */ LADR-2009-11A/ladr/index.html.master0000644000175000017500000000610010467113317016227 0ustar mccunemccune LADR DOCS

LADR

Library of Automated Deduction Routines

Version August-2006A
Top functions Interpretations Inference Rules Formulas and Clauses Indexing and Unification Terms Basic Routines
LADR-2009-11A/ladr/fatal.c0000644000175000017500000000402410637466321014203 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "fatal.h" /* Private definitions and types */ static int Fatal_exit_code = 1; /************* * * bell() * *************/ /* DOCUMENTATION Send the bell character '\007' to a file. */ /* PUBLIC */ void bell(FILE *fp) { fprintf(fp, "%c", '\007'); } /* bell */ /************* * * get_fatal_exit_code() * *************/ /* DOCUMENTATION This function returns the exit code that will be used in case fatal_error() is called. */ /* PUBLIC */ int get_fatal_exit_code() { return Fatal_exit_code; } /* get_fatal_exit_code */ /************* * * set_fatal_exit_code() * *************/ /* DOCUMENTATION This routine changes the exit code that will be used in case fatal_error() is called. The default value is 1. */ /* PUBLIC */ void set_fatal_exit_code(int exit_code) { Fatal_exit_code = exit_code; } /* set_fatal_exit_code */ /************* * * fatal_error() * *************/ /* DOCUMENTATION This routine should be called if something terrible happens. The message is printed to stdout and to stderr, and the process exits with the fatal_exit_code (default 1). */ /* PUBLIC */ void fatal_error(char *message) { fprintf(stdout, "\nFatal error: %s\n\n", message); fprintf(stderr, "\nFatal error: %s\n\n", message); exit(Fatal_exit_code); } /* fatal_error */ LADR-2009-11A/ladr/sed.10000644000175000017500000000002411074677355013610 0ustar mccunemccunes/itoa/int_to_str/g LADR-2009-11A/ladr/std_options.h0000644000175000017500000000224111151265364015461 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_STD_OPTIONS_H #define TP_STD_OPTIONS_H #include "options.h" #include "symbols.h" #include "clock.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from std_options.c */ void init_standard_options(void); void process_standard_options(void); int clocks_id(void); int prolog_style_variables_id(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/mindex.c0000644000175000017500000004540510637466322014411 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "mindex.h" /* Private definitions and types */ struct mindex_pos { Mindex index; Querytype query_type; Term query_term; Term found_term; Context query_subst; Context found_subst; Trail tr; Btu_state btu_position; /* backtrack unification */ Btm_state btm_position; /* backtrack matching */ BOOL partial_match; /* FPA */ Fpa_state fpa_position; /* LINEAR */ Plist linear_position; /* DISCRIM_WILD */ /* DISCRIM_BIND */ Discrim_pos discrim_position; Mindex_pos next; /* for avail list */ }; /* * memory management */ #define PTRS_MINDEX PTRS(sizeof(struct mindex)) static unsigned Mindex_gets, Mindex_frees; #define PTRS_MINDEX_POS PTRS(sizeof(struct mindex_pos)) static unsigned Mindex_pos_gets, Mindex_pos_frees; /************* * * Mindex get_mindex() * *************/ static Mindex get_mindex(void) { Mindex p = get_cmem(PTRS_MINDEX); p->index_type = -1; p->unif_type = -1; Mindex_gets++; return(p); } /* get_mindex */ /************* * * free_mindex() * *************/ static void free_mindex(Mindex p) { free_mem(p, PTRS_MINDEX); Mindex_frees++; } /* free_mindex */ /************* * * Mindex_pos get_mindex_pos() * *************/ static Mindex_pos get_mindex_pos(void) { Mindex_pos p = get_cmem(PTRS_MINDEX_POS); p->query_type = -1; Mindex_pos_gets++; return(p); } /* get_mindex_pos */ /************* * * free_mindex_pos() * *************/ static void free_mindex_pos(Mindex_pos p) { free_mem(p, PTRS_MINDEX_POS); Mindex_pos_frees++; } /* free_mindex_pos */ /************* * * fprint_mindex_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the mindex package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_mindex_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct mindex); fprintf(fp, "mindex (%4d) %11u%11u%11u%9.1f K\n", n, Mindex_gets, Mindex_frees, Mindex_gets - Mindex_frees, ((Mindex_gets - Mindex_frees) * n) / 1024.); n = sizeof(struct mindex_pos); fprintf(fp, "mindex_pos (%4d) %11u%11u%11u%9.1f K\n", n, Mindex_pos_gets, Mindex_pos_frees, Mindex_pos_gets - Mindex_pos_frees, ((Mindex_pos_gets - Mindex_pos_frees) * n) / 1024.); } /* fprint_mindex_mem */ /************* * * p_mindex_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the mindex package. */ /* PUBLIC */ void p_mindex_mem() { fprint_mindex_mem(stdout, TRUE); } /* p_mindex_mem */ /* * end of memory management */ /************* * * mindex_init() * *************/ /* DOCUMENTATION This routine allocates and returns an (empty) Mindex, which is used to retrieve unifiable terms.
  • index_type: {LINEAR, FPA, DISCRIM_WILD, DISCRIM_BIND}
  • unif_type: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
Types of retrieval. LINEAR and FPA indexes support all types of retrieval (FPA is slow for GENERALIZATION). DISCRIM_WILD and DISCRIM_BIND indexes support GENERALIZATION retrieval only. See mindex_retrieve_first().

Associative-commutative (AC) and commutative (C) symbols. DISCRIM_BIND does not support AC symbols. All other combinations are okay. If you have any AC or C symbols, you must specify unif_type BACKTRACK_UNIF. (BACKTRACK_UNIF is also okay with no AC or C symbols, but it is a little bit slower than ORDINARY_UNIF.)

AC symbols must be declared (with set_assoc_comm()) before calling mindex_update(). C symbols need not be declared before mindex_update(), but they must be declared (with set_commutative()) before calling mindex_retrieve_first(). */ /* PUBLIC */ Mindex mindex_init(Mindextype mtype, Uniftype utype, int fpa_depth) { Mindex mdx = get_mindex(); mdx->index_type = mtype; mdx->unif_type = utype; switch(mtype) { case LINEAR: mdx->linear_first = mdx->linear_last = NULL; break; case FPA: mdx->fpa = fpa_init_index(fpa_depth); break; case DISCRIM_WILD: mdx->discrim_tree = discrim_init(); break; case DISCRIM_BIND: mdx->discrim_tree = discrim_init(); break; default: free_mindex(mdx); mdx = NULL; } return mdx; } /* mindex_init */ /************* * * mindex_empty() * *************/ /* DOCUMENTATION This Boolean routine checks if an Mindex is empty, that is, has no terms. It must exist (be non-NULL). */ /* PUBLIC */ BOOL mindex_empty(Mindex mdx) { switch (mdx->index_type) { case FPA: return fpa_empty(mdx->fpa); break; case LINEAR: return mdx->linear_first == NULL; break; case DISCRIM_WILD: case DISCRIM_BIND: return discrim_empty(mdx->discrim_tree); break; } return FALSE; } /* mindex_empty */ /************* * * mindex_free() * *************/ /* DOCUMENTATION This routine frees an empty Mindex. (If the Mindex is not empty, nothing happens.) */ /* PUBLIC */ void mindex_free(Mindex mdx) { if (!mindex_empty(mdx)) fprintf(stderr, "WARNING, mindex_free called with nonempty mindex.\n"); else { switch (mdx->index_type) { case FPA: zap_fpa_index(mdx->fpa); break; case LINEAR: break; case DISCRIM_WILD: case DISCRIM_BIND: discrim_dealloc(mdx->discrim_tree); break; } free_mindex(mdx); } } /* mindex_free */ /************* * * mindex_destroy() * *************/ /* DOCUMENTATION This frees all the memory associated with an Mindex. Do not refer to the Mindex after calling this routine. */ /* PUBLIC */ void mindex_destroy(Mindex mdx) { if (!mindex_empty(mdx)) { fprintf(stdout, "\nWARNING: destroying nonempty mindex.\n\n"); fprintf(stderr, "\nWARNING: destroying nonempty mindex.\n\n"); } switch (mdx->index_type) { case FPA: zap_fpa_index(mdx->fpa); break; case LINEAR: zap_plist(mdx->linear_first); break; case DISCRIM_WILD: case DISCRIM_BIND: destroy_discrim_tree(mdx->discrim_tree); break; } free_mindex(mdx); } /* mindex_destroy */ /************* * * linear_insert() * *************/ static void linear_insert(Mindex mdx, Term t) { Plist p = get_plist(); p->v = t; p->next = NULL; if (mdx->linear_last != NULL) mdx->linear_last->next = p; else mdx->linear_first = p; mdx->linear_last = p; } /* linear_insert */ /************* * * linear_delete() * *************/ static void linear_delete(Mindex mdx, Term t) { Plist curr, prev; prev = NULL; curr = mdx->linear_first; while (curr != NULL && curr->v != t) { prev = curr; curr = curr->next; } if (curr == NULL) { fprint_term(stderr, t); fprintf(stderr, "\n"); fatal_error("mindex_delete (linear), term not found."); } else { if (prev != NULL) prev->next = curr->next; else mdx->linear_first = curr->next; if (curr == mdx->linear_last) mdx->linear_last = prev; free_plist(curr); } } /* linear_delete */ /************* * * linear_update() * *************/ static void linear_update(Mindex mdx, Term t, Indexop op) { if (op == INSERT) linear_insert(mdx, t); else linear_delete(mdx, t); } /* linear_update */ /************* * * mindex_update() * *************/ /* DOCUMENTATION This routine inserts (op==INSERT) or deletes (op==DELETE) a Term t into/from an Mindex mdx.

It is your responsibility to remember that t is in the index, because we don't currently have a routine "mindex_member()". */ /* PUBLIC */ void mindex_update(Mindex mdx, Term t, Indexop op) { if (mdx->index_type == FPA) fpa_update(t, mdx->fpa, op); else if (mdx->index_type == LINEAR) linear_update(mdx, t, op); else if (mdx->index_type == DISCRIM_WILD) discrim_wild_update(t, mdx->discrim_tree, t, op); else if (mdx->index_type == DISCRIM_BIND) discrim_bind_update(t, mdx->discrim_tree, t, op); else { fatal_error("ERROR, mindex_update: bad mindex type."); } } /* mindex_update */ /************* * * mindex_retrieve_first * *************/ /* DOCUMENTATION This routine finds and returns the first answer to a query (returning NULL if there are no answers).

  • Term t: the query term;
  • Mindex mdx: the Mindex;
  • int query_type: UNIFY, INSTANCE, GENERALIZATION, VARIANT, or IDENTICAL;
  • Context query_subst: subsitution for variables in query term t; this can be NULL for GENERALIZATION, and IDENTICAL;
  • Context found_subst: subsitution for variables in the answer term; this can be NULL for INSTANCE, VARIANT, and IDENTICAL;
  • BOOL partial_match: If TRUE, then for GENERALIZATION, with BACKTRACK_UNIF, when t has an AC symbol at the root, allow the retrieved term to match only part of t, with the remainder of the retrieved term placed in fond_subst->partial_term. This is used for AC rewriting, for example, to let x+x=x rewrite a+a+b.
  • Mindex_pos *ppos (output parameter): If an answer is returned, this address is set to a pointer to a structure that holds the position so you can get the rest of the answers.
If you ask for a type of retrieval not supported by the Mindex mdx, you will get no answers (and no error message).

Here is an example of how to retrieve all answers. Assume we have Term t and Mindex mdx.

{
  Mindex_pos pos;
  Term t2;
  Context cq = get_context();
  Context cf = get_context();
  int n = 0;
  
  t2 = mindex_retrieve_first(t, mdx, UNIFY, cq, cf, FALSE, &pos);
  while (t2 != NULL) {
    t2 = mindex_retrieve_next(pos);
    n++;
  }
  free_context(cq);
  free_context(cf);
  printf("there are %d mates\n", n);
}
*/ /* PUBLIC */ Term mindex_retrieve_first(Term t, Mindex mdx, Querytype qtype, Context query_subst, Context found_subst, BOOL partial_match, Mindex_pos *ppos) { Mindex_pos pos; if ((mdx->index_type == DISCRIM_WILD || mdx->index_type == DISCRIM_BIND) && qtype != GENERALIZATION) return NULL; else { pos = get_mindex_pos(); pos->index = mdx; pos->query_type = qtype; pos->query_term = t; pos->query_subst = query_subst; pos->found_term = NULL; pos->found_subst = found_subst; pos->tr = NULL; pos->btu_position = NULL; pos->btm_position = NULL; pos->partial_match = partial_match; if (mdx->index_type == FPA) pos->fpa_position = NULL; else if (mdx->index_type == DISCRIM_WILD) pos->discrim_position = NULL; else if (mdx->index_type == DISCRIM_BIND) pos->discrim_position = NULL; else if (mdx->index_type == LINEAR) pos->linear_position = mdx->linear_first; *ppos = pos; return mindex_retrieve_next(pos); } } /* mindex_retrieve_first */ /************* * * next_candidate() * *************/ static Term next_candidate(Mindex_pos pos) { Term tf; if (pos->index->index_type == FPA) { if (pos->fpa_position == NULL) { tf = fpa_first_answer(pos->query_term, pos->query_subst, pos->query_type, pos->index->fpa, &(pos->fpa_position)); } else tf = fpa_next_answer(pos->fpa_position); } else if (pos->index->index_type == DISCRIM_WILD) { if (pos->discrim_position == NULL) tf = discrim_wild_retrieve_first(pos->query_term, pos->index->discrim_tree, &(pos->discrim_position)); else tf = discrim_wild_retrieve_next(pos->discrim_position); } else if (pos->index->index_type == DISCRIM_BIND) { if (pos->discrim_position == NULL) tf = discrim_bind_retrieve_first(pos->query_term, pos->index->discrim_tree, pos->found_subst, &(pos->discrim_position)); else tf = discrim_bind_retrieve_next(pos->discrim_position); } else if (pos->index->index_type == LINEAR) { if (pos->linear_position == NULL) tf = NULL; else { tf = pos->linear_position->v; pos->linear_position = pos->linear_position->next; } } else tf = NULL; return tf; } /* next_candidate */ /************* * * retrieve_next_backtrack() * *************/ static Term retrieve_next_backtrack(Mindex_pos pos) { Term tq = pos->query_term; Term tf = pos->found_term; Context cq = pos->query_subst; Context cf = pos->found_subst; if (pos->query_type == UNIFY) { /* We already have a found_term from a previous call; * try for another unifier. */ if (pos->btu_position != NULL) { pos->btu_position = unify_bt_next(pos->btu_position); if (pos->btu_position == NULL) tf = NULL; } if (pos->btu_position == NULL) { /* This is either the first call for the query, or there are * no more unifiers for the previous found_term. */ tf = next_candidate(pos); while (tf != NULL && pos->btu_position == NULL) { pos->btu_position = unify_bt_first(tq, cq, tf, cf); if (pos->btu_position == NULL) tf = next_candidate(pos); } } } /* UNIFY */ else if (pos->query_type == INSTANCE || pos->query_type == GENERALIZATION) { if (pos->btm_position != NULL) { pos->btm_position = match_bt_next(pos->btm_position); if (pos->btm_position == NULL) tf = NULL; } if (pos->btm_position == NULL) { tf = next_candidate(pos); while (tf != NULL && pos->btm_position == NULL) { if (pos->query_type == INSTANCE) pos->btm_position = match_bt_first(tq, cq, tf, pos->partial_match); else pos->btm_position = match_bt_first(tf, cf, tq, pos->partial_match); if (pos->btm_position == NULL) tf = next_candidate(pos); } } } /* INSTANCE || GENERALIZATION */ else if (pos->query_type == VARIANT) { fatal_error("retrieve_next_backtrack, VARIANT not supported."); } /* VARIANT */ else if (pos->query_type == IDENTICAL) { fatal_error("retrieve_next_backtrack, IDENTICAL not supported."); } /* IDENTICAL */ if (tf == NULL) { free_mindex_pos(pos); return NULL; } else { pos->found_term = tf; return tf; } } /* retrieve_next_backtrack */ /************* * * mindex_retrieve_next * *************/ /* DOCUMENTATION This routine finds and returns the next answer to a query. See mindex_retrieve_first() for an explanation. */ /* PUBLIC */ Term mindex_retrieve_next(Mindex_pos pos) { if (pos->index->unif_type == BACKTRACK_UNIF) return retrieve_next_backtrack(pos); else { Term tq, tf; Context cq, cf; Trail tr; BOOL ok; tq = pos->query_term; cq = pos->query_subst; cf = pos->found_subst; undo_subst(pos->tr); /* ok if NULL or not used */ pos->tr = NULL; tf = next_candidate(pos); if (tf != NULL && pos->index->index_type == DISCRIM_BIND) ok = TRUE; else ok = FALSE; while (tf && !ok) { #if 0 printf("potential mate, %d: ", tf->INDEX_ID); p_term(tf); #endif tr = NULL; switch (pos->query_type) { case UNIFY: ok = unify(tq, cq, tf, cf, &(pos->tr)); break; case GENERALIZATION: ok = match(tf, cf, tq, &(pos->tr)); break; case INSTANCE: ok = match(tq, cq, tf, &(pos->tr)); break; case VARIANT: ok = variant(tq, cq, tf, &(pos->tr)); break; case IDENTICAL: ok = term_ident(tq, tf); break; default: ok = FALSE; break; } if (!ok) tf = next_candidate(pos); } if (ok) { #if 0 printf(" MATE, %d: ", tf->INDEX_ID); p_term(tf); #endif return tf; } else { free_mindex_pos(pos); return NULL; } } } /* mindex_retrieve_next */ /************* * * mindex_retrieve_cancel * *************/ /* DOCUMENTATION This routine should be called if you get some, but not all, answers to a query. For example, if you need only one answer you can do something like the following:
{
  Mindex_pos pos;
  Term t2;
  Context cf = get_context();
  
  t2 = mindex_retrieve_first(t, mdx, GENERALIZATION, (Context) NULL, cf, &pos);
  if (t2 != NULL) {
    printf("we found a mate!\n");
    mindex_retrieve_cancel(pos);
  }
  else
    printf("no answer\n");
  free_context(cf);
}
If you fail to call this routine, then the memory associated with an Mindex_pos will be forever lost, that is, you will have a memory leak. */ /* PUBLIC */ void mindex_retrieve_cancel(Mindex_pos pos) { /* Clean up the unification states. The Mindex_pos doesn't know * what kind of unification applies, so try them all. */ if (pos->tr != NULL) undo_subst(pos->tr); else if (pos->btm_position != NULL) match_bt_cancel(pos->btm_position); else if (pos->btu_position != NULL) unify_bt_cancel(pos->btu_position); if (pos->index->index_type == FPA) fpa_cancel(pos->fpa_position); else if (pos->index->index_type == LINEAR) ; /* do nothing */ else if (pos->index->index_type == DISCRIM_WILD) discrim_wild_cancel(pos->discrim_position); else if (pos->index->index_type == DISCRIM_BIND) discrim_bind_cancel(pos->discrim_position); free_mindex_pos(pos); } /* mindex_retrieve_cancel */ /************* * * fprint_linear_index() * *************/ static void fprint_linear_index(FILE *fp, Plist first) { Plist p; for (p = first; p != NULL; p = p->next) { Term t = p->v; fprintf(fp, "FPA_ID=%u: ", (unsigned) FPA_ID(t)); fprint_term(fp, t); fprintf(fp, "\n"); } } /* fprint_linear_index */ /************* * * fprint_mindex() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) Mindex mdx. */ /* PUBLIC */ void fprint_mindex(FILE *fp, Mindex mdx) { switch (mdx->index_type) { case LINEAR: fprintf(fp, "\nThis is an Mindex of type LINEAR.\n"); fprint_linear_index(fp, mdx->linear_first); break; case FPA: fprintf(fp, "\nThis is an Mindex of type FPA.\n"); fprint_fpa_index(fp, mdx->fpa); break; case DISCRIM_WILD: fprintf(fp, "\nThis is an Mindex of type DISCRIM_WILD.\n"); fprint_discrim_wild_index(fp, mdx->discrim_tree); break; case DISCRIM_BIND: fprintf(fp, "\nThis is an Mindex of type DISCRIM_BIND.\n"); fprint_discrim_bind_index(fp, mdx->discrim_tree); break; } } /* fprint_mindex */ LADR-2009-11A/ladr/hints.h0000644000175000017500000000300111151265364014234 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_HINTS_H #define TP_HINTS_H #include "subsume.h" #include "clist.h" #include "backdemod.h" #include "resolve.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from hints.c */ void init_hints(Uniftype utype, int bsub_wt_attr, BOOL collect_labels, BOOL back_demod_hints, void (*demod_proc) (Topform, int, int, BOOL, BOOL)); void done_with_hints(void); int redundant_hints(void); void index_hint(Topform c); void unindex_hint(Topform c); void adjust_weight_with_hints(Topform c, BOOL degrade, BOOL breadth_first_hints); void keep_hint_matcher(Topform c); void back_demod_hints(Topform demod, int type, BOOL lex_order_vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/html/0000755000175000017500000000000010775516357013724 5ustar mccunemccuneLADR-2009-11A/ladr/html/flatdemod.html0000644000175000017500000000704010775516357016552 0ustar mccunemccune flatdemod.h

#include "flatdemod.h"

This page has information from files flatdemod.h and flatdemod.c.

Contents


Public Routines in File flatdemod.c

Index

discrim_flat_canceldiscrim_flat_retrieve_nextfdemod_clause
discrim_flat_retrieve_firstfapply_demodfdemod_rewrites
discrim_flat_retrieve_leaffdemod_attemptsfdemodulate

Details


void discrim_flat_cancel(Discrim_pos pos);

void *discrim_flat_retrieve_first(Flatterm f, Discrim root,
				  Context subst, Discrim_pos *ppos);

Plist discrim_flat_retrieve_leaf(Flatterm fin, Discrim root,
				 Context subst, Flatterm *ppos);

void *discrim_flat_retrieve_next(Discrim_pos pos);

Flatterm fapply_demod(Term t, Context c);
Special-purpose apply for Flatterm demodulation. Apply a substitution to a (ordinary) Term, building a Flatterm. Assumptions: (1) the terms in the substitution are Flatterms; (2) every variable in the term is bound. In the result, Flatterms that are copied from the substitution have the "reduced_flag" set.
int fdemod_attempts();
Return the number of flatterm rewrite attempts so far.
void fdemod_clause(Topform c, Mindex idx,
		   int *step_limit, int size_limit, BOOL lex_order_vars);
Demodulate Topform c, using demodulators in Mindex idx. If any rewriting occurs, the justification is appended to the clause's existing justification.

This version uses flatterm retrievel.


int fdemod_rewrites();
Return the number of successful flatterm rewrites so far.
Term fdemodulate(Term t, Discrim root,
		 int *step_limit, int size_limit, int *sequence,
		 I3list *just_head, BOOL lex_order_vars);
This routine demodulates a term. ID numbers of demodulators are put on the front of just_head, so you'll probably want to reverse the list before putting it into the clause justification.

This version uses flatterm retrieval.


Public Definitions in File flatdemod.h


Introduction


LADR-2009-11A/ladr/html/listterm.html0000644000175000017500000001057710775516357016467 0ustar mccunemccune listterm.h

#include "listterm.h"

This page has information from files listterm.h and listterm.c.

Contents


Public Routines in File listterm.c

Index

cons_termlistterm_conslistterm_memberlistterm_zap
get_nil_termlistterm_ilistterm_reversenil_term
listterm_appendlistterm_lengthlistterm_to_tlistproper_listterm

Details


BOOL cons_term(Term t);
This function checks if a term is a "cons", that is, arity 2 with the official "cons" symbol.
Term get_nil_term();
Allocate and return an empty listterm.
Term listterm_append(Term list, Term element);
This routine appends an element to a listterm. The resulting listterm is returned. Neither the list nor the element is copied. You should not refer to the argument "list" after calling this routine---a good way to call it is like this:
list = listterm_append(list, element)

If "list" is not a proper_listterm(), the result will be well-formed, but it might not be what you expect.


Term listterm_cons(Term t1, Term t2);
This routine returns the "cons" of two terms. The two terms are not copied.
Term listterm_i(Term lst, int i);
Return the i-th member, counting from 1, of a listterm. If there are less than i members, return NULL.
int listterm_length(Term t);
This function returns the length of a listterm.
BOOL listterm_member(Term t, Term lst);
This function checks if Term t is a member of a listterm (Term lst).
Term listterm_reverse(Term t);
Reverse a listterm. A new list structure is created, but the members are not copied. The old list structure is freed.
Plist listterm_to_tlist(Term t);
Given a proper listterm (e.g, [a,b,c]), return a Plist of the members. The members are not copied.
void listterm_zap(Term t);
Free a list structure, but do not free its members.
BOOL nil_term(Term t);
This function checks if a term is a "nil", that is, arity 0 with the official "nil" symbol.
BOOL proper_listterm(Term t);
This function checks if a term is a proper listterm, that is, a nil_term(), or a cons_term() whose tail is a proper_listterm().

Public Definitions in File listterm.h


Introduction

This package has routines for managing binary-tree lists built from Terms, which allows you to do some LISPy and Prology things. However, you must be careful to keep track of any terms that are shared and to recycle your own garbage.
LADR-2009-11A/ladr/html/clash.html0000644000175000017500000000701510775516360015701 0ustar mccunemccune clash.h

#include "clash.h"

This page has information from files clash.h and clash.c.

Contents


Public Routines in File clash.c

Index

append_clashatom_to_literalfprint_clash_memzap_clash
apply_litclashp_clash_mem

Details


Clash append_clash(Clash p);
This routine simply allocates a new clash node, links it in after the given node, and returns the new node.
Literals apply_lit(Literals lit, Context c);
This routine applies a substitution to a literal and returns the instance. The given literal is not changed.
Literals atom_to_literal(Term atom);
This routine takes an atom and returns its parent literal.
void clash(Clash c,
	   BOOL (*sat_test) (Literals),
	   Just_type rule,
	   void (*proc_proc) (Topform));
This routine takes a complete clash list and computes the resolvents.
  • clash -- a complete clash list corresponding to the nucleus.
  • sat_test -- a Boolean function on clauses which identifies potential satellites (e.g., positive clauses for hyperresolution).
  • rule -- the name of the inference rule for the justification list (see just.h).
  • proc_proc -- procedure for processing resolvents.

void fprint_clash_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the clash package. The Boolean argument heading tells whether to print a heading on the table.
void p_clash_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the clash package.
void  zap_clash(Clash p);
Free a clash list. Contexts in clashable nodes (which are assumed to exist and be empty) are freed as well.

Public Definitions in File clash.h

typedef struct clash  * Clash;

struct clash {
  BOOL       clashable;
  BOOL       clashed;
  BOOL       flipped;  /* Is nuc_lit or sat_lit a flipped equality? */
  Literals    nuc_lit;
  Context    nuc_subst;
  Literals    sat_lit;
  Context    sat_subst;
  Mindex     mate_index;
  Mindex_pos mate_pos;
  Clash      next;
};


Introduction

This package deals with clash structures, which are used for binary resolution, hyperresolution, and UR-resolution. The inference rule sets up a clash list (corresponding to the nucleus), and then calls clash() to compute all of the resolvents.
LADR-2009-11A/ladr/html/topform.html0000644000175000017500000003016410775516357016304 0ustar mccunemccune topform.h

#include "topform.h"

This page has information from files topform.h and topform.c.

Contents


Public Routines in File topform.c

Index

append_label_attributefprint_topform_memp_clauseterm_to_topform
check_upward_clause_linksfsym_set_in_topformsp_topform_memtopform_properties
cl_id_comparefunction_symbols_in_topformrelation_symbols_in_topformtopform_to_term
cl_wt_id_comparefunction_symbols_in_topformsrelation_symbols_in_topformstopform_to_term_without_attributes
clause_set_variablesget_topformrenum_vars_mapupward_clause_links
copy_clauseinherit_attributesrenumber_variableszap_topform
copy_clause_with_flaginitial_clausersym_set_in_topforms
copy_clause_with_flagsmin_depthterm_renumber_variables
fprint_clausenegative_clause_possibly_compressedterm_to_clause

Details


void append_label_attribute(Topform tf, char *s);

BOOL check_upward_clause_links(Topform c);
In the given Topform c, check that the "container" field of each subterm point to c.
Ordertype cl_id_compare(Topform c1, Topform c2);

Ordertype cl_wt_id_compare(Topform c1, Topform c2);

void clause_set_variables(Topform c, int max_vars);
This routine traverses a clause and changes the constants that should be variables, into variables. On input, the clause should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input clauses that are built without regard to variable/constant distinction.


Topform copy_clause(Topform c);
This routine builds and returns a copy of a clause. The container field of each nonvariable subterm points to the clause.
Topform copy_clause_with_flag(Topform c, int flag);
This routine builds and returns a copy of a clause. The given termflag is copied for all subterms (including atoms, excluding variables).
Topform copy_clause_with_flags(Topform c);
This routine builds and returns a copy of a clause. All termflags are copied for all subterms (including atoms, excluding variables).
void fprint_clause(FILE *fp, Topform c);
This routine prints a clause to a file.
void fprint_topform_mem(FILE *fp, int heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the clause package. The Boolean argument heading tells whether to print a heading on the table.
Ilist fsym_set_in_topforms(Plist lst);

I2list function_symbols_in_topform(Topform c, I2list g);
Collect the multiset of function symbols in a clause.
I2list function_symbols_in_topforms(Plist lst);
Collect the multiset of function symbols (including constants) in clauses in a Plist. An I2list of SYMNUMs is returned.
Topform get_topform(void);

void inherit_attributes(Topform par1, Context s1,
			Topform par2, Context s2,
			Topform child);
This takes two parent clauses and their associated substitutions, and a child clause. All inheritable attributes on the parents are instantiated and appended to the child's attributes.

Either parent can be NULL.


BOOL initial_clause(Topform c);
Is (was) the clause part of the initial sos (after processing input clauses, before starting search)/
BOOL min_depth(Literals lit);
Does the Literals have minimum depth of all literals the containing clause?
BOOL negative_clause_possibly_compressed(Topform c);
Is (was) the clause part of the initial sos (after processing input clauses, before starting search)/
void p_clause(Topform c);
This routine prints a clause to stdout.
void p_topform_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the clause package.
I2list relation_symbols_in_topform(Topform c, I2list g);
Collect the multiset of relation symbols in a clause.
I2list relation_symbols_in_topforms(Plist lst);
Collect the multiset of relation symbols (including propositional constants) in clauses in a Plist. An I2list of SYMNUMs is returned.
Plist renum_vars_map(Topform c);

void renumber_variables(Topform c, int max_vars);
This routine renumbers the variables of a clause. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

The intended is use is for inferred clauses that may contain variable indexes greater than max_vars.


Ilist rsym_set_in_topforms(Plist lst);

void term_renumber_variables(Term t, int max_vars);
This routine renumbers the variables of a term. The variables are renumbered 0, 1, 2 ... according the the first occurrence, reading from the left.

If there are more than max_vars distinct variables, a fatal error occurs.

Do not use this to renumber variables of a clause (see renumber_variables).


Topform term_to_clause(Term t);
This routine takes a Term t (presumably a disjunction with binary symbol or_sym()), and constructs a Topform. The Topform is entirely new.

The main use of this routine is intended to be as follows: a Term representing a clause is parsed (using mixfix notation) from the input, then here it is copied translated into a Topform data structure.


Topform term_to_topform(Term t, BOOL is_formula);

Term topform_properties(Topform c);
Construct a term containing a list of miscellaneous properties of a Topform. This is meant to be used as an attribute on Topforms for debugging.
Term topform_to_term(Topform tf);
This routine takes a Topform and returns an entirely new Term which represents the clause. The disjunction symbol for the term is binary or_sym(), and the negation symbols is not_sym(). The attributes are included, but not the id or justifiction.
Term topform_to_term_without_attributes(Topform tf);
This routine takes a Topform and returns an entirely new Term which represents the clause. The disjunction symbol for the term is binary or_sym(), and the negation symbols is not_sym(). The attributes, id, and justifiction are NOT included.
void upward_clause_links(Topform c);
In the given Topform c, make the "container" field of each subterm point to c.
void zap_topform(Topform tf);
This routine frees a Topform (but not any justification list). The caller should make sure that nothing (e.g., indexes) refer to the clause or any of its subterms.

If the clause has a justification or an official ID, use the higher-level routine delete_clause(c) instead.


Public Definitions in File topform.h

typedef struct topform * Topform;

struct topform {

  /* for both clauses and formulas */

  int              id;
  struct clist_pos *containers;     /* Clists that contain the Topform */
  Attribute        attributes;
  struct just      *justification;
  int              weight;
  char             *compressed;     /* if nonNULL, a compressed form */

  /* for clauses only */

  Literals         literals;        /* NULL can mean the empty clause */

  /* for formulas only */

  Formula          formula;

  int   semantics;        /* evaluation in interpretations */

  /* The rest of the fields are flags.  These could be bits. */

  char   is_formula;      /* is this really a formula? */
  char   normal_vars;     /* variables have been renumbered */
  char   used;            /* used to infer a clause that was kept */
  char   official_id;     /* Topform is in the ID table */
  char   initial;         /* existed at the start of the search */
  char   neg_compressed;  /* negative and compressed */
  char   matches_hint;    /* does this clause match a hint? */
  char   subsumer;        /* has this clause back subsumed anything? */

};


Introduction

A Topform can be used to store a formula or a clause. The field is_formula says which it is.

In earlier versions of LADR, this data structure was called Clause. When we decided to put non-clausal formulas in proofs, they needed to have IDs, attributes, and justifications, so we elevated the data structure to include non-clausal formulas and changed the name to Topform (top formula).

In many cases, when we say "clause", we mean a list of Literals. For example, most of the functions that tell the properties of clauses (positive_clause, number_of_literals, etc.) take a list of Literals, not a Topform.

If C had data structures with inheritance, this would be a good place to use it.


LADR-2009-11A/ladr/html/discrim.html0000644000175000017500000001212410775516357016244 0ustar mccunemccune discrim.h

#include "discrim.h"

This page has information from files discrim.h and discrim.c.

Contents


Public Routines in File discrim.c

Index

destroy_discrim_treediscrim_initfree_discrim_posp_discrim_mem
discrim_deallocfprint_discrim_memget_discrim
discrim_emptyfree_discrimget_discrim_pos

Details


void destroy_discrim_tree(Discrim d);
This routine frees all the memory associated with a discrimination index. It can be used with either wild or tame trees.
void discrim_dealloc(Discrim d);
This routine frees an empty discrimination index (wild or tame).
BOOL discrim_empty(Discrim d);
This Boolean function checks if a discrimination index is empty. It can be used with either wild or tame trees.
Discrim discrim_init(void);
This routine allocates and returns an empty discrimination index. It can be used for either wild or tame indexing.
void fprint_discrim_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrim package. The Boolean argument heading tells whether to print a heading on the table.
void free_discrim(Discrim p);

void free_discrim_pos(Discrim_pos p);

Discrim get_discrim(void);

Discrim_pos get_discrim_pos(void);
The structure is not initialized.
void p_discrim_mem(void);
This routine prints (to stdout) memory usage statistics for data types associated with the discrim package.

Public Definitions in File discrim.h

typedef struct discrim * Discrim;

struct discrim {       /* node in a discrimination tree */
  Discrim   next;      /* sibling */
  union {
    Discrim kids;      /* for internal nodes */
    Plist data;        /* for leaves */
  } u;
  short symbol;        /* variable number or symbol number */
  char type;           /* term type and for ac indexing type */
};

typedef struct discrim_pos * Discrim_pos;

struct discrim_pos {  /* to save position in set of answers */
  void    *query;
  Context subst;        /* substitution */
  Plist   data;         /* identical terms from leaf of discrim tree */
  void    *backtrack;   /* data for backtracking */
};

/* type of discrimination tree node */

enum { DVARIABLE, DRIGID, AC_ARG_TYPE, AC_NV_ARG_TYPE };

#define DVAR(d)  ((d)->type == DVARIABLE)


Introduction

This package implements two kinds of discrimination indexing for first-order terms. Both kinds support GENERALIZATION retrieval only (e.g., for forward demodulation and forward subsumption).

The "wild" kind is an imperfect filter, and it does not bind variables. The caller must also call a routine, say match(), to check if the answers are really more general than the query term and to construct the substitution. Wild indexing supports associative-commutative (AC) and commutative (C) symbols. Indexing terms with AC symbols works by considering the number of arguments and the number of nonvariable arguments of AC terms that do not occur in other AC terms. (The term "wild" is used because all variables in the discrimination tree are treated as the the wildcard symbol *).

With the "bind" kind, every answer is more general than the query term, and the matching substitution is constructed during the retrieval. Wild indexing supports commutative (C) symbols, but it does not support associative-commutative (AC) symbols. Retrieval with C symbols can produce duplicate answers.

There is probably a higher-level package (mindex ?) which provides a uniform interface to these and other indexing methods.


LADR-2009-11A/ladr/html/hints.html0000644000175000017500000000373510775516360015741 0ustar mccunemccune hints.h

#include "hints.h"

This page has information from files hints.h and hints.c.

Contents


Public Routines in File hints.c

Index

adjust_weight_with_hintsdone_with_hintsinit_hintsunindex_hint
back_demod_hintsindex_hintredundant_hints

Details


void adjust_weight_with_hints(Topform c,
			      BOOL degrade,
			      BOOL breadth_first_hints);

void back_demod_hints(Topform demod, int type, BOOL lex_order_vars);

void done_with_hints(void);

void index_hint(Topform c);
Index a clause C as a hint (make sure to call init_hints first). If the clause is equivalent to a previously indexed hint H, any labels on C are copied to H, and C is not indexed.
void init_hints(Uniftype utype,
		int bsub_wt_attr,
		BOOL collect_labels,
		BOOL back_demod_hints,
		void (*demod_proc) (Topform, int, int, BOOL, BOOL));

int redundant_hints(void);

void unindex_hint(Topform c);

Public Definitions in File hints.h


Introduction


LADR-2009-11A/ladr/html/top_input.html0000644000175000017500000001003710775516360016626 0ustar mccunemccune top_input.h

#include "top_input.h"

This page has information from files top_input.h and top_input.c.

Contents


Public Routines in File top_input.c

Index

accept_listinit_standard_ladrprocess_input_formulasread_commands
embed_formulas_in_topformsp_top_input_memprocess_opread_from_file
flag_handlerparm_handlerprocess_redeclareset_program_name
fprint_top_input_memprocess_goal_formulasread_all_input

Details


void accept_list(char *name, int type, Plist *l);

Plist embed_formulas_in_topforms(Plist formulas, BOOL assumption);
The formulas are not copied. Any attributes on the top of the formula are moved to the Topform. An ID is not assigned. Topforms get the justifiction "input".
void flag_handler(FILE *fout, Term t, BOOL echo, int unknown_action);

void fprint_top_input_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the top_input package. The Boolean argument heading tells whether to print a heading on the table.
void init_standard_ladr(void);
This routine initializes various LADR packaages.
void p_top_input_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the top_input package.
void parm_handler(FILE *fout, Term t, BOOL echo, int unknown_action);

Plist process_goal_formulas(Plist formulas, BOOL echo);

Plist process_input_formulas(Plist formulas, BOOL echo);
Input is Plist of Topforms containing formulas.
void process_op(Term t, BOOL echo, FILE *fout);

void process_redeclare(Term t, BOOL echo, FILE *fout);

void read_all_input(int argc, char **argv, FILE *fout,
		    BOOL echo, int unknown_action);

Term read_commands(FILE *fin, FILE *fout, BOOL echo, int unknown_action);
This is a legacy routine.
void read_from_file(FILE *fin, FILE *fout, BOOL echo, int unknown_action);

void set_program_name(char *name);

Public Definitions in File top_input.h

/* Types of object that can be input */

enum { TERMS, FORMULAS };

/* What shall we do if we read an unknown flag or parameter? */

enum {
  IGNORE_UNKNOWN,
  NOTE_UNKNOWN,
  WARN_UNKNOWN,
  KILL_UNKNOWN
};


Introduction


LADR-2009-11A/ladr/html/term.html0000644000175000017500000006073010775516357015567 0ustar mccunemccune term.h

#include "term.h"

This page has information from files term.h and term.c.

Contents


Public Routines in File term.c

Index

all_args_varsget_rigid_termplist_of_subtermsterm1
arg_positionget_rigid_term_dangerouslyposition_of_subtermterm2
args_distinct_varsget_rigid_term_likeposition_of_term_in_tlistterm_at_pos
biggest_variableget_variable_termrenum_vars_recurseterm_depth
build_binary_termgreatest_symnum_in_termsame_structureterm_ident
build_binary_term_safegreatest_variableset_of_ivariablesterm_set_variables
build_unary_termground_termset_of_ivarsterm_symbol
build_unary_term_safehash_termset_of_variablesterm_to_int
check_upward_term_linksint_to_termset_of_varstlist_member
contains_skolem_functionis_constantset_vars_recursetlist_set
contains_skolem_termis_termskolem_termtlist_subset
copy_plist_of_termsmultiset_of_varssprint_termupward_term_links
copy_termmultiset_varssubst_termvariables_multisubset
eq_termnat_to_termsubst_var_termvariables_subset
fprint_termnatural_constant_termsymbol_countzap_plist_of_terms
fprint_term_memoccurrencessymbol_in_termzap_term
free_termoccurs_insymbol_occurrences
free_vars_termp_termsymbols_in_term
fsym_set_in_termp_term_memterm0

Details


BOOL all_args_vars(Term t);
This Boolean routine checks if all argumets of Term t are VARIABLEs. (It is true also if t is a VARIABLE.)
int arg_position(Term parent, Term child);
If the given terms are in a parent-child relatioship, return the argument position (index) of the child. Otherwise, return -1.
BOOL args_distinct_vars(Term t);
Is the Term a nonvariable with distinct variables as arguments? (Constants satisfy this.)
int biggest_variable(Term t);
This routine returns the greatest variable index of any variable int the given term t. If t is ground, -1 is returned.
Term build_binary_term(int sn, Term a1, Term a2);
Build and return a binary term with SYMNUM sn, first term a1, and second term a2.

WARNING: if sn is not a binary symbol, bad things will happen!


Term build_binary_term_safe(char *str, Term a1, Term a2);
Build and return a binary term with root str, first term a1, and second term a2.

If you know the symnum, and you're certain it has arity 2, you can use the faster routine build_binary_term() instead;


Term build_unary_term(int sn, Term a);
Build and return a unary term with SYMNUM sn and argument term a.

WARNING: if sn is not a unary symbol, bad things will happen!


Term build_unary_term_safe(char *str, Term a);
Build and return a unary term with root str, argument a.

If you know the symnum, and you're certain it has arity 1, you can use the faster routine build_unary_term() instead;


BOOL check_upward_term_links(Term t, void *p);
In the given Term t, check that the "container" field of t and each subterm, except variables, point to (void *) p.
BOOL contains_skolem_function(Term t);

BOOL contains_skolem_term(Term t);

Plist copy_plist_of_terms(Plist terms);

Term copy_term(Term t);
This routine copies a term. Only the symbols and structure are copied---any extra fields such as bits or u are NOT copied.
BOOL eq_term(Term a);
This function checks if an atom is an equality atom (positive or negative) for the purposes of paramodulation and demodulation.
void fprint_term(FILE *fp, Term t);
This routine prints (to FILE *fp) a term. A newline is NOT printed.
void fprint_term_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for Terms. The Boolean argument heading tells whether to print a heading on the table.
void free_term(Term p);
This routine frees a term node only. To recursively free all of the subterms as well, call zap_term(t) instead.
Plist free_vars_term(Term t, Plist vars);
Return the set of constants that look like variables. The terms are newly constructed; if they are not used, the list should be deallocated with zap_tlist().
Ilist fsym_set_in_term(Term t);

Term get_rigid_term(char *sym, int arity);
This routine allocates and returns a term node with the given symbol and arity. If you already have a similar term node, say t, (containing the symbol and arity you need) call get_rigid_term_like(t) instead.
Term get_rigid_term_dangerously(int symnum, int arity);
This routine can be used to allocate a term node if all you have is the symbol ID and arity. If the arity is not correct for the symbol ID, terrible things will happen!

If you have a similar term, use get_rigid_term_like() instead. If you can afford the time to access the symbol table, use sn_to_str() and get_rigid_term() instead.


Term get_rigid_term_like(Term t);
This routine allocates and returns a term node with the same symbol and arity as the given Term t.
Term get_variable_term(int var_num);
This routine returns a term of type VARIABLE. The index of the variable is set to var_num, which should be an integer >= 0.
int greatest_symnum_in_term(Term t);
This function returns the greatest SYMNUM (of a CONSTANT or COMPLEX term) in the given Term t. If the term is a VARIABLE, return -1.
int greatest_variable(Term t);
This routine returns the greatest variable index in a term. If the term is ground, -1 is returned.
BOOL ground_term(Term t);
This function checks if a term is ground, that is, has no variables.
unsigned hash_term(Term t);

Term int_to_term(int i);
This routine takes an integer and returns the Term representation.
BOOL is_constant(Term t, char *str);
Is term t a specific constant?
BOOL is_term(Term t, char *str, int arity);
Does term t have the the given symbol and arity?
I2list multiset_of_vars(Term t, I2list vars);

I2list multiset_vars(Term t);

Term nat_to_term(int n);
This routine takes a nonnegative integer and returns a constant Term with the string representation of the integer as the constant symbol.
int natural_constant_term(Term t);
This routine takes a term, and if the term represents an nonnegative integer, that integer is returned; otherwise, -1 is returned.
int occurrences(Term t, Term target);
This function returns the number of occurrences of Term target in Term t. The checks are made with term_ident().
BOOL occurs_in(Term t1, Term t2);
This function checks if Term t2 is identical to a subterm of Term t1, including the case term_ident(t1,t2). All identity checks are done with term_ident(), so extra fields such as bits or u are not checked.
void p_term(Term t);
This routine prints a term, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_term() instead. If you want the term put into a string, use sprint_term() instead.
void p_term_mem(void);
This routine prints memory usage statistics for Terms to stdout.
Plist plist_of_subterms(Term t);

Ilist position_of_subterm(Term t, Term subterm);

int position_of_term_in_tlist(Term t, Plist lst);

Term renum_vars_recurse(Term t, int vmap[], int max_vars);
This routine renumbers the variables of a term. It is assumed that vmap has been filled with -1 on the initial call and that the size of vmap is at least max_vars.

This returns a Term instead of being void, in case the given term is itself a variable. (Recall that variables may be shared, so we can't just change a variable's index.


BOOL same_structure(Term a, Term b);
If variables are ignored, are the terms identical?
Ilist set_of_ivariables(Term t);
Given a Term, return the set of integers corresponding to its variables.
Ilist set_of_ivars(Term t, Ilist ivars);
See set_of_ivariables(t).
Plist set_of_variables(Term t);
Given a Term, return the set of variables.
Plist set_of_vars(Term t, Plist vars);
See set_of_variables(t).
Term set_vars_recurse(Term t, char *vnames[], int max_vars);
This routine sets the variables of a term. It is assumed that vnames has been filled with NULL on the initial call and that the size of vnames is at least max_vars.

This returns a Term instead of being void, in case the given term is itself becomes a variable.


BOOL skolem_term(Term t);

void sprint_term(String_buf sb, Term t);
This (recursive) routine appends the string representation of a term to a String_buf. A newline is not included.
Term subst_term(Term t, Term target, Term replacement);
In term t, replace all occurrences of Term target with copies of Term replacement. Free all of the replaced terms;
Term subst_var_term(Term t, int symnum, int varnum);
In Term t, replace all CONSTANT terms containing SYMNUM symnum with a variable containing VARNUM varnum. Free the replaced constants and return the result.
int symbol_count(Term t);
This routine returns the total number of symbols (i.e., the number of nodes) in the given term t.
BOOL symbol_in_term(int symnum, Term t);

int symbol_occurrences(Term t, int symnum);
Return the number of occurrences of a symbol in a term.
I2list symbols_in_term(Term t, I2list g);
This routine collects the multiset of nonvariable symbols in a term. An Ilist of symbol IDs (symnums) is returned
Term term0(char *sym);
Build constant Term.
Term term1(char *sym, Term arg);
Build a unary term. The argument Term is not copied.
Term term2(char *sym, Term arg1, Term arg2);
Build a binary term. The argument Terms are not copied.
Term term_at_pos(Term t, Ilist pos);

int term_depth(Term t);
Return the depth of a term. Variables and constants have depth 0.
BOOL term_ident(Term t1, Term t2);
This function checks if two terms are identical. Only the structure and symbols are checked---any extra fields such as bits or u are NOT checked.
void term_set_variables(Term t, int max_vars);
This routine traverses a term and changes the constants that should be variables, into variables. On input, the term should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

If you are dealing with clauses, use clause_set_variables() instead.


char *term_symbol(Term t);
Return the print string associated with the given nonvariable term. If the term is a variable, return NULL.
BOOL term_to_int(Term t, int *result);
Given a term, see if it represents an integer. If so, set *result to the integer and return TRUE. If not, return FALSE.

The term representation of a negative integer is the function symbol "-" applied to a nonnegative integer.


BOOL tlist_member(Term t, Plist lst);
This function checks if a term is a member of a Plist. The function term_ident(t1,t2) is used.
BOOL tlist_set(Plist a);

BOOL tlist_subset(Plist a, Plist b);

void upward_term_links(Term t, void *p);
In the given Term t, make the "container" field of t and each subterm, except variables, point to (void *) p.
BOOL variables_multisubset(Term a, Term b);

BOOL variables_subset(Term t1, Term t2);

void zap_plist_of_terms(Plist lst);
Free a Plist of terms.
void zap_term(Term t);
This routine frees a term t and all of its subterms. You should not refer to t after calling zap_term(t).

Public Definitions in File term.h

#define MAX_VARS  100   /* max number of (distinct) variables per term */
#define MAX_VNUM  5000  /* maximum variable ID, for array of vars */

#define MAX_VAR   INT_MAX     /* max var ID that fits in sym field of term */
#define MAX_SYM   INT_MAX     /* max ID of any rigid symbol */
#define MAX_ARITY UCHAR_MAX   /* max arity of any term (don't make this big) */

#define FLAGS_TYPE unsigned char  /* for private_flags field of Term */

typedef struct term * Term;     /* Term is a pointer to a term struct */

struct term {
  int            private_symbol; /* const/func/pred/var symbol ID */
  unsigned char  arity;          /* number of auguments */
  FLAGS_TYPE     private_flags;  /* for marking terms in various ways */
  Term           *args;          /* array (size arity) of pointers to args */
  void           *container;     /* containing object */
  union {
    unsigned     id;             /* unique ID, probably for FPA indexing */
    void         *vp;            /* auxiliary pointer */
  } u;
};

/* to check type of term */
#define VARIABLE(t) ((t)->private_symbol >= 0)
#define CONSTANT(t) ((t)->private_symbol < 0 && (t)->arity == 0)
#define COMPLEX(t)  ((t)->private_symbol < 0 && (t)->arity > 0)

/* to get symbol ID from a CONSTANT or COMPLEX term */
#define SYMNUM(t)   (-((t)->private_symbol))

/* to get the variable number of a VARIABLE term */
#define VARNUM(t)   ((t)->private_symbol)

/* to get the arity of a term (VARIABLE terms have arity 0) */
#define ARITY(t)    ((t)->arity)

/* to get the i-th argument of a term (make sure i is in [0..arity-1]) */
#define ARG(t,i)    ((t)->args[i])

/* to get the array of arguments */
#define ARGS(t)    ((t)->args)


Introduction

The Term data structure is designed mainly to represent first-order untyped terms. It is generally used for atoms as well, because the indexing and unification methods don't care whether an object is a term or an atom.

No term structure sharing is supported at this level of abstraction. (Higher-level packagers can build terms with shared structure if they wish.) Because we envision applications with tens of millions of terms, small size for the individual nodes is important. So we have some overloaded fields, and macros are provided to get some of the information from from term nodes.

There are three types of term, and the Boolean macros VARIABLE(t), CONSTANT(t), and COMPLEX(t) should be used to find out what type a term is. If you have a CONSTANT or COMPLEX term t, you can get its symbol id with SYMNUM(t) (from which you can get other information about the symbol such as the print string and any special properties). If you have a variable t, you can get its index with VARNUM(t), which is a signed integral type in the range [0..MAX_VAR]. Warning: MAX_VAR is a big number---a higher-level unification package will typically have a much smaller MAX_VARS defined for array sizes, because it does array indexing with VARNUM(t).

The macro ARITY(t) gets the arity of a term (constants and variables have arity 0), and ARG(t,i) gets the i-th argument (counting from 0) of a term. When using ARG(t,i), make sure that i is in range [0..ARITY(t)-1], because ARG does not check.

Here is an example of recursing through a term.

int symbol_count(Term t)
{
  int count = 0;
  int i;
  for (i = 0; i < ARITY(t); i++)
    count += symbol_count(ARG(t,i));
  return count+1;
}

LADR-2009-11A/ladr/html/hash.html0000644000175000017500000000435110775516356015537 0ustar mccunemccune hash.h

#include "hash.h"

This page has information from files hash.h and hash.c.

Contents


Public Routines in File hash.c

Index

fprint_hash_memhash_destroyhash_inithash_lookup
hash_deletehash_infohash_insertp_hash_mem

Details


void fprint_hash_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the hash package. The Boolean argument heading tells whether to print a heading on the table.
void hash_delete(void *v, unsigned hashval, Hashtab h,
		 BOOL (*id_func) (void *, void *));

void hash_destroy(Hashtab h);
Free all of the memory used by the given hash table. Do not refer to the table after calling this routine. The hash table need not be empty;
void hash_info(Hashtab h);

Hashtab hash_init(int size);
Allocate and initialize a hash table of the given size.
void hash_insert(void *v, unsigned hashval, Hashtab h);

void *hash_lookup(void *v, unsigned hashval, Hashtab h,
		  BOOL (*id_func) (void *, void *));

void p_hash_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the hash package.

Public Definitions in File hash.h


Introduction


LADR-2009-11A/ladr/html/fpalist.html0000644000175000017500000001025210775516357016254 0ustar mccunemccune fpalist.h

#include "fpalist.h"

This page has information from files fpalist.h and fpalist.c.

Contents


Public Routines in File fpalist.c

Index

first_fposfpalist_insertnext_fposzap_fpa_chunks
fpalist_deletefprint_fpalist_memp_fpa_listzap_fpalist
fpalist_emptyget_fpa_listp_fpalist_mem

Details


struct fposition first_fpos(Fpa_list f);

void fpalist_delete(Fpa_list p, Term t);

BOOL fpalist_empty(Fpa_list p);

void fpalist_insert(Fpa_list p, Term t);

void fprint_fpalist_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpalist package. The Boolean argument heading tells whether to print a heading on the table.
Fpa_list get_fpa_list();

struct fposition next_fpos(struct fposition p);

void p_fpa_list(Fpa_chunk c);

void p_fpalist_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the fpalist package.
void zap_fpa_chunks(Fpa_chunk p);

void zap_fpalist(Fpa_list p);

Public Definitions in File fpalist.h

/* We use the Term ID to order FPA lists. */

#define FPA_ID_TYPE unsigned
#define FPA_ID_MAX UINT_MAX
#define FPA_ID(t) (((Term) t)->u.id)

/*
  I experimented with using the address of the term as the
  term ID for ordering FPA lists.  Although not technically
  legal in C (because addresses in different arrays (malloced blocks)
  are compared), I believe it works correctly on all modern systems.
  (It didn't work in DOS.)
  However, there is a practical problem.
  On some systems, malloc() returns addresses in increasing order,
  and on others, they are decreasing, giving answers to queries in
  the reverse order, causing different searches.

  define FPA_ID_TYPE Term
  define FPA_ID_MAX ((Term) ULONG_MAX) //
  define FPA_ID(t) ((Term) t)
*/

#define FLT(x,y) (FPA_ID(x) <  FPA_ID(y))
#define FGT(x,y) (FPA_ID(x) >  FPA_ID(y))
#define FLE(x,y) (FPA_ID(x) <= FPA_ID(y))
#define FGE(x,y) (FPA_ID(x) >= FPA_ID(y))

#define FTERM(p) ((p).f == NULL ? NULL : (p).f->d[(p).i])

/* FPA lists */

typedef struct fpa_chunk *Fpa_chunk;
typedef struct fpa_list *Fpa_list;

struct fpa_chunk {
  int size;         /* size of array */
  Term *d;          /* array for chunk */
  int n;            /* current number of items in chunk (right justified) */
  Fpa_list head;    /* beginning of list to which this chunk belongs */
  Fpa_chunk next;   /* list of chunks is singly-linked */
};

struct fpa_list {
  Fpa_chunk chunks;
  int num_chunks;
  int chunksize;
  int num_terms;
};

/* to maintain a position in an FPA list while traversing for set operations */

struct fposition {
  Fpa_chunk f;
  int i;
};


Introduction


LADR-2009-11A/ladr/html/nonport.html0000644000175000017500000000306110775516356016310 0ustar mccunemccune nonport.h

#include "nonport.h"

This page has information from files nonport.h and nonport.c.

Contents


Public Routines in File nonport.c

Index

get_bitshostnamemy_process_idusername

Details


int get_bits(void);
If (64-bit long and pointer) return 64, else return 32.
char *hostname(void);
Return the hostname of the computer on which the current job is running.
int my_process_id(void);
Return the process ID of the current process.
char *username(void);
Return the name of the user who started the current job.

Public Definitions in File nonport.h


Introduction

This package has some utilities that might not be portable to other environments. If you get errors trying to compile this package, you can either modify nonport.c, or
#define PRIMITIVE_ENVIRONMENT
in nonport.h, which disables everything.
LADR-2009-11A/ladr/html/string.html0000644000175000017500000000553210775516356016124 0ustar mccunemccune string.h

#include "string.h"

This page has information from files string.h and string.c.

Contents


Public Routines in File string.c

Index

initial_substringnew_str_copystr_to_intwhich_string_member
itoareverse_charsstring_member
natural_stringstr_identsubstring

Details


BOOL initial_substring(char *x, char *y);
Is x an initial substring of y?
char *itoa(int n, char *s);
This routine converts an integer to a string (in decimal form). The character array s must be large enough to hold the string. The string is returned.
int natural_string(char *str);

char *new_str_copy(char *str);
Return a malloced copy of the given string. To avoid memory leaks, call free() on the copy if you finish referring to it.
void reverse_chars(char *s, int start, int end);
This routine reverses an array of characters. You must give the starting and ending positions.
BOOL str_ident(char *s, char *t);
This function routine checks identity of two strings.
BOOL str_to_int(char *str, int *ip);
This routine tries to convert a string into an integer (using strtol()). If successful, TRUE is returned and *ip is set to the integer. If failure, FALSE is returned.
BOOL string_member(char *string, char **strings, int n);
Is "string" a member of an array of "strings"?
BOOL substring(char *x, char *y);
Is x a substring of y?
int which_string_member(char *string, char **strings, int n);
If "string" is a member of an array of "strings", return the index; else return -1.

Public Definitions in File string.h


Introduction

This package contains a few utilities for character strings.
LADR-2009-11A/ladr/html/random.html0000644000175000017500000000705610775516357016102 0ustar mccunemccune random.h

#include "random.h"

This page has information from files random.h and random.c.

Contents


Public Routines in File random.c

Index

random_clauserandom_nonvariable_termrandom_pathrandom_term
random_complex_termrandom_op_termrandom_permutation

Details


Topform random_clause(int v, int a0, int a1, int a2, int a3,
		     int max_depth, int max_lits);
This routin builds and returns a random clause. The arguments are like random_term(), with an extra argument giving the maximum number of literals.
Term random_complex_term(int v, int a0, int a1, int a2, int a3,
			     int max_depth);
This is like random_term(), except that the returned term will not be a variable or a constant. Subterms may be variables or constants.
Term random_nonvariable_term(int v, int a0, int a1, int a2, int a3,
			     int max_depth);
This is like random_term(), except that the returned term will not be a variable. Subterms may be variables.
Term random_op_term(int depth);

Ilist random_path(int length_max, int value_max);
This routine returns a random-length list of random integers. The range for the length is [1..length_max], and the range for the values is [1..value_max].
void random_permutation(int *a, int size);
This routine places a random permtation of [0..size-1] into the array a. (The randomness is not very good.)
Term random_term(int v, int a0, int a1, int a2, int a3,
		 int max_depth);
This routine generates a random term, with depth <= max_depth, and with subterms of arity <= 3. The parameters [v, a0, a1, a2, a3] tells how many variables (named v0,v1,...), constants (named a0,a1,...), unary (named g0,g1,...), binary (named f0,f1,...), ternary (named h0,h1,...), symbols to select from. For example,
random_term(3, 2, 1, 1, 0, 5)
asks for a term, of depth <= 5, with <= 3 variable, <= 2 constant, <= 1 unary, <=1 binary, and 0 ternary symbols.

Public Definitions in File random.h


Introduction

These are some routines I used for testing and debugging some of the low-level code. The main reason I wrote these is so that I could write and test the early code without having to input terms. Maybe I'll see how far I can go before I have to write a term parser.

And, who knows, maybe the next big breakthrough in automated theorem proving will depend on randonly generated terms!


LADR-2009-11A/ladr/html/subsume.html0000644000175000017500000001007510775516357016300 0ustar mccunemccune subsume.h

#include "subsume.h"

This page has information from files subsume.h and subsume.c.

Contents


Public Routines in File subsume.c

Index

back_subsumeforward_subsumesubsumesunit_delete
back_subsume_onenonunit_subsumption_testssubsumes_bt
back_unit_del_by_indexsimplify_literalstry_unit_conflict
eq_removable_literalsimplify_literals2unit_conflict_by_index

Details


Plist back_subsume(Topform c, Lindex idx);
Look in the index and return the list of clauses subsumed by c.
Topform back_subsume_one(Topform c, Lindex idx);
Look in the index for a clause subsumed by c. The first one found is returned. (It is not necessarily the first of the subsumees that was inserted into the index.)
Plist back_unit_del_by_index(Topform unit, Lindex idx);
Given a unit clause and a literal index, return the Plist of clauses containing literals that are instances of the negation of the unit clause.

Such clauses can be "back unit deleted".


BOOL eq_removable_literal(Topform c, Literals lit);
Can a literal in a clause be removed by resolution with x=x without instantiating any other literal in the clause?

If so, instantiate any inheritable (e.g., answer) attributes with the corresponding substitution.


Topform forward_subsume(Topform d, Lindex idx);

int nonunit_subsumption_tests(void);

void simplify_literals(Topform c);
Remove any literals t!=t.
void simplify_literals2(Topform c);
1. If there are any literals t=t, the clause becomes true_sym(). 2. Remove any literals t!=t. 3. If there are any literals s!=t, where unify(s,t), without instantiating any other literals, remove the literal.
BOOL subsumes(Topform c, Topform d);
This routine checks if Topform c subsumes Topform d. Ordinary unification is used; in particular, symmetry of equality is not built in.


BOOL subsumes_bt(Topform c, Topform d);
This routine checks if Topform c subsumes Topform d. Backtrack unification is used; in particular, AC and commutative/symmetric matching are applied where appropriate.
Topform try_unit_conflict(Topform a, Topform b);

void unit_conflict_by_index(Topform c, Lindex idx, void (*empty_proc) (Topform));
Look in idx for unit conflicts
void unit_delete(Topform c, Lindex idx);
Given a clause and a literal index, remove the literals that can be removed by "unit deletion" with units in the index. Update the clause's justification for each removed literal.

Public Definitions in File subsume.h


Introduction


LADR-2009-11A/ladr/html/memory.html0000644000175000017500000000665010775516356016130 0ustar mccunemccune memory.h

#include "memory.h"

This page has information from files memory.h and memory.c.

Contents


Public Routines in File memory.c

Index

bytes_pallocedfree_memmega_mem_callsset_max_megs
disable_max_megsget_cmemmegs_mallocedset_max_megs_proc
enable_max_megsget_memmemory_reporttp_alloc

Details


int bytes_palloced(void);
How many bytes have been allocated by the palloc() routine? This includes all of the get_mem() calls.
void disable_max_megs(void);

void enable_max_megs(void);

void free_mem(void *q, unsigned n);
Free a chunk of memory that holds n pointers (not n bytes) that was returned from a previous get_mem() or get_cmem() call.
void *get_cmem(unsigned n);
Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is initialized to all 0.
void *get_mem(unsigned n);
Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is NOT initialized.
unsigned mega_mem_calls(void);

int megs_malloced(void);
This routine returns the number of megabytes that palloc() has obtained from the operating system by malloc();
void memory_report(FILE *fp);

void set_max_megs(int megs);
This routine changes the limit on the amount of memory obtained from malloc() by palloc(). The argument is in megabytes. The default value is DEFAULT_MAX_MEGS.
void set_max_megs_proc(void (*proc)(void));
This routine is used to specify the routine that will be called if max_megs is exceeded.
void *tp_alloc(size_t n);
Allocate n bytes of memory, aligned on a pointer boundary. The memory is not initialized, and it cannot be freed.

Public Definitions in File memory.h

/* The following definitions exist because the memory get/free
   routines measure memory by pointers instead of bytes. */

#define CEILING(n,d)   ((n)%(d) == 0 ? (n)/(d) : (n)/(d) + 1)
#define BYTES_POINTER  sizeof(void *)  /* bytes per pointer */
#define PTRS(n)        CEILING(n, BYTES_POINTER) /* ptrs needed for n bytes */


Introduction


LADR-2009-11A/ladr/html/tptp_trans.html0000644000175000017500000000354110775516360017005 0ustar mccunemccune tptp_trans.h

#include "tptp_trans.h"

This page has information from files tptp_trans.h and tptp_trans.c.

Contents


Public Routines in File tptp_trans.c

Index

declare_tptp_parse_typesmap_for_bad_tptp_symssyms_in_form
ladr_list_to_tptp_listreplace_bad_tptp_syms_formtptp_input_to_ladr_formula

Details


void declare_tptp_parse_types(void);

Plist ladr_list_to_tptp_list(Plist in, char *name, char *type);

I2list map_for_bad_tptp_syms(Ilist syms);

Term replace_bad_tptp_syms_form(Term t, BOOL clausal, I2list map);

Ilist syms_in_form(Term t, BOOL clausal);

Formula tptp_input_to_ladr_formula(Term t);

Public Definitions in File tptp_trans.h


Introduction


LADR-2009-11A/ladr/html/fastparse.html0000644000175000017500000001063710775516357016611 0ustar mccunemccune fastparse.h

#include "fastparse.h"

This page has information from files fastparse.h and fastparse.c.

Contents


Public Routines in File fastparse.c

Index

fast_fwrite_clausefast_read_clausefast_set_defaults
fast_fwrite_term_nlfast_read_termfast_set_symbol

Details


void fast_fwrite_clause(FILE *fp, Topform c);
This routine writes a clause in fastparse form.
void fast_fwrite_term_nl(FILE *fp, Term t);
This routine writes a term in prefix form, without parentheses, commas, or spaces, followed by ".\n". If a variable number is >= 9, then '?' is printed for that variable.

If each symbol is one character, then terms written by this routine should be readable by fast_read_term().

There is nothing particularly "fast" about this routine.


Topform fast_read_clause(FILE *fin, FILE *fout);
This routine reads a clause in fast-parse form.

If the clause has more than one literal, then '|' must first be declared as binary with fast_set_symbol(), and if the clause has any negative literals, then '~' must first be declared as unary.

For example, the fast-parse form of p(a,b) | ~q | ~(f(x)=x) is

|pab|~q~=fxx.

Term fast_read_term(FILE *fin, FILE *fout);
This routine reads a prefix term.
  • The term must start on a new line and end with a period.
  • Without parentheses, commas, or spaces.
  • Each symbol is one character.
  • Variables are 'r' -- 'z'.
  • Symbols with arity > 0 (including '=') must declared first by calling fast_set_symbol().
  • If the first character is '%', the line is a comment and sent directly to the output stream fout.
  • Example:
    =mxxx.
    =jxyjyx.
    =jxxmxx.
    =jjxyzjxjyz.
    

void fast_set_defaults(void);
Call this routine to declare a fixed set of symbols for fast parsing.
  • binary: [=mjfd*+/]
  • unary: [cgi-~']
The defaults can be overridden by nsubsequent calls to fast_set_symbol
void fast_set_symbol(char c, int arity);
Call this routine to declare a symbol/arity for fast parsing. Since fast parsing handles single-characters symbols only, you send character/arity to this routine.

For fast parsing, variables are always 'r' -- 'z', and those symbols should not be declared.

Also, you don't need to call this routine for constants.


Public Definitions in File fastparse.h


Introduction

This package is meant for use when there are a great number of terms to be read and written. I wrote it when I was looking for a single axiom for lattice theory and was filtering trillions (really) of equations.

The ordinary parsing is very general and rather slow.

This package reads and writes prefix terms, without parentheses commas, or spaces. Each symbol is one character. Each term to be read starts on a new line and ends with a period. The user has to declare the arities of symbols by calling fast_set_symbol().

Here's an example to read lattice equations in fast-parse form and write them in ordinary form.

int main(int argc, char **argv)
{
  Term t;
  fast_set_symbol('=', 2);
  fast_set_symbol('m', 2);
  fast_set_symbol('j', 2);
  t = fast_read_term(stdin, stderr);
  while (t != NULL) {
    fwrite_term_nl(stdout, t);
    zap_term(t);
    t = fast_read_term(stdin, stderr);
  }
  exit(0);
}

There are also routines for reading and writing fast-parse clauses.


LADR-2009-11A/ladr/html/paramod.html0000644000175000017500000000604510775516360016234 0ustar mccunemccune paramod.h

#include "paramod.h"

This page has information from files paramod.h and paramod.c.

Contents


Public Routines in File paramod.c

Index

para_from_intopara_posparamodulate
basic_paramodulation_prunespara_instance_prunespara_pos2

Details



void paramodulation_options(BOOL ordered_inference,
			    BOOL check_instances,
			    BOOL positive_inference,
			    BOOL basic_paramodulation,
			    BOOL para_from_vars,
			    BOOL para_into_vars,
			    BOOL para_from_small);

int basic_paramodulation_prunes(void);
How many paramodulants were killed because they failed the "basic" test.
void para_from_into(Topform from, Context cf,
		    Topform into, Context ci,
		    BOOL check_top,
		    void (*proc_proc) (Topform));
Paramodulate from one clause into another (non-backtrack unification version).

For oriented equality atoms, we go from left sides only and into both sides. For nonoriented equality atoms, we go from and into both sides.


int para_instance_prunes();

Topform para_pos(Topform from_clause, Ilist from_pos,
		 Topform into_clause, Ilist into_pos);
Construct a paramodulant from the given data. A fatal error occurs if it does not exist. In building the justification, the position vectors are copied.
Topform para_pos2(Topform from, Ilist from_pos, Topform into, Ilist into_pos);
Construct a paramodulant from the given data. A fatal error occurs if it does not exist. In building the justification, the position vectors are copied. This is similar to para_pos(), except that it allows the into_term to be a variable.
Topform paramodulate(Literals from_lit, int from_side, Context from_subst,
		     Topform into_clause, Ilist into_pos, Context into_subst);

Public Definitions in File paramod.h

/* where to paramodulate into */

typedef enum { PARA_ALL,
	       PARA_ALL_EXCEPT_TOP,
	       PARA_TOP_ONLY } Para_loc;


Introduction

This package has a paramodulation inference rule.
LADR-2009-11A/ladr/html/weight.html0000644000175000017500000000250210775516357016100 0ustar mccunemccune weight.h

#include "weight.h"

This page has information from files weight.h and weight.c.

Contents


Public Routines in File weight.c

Index

clause_weightinit_weightweight

Details


int clause_weight(Literals lits);

void init_weight(Plist rules,
		 int variable_weight,
		 int constant_weight,
		 int not_weight,
		 int or_weight,
		 int sk_constant_weight,
		 int prop_atom_weight,
		 int skolem_penalty,
		 int nest_penalty,
		 int depth_penalty,
		 int var_penalty);
Initialize weighting. The rules are copied.
int weight(Term t, Context subst);

Public Definitions in File weight.h


Introduction


LADR-2009-11A/ladr/html/fpa.html0000644000175000017500000001717410775516357015372 0ustar mccunemccune fpa.h

#include "fpa.h"

This page has information from files fpa.h and fpa.c.

Contents


Public Routines in File fpa.c

Index

fpa_cancelfpa_updatemega_next_callsp_fpa_state
fpa_emptyfprint_fpa_indexp_fpa_densityp_path
fpa_first_answerfprint_fpa_memp_fpa_indexzap_fpa_index
fpa_init_indexfprint_fpa_statep_fpa_mem
fpa_next_answerfprint_pathp_fpa_query

Details


void fpa_cancel(Fpa_state q);
This routine should be called if you get some, but not all answers to an fpa query. See fpa_first_answer() and fpa_next_answer().
BOOL fpa_empty(Fpa_index idx);
This Boolean routine checks if an FPA/Path index is empty.
Term fpa_first_answer(Term t, Context c, Querytype query_type,
		      Fpa_index idx, Fpa_state *ppos);
This routine extracts and returns the first answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree.

The query types are UNIFY, INSTANCE, GENERALIZATION, VARIANT, and IDENTICAL.

If Context c is not NULL, then the instance of the term (in the context) is used for the query.


Fpa_index fpa_init_index(int depth);
This routine allocates and returns an empty FPA/Path index. Parameter depth tells how deep to index the terms. For example, depth=0 means to index on the root symbol only.
Term fpa_next_answer(Fpa_state q);
This routine extracts and returns the next answer term from an Fpa_state tree. If there are no more answers, NULL is returned, and the tree is freed. If you wish to stop getting answers before NULL is returned, call zap_fpa_state(q) to free the Fpa_state tree.
void fpa_update(Term t, Fpa_index idx, Indexop op);
This routine inserts (op==INSERT) a term into an Fpa_index or deletes (op==DELETE) a term from an Fpa_index.

IMPORTANT: FPA indexing owns the FPA_ID field of the term.

A fatal error occurs if you try to delete a term that was not previously inserted.


void fprint_fpa_index(FILE *fp, Fpa_index idx);
This routine prints (to FILE *fp) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first.
void fprint_fpa_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpa package. The Boolean argument heading tells whether to print a heading on the table.
void fprint_fpa_state(FILE *fp, Fpa_state q, int depth);
This (recursive) routine prints (to FILE *fp) an Fpa_state tree. The depth parameter should be 0 on the top call. This is an AND/OR tree, with lists of terms (ordered by FPA_ID) at the leaves. If FPA_DEBUG is not defined in fpa.h, the paths corresponding to the leaves are not printed, and the tree is hard to understand without the paths.
void fprint_path(FILE *fp, Ilist p);
This routine prints (to FILE *fp) an FPA Path. A newline is NOT printed.
unsigned mega_next_calls(void);

void p_fpa_density(Fpa_index idx);

void p_fpa_index(Fpa_index idx);
This routine prints (to stdout) an Fpa_index. WARNING: An Fpa_index can be very big, and it is printed as a tree, so if you use this routine, I suggest trying it on a small index first.
void p_fpa_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the fpa package.
void p_fpa_query(Term t, Querytype query_type, Fpa_index idx);
This routine constructs an fpa_query tree and prints it to stdout.
void p_fpa_state(Fpa_state q);
This routine prints (to stdout) an Fpa_state tree. See the description of fprint_fpa_state().
void p_path(Ilist p);
This routine prints (to stdout) an FPA Path. A newline is NOT printed.
void zap_fpa_index(Fpa_index idx);
This routine removes all the entries from an Fpa_index idx and frees all of the associated memory.

Public Definitions in File fpa.h

/* #define FPA_DEBUG */

typedef struct fpa_index * Fpa_index;
typedef struct fpa_state * Fpa_state;


Introduction

This package implements FPA/Path indexing for first-order terms. It is used to retrieive terms that are likely to unify (in various ways) with a query term. The answers are not guaranteed to unify, and the caller must call some kind of unification routine to check and to construct a substitution.

The unification types are FPA_UNIFY, FPA_INSTANCE, FPA_GENERALIZATION, FPA_VARIANT, and FPA_IDENTICAL. Performance is very good for FPA_INSTANCE, FPA_VARIANT, and FPA_IDENTICAL, fair for FPA_UNIFY, and poor for FPA_GENERALIZATION. (Use Discrimination indexing for FPA_GENERALIZATION, e.g., forward demodulation and forward subsumption.)

Associative-commutative (AC) function symbols are handled by simply ignoring all subterms of AC symbols (which can give bad performance). Commutative/symmetric (C) operations are handled.


LADR-2009-11A/ladr/html/avltree.html0000644000175000017500000001411610775516357016257 0ustar mccunemccune avltree.h

#include "avltree.h"

This page has information from files avltree.h and avltree.c.

Contents


Public Routines in File avltree.c

Index

avl_checkavl_insertavl_placeavl_zap
avl_deleteavl_item_at_positionavl_positionfprint_avltree_mem
avl_findavl_largestavl_sizep_avl
avl_heightavl_nth_itemavl_smallestp_avltree_mem

Details


void avl_check(Avl_node p,
	       Ordertype (*compare) (void *, void *));
Check that each node of an AVL tree has the following properties: (1) "size" and "height" fields are correct; (2) heights of the two children differ by at most 1. In addition, check that the inorder traversal of the whole tree really is in order.
Avl_node avl_delete(Avl_node p, void *item,
		    Ordertype (*compare) (void *, void *));
Delete an item from an AVL tree and return the updated tree. If the item is not in the tree (that is, if the comparison function does not return SAME_AS for any item in the tree), a fatal error occurs.
void *avl_find(Avl_node p, void *item,
	       Ordertype (*compare) (void *, void *));
Look for an item in an AVL tree. That is, look for an item for which the comparison function returns SAME_AS. If it is found, return the item in the tree; otherwise return NULL;
int avl_height(Avl_node p);
Return the height of an AVL tree. Leaves have height 1.
Avl_node avl_insert(Avl_node p, void *item,
		    Ordertype (*compare) (void *, void *));
Insert an item into an AVL tree, and return the updated tree. The item is an arbitrary pointer, and the caller gives a function that takes two pointers and compares two items. The comparison function must return LESS_THAN, SAME_AS, or GREATER_THAN.

If the item is already in the tree (that is, if the comparison function return SAME_AS for any item already in the tree), a fatal error occurs.


void *avl_item_at_position(Avl_node p, double pos);
Given an AVL tree and a position pos, 0.0 < pos <= 1.0, return the item at that position. If the tree is empty, or if pos is out of range, NULL is returned. The index (counting from 1) of the returned item is ceiling(pos * p->size).
void *avl_largest(Avl_node p);
Return the largest (rightmost) item in an AVL tree.
void *avl_nth_item(Avl_node p, int n);
Return the n-th item (counting from 1) in an AVL tree. If n is out of range, NULL is returned.
int avl_place(Avl_node p, void *item,
	      Ordertype (*compare) (void *, void *));
How far (counting from 1) from the beginning of the tree is the item. If the item is not already in the tree, this function says how far it would be if it were inserted first.
double avl_position(Avl_node p, void *item,
		    Ordertype (*compare) (void *, void *));
Return x, 0 < x <= 1, telling the position of the item in the tree. The last item always has position 1.0. The first item in a tree of size 10 has position 0.1.


int avl_size(Avl_node p);
Return the number of nodes in an AVL tree.
void *avl_smallest(Avl_node p);
Return the smallest (leftmost) item in an AVL tree.
void avl_zap(Avl_node p);
Free an entire AVL tree. This does not affect any of the data to which the tree refers.
void fprint_avltree_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the avltree package. The Boolean argument heading tells whether to print a heading on the table.
void p_avl(Avl_node p, int level);
Print an AVL tree to stdout. The pointers to the items are printed as integers.
void p_avltree_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the avltree package.

Public Definitions in File avltree.h

typedef struct avl_node * Avl_node;


Introduction

This is a simple implementation of AVL trees. These are binary search trees with the property that for each node, the difference in height of the two subtrees is at most one.

The items that are stored in the tree are simply pointers, which are assumed to contain the keys and data.

The caller supplies a comparison function, for example

    Ordertype compare(void *v1, void *v2)
or
    Ordertype compare(struct my_data *p1, struct my_data *p2)
that is assumed to return LESS_THAN, GREATER_THAN, or SAME_AS.

Aside from the ordinary "insert", "find", and "delete" operations, there is a "position" operation that tells where an item is in w.r.t. the inorder traversal of the tree, and an operation that finds the item at a given position.


LADR-2009-11A/ladr/html/compress.html0000644000175000017500000000317710775516357016455 0ustar mccunemccune compress.h

#include "compress.h"

This page has information from files compress.h and compress.c.

Contents


Public Routines in File compress.c

Index

compress_clauseuncompress_clauseuncompress_term
compress_termuncompress_clauses

Details


void compress_clause(Topform c);
When clasues are compressed, they lose any orientation marks on atoms. Marks are restored by a call to orient_equalities during uncompression.
char *compress_term(Term t);

void uncompress_clause(Topform c);

void uncompress_clauses(Plist p);
Given a Plist of clauses, uncompress the compressed ones.
Term uncompress_term(char *s, int *ip);

Public Definitions in File compress.h


Introduction


LADR-2009-11A/ladr/html/just.html0000644000175000017500000003520510775516357015604 0ustar mccunemccune just.h

#include "just.h"

This page has information from files just.h and just.c.

Contents


Public Routines in File just.c

Index

append_justflip_justjmap1propositional_just
back_demod_justfprint_just_memjmap2resolve_just
back_unit_deletion_justget_clause_ancestorsjstringsb_append_id
binary_res_justget_instancejustjust_countsb_write_ids
binary_res_just_by_idget_justmap_justsb_write_just
clause_levelget_parajustmark_parents_as_usedsb_xml_write_just
clausify_justget_parentsmerge_justterm_to_just
copy_justgoal_justnew_symbol_justunit_del_just
copy_justificationhas_copy_flip_justp_justxx_just
demod_justhas_copy_justp_just_memxxres_just
deny_justhas_input_justpara_justzap_just
expand_def_justinput_justpara_just_rev_copy
factor_justinstance_justprimary_just_type
first_negative_parentivy_justproof_length

Details


Just append_just(Just j1, Just j2);
This appends two justifications. No copying occurs.
Just back_demod_just(Topform c);
This routine builds and returns a justification list for back_demod.
Just back_unit_deletion_just(Topform c);
This routine builds and returns a justification list for back_unit_deletion.
Just binary_res_just(Topform c1, int n1, Topform c2, int n2);
This routine builds and returns a justification list for binary resolution. (Binary res justifications may also be constructed in resolve(), along with hyper and UR.)
Just binary_res_just_by_id(int c1, int n1, int c2, int n2);
Similar to binary_res_just, except that IDs are given instead of clauses.
int clause_level(Topform c);
Return the level of a clause. Input clauses have level=0, and a derived clause has level 1 more than the max of the levels of its parents.
Just clausify_just(Topform tf);
This routine builds and returns a justification list for clausify.
Just copy_just(Topform c);
This routine builds and returns a justification list for copy.
Just copy_justification(Just j);
Copy a justification.
Just demod_just(I3list steps);
This routine builds and returns a justification for a demodulation.
Just deny_just(Topform tf);
This routine builds and returns a justification list for deny.
Just expand_def_just(Topform tf, Topform def);
This routine builds and returns a justification list for expand_def.
Just factor_just(Topform c, int lit1, int lit2);
This routine builds and returns a justification list for a factorization.
Topform first_negative_parent(Topform c);

Just flip_just(int n);
This routine builds and returns a justification for equality flipping.
void fprint_just_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the just package. The Boolean argument heading tells whether to print a heading on the table.
Plist get_clause_ancestors(Topform c);
This routine returns the Plist of clauses that are ancestors of Topform c, including clause c. The result is sorted (increasing) by ID. If any of the ancestors are compressed, they are uncompressed (in place) and left uncompressed.
Instancejust get_instancejust(void);

Just get_just(void);

Parajust get_parajust(void);

Ilist get_parents(Just just, BOOL all);
This routine returns an Ilist of parent IDs. If (all), get parents from the whole justification; otherwise get parents from the first node only.
Just goal_just(void);
This routine builds and returns a justification list for goal.
BOOL has_copy_flip_just(Topform c);
Does a clause have justification "copy, flip", and nothing else?
BOOL has_copy_just(Topform c);
Does a clause have justification "copy"?
BOOL has_input_just(Topform c);
Does a clause have justtification "input"?
Just input_just(void);
This routine builds and returns a justification list for input.
Just instance_just(Topform parent, Plist pairs);
This routine builds and returns a justification list for an instance inference. The list of pairs is not copied.
Just ivy_just(Just_type type,
	      int parent1, Ilist pos1,
	      int parent2, Ilist pos2,
	      Plist pairs);

int jmap1(I3list map, int i);
A jmap maps ints to pairs of ints. This returns the first. If i is not in the map, i is returned.
char *jmap2(I3list map, int i, char *a);
A jmap maps ints to pairs of ints. This returns a string representation of the second. If i is not in the map, or if the int value of is INT_MIN, "" is returned. Starting with 0, the strings are "A" - "Z", "A26", "A27", ... . The argument *a must point to available space for the result. The result is returned.
char *jstring(Just j);
What is the string, e.g., "resolve" associated with a justification node?
int just_count(Just j);
Return the number of justification elements in a justtification.
void map_just(Just just, I2list map);
Update the clause IDs in a justification according to the map.
void mark_parents_as_used(Topform c);

Just merge_just(int n);
This routine builds and returns a justification for the merging a literal. The n-th literal has been removed because it is identical to another literal.
Just new_symbol_just(Topform c);
This routine builds and returns a justification list for new_symbol inference.
void p_just(Just j);

void p_just_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the just package.
Just para_just(Just_type rule,
	       Topform from, Ilist from_vec,
	       Topform into, Ilist into_vec);
This routine builds and returns a justification list for a paramodulation inference. The position vectors are not copied.
Just para_just_rev_copy(Just_type rule,
			Topform from, Ilist from_vec,
			Topform into, Ilist into_vec);
This routine builds and returns a justification list for a paramodulation inference. The position vectors are copied and reversed.
BOOL primary_just_type(Topform c, Just_type t);
Does a clause have justtification "input"?
int proof_length(Plist proof);

Just propositional_just(Topform c);
This routine builds and returns a justification list for propositional.
Just resolve_just(Ilist g, Just_type type);
This routine builds and returns a justification for resolution rules. This handles binary, hyper, ur, and maybe others.
void sb_append_id(String_buf sb, int id, I3list map);

void sb_write_ids(String_buf sb, Ilist p, I3list map);

void sb_write_just(String_buf sb, Just just, I3list map);
This routine writes (to a String_buf) a clause justification. No whitespace is printed before or after.
void sb_xml_write_just(String_buf sb, Just just, I3list map);

Just term_to_just(Term lst);

Just unit_del_just(Topform deleter, int literal_num);
This routine builds and returns a justification list for a factorization.
Just xx_just(int n);
This routine builds and returns a justification for the XX rule, which removes literals that are instances of x!=x.
Just xxres_just(Topform c, int lit);
This routine builds and returns a justification list for resolution with x=x.
void zap_just(Just just);
This routine frees a justification list, including any sublists.

Public Definitions in File just.h

typedef enum {
  INPUT_JUST,         /* Primary                              */
  GOAL_JUST,          /* Primary                              */
  DENY_JUST,          /* Primary    int       (ID)            */
  CLAUSIFY_JUST,      /* Primary    int       (ID)            */
  COPY_JUST,          /* Primary    int       (ID)            */
  BACK_DEMOD_JUST,    /* Primary    int       (ID)            */
  BACK_UNIT_DEL_JUST, /* Primary    int       (ID)            */
  NEW_SYMBOL_JUST,    /* Primary    int       (ID)            */
  EXPAND_DEF_JUST,    /* Primary    Ilist     (ID,def-ID)     */
  BINARY_RES_JUST,    /* Primary    Ilist                     */
  HYPER_RES_JUST,     /* Primary    Ilist                     */
  UR_RES_JUST,        /* Primary    Ilist                     */
  FACTOR_JUST,        /* Primary    Ilist     (ID,lit1,lit2)  */
  XXRES_JUST,         /* Primary    Ilist     (ID,lit)        */
  PARA_JUST,          /* Primary    Parajust                  */
  PARA_FX_JUST,       /* Primary    Parajust                  */
  PARA_IX_JUST,       /* Primary    Parajust                  */
  PARA_FX_IX_JUST,    /* Primary    Parajust                  */
  INSTANCE_JUST,      /* Primary    Instancejust              */
  PROPOSITIONAL_JUST, /* Primary    int       (ID)            */

  DEMOD_JUST,         /* Secondary  I3list                    */
  UNIT_DEL_JUST,      /* Secondary  Ilist     (lit,ID)        */
  FLIP_JUST,          /* Secondary  int       (lit)           */
  XX_JUST,            /* Secondary  int       (lit)           */
  MERGE_JUST,         /* Secondary  int       (lit)           */

  IVY_JUST,           /* Primary    Ivyjust                   */

  UNKNOWN_JUST        /* probably an error                    */
} Just_type;

typedef struct parajust * Parajust;

struct parajust {
  int from_id;
  int into_id;
  Ilist from_pos;
  Ilist into_pos;
};

typedef struct instancejust * Instancejust;

struct instancejust {
  int parent_id;
  Plist pairs;
};

typedef struct ivyjust * Ivyjust;

struct ivyjust {
  Just_type type;  /* input,resolve,paramod,instantiate,flip,propositional */
  int parent1;
  int parent2;
  Ilist pos1;
  Ilist pos2;
  Plist pairs;  /* for instantiate */
};

typedef struct just * Just;

struct just {
  Just_type type;
  Just next;
  union {
    int id;
    Ilist lst;
    Parajust para;
    I3list demod;
    Instancejust instance;
    Ivyjust ivy;
  } u;
};

/* A justification starts with a Primary part and then
   has a sequence (maybe none) of Secondary parts.
   Each type has some data, an integer or Ilist (integer
   list) giving clause IDs, or positions of literals or
   subterms.
*/


Introduction


LADR-2009-11A/ladr/html/demod.html0000644000175000017500000000541310775516357015705 0ustar mccunemccune demod.h

#include "demod.h"

This page has information from files demod.h and demod.c.

Contents


Public Routines in File demod.c

Index

demod1demod_rewritesdemodulator_typeparticular_demod
demod_attemptsdemodulateidx_demodulator

Details


void demod1(Topform c, Topform demodulator, int direction,
	    Ilist *fpos, Ilist *ipos,
	    BOOL lex_order_vars);
Special purpose demodulation routine.

Given a clause and a demodulator that rewrites the clause, rewrite the innermost leftmost subterm to which the demodulator applies. Return the rewritten term and the position vectors of the from and into terms.


int demod_attempts();
Return the number of rewrite attempts so far (for the whole process).
int demod_rewrites();
Return the number of successful rewrites so far (for the whole process).
Term demodulate(Term t, Mindex demods, Ilist *just_head, BOOL lex_order_vars);
This routine demodulates a term. ID numbers of demodulators are put on the front of just_head, so you'll probably want to reverse the list before putting it into the clause justification.
int demodulator_type(Topform c, int lex_dep_demod_lim, BOOL sane);
Return NOT_DEMODULATOR, ORIENTED, LEX_DEP_LR, LEX_DEP_RL, or LEX_DEP_BOTH.
void idx_demodulator(Topform c, int type, Indexop operation, Mindex idx);

void particular_demod(Topform c, Topform demodulator, int target, int direction,
		      Ilist *fpos, Ilist *ipos);
Special purpose demodulation routine.

Given a clause and which applies to the clause, return the rewritten clause and the position vectors of the from and into terms.


Public Definitions in File demod.h


Introduction


LADR-2009-11A/ladr/html/accanon.html0000644000175000017500000000431310775516357016215 0ustar mccunemccune accanon.h

#include "accanon.h"

This page has information from files accanon.h and accanon.c.

Contents


Public Routines in File accanon.c

Index

ac_canonicalcheck_ac_canonicalflatten

Details


void ac_canonical(Term t, int bit);
This routine transforms a term into AC canonical form, which means that all AC subterms are right associated and sorted. The routine term_compare_ncv() is used to compare AC arguments, and the order is CONSTANT < COMPLEX < VARIABLE; within type, the order is by VARNUM and lexigocgaphic by SYMNUM.

Terms can be marked as fully reduced (which implies AC canonical). The argument "bit" tells which term bit is used for the mark (bit=-1 means to ignore marks). If such a term is found, it is skipped. Also, we make sure that any transformed terms are not marked (they will be AC canonical, but they might not be reduced).


int check_ac_canonical(Term t);
This Boolean routine simply checks if a term is AC canonical. It should only be used if you suspect something is wrong, because it is inefficient (it copies the term, calls ac_canonical() on the copy, then does term_ident() with the original term).
void flatten(Term t, Term *a, int *ip);
This routine

Public Definitions in File accanon.h

/* If you get an error message "flatten, too many arguments", increase
 * the following symbol (2500 is enough for the dem_alu problem.)
 */

#define MAX_ACM_ARGS 2500


Introduction


LADR-2009-11A/ladr/html/mindex.html0000644000175000017500000002422710775516357016105 0ustar mccunemccune mindex.h

#include "mindex.h"

This page has information from files mindex.h and mindex.c.

Contents


Public Routines in File mindex.c

Index

fprint_mindexmindex_emptymindex_retrieve_cancelmindex_update
fprint_mindex_memmindex_freemindex_retrieve_firstp_mindex_mem
mindex_destroymindex_initmindex_retrieve_next

Details


void fprint_mindex(FILE *fp, Mindex mdx);
This routine prints (to FILE *fp) Mindex mdx.
void fprint_mindex_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the mindex package. The Boolean argument heading tells whether to print a heading on the table.
void mindex_destroy(Mindex mdx);
This frees all the memory associated with an Mindex. Do not refer to the Mindex after calling this routine.
BOOL mindex_empty(Mindex mdx);
This Boolean routine checks if an Mindex is empty, that is, has no terms. It must exist (be non-NULL).
void mindex_free(Mindex mdx);
This routine frees an empty Mindex. (If the Mindex is not empty, nothing happens.)
Mindex mindex_init(Mindextype mtype, Uniftype utype, int fpa_depth);
This routine allocates and returns an (empty) Mindex, which is used to retrieve unifiable terms.
  • index_type: {LINEAR, FPA, DISCRIM_WILD, DISCRIM_BIND}
  • unif_type: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
Types of retrieval. LINEAR and FPA indexes support all types of retrieval (FPA is slow for GENERALIZATION). DISCRIM_WILD and DISCRIM_BIND indexes support GENERALIZATION retrieval only. See mindex_retrieve_first().

Associative-commutative (AC) and commutative (C) symbols. DISCRIM_BIND does not support AC symbols. All other combinations are okay. If you have any AC or C symbols, you must specify unif_type BACKTRACK_UNIF. (BACKTRACK_UNIF is also okay with no AC or C symbols, but it is a little bit slower than ORDINARY_UNIF.)

AC symbols must be declared (with set_assoc_comm()) before calling mindex_update(). C symbols need not be declared before mindex_update(), but they must be declared (with set_commutative()) before calling mindex_retrieve_first().


void mindex_retrieve_cancel(Mindex_pos pos);
This routine should be called if you get some, but not all, answers to a query. For example, if you need only one answer you can do something like the following:
{
  Mindex_pos pos;
  Term t2;
  Context cf = get_context();
  
  t2 = mindex_retrieve_first(t, mdx, GENERALIZATION, (Context) NULL, cf, &pos);
  if (t2 != NULL) {
    printf("we found a mate!\n");
    mindex_retrieve_cancel(pos);
  }
  else
    printf("no answer\n");
  free_context(cf);
}
If you fail to call this routine, then the memory associated with an Mindex_pos will be forever lost, that is, you will have a memory leak.
Term mindex_retrieve_first(Term t, Mindex mdx, Querytype qtype,
			   Context query_subst, Context found_subst,
			   BOOL partial_match,
			   Mindex_pos *ppos);
This routine finds and returns the first answer to a query (returning NULL if there are no answers).
  • Term t: the query term;
  • Mindex mdx: the Mindex;
  • int query_type: UNIFY, INSTANCE, GENERALIZATION, VARIANT, or IDENTICAL;
  • Context query_subst: subsitution for variables in query term t; this can be NULL for GENERALIZATION, and IDENTICAL;
  • Context found_subst: subsitution for variables in the answer term; this can be NULL for INSTANCE, VARIANT, and IDENTICAL;
  • BOOL partial_match: If TRUE, then for GENERALIZATION, with BACKTRACK_UNIF, when t has an AC symbol at the root, allow the retrieved term to match only part of t, with the remainder of the retrieved term placed in fond_subst->partial_term. This is used for AC rewriting, for example, to let x+x=x rewrite a+a+b.
  • Mindex_pos *ppos (output parameter): If an answer is returned, this address is set to a pointer to a structure that holds the position so you can get the rest of the answers.
If you ask for a type of retrieval not supported by the Mindex mdx, you will get no answers (and no error message).

Here is an example of how to retrieve all answers. Assume we have Term t and Mindex mdx.

{
  Mindex_pos pos;
  Term t2;
  Context cq = get_context();
  Context cf = get_context();
  int n = 0;
  
  t2 = mindex_retrieve_first(t, mdx, UNIFY, cq, cf, FALSE, &pos);
  while (t2 != NULL) {
    t2 = mindex_retrieve_next(pos);
    n++;
  }
  free_context(cq);
  free_context(cf);
  printf("there are %d mates\n", n);
}

Term mindex_retrieve_next(Mindex_pos pos);
This routine finds and returns the next answer to a query. See mindex_retrieve_first() for an explanation.
void mindex_update(Mindex mdx, Term t, Indexop op);
This routine inserts (op==INSERT) or deletes (op==DELETE) a Term t into/from an Mindex mdx.

It is your responsibility to remember that t is in the index, because we don't currently have a routine "mindex_member()".


void p_mindex_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the mindex package.

Public Definitions in File mindex.h

/* types of index */

typedef enum { LINEAR,
	       FPA,
	       DISCRIM_WILD,
	       DISCRIM_BIND
             } Mindextype;

/* types of unification */

typedef enum { ORDINARY_UNIF,
	       BACKTRACK_UNIF
             } Uniftype;

typedef struct mindex * Mindex;
typedef struct mindex_pos * Mindex_pos;

struct mindex {
  Mindextype index_type;
  Uniftype   unif_type;

  /* FPA */
  Fpa_index  fpa;

  /* LINEAR */
  Plist   linear_first;
  Plist   linear_last;

  /* DISCRIM_WILD and DISCRIM_BIND */
  Discrim   discrim_tree;

  Mindex     next;  /* for avail list */
};


Introduction

This is an indexing/unification package to store terms and to retrieve unifiable terms. (It is really just an interface to the various indexing and unification packages.) Several types of indexing and unification are supported. When you allocate an index (with mindex_init()), you specify the type of index and the type of unification.

Types of Retrieval

UNIFY, INSTANCE, GENERALIZATION, VARIANT, IDENTICAL.

Types of Unification

Associative-commutative (AC) and commutative/symmetric (C) symbols are supported in most cases. If you have any AC or C symbols, you must use backtrack unification, which handles more than one unifier for a pair of terms; otherwise, you can use ordinary unification, which assumes at most one unifier for a pair of terms. (For the empty theory, ordinary unification is a bit faster than backtrack unification.)

Types of Indexing

  • LINEAR : This is indexing without an index. The terms you insert are put on a list, and each is tested in turn. This supports AC and C symbols.
  • FPA : This is FPA/Path indexing. Supports AC symbols (in a primitive way, by treating them as constants) and C symbols.
  • DISCRIM_WILD : Discrimination indexing, where matching is separate from unidexing. This supports AC symbols and C symbols. With C symbols, you can get duplicate answers. Supports GENERALIZATION retrieval only.
  • DISCRIM_BIND : Discrimination indexing, where matching occurs during indexing. This supports C symbols, but not AC symbols. Supports GENERALIZATION retrieval only.

LADR-2009-11A/ladr/html/fatal.html0000644000175000017500000000323410775516356015702 0ustar mccunemccune fatal.h

#include "fatal.h"

This page has information from files fatal.h and fatal.c.

Contents


Public Routines in File fatal.c

Index

bellfatal_errorget_fatal_exit_codeset_fatal_exit_code

Details


void bell(FILE *fp);
Send the bell character '\007' to a file.
void fatal_error(char *message);
This routine should be called if something terrible happens. The message is printed to stdout and to stderr, and the process exits with the fatal_exit_code (default 1).
int get_fatal_exit_code();
This function returns the exit code that will be used in case fatal_error() is called.
void set_fatal_exit_code(int exit_code);
This routine changes the exit code that will be used in case fatal_error() is called. The default value is 1.

Public Definitions in File fatal.h


Introduction

This package is just a few utilities for handling fatal errors.
LADR-2009-11A/ladr/html/definitions.html0000644000175000017500000000370710775516357017134 0ustar mccunemccune definitions.h

#include "definitions.h"

This page has information from files definitions.h and definitions.c.

Contents


Public Routines in File definitions.c

Index

expand_with_definitionis_definitionseparate_definitions
expand_with_definitionsprocess_definitions

Details


Formula expand_with_definition(Formula f, Formula def);

void expand_with_definitions(Plist formulas,
			     Plist defs,
			     Plist *results,
			     Plist *rewritten);
All arguments are plists of Topforms containing formulas.
BOOL is_definition(Formula f);

void process_definitions(Plist formulas,
			 Plist *results,
			 Plist *defs,
			 Plist *rewritten);
All arguments are plists of Topforms containing formulas.
void separate_definitions(Plist formulas,
			  Plist *defs,
			  Plist *nondefs);
All arguments are plists of Topforms containing formulas.

Public Definitions in File definitions.h


Introduction


LADR-2009-11A/ladr/html/ibuffer.html0000644000175000017500000000546110775516356016241 0ustar mccunemccune ibuffer.h

#include "ibuffer.h"

This page has information from files ibuffer.h and ibuffer.c.

Contents


Public Routines in File ibuffer.c

Index

fd_read_to_ibufibuf_initibuf_rewindibuf_xread
ibuf_bufferibuf_lengthibuf_writep_ibuf
ibuf_freeibuf_readibuf_write_block

Details


Ibuffer fd_read_to_ibuf(int fd);

int *ibuf_buffer(Ibuffer ibuf);

void ibuf_free(Ibuffer ibuf);
Free an Ibuffer.
Ibuffer ibuf_init(void);
Allocate and initialize an Ibuffer.
int ibuf_length(Ibuffer ibuf);

int ibuf_read(Ibuffer ibuf);
Get the next integer from an Ibuffer. This version returns IBUF_EOF (INT_MIN) if there is nothing to read.
void ibuf_rewind(Ibuffer ibuf);
Reset an Ibuffer for reading.
void ibuf_write(Ibuffer ibuf, int i);
Write an integer to an Ibuffer.
void ibuf_write_block(Ibuffer ibuf, int *a, int n);
Write an array of integers to an Ibuffer.
int ibuf_xread(Ibuffer ibuf);
Get the next integer from an Ibuffer. This version assumes there is an integer to read; if it is at the end IBUF_EOF, a fatal error occurs.
void p_ibuf(Ibuffer ibuf);
Print a an Ibuffer to a stdout. This is mainly for debugging.

Public Definitions in File ibuffer.h

#define IBUF_INIT_SIZE    40000
#define IBUF_EOF        INT_MIN

struct ibuffer {
  int write_position; /* current number of ints in buf (next pos to write) */
  int read_position;  /* next pos to read */
  int size;           /* size of buf */
  int *buf;           /* the buffer */
};

typedef struct ibuffer * Ibuffer;


Introduction


LADR-2009-11A/ladr/html/tlist.html0000644000175000017500000000401710775516357015753 0ustar mccunemccune tlist.h

#include "tlist.h"

This page has information from files tlist.h and tlist.c.

Contents


Public Routines in File tlist.c

Index

constants_in_termtlist_removezap_tlist
tlist_copytlist_union

Details


Ilist constants_in_term(Term t, Ilist p);
Given a term t, return a plist containing the set of constants in t.
Plist tlist_copy(Plist p);

Plist tlist_remove(Term t, Plist p);
Remove a term from a Plist. Term_ident() is used, and the term in the list is zapped.
Plist tlist_union(Plist a, Plist b);
Return the union of two Plists of terms. If the inputs are sets, the output is a set. Do not refer the inputs after the call. Duplicates are zapped.
void zap_tlist(Plist p);
Zap each term in the list and free the list. If you want to free the list only, without zapping the terms, use zap_plist(p) instead.

Public Definitions in File tlist.h


Introduction

This little package handles singly-linked lists of terms. The data type Plist is used to build the lists.

Note that there is another package, listterm, that does similar things, but constructing the lists from ordinary terms, as in Prolog.


LADR-2009-11A/ladr/html/termorder.html0000644000175000017500000001253310775516357016621 0ustar mccunemccune termorder.h

#include "termorder.h"

This page has information from files termorder.h and termorder.c.

Contents


Public Routines in File termorder.c

Index

assign_order_methodflatterm_compare_vrkbo_weightterm_compare_vcp
flat_greatergreater_multiset_current_orderinglrpoterm_compare_vr
flat_kbo_weightinit_kbo_weightslrpo_multisetterm_greater
flat_lrpokboterm_compare_ncvterm_order

Details


void assign_order_method(Order_method method);

BOOL flat_greater(Flatterm alpha, Flatterm beta, BOOL lex_order_vars);

int flat_kbo_weight(Flatterm f);

BOOL flat_lrpo(Flatterm s, Flatterm t, BOOL lex_order_vars);

Ordertype flatterm_compare_vr(Flatterm a, Flatterm b);
This routine compares two flatterms. variable < nonvariable; within type, the order is by VARNUM and lexigocgaphic by symbol precedence. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}.
BOOL greater_multiset_current_ordering(Term t1, Term t2);

void init_kbo_weights(Plist weights);
Plist should be a list of terms, e.g., a=3, g=0. Symbols are written as constants; arity is deduced from the symbol table.
BOOL kbo(Term alpha, Term beta, BOOL lex_order_vars);
Is alpha kbo-greater-than beta?
int kbo_weight(Term t);

BOOL lrpo(Term s, Term t, BOOL lex_order_vars);
This routine checks if Term s > Term t in the Lexicographic Recursive Path Ordering (LRPO), also known as Recursive Path Ordering with Status (RPOS).

Function symbols can have either multiset or left-to-right status (see symbols.c). If all symbols are multiset, this reduces to the Recursive Path Ordering (RPO). If all symbols are left-to-right, this reduces to Lexicographic Path Ordering (LPO).


BOOL lrpo_multiset(Term t1, Term t2, BOOL lex_order_vars);
This routine
Ordertype term_compare_ncv(Term t1, Term t2);
This routine compares two terms. The ordering is total: CONSTANT < COMPLEX < VARIABLE; within type, the order is by VARNUM and lexigocgaphic by SYMNUM. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}.
Ordertype term_compare_vcp(Term t1, Term t2);
This routine compares two terms. The ordering is total: VARIABLE < CONSTANT < COMPLEX; within type, the order is by VARNUM and lexigocgaphic by SYMNUM. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN}.
Ordertype term_compare_vr(Term t1, Term t2);
This routine compares two terms. variable < nonvariable; within type, the order is by VARNUM and lexigocgaphic by symbol precedence. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}.
BOOL term_greater(Term alpha, Term beta, BOOL lex_order_vars);
Is alpha > beta in the current term ordering? (LPR, RPO, KBO)
Ordertype term_order(Term alpha, Term beta);
Compare two terms with the current term ordering (LPR, RPO, KBO) Return GREATER_THAN, LESS_THAN, or NOT_COMPARABLE.

Public Definitions in File termorder.h

/* Term ordering method */

typedef enum { LRPO_METHOD,
	       LPO_METHOD,
	       RPO_METHOD,
	       KBO_METHOD
             } Order_method;


Introduction


LADR-2009-11A/ladr/html/formula.html0000644000175000017500000004101710775516357016262 0ustar mccunemccune formula.h

#include "formula.h"

This page has information from files formula.h and formula.c.

Contents


Public Routines in File formula.c

Index

andformula_identgreatest_qvarpositive_formula
clausal_formulaformula_megsgreatest_symnum_in_formulaquant_form
closed_formulaformula_set_variableshash_formularelation_in_formula
constants_in_formulaformula_sizeimprelation_symbols_in_formula
copy_plist_of_formulasformula_to_termimpbyrelation_symbols_in_formulas
dualformulas_to_conjunctionliteral_formularename_all_bound_vars
dual_typeformulas_to_disjunctionmake_conjunctionrename_these_bound_vars
eliminate_rebindingfprint_formulamake_disjunctionsubformula_contains_attributes
flatten_topfprint_formula_memnegatesubst_free_var
formula_canon_eqfree_formulannfterm_to_formula
formula_contains_attributesfree_variablennf2universal_closure
formula_copyfunction_symbols_in_formulaorzap_formula
formula_flattenfunction_symbols_in_formulasp_formula
formula_getget_quant_formp_formula_mem

Details


Formula and(Formula a, Formula b);

BOOL clausal_formula(Formula f);

BOOL closed_formula(Formula f);

Ilist constants_in_formula(Formula f);

Plist copy_plist_of_formulas(Plist formulas);

Formula dual(Formula f);
Change a formula into its dual. This is destructive.
BOOL dual_type(int op);

Formula eliminate_rebinding(Formula f);
This routine renames quantified variables so that no quantified variable occurs in the scope of a quantified variable with the same name.

If you wish to rename variables so that each quantifer has a unique variable, you can use the routine unique_quantified_vars() instead.

The argument f is "used up" during the procedure.

(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.)


Formula flatten_top(Formula f);

void formula_canon_eq(Formula f);
For each equality in the formula, if the right side greater according to "term_compare_ncv", flip the equality.
BOOL formula_contains_attributes(Formula f);
Does the formula or any of its subformulas contain attributes?
Formula formula_copy(Formula f);
This function returns a copy of the given formula. All subformulas, including the atoms, are copied.
Formula formula_flatten(Formula f);
This routine (recursively) flattens all AND and OR subformulas.
Formula formula_get(int arity, Ftype type);

BOOL formula_ident(Formula f, Formula g);
This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality.


unsigned formula_megs(void);
Return the approximate number of megabytes in use for storage of formulas.
void formula_set_variables(Formula f, int max_vars);
This routine traverses a formula and changes the constants that should be variables, into variables. On input, the formula should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input formulas that are built without regard to variable/constant distinction.


int formula_size(Formula f);
How many nodes are in the formula. (Atomic formulae count as 1.)
Term formula_to_term(Formula f);

Formula formulas_to_conjunction(Plist formulas);
Given a Plist of formulas, form a conjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty conjunction is TRUE.


Formula formulas_to_disjunction(Plist formulas);
Given a Plist of formulas, form a disjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty disjunction is FALSE.


void fprint_formula(FILE *fp, Formula f);
This routine prints a formula to a file. If you wish to have a formula printed without extra parentheses, you can call fprint_formula_term() instead.
void fprint_formula_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the formula package. The Boolean argument heading tells whether to print a heading on the table.
void free_formula(Formula p);

BOOL free_variable(char *svar, Formula f);

I2list function_symbols_in_formula(Formula f, I2list g);
Collect the multiset of function symbols in a formula.
I2list function_symbols_in_formulas(Plist lst);
Collect the multiset of function symbols (including constants) in formulas in a Plist. An I2list of SYMNUMs is returned.
Formula get_quant_form(Ftype type, char *qvar, Formula subformula);

int greatest_qvar(Formula f);
Return the greatest SYMNUM of a quantified variable in Formula f.

Recall that in Formulas, a quantified variable is represented as a constant (which is bound by the quantifier). If the formula has no quantified variables, return -1.


int greatest_symnum_in_formula(Formula f);
Return the greatest SYMNUM of a any subterm. This includes quantifed variables that don't occur in any term.

This routine is intended to be used if you need malloc an array for indexing by SYMNUM.


unsigned hash_formula(Formula f);
This is a simple hash function for formulas. It shifts symbols by 3 bits and does exclusive ORs.
Formula imp(Formula a, Formula b);

Formula impby(Formula a, Formula b);

BOOL literal_formula(Formula f);

Formula make_conjunction(Formula f);
If the formula is not a conjunction, make it so.
Formula make_disjunction(Formula f);
If the formula is not a dismunction, make it so.
Formula negate(Formula a);

Formula nnf(Formula f);
Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

This routine is destructive; a good way to call it is f = nnf(f).


Formula nnf2(Formula f, Fpref pref);
Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

The argument "pref" should be either CONJUNCTION or DISJUNCTION, and it specifies the preferred form to use when translating IFFs.

This rouine is destructive; a good way to call it is f = nnf2(f, CONJUNCTION).


Formula or(Formula a, Formula b);

void p_formula(Formula c);
This routine prints a formula, followed by ".\n" and fflush, to stdout. If you wish to have a formula printed without extra parentheses, you can call p_formula_term() instead. If you don't want the newline, use fprint_formula() instead.
void p_formula_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the formula package.
BOOL positive_formula(Formula f);
Ignoring quantifiers, does the formula consist of an atomic formula or the conjunction of atomic formulas?
BOOL quant_form(Formula f);

BOOL relation_in_formula(Formula f, int symnum);
Collect the multiset of relation symbols in a formula.
I2list relation_symbols_in_formula(Formula f, I2list g);
Collect the multiset of relation symbols in a formula.
I2list relation_symbols_in_formulas(Plist lst);
Collect the multiset of relation symbols (including constants) in formulas in a Plist. An I2list of SYMNUMs is returned.
void rename_all_bound_vars(Formula f);

void rename_these_bound_vars(Formula f, Ilist vars);

BOOL subformula_contains_attributes(Formula f);
Does any proper subformula contain attributes?
void subst_free_var(Formula f, Term target, Term replacement);
In formula f, substitute free occurrences of target with replacement. The function term_ident() is used, and the target can be any term.
Formula term_to_formula(Term t);
Assume that no subterm (of t) representing a formula is a term of type VARIABLE. The given Term is not changed.
Formula universal_closure(Formula f);
Construct the universal closure of Formula f. The Formula is consumed during the construction.
void zap_formula(Formula f);
Free a formula, including all of its subformulas, including its atoms. If a subformula as excess references, the refcount is decremented instead.

Public Definitions in File formula.h

/* formula types */

typedef enum {
  ATOM_FORM=0, AND_FORM, OR_FORM, NOT_FORM, IFF_FORM,
  IMP_FORM, IMPBY_FORM, ALL_FORM, EXISTS_FORM} Ftype;

typedef struct formula * Formula;
struct formula {
  Ftype       type;
  int         arity;
  char        *qvar;         /* quantified variable */
  Formula     *kids;         /* for non-atoms */
  Term        atom;          /* for atoms */
  Attribute   attributes;    /* */
  int excess_refs;           /* count of extra references */
};

/* formula preference */

typedef enum { CONJUNCTION,
	       DISJUNCTION
             } Fpref;

/* macros */

#define TRUE_FORMULA(f)  ((f)->type == AND_FORM && (f)->arity == 0)
#define FALSE_FORMULA(f) ((f)->type == OR_FORM  && (f)->arity == 0)


Introduction


LADR-2009-11A/ladr/html/discrimw.html0000644000175000017500000001031310775516357016431 0ustar mccunemccune discrimw.h

#include "discrimw.h"

This page has information from files discrimw.h and discrimw.c.

Contents


Public Routines in File discrimw.c

Index

discrim_wild_canceldiscrim_wild_retrieve_nextfprint_discrim_wild_indexp_discrim_wild_index
discrim_wild_retrieve_firstdiscrim_wild_updatefprint_discrimw_memp_discrimw_mem

Details


void discrim_wild_cancel(Discrim_pos pos);
This routine should be called if you get some, but not all answers to a wild discrimintaion query. The memory associated the retrieval state is freed.
void *discrim_wild_retrieve_first(Term t, Discrim root,
				  Discrim_pos *ppos);
This routine, along with discrim_wild_retrieve_next(), gets answers from a wild discrimination index. This routine retrieves the first object associated with a term more general than Term t. (NULL is returned if there is none.)

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_wild_cancel() to clear the substitution and free memory associated with the Discrim_pos.


void *discrim_wild_retrieve_next(Discrim_pos pos);
This routine retrieves the next object in the sequence of answers to a query of a wild discrimination tree. See discrim_wild_retrieve_first().
void discrim_wild_update(Term t, Discrim root, void *object, Indexop op);
This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a wild discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted.


void fprint_discrim_wild_index(FILE *fp, Discrim d);
This routine prints (to FILE *fp) a wild discrimination index.
void fprint_discrimw_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrimw package. The Boolean argument heading tells whether to print a heading on the table.
void p_discrim_wild_index(Discrim d);
This routine prints (to stdout) a wild discrimination index.
void p_discrimw_mem(void);
This routine prints (to stdout) memory usage statistics for data types associated with the discrimw package.

Public Definitions in File discrimw.h


Introduction

Discrimination tree indexing in which all variables variables are represented as wildcards in the index. Matching occurs after retrieval of candidates.
LADR-2009-11A/ladr/html/clauses.html0000644000175000017500000000715510775516357016261 0ustar mccunemccune clauses.h

#include "clauses.h"

This page has information from files clauses.h and clauses.c.

Contents


Public Routines in File clauses.c

Index

all_clauses_hornequality_in_clausesmost_literalspos_equality_in_clauses
all_clauses_positiveintersect_clausesneg_nonunit_clauses
all_clauses_unitmax_clause_symbol_countnegative_clauses
clause_member_plistmax_clause_weightnonneg_clauses

Details


BOOL all_clauses_horn(Plist l);
Is every clause in the Plist a Horn clause?
BOOL all_clauses_positive(Plist l);
Is every clause in the Plist a unit clause?
BOOL all_clauses_unit(Plist l);
Is every clause in the Plist a unit clause?
Topform clause_member_plist(Plist p, Topform c);
Is a clause a member of a Plist? A deep identity check is done (clause_ident).
BOOL equality_in_clauses(Plist clauses);
Does the Plist contain a clause with a positive equality literal?
Plist intersect_clauses(Plist a, Plist b);
Intersect 2 Plists of clauses. The order of the result is determined by the order of the first list. A deep identity check is done (clause_ident).
int max_clause_symbol_count(Plist p);
Given a Plist of clauses, return the symbol_count of a clause with most symbols.
int max_clause_weight(Plist p);
Given a Plist of clauses, return the weight of the heaviest clause. The weight field of the clause is used.
int most_literals(Plist clauses);
Given a Plist of clauses, what is the maximum number of literals in a clause.
int neg_nonunit_clauses(Plist l);
How many negative nonunits are in a Plist of clauses?
int negative_clauses(Plist l);
How many negative clauses are in a Plist of clauses?
Plist nonneg_clauses(Plist clauses);
Given a Plist of clauses, return the subset of nonnegative clauses.
BOOL pos_equality_in_clauses(Plist clauses);
Does the Plist contain a clause with a positive equality literal?

Public Definitions in File clauses.h


Introduction

This package contains various functions on Plists of clauses.
LADR-2009-11A/ladr/html/features.html0000644000175000017500000000337410775516357016437 0ustar mccunemccune features.h

#include "features.h"

This page has information from files features.h and features.c.

Contents


Public Routines in File features.c

Index

feature_lengthfeatures_less_or_equalp_features
featuresinit_features

Details


int feature_length(void);

Ilist features(Literals lits);
Given a clause, build the feature vector. Features: positive literals negative literals foreach relation symbol positive occurrences negative occurrences foreach function symbol positive occurrences negative occurrences positive maxdepth negative maxdepth
BOOL features_less_or_equal(Ilist c, Ilist d);
Return TRUE if Ilists c and d are thr same length and each member of c is <= the corresponding member of d.
void init_features(Ilist fsyms, Ilist rsyms);

void p_features(Ilist f);

Public Definitions in File features.h


Introduction


LADR-2009-11A/ladr/html/basic.html0000644000175000017500000000612610775516357015700 0ustar mccunemccune basic.h

#include "basic.h"

This page has information from files basic.h and basic.c.

Contents


Public Routines in File basic.c

Index

apply_basicbasic_termmark_all_nonbasicnonbasic_term
apply_basic_substituteclear_all_nonbasic_marksmark_term_nonbasicp_term_basic
basic_paramodinit_basic_paramodnonbasic_flagset_basic_paramod

Details


Term apply_basic(Term t, Context c);
This is similar to apply(), but it makes "nonbasic" marks for "basic paramodulation".
Term apply_basic_substitute(Term t, Term beta, Context c_from,
			    Term into_term, Context c_into);
This is similar to apply_substitute(), but it makes "nonbasic" marks for "basic paramodulation".
BOOL basic_paramod(void);
Is basic paramodulation enabled?
BOOL basic_term(Term t);
Check if a term is basic. This simply checks the "nonbasic" mark.
void clear_all_nonbasic_marks(Term t);

void init_basic_paramod(void);

void mark_all_nonbasic(Term t);

void mark_term_nonbasic(Term t);

int nonbasic_flag(void);

BOOL nonbasic_term(Term t);
Check if a term is nonbasic. This simply checks the "nonbasic" mark.
void p_term_basic(Term t);

void set_basic_paramod(BOOL flag);
Set or clear basic paramodulation.

Public Definitions in File basic.h


Introduction


LADR-2009-11A/ladr/html/clause_misc.html0000644000175000017500000000701510775516357017104 0ustar mccunemccune clause_misc.h

#include "clause_misc.h"

This page has information from files clause_misc.h and clause_misc.c.

Contents


Public Routines in File clause_misc.c

Index

clist_copycopy_clauses_to_clistdelete_clistmove_clauses_to_clist
copy_clause_ijadelete_clauseinput_clauses
copy_clauses_ijadelete_clausesmake_clause_basic

Details


Clist clist_copy(Clist a, BOOL assign_ids);
Copy a clist of clauses. Justificatons and attributes are copied, and the clauses get new IDs.
Topform copy_clause_ija(Topform c);
Copy a clause, including ID, justification, attributes, and termflags. Clauses constructed with this routine should be deallocated with delete_clause().
Plist copy_clauses_ija(Plist p);
Copy a Plist of clauses. Clauses are coped with copy_clause_ija(), which copies ID, justification, attributes, and termflags.
Clist copy_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids);

void delete_clause(Topform c);
This routine frees a clause and all of its subterms. If the clause has an ID, it is unassigned. If the clause has a justification list, it is freed.

This routine is not in the clause package, because (at this time) the clause package doesn't know about just.h or clauseid.h.


void delete_clauses(Plist p);
Delete (deep) a Pist of clauses.
void delete_clist(Clist l);
For each Topform in the Clist, remove it from the Clist; if it occurs in no other Clists, call delete_clause(). Finally, free the Clist.

This routine is not in the clist package, because (at this time) the clist package doesn't know about just.h or clauseid.h.


Plist input_clauses(Plist a);
Given a Plist of clauses, return the Plist of input clauses (in the same order).
void make_clause_basic(Topform c);
This routine clears all of the "nonbasic" marks in a clause.
Clist move_clauses_to_clist(Plist clauses, char *name, BOOL assign_ids);

Public Definitions in File clause_misc.h


Introduction


LADR-2009-11A/ladr/html/termflag.html0000644000175000017500000000767210775516357016427 0ustar mccunemccune termflag.h

#include "termflag.h"

This page has information from files termflag.h and termflag.c.

Contents


Public Routines in File termflag.c

Index

claim_term_flagrelease_term_flagterm_flag_clear_recursively
copy_term_with_flagterm_flagterm_flag_set
copy_term_with_flagsterm_flag_clearterm_flags

Details


int claim_term_flag();
This routine returns an available flag number for marking terms. If the use will be temporary, make sure to call release_term_flag() when you are finished using the marks. A fatal error occurs if no more flags are available.
Term copy_term_with_flag(Term t, int flag);
This routine copies a term, including one specified flag of the term and its subterms. Any other flags or extra fields are not copied.
Term copy_term_with_flags(Term t);
This routine copies a term, including all of the flags of the term and its subterms. Any other extra fields are not copied.
void release_term_flag(int bit);
This routine frees a flag number for future use.
BOOL term_flag(Term t, int flag);
This function gets the value of a flag on a term. The flag argument is a small integer in the range [0 ... n-1], where n is the number of bits available for flags. If n is out of range, FALSE is returned.
void term_flag_clear(Term t, int flag);
This routine clears a flag on a term. The flag argument is a small integer in the range [0 .. n-1], where n is the number of bits available for flags. If n is out of range, none of the flags will change.
void term_flag_clear_recursively(Term t, int flag);

void term_flag_set(Term t, int flag);
This routine sets a flag on a term. The flag argument is a small integer in the range [0 .. n-1], where n is the number of bits available for flags. If n is out of range, none of the flags will change.

Term flags are stored as bits in the field private_flags. (Look at the definition of Term to find out big private_flags is.) If you need more flags, you can simply change the type of private_flags to unsigned short (usually 16 bits) or unsigned int (usually 32 bits). It is your responsibility to make sure that all of the flags you use are in range.


int term_flags();
This routine returns the number of bits available for term flags. The value should always be at least 8. If the value is n, you can use flags numbered [0 ... n-1].

Public Definitions in File termflag.h

#define TP_BIT(bits, flag)     (bits & flag)


Introduction


LADR-2009-11A/ladr/html/unify.html0000644000175000017500000003602310775516357015750 0ustar mccunemccune unify.h

#include "unify.h"

This page has information from files unify.h and unify.c.

Contents


Public Routines in File unify.c

Index

applyfprint_trailoccur_checkundo_subst_2
apply_substitutefprint_unify_memp_contextunify
apply_substitute2free_contextp_trailvariable_substitution
context_to_pairsget_contextp_unify_memvariant
empty_substitutionmatchsubst_changes_termvars_in_trail
fprint_contextmatch_weightundo_subst

Details


Term apply(Term t, Context c);
This routine applies the substitution in Context c to Term t. See the explanation of unify() for an example of the use of apply().
Term apply_substitute(Term t, Term beta, Context c_from,
		      Term into_term, Context c_into);
This routine is like apply(), but when it reaches a particular subterm (into_term) of the source term (t), it continues with another source term (beta). This routine is intended to be used for paramodulation, to avoid unnecessary work. For example, when paramodulating alpha=beta into p[into_term], where alpha unifies with into_term, we construct the appropriate instance of p[beta] in one step by using this routine.
Term apply_substitute2(Term t, Term beta, Context c_from,
		       Ilist into_pos, Context c_into);
Similar to apply_substitute, but the into_term is specified with a position vector instead of the term itself. This is so that the into term can be a variable. (Recall that variables are probably shared, and we have to specify an *occurrence*.)
Plist context_to_pairs(Ilist varnums, Context c);

BOOL empty_substitution(Context s);

void fprint_context(FILE *fp, Context c);
This routine prints (to FILE *fp) a Context.
void fprint_trail(FILE *fp, Trail t);
This routine prints (to FILE *fp) a Trail. The whole list is printed.
void fprint_unify_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the unify package. The Boolean argument heading tells whether to print a heading on the table.
void free_context(Context p);

Context get_context(void);

BOOL match(Term t1, Context c1, Term t2, Trail *trp);
This routine checks if Term t2 (without a Context) is an instance of Term t1 (in Context c1). If successful, Context c1 and Trail * trp are updated. The calling sequence and the use of Contexts and Trails is similar to those for unify().
BOOL match_weight(Term t1, Context c1, Term t2, Trail *trp, int var_sn);
Special-purpose match for weighting.
BOOL occur_check(int vn, Context vc, Term t, Context c);
This function checks if a variable with index vn (in Context vc) occurs in Term t (in Context c), including the top case, where t is the variable in question.
void p_context(Context c);
This routine prints (to stdout) a Context.
void p_trail(Trail t);
This routine prints (to stdout) a Trail. The whole list is printed.
void p_unify_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the unify package.
BOOL subst_changes_term(Term t, Context c);
This routine checks if a subsitution would change a term, if applied.
void undo_subst(Trail tr);
This routine clears substitution entries recoded in Trail tr, and frees the corresponding Trail nodes.
void undo_subst_2(Trail tr, Trail sub_tr);
It is assumed that Trail sub_tr is a subtrail of Trail tr. This routine clears part (maybe all) of a substitution, by clearing the entries from tr up to, but not including sub_tr. The corresponding Trail nodes are deallocated, so the caller should no longer refer to tr. (This is useful for inference rules like hyperresolution, which backtrack, undoing parts of substitutions.)
BOOL unify(Term t1, Context c1,
	   Term t2, Context c2, Trail *trp);
This routine tries to unify two terms in their respective contexts. Trail * trp is the address of a Trail. If successful, the trail is extended (at its front) with substitutions that were made, and trp is updated to point to the new beginning of the trail. If unify fails, the Contexts and the Trail * are not changed.

You must make sure, before calling unify(), that no variable v in t1 or t2 has VARNUM(v) >= MAXVARS. This is usually accomplished by calling a routine that renames variables.

Here is an example how to use unify(), apply(), and undo_subst(). Assume we have terms t1 and t2. (Terms t1 and t2 may share variables, but we "separate" the variables by using different contexts. That is, variable v1 in context c1 is different from variable v1 in context c2.)

    {
        Context c1 = get_context();
        Context c2 = get_context();
        Trail tr = NULL;
        if (unify(t1, c1, t2, c2, &tr)) {
            Term t3 = apply(t1, c1);
            Term t4 = apply(t2, c2);
            if (term_ident(t3, t4))
                printf("everything is OK\n");
            else
                printf("something is broken\n");
            undo_subst(tr);
            zap_term(t3);
            zap_term(t4);
        }
        else
            printf("unify fails\n");
        free_context(c1);
        free_context(c2);
    }

BOOL variable_substitution(Context s);

BOOL variant(Term t1, Context c1,
	    Term t2, Trail *trp);
This routine checks if Term t1 (in Context c1) and Term t2 (without a Context) are variants, that is, if each is an instance of the other. If successful, the unifying substitution is in Context c1. The calling sequence and the use of Contexts and Trails is the same as for unify().
Ilist vars_in_trail(Trail tr);
Return the list of variables (as integers) in a trail. Note that this ignores the contexts associated with the varibles.

Public Definitions in File unify.h

/* Dereference a variable. */

#define DEREFERENCE(t, c) { int i; \
    while (c!=NULL && VARIABLE(t) && c->terms[i=VARNUM(t)]) \
    { t = c->terms[i]; c = c->contexts[i]; } } 

/* A Context records a substitution of terms for variables. */

typedef struct context * Context;

struct context {
  Term    terms[MAX_VARS];    /* terms substituted for variables */
  Context contexts[MAX_VARS]; /* Contexts corresponding to terms */
  int     multiplier;         /* for getting separate vars in apply */
  Term    partial_term;       /* for AC matching */
};

typedef struct trail * Trail;

/* The following type is for backtrack unification and matching. */

typedef enum { NO_ALT = 0,
	       AC_ALT,
	       COMM_ALT
             } Unif_alternative;


Introduction

This package handles ordinary unification and matching of terms. The methods are probably different from what you learned in your logic course, so pay close attention.

In situations where you consider instantiating the variables of a term t, you will have an associated Context c. The Context keeps track of the terms that are substituted for the variables--- think of it as a substitution table indexed by the variable number.

Contexts allow you to separate variables of two terms without creating a renamed copy of one of the terms. Say we have two terms with different Contexts: (t1,c1) and (t2,c2). If t1 and t2 share a variable, say v3, occurrences in t1 are a different variable from occurrences in t2, because the contexts are different. Think of the those variables as (v3,c1) and (v3,c2). In fact, when an instantiation is recorded in a Context, the variable in question is set to a pair, say (t4,c4) rather than just t4, because we have to know how to interpret the variables of t4.

There are situations where the terms being unified really do share variables, for example when factoring the literals of a clause; in those cases, you simply use the same context for both terms.

When you call unify(), match(), or any other routine that tries to make terms identical by instantiation, the terms you give are not changed---all of the action happens in their contexts (and in the trail, see below). So you do not have to copy terms before calling the routine.

When a unify or match routine succeeds, the Contexts are updated to reflect the common instance of the terms. Also, a Trail is returned. A Trail is a linked list of (variable,context) pairs telling exactly which variables were instantiated during the operation. Its purpose is to quickly restore the Contexts to their previous states.

You must explicitly allocate and free Contexts. To save time, we don't initialize the arrays each time a Context is re-allocated, and we don't check that Contexts are clear when they are freed. Therefore, you must make sure that a Context is clear before freeing it. See undo_subst(). Also, if you forget to clear the Context with undo_subst(), you will have a memory leak, because the Trail will be lost. (If you suspect that you have a bug which causes a non-empty context to be freed, you can enable a run-time check in free_context() and recompile unify.c.)

When you wish to find out what a context does to a term t, you can call apply(), which builds a new copy of the term with all of the instantiations of the context applied to the term t. But I wrote above that (v3,c1) is a different variable from (v3,c2)---what does apply do with uninstantiated variables? Each context has a unique multiplier (a small natural number); When apply() gets to an uninstantiated variable v, it returns a variable with index (multiplier*MAX_VARS)+VARNUM(v). Of course, this can give you VARNUMs > MAX_VARS, so you may have to rename variables of the result before calling a unification routine on the result.

Unification and matching can be used incrementally. For example, you can all unify() with a context which has entries from a previous call to unify(). Hyperresolution can be implemented by backtracking through the negative literals of a nucleus and the satellites that unify with a given literal of the nucleus, constructing and undoing partial substitutions along the way. Another example is subsumption. Checking whether one clause subsumes another can be done by incremental matching, backtracking through the literals of the potential subsumer, trying to map them to the literals of the other clause.

Associative-commutative unification and matching, and commutative unification and matching, use different unification code, because they have to deal with multiple unifiers for a pair of terms. (These other kinds of unification and matching may use the Context data type defined here.)


LADR-2009-11A/ladr/html/options.html0000644000175000017500000002774210775516357016321 0ustar mccunemccune options.h

#include "options.h"

This page has information from files options.h and options.c.

Contents


Public Routines in File options.c

Index

flag_id_to_stroption_dependencies_stateset_flag
assign_parmflag_parm_dep_defaultoption_updatesstr_to_flag_id
assign_stringparmflag_parm_dependencyover_parm_limitstr_to_parm_id
at_parm_limitflag_stringparm_dep_defaultp_optionsstr_to_stringparm_id
clear_flagflag_stringparm_dependencyp_options_memstringparm
disable_option_dependenciesfprint_optionsparmstringparm1
enable_option_dependenciesfprint_options_memparm_defaultstringparm1_default
flag_defaultinit_flagparm_flag_dependencystringparm_id_to_str
flag_flag_dep_defaultinit_parmparm_id_to_strupdate_flag
flag_flag_dependencyinit_stringparmparm_parm_dependency

Details



int flag(int flag_id);
This Boolean routine returns the value of a flag. If the Flag index is out of range, bad things can happen.
void assign_parm(int id, int val, BOOL echo);
This routine assigns a value to a parm. The parm is identified by its integer ID (which is available from str_to_parm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs.
void assign_stringparm(int id, char *val, BOOL echo);
This routine assigns a value to a stringparm. The stringparm is identified by its integer ID (which is available from str_to_stringparm_id()). If the ID is not valid, or if the value is out of range, a fatal error occurs.
BOOL at_parm_limit(int value, int parm_id);
This assumes that -1 represents infinity.
void clear_flag(int id, BOOL echo);
This routine clears a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs.
void disable_option_dependencies(void);

void enable_option_dependencies(void);

int flag_default(int flag_id);

void flag_flag_dep_default(int id, BOOL val, int dep_id);
This routine declares that a flag depends on another flag. If flag "id" gets value "val", then flag "dep_id" is automatically given its default value.
void flag_flag_dependency(int id, BOOL val, int dep_id, BOOL dep_val);
This routine declares that a flag depends on another flag. If flag "id" gets value "val", then flag "dep_id" is automatically given value "dep_val".
char *flag_id_to_str(int id);
Given a flag ID, return the corresponding name of the flag.
void flag_parm_dep_default(int id, BOOL val, int dep_id);
This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given its default value.
void flag_parm_dependency(int id, BOOL val, int dep_id, int dep_val);
This routine declares that a parm depends on a flag. If flag "id" gets value "val", then parm "dep_id" is automatically given value "dep_val".
void flag_stringparm_dep_default(int id, BOOL val, int dep_id);
This routine declares that a stringparm depends on a flag. If flag "id" gets value "val", then stringparm "dep_id" is automatically given its default value.
void flag_stringparm_dependency(int id, BOOL val, int dep_id, char *dep_val);
This routine declares that a stringparm depends on a flag. If flag "id" gets value "val", then stringparm "dep_id" is automatically given value "dep_val".
void fprint_options(FILE *fp);
This routine prints (to FILE *fp) the current values of all of the the options (flags, parms, and stringparms).
void fprint_options_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the options package. The Boolean argument heading tells whether to print a heading on the table.
int init_flag(char *name,
	      BOOL default_value);
Initialize a flag (boolean-valued option). You give it a name and a default value, and an integer id is returned. Flags are typically changed by user commands which are parsed by read_commands(). The value of a flag is checked with flag(ID).
int init_parm(char *name,
	      int default_value,
	      int min_value,
	      int max_value);
Initialize a parm (integer-valued option). You give it a name, a default value, and min and max values. An integer id is returned. Parms are typically changed by user commands which are parsed by read_commands(). The value of a parm is checked with parm(ID).
int init_stringparm(char *name,
		    int n,
		    ...);
Initialize a stringparm (string-valued option). You give it a name, a number n of possible values, and n strings which are the possible values. An integer id is returned The first string given is the default value.

Stringparms are typically changed by user commands which are parsed by read_commands(). The value of a stringparm is checked with the Boolean routine stringparm(ID, string).


BOOL option_dependencies_state(void);

int option_updates(void);
How many times have Flags, Parms, or Stringparms been updated?
BOOL over_parm_limit(int value, int parm_id);
This assumes that -1 represents infinity.
void p_options(void);
This routine prints (to stdout) the current values of the the options (flags, parms, and stringparms).
void p_options_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the options package.
int parm(int parm_id);
This integer routine returns the value of a parameter. If the parm index is out of range, bad things can happen.
int parm_default(int parm_id);

void parm_flag_dependency(int id, int dep_id, int dep_val);
This routine declares that a flag depends on a parm. If parm "id" gets changed, then flag "dep_id" is automatically given value "dep_val".
char *parm_id_to_str(int id);
Given a parm ID, return the corresponding name of the parm.
void parm_parm_dependency(int id, int dep_id, int dep_val, BOOL multiply);
This routine declares that a parm depends on a parm. If (multiply == TRUE), then dep_val is a multiplier instead of a value.
void set_flag(int id, BOOL echo);
This routine sets a flag. The flag is identified by its integer ID (which is available from str_to_flag_id()). If the ID is not valid, a fatal error occurs.
int str_to_flag_id(char *name);
This routine converts the string name of a flag to its integer ID. If the string name is not valid, -1 is returned.
int str_to_parm_id(char *name);
This routine converts the string name of a parm to its integer ID. If the string name is not valid, -1 is returned.
int str_to_stringparm_id(char *name);
This routine converts the string name of a stringparm to its integer ID. If the string name is not valid, -1 is returned.
BOOL stringparm(int id, char *s);
This routine checks if the current value of a stringparm matches the given string. The ID must be valid.
char *stringparm1(int id);
This routine returns the current value of a stringparm. The ID must be valid.
char *stringparm1_default(int id);

char *stringparm_id_to_str(int id);
Given a stringparm ID, return the corresponding name of the stringparm.
void update_flag(FILE *fout, int id, BOOL val, BOOL echo);
This performs the role of set_flag() and clear_flag(). In addition, an output file is given for dependency messages.

Public Definitions in File options.h

#define MAX_FLAGS                100
#define MAX_PARMS                100
#define MAX_STRINGPARMS          100


Introduction

There are 3 types of option:
  • Flags: Boolean
  • Parms: Integer
  • Stringparm: String

To introduce a new option, choose an integer ID that is unique for the type of option, and call the appropriate initialization routine. Then you can change the value of the option and check its value as you like.

The routine read_commands() (in the "commands" package) will parse the user's set, clear, and assign commands, making the appropriate changes to the values of the options.

In most cases, the applications programmer will be using the following routines.

  • Flags: init_flag(), flag().
  • Parms: init_parm(), parm().
  • Stringparm: init_stringparm(), stringparm().

LADR-2009-11A/ladr/html/xproofs.html0000644000175000017500000000461310775516360016310 0ustar mccunemccune xproofs.h

#include "xproofs.h"

This page has information from files xproofs.h and xproofs.c.

Contents


Public Routines in File xproofs.c

Index

check_parents_and_uplinks_in_proofexpand_proofproof_id_to_clauserenumber_proof
copy_and_renumber_proofgreatest_id_in_proofproof_to_xproof

Details


void check_parents_and_uplinks_in_proof(Plist proof);

Plist copy_and_renumber_proof(Plist proof, int start);
We assume that every clause occurs after its parents.
Plist expand_proof(Plist proof, I3list *pmap);
Given a proof, return a more detailed proof, entirely new, leaving the given proof unchanged. Also returned is an I3list mapping new IDs to pairs . The n compnent identifies the sub-steps arising from the expansions, e.g., 66 -> <23,4> means that step 66 in the new proof corresponds to the 4th substep in expanding step 23 of the old proof. Clauses in the new proof that match clauses in the old proof retain the IDs from the old proof, and there is no entry in the map for them.
int greatest_id_in_proof(Plist proof);

Topform proof_id_to_clause(Plist proof, int id);

Plist proof_to_xproof(Plist proof);

void renumber_proof(Plist proof, int start);
We assume that every clause occurs after its parents.

Public Definitions in File xproofs.h


Introduction


LADR-2009-11A/ladr/html/std_options.html0000644000175000017500000000242210775516360017151 0ustar mccunemccune std_options.h

#include "std_options.h"

This page has information from files std_options.h and std_options.c.

Contents


Public Routines in File std_options.c

Index

clocks_idinit_standard_optionsprocess_standard_optionsprolog_style_variables_id

Details


int clocks_id(void);

void init_standard_options(void);

void process_standard_options(void);

int prolog_style_variables_id(void);

Public Definitions in File std_options.h


Introduction


LADR-2009-11A/ladr/html/banner.html0000644000175000017500000000211510775516360016050 0ustar mccunemccune banner.h

#include "banner.h"

This page has information from files banner.h and banner.c.

Contents


Public Routines in File banner.c

Index

print_bannerprint_separator

Details


void print_banner(int argc, char **argv,
		  char *name, char *version, char *date,
		  BOOL as_comments);
Print the standard banner.
void print_separator(FILE *fp, char *str, BOOL initial_newline);
Print the standard separator line.

Public Definitions in File banner.h


Introduction


LADR-2009-11A/ladr/html/resolve.html0000644000175000017500000000735210775516360016272 0ustar mccunemccune resolve.h

#include "resolve.h"

This page has information from files resolve.h and resolve.c.

Contents


Public Routines in File resolve.c

Index

copy_inferencemerge_literalsresolve3
binary_factorshyper_resolutionres_instance_prunesur_resolution
binary_resolutioninstantiate_clauseresolve2xx_resolve2

Details



void resolution_options(BOOL ordered,
			BOOL check_instances,
			BOOL initial_nuclei,
			int ur_nucleus_limit);

void binary_factors(Topform c, void (*proc_proc) (Topform));

void binary_resolution(Topform c,
		       int res_type,  /* POS_RES, NEG_RES, ANY_RES */
		       Lindex idx,
		       void (*proc_proc) (Topform));
Binary resolution.
Topform copy_inference(Topform c);
This makes a "copy" inference; that is, a copy of the clause in which the justification is "copy". All attributes are copied (not just the inheritible attributes). An ID is not assigned.
void hyper_resolution(Topform c, int pos_or_neg, Lindex idx,
		      void (*proc_proc) (Topform));
Hyperresolution.
Topform instantiate_clause(Topform c, Context subst);

void merge_literals(Topform c);

int res_instance_prunes();

Topform resolve2(Topform c1, int n1, Topform c2, int n2, BOOL renumber_vars);
Resolve, if possible, two clauses on the literals (specified by literals, counting from 1). Include justification, transfer inheritable attributes, but do not assign an ID. Renumbering of variables is optional.

if n2 < 0, then the literal is abs(n2), and it should be flipped.


Topform resolve3(Topform c1, Literals l1, Topform c2, Literals l2, BOOL renumber_vars);
Similar to resolve2(), but literals are given instead of integers.
void ur_resolution(Topform c, int target_constraint, Lindex idx,
		   void (*proc_proc) (Topform));
Unit-resulting resolution.
Topform xx_resolve2(Topform c, int n, BOOL renumber_vars);
Resolve, if possible, a clause with x=x. Renumber vars, include justification, transfer inheritable attributes, but do not assign an ID.

Public Definitions in File resolve.h

enum {  /* literal selection */
  LIT_SELECTION_NONE,
  LIT_SELECTION_MAXIMAL,
  LIT_SELECTION_ALL
};

enum {  /* types of resolution (binary, hyper, UR) */
  POS_RES,  /* positive */
  NEG_RES,  /* negative */
  ANY_RES   /* unrestricted by sign */
};


Introduction


LADR-2009-11A/ladr/html/btu.html0000644000175000017500000001076710775516357015417 0ustar mccunemccune btu.h

#include "btu.h"

This page has information from files btu.h and btu.c.

Contents


Public Routines in File btu.c

Index

fprint_btu_memp_btu_memunify_bt_first
p_bt_treeunify_bt_cancelunify_bt_next

Details


void fprint_btu_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the btu package. The Boolean argument heading tells whether to print a heading on the table.
void p_bt_tree(Btu_state bt, int n);
This (recursive) routine prints (to stdout) a backtrack unification state. Parameter n should be 0 on the top call.
void p_btu_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the btu package.
void unify_bt_cancel(Btu_state bt);
This routine frees the memory associated with a state in backtrack unification. This should be called if you decide to get some, but not all, unifiers from unify_bt_first() and unify_bt_next().
Btu_state unify_bt_first(Term t1, Context c1,
			Term t2, Context c2);
This routine gets the first unifier for a pair of terms and returns a Btu_state (or NULL if there are no unifiers) to be used for calls to unify_bt_next() to get the rest of the unifiers. This unification handles associative-commutative (AC) and commutative (C) symbols, so there can be more than one unifier. (Commutatvie unification is primitive, and you can get duplicate unifiers.)

This is called "backtrack unification", because the unifiers are constructed incrementally, as needed. Here is an example of how to do it. Assume we have Terms t1 and t2.

  {
    Context c1 = get_context();
    Context c2 = get_context();
    bt = unify_bt_first(t1, c1, t2, c2);
    while (bt != NULL) {
      t3 = apply(t1, c1);
      t4 = apply(t2, c2);
      
      zap_term(t4);
      bt = unify_bt_next(bt);
      }
    free_context(c1);
    free_context(c2);
  }
The routine unify_bt_next() takes care of clearing the substitutions before getting the next unifier. If you decide not to get all of the unifiers, you should call unify_bt_cancel() to free the memory used by the Btu_state.

If there are no AC or C symbols, it is a little bit faster to use unify() (ordinary unification) instead of backtrack unification.


Btu_state unify_bt_next(Btu_state bt1);
This routine gets the next unifier for "backtrack unification". See unify_bt_first() for an explanation.

Public Definitions in File btu.h

typedef struct btu_state * Btu_state;


Introduction

This package handles "backtrack unification", that is, unification that allows more than one unifier for a pair of terms, and computes the unifiers incrementally by backtracking. As I write this, we support associative commutative (AC) operations and commutative/symmetric (C) operations. Symbols are declared to be AC with set_assoc_comm() and C with set_commutative(). The use of Terms and Contexts is similar to ordinary unification, except that the means for undoing substitutions is different.
LADR-2009-11A/ladr/html/clause_eval.html0000644000175000017500000000305310775516357017076 0ustar mccunemccune clause_eval.h

#include "clause_eval.h"

This page has information from files clause_eval.h and clause_eval.c.

Contents


Public Routines in File clause_eval.c

Index

compile_clause_eval_ruleeval_clause_in_rulerule_contains_semanticszap_clause_eval_rule

Details


Clause_eval compile_clause_eval_rule(Term t);

BOOL eval_clause_in_rule(Topform c, Clause_eval p);
The following properties have fields in the clause, and if they hold, those flags should already be set: matches_hint, weight, semantics.
BOOL rule_contains_semantics(Clause_eval p);

void zap_clause_eval_rule(Clause_eval p);

Public Definitions in File clause_eval.h

typedef struct clause_eval *Clause_eval;


Introduction


LADR-2009-11A/ladr/html/interp.html0000644000175000017500000004155010775516360016112 0ustar mccunemccune interp.h

#include "interp.h"

This page has information from files interp.h and interp.c.

Contents


Public Routines in File interp.c

Index

assign_discriminator_countsevaluable_literalsident_interp_permp_interp
canon_interpevaluable_termint_powerp_interp_mem
compare_interpevaluable_topforminterp_commentsp_interp_profile
compile_interpfactorialinterp_remove_constantsperms_required
copy_interpfprint_interp_cookedinterp_remove_constants_recursepermute_interp
create_profilefprint_interp_meminterp_remove_otherssame_discriminator_counts
eval_formulafprint_interp_portableinterp_remove_others_recursesame_profiles
eval_literalsfprint_interp_rawinterp_sizetranspose_binary
eval_literals_false_instancesfprint_interp_standardinterp_tableupdate_interp_with_constant
eval_literals_true_instancesfprint_interp_standard2iso_checksupdate_profile
eval_term_groundfprint_interp_tabulariso_permszap_interp
eval_topformfprint_interp_texisomorphic_interps
evaluable_atomfprint_interp_xmlnormal3_interp
evaluable_formulaident_interpnormal_interp

Details


void assign_discriminator_counts(Interp a, Plist discriminators);

Interp canon_interp(Interp a);
Return the (unique) canonical form of the interp. The input interp (which is not changed) is assumed to be in normal form.
Ordertype compare_interp(Interp a, Interp b);
Compare two compatible interpretations. Return SAME_AS, GREATER_THAN, or LESS_THAN.
Interp compile_interp(Term t, BOOL allow_incomplete);
This routine takes a term representing an interpretation and builds a data structure that allows fast evaluation of clauses and formulas w.r.t. the interpretation. Here is an example of the term form of an interpretation.
   interpretation(3, [
       function(e,      [0]),
       function(*(_,_), [0,1,2,1,2,0,2,0,1]),
       relation(p,      [1])
       relation(q(_),   [1,0,1])
       ])
The given Term t is not changed.
Interp copy_interp(Interp p);
This routine copies an interpretation. We don't check for errors.
void create_profile(Interp a, Plist discriminators);

BOOL eval_formula(Formula f, Interp p);
This routine evaluates a closed formula in an interpretation.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the formula (other than eq_sym(), which is always built in) is absent from the interpetation.

A fatal error occurs if the formula contains any terms of type VARIABLE. (Variables bound by quantifier are represented as terms of type CONSTANT.)


BOOL eval_literals(Literals lits, Interp p);
This routine evaluates a clause in an interpretation. If all instances (over the domain of the interpretation) of the clause are true in the interpretaion, TRUE is returned. If any instance is false, FALSE is returned.

Note that if the interpretation has d elements and the clause has v variables, it takes d^v evaluations to verify the clause.

All natural numbers are interpreted as domain values, and if any domain values are out of range, a fatal error occurs.

A fatal error occurs if any constant, function or predicate symbol in the clause (other than eq_sym(), which is always built in) is absent from the interpetation.


int eval_literals_false_instances(Literals lits, Interp p);

int eval_literals_true_instances(Literals lits, Interp p);
This routine evaluates a clause in an interpretation. The number of false instances is returned.f The variables in the clause must be normal (0,1,2,...).
int eval_term_ground(Term t, Interp p, int *vals);

BOOL eval_topform(Topform tf, Interp p);

BOOL evaluable_atom(Term a, Interp p);

BOOL evaluable_formula(Formula f, Interp p);

BOOL evaluable_literals(Literals lits, Interp p);

BOOL evaluable_term(Term t, Interp p);

BOOL evaluable_topform(Topform tf, Interp p);

long unsigned factorial(int n);
If overflow, return 0.
void fprint_interp_cooked(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in cooked form, e.g., f(0,2)=1.
void fprint_interp_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the interp package. The Boolean argument heading tells whether to print a heading on the table.
void fprint_interp_portable(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in portable form.
void fprint_interp_raw(FILE *fp, Interp p);
This routine pretty prints (to FILE *fp) an interpretation in raw form.
void fprint_interp_standard(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in standard form, with each operation on a separate line.
void fprint_interp_standard2(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in standard form, with each operation on a separate line, except that binary operations are printed on multiple lines.
void fprint_interp_tabular(FILE *fp, Interp p);
This routine pretty prints (to FILE *fp) an interpretation in tabular (not easily parsable). Arities > 2 are not pretty.
void fprint_interp_tex(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in a form that might be useful as input to LaTeX.
void fprint_interp_xml(FILE *fp, Interp p);
This routine prints (to FILE *fp) a compiled interpretation, in a form that might be useful as input to LaTeX.
BOOL ident_interp(Interp a, Interp b);
Are interpretations A and B identical? It is assumed that A and B are the same size and have the same symbols.
BOOL ident_interp_perm(Interp a, Interp b, int *p);
Is interpretation B identical to a given permutation of interpretation A? If so, then A and B are isomorphic. It is assumed that A and B are the same size and have the same symbols.
int int_power(int n, int exp);
Return n^exp. If exp is negative, return -1. If the result is too big to fit into an int, return INT_MAX.
Term interp_comments(Interp a);
Return the comments of an interpretation.
void interp_remove_constants(Term t);
In a non-compiled interpretation, remove all constants.
Term interp_remove_constants_recurse(Term ops);
In a non-compiled interpretation, remove all constants.
void interp_remove_others(Term t, Plist keepers);
In a non-compiled interpretation, remove all others.
Term interp_remove_others_recurse(Term ops, Plist keepers);
In a non-compiled interpretation, remove all others.
int interp_size(Interp a);
Return the domain size of an interpretation.
int *interp_table(Interp p, char *sym, int arity);
Given a symbol and arity, return the corresponding table.
long unsigned iso_checks(void);
Return the number of isomorphism checks. For normal checks, ones where the occurrence-types don't match are not counted.
long unsigned iso_perms(void);
Return the number of permutations seen during isomorphism checks.
BOOL isomorphic_interps(Interp a, Interp b, BOOL normal);
Are interpretations A and B isomorphic? We assume they are compatible (same operations/arities). If the flag normal is set, it is assumed that both interps were produced by normal_interp(); this allows some optimization.
Interp normal3_interp(Interp a, Plist discriminators);

Interp normal_interp(Interp a);
This routine returns a normalized copy of an interpretation. Normalized interpretations are used to speed up isomorphism checking.

Consider, in all of the function tables, the number of occurrences of each element. If we have a size-4 interpretation with a binary function, a unary function, and a constant, the occurrence array might be something like [7,6,4,4], meaning that there are 7 occurrences of 0, 6, occurrences of 1, 4 occurrences of 2, and 4 occurrences of 3. If the occurrence array is nonincreasing, the interpretation is in a normal form. (Normal forms are not unique; otherwise, isomorphism checking would be trivial.)

If 2 normal interpretations have different occurrence arrays, they cannot be isomorphic. That's the first check we make.

When checking whether two interpretations are isomorphic, we look at permutations of one of the interpretations, and we can use occurrence array to eliminate some of the permutations. Examples: with occurrence array [7,6,4,4], we look at only 2 permutations: (0,1,2,3) and (0,1,3,2); with occurrence array [4,4,4,3,3], we'd look at 12 (6*2) permutations instead of 120 (5!).


void p_interp(Interp p);
This routine prints (to stdout) a compiled interpretation, in portable form, with each operation on a separate line.
void p_interp_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the interp package.
void p_interp_profile(Interp a, Plist discriminators);

long unsigned perms_required(Interp a);

Interp permute_interp(Interp source, int *p);
This routine returns a permutation of an interpretation. The permuted interpretation does not contain the term representation (because it would be nontrivial to construct it).
BOOL same_discriminator_counts(Interp a, Interp b);

BOOL same_profiles(Interp a, Interp b);

void transpose_binary(Term t);
This routine takes a term representing an interpretation and (destructively) transposes all of the binary functions and relations. It is assumed that the interpretation is well-formed. You can check well-formedness first by calling compile_interp().
void update_interp_with_constant(Interp p, Term constant, int val);

void update_profile(Topform c, Interp a, int *next)
     /* vecs[domain_element][profile_component] */
      ;

void zap_interp(Interp p);
Free a compiled interpretation.

Public Definitions in File interp.h

typedef struct interp *Interp;

enum { SEMANTICS_NOT_EVALUATED,
       SEMANTICS_NOT_EVALUABLE,
       SEMANTICS_TRUE,
       SEMANTICS_FALSE
 };


Introduction


LADR-2009-11A/ladr/html/btm.html0000644000175000017500000001040710775516357015376 0ustar mccunemccune btm.h

#include "btm.h"

This page has information from files btm.h and btm.c.

Contents


Public Routines in File btm.c

Index

fprint_btm_memmatch_bt_firstp_btm_mem
match_bt_cancelmatch_bt_nextp_btm_state

Details


void fprint_btm_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the btm package. The Boolean argument heading tells whether to print a heading on the table.
void match_bt_cancel(Btm_state bt);
This routine clears any substitution and frees memory associated with a backtrack matching state. This should be called if you get some, but not all, matching substitutions in backtrack matching. See match_bt_first().
Btm_state match_bt_first(Term t1, Context c1, Term t2, int partial);
This is backtracking matching, to be used when there can be more than one unifier. This version handles (any number of) commutative (C) and associative-commutative (AC) function symbols.

The flag `partial' says that if the top level is AC, then not all arguments of t2 have to be matched. The non-matched args are put in c1->partial_term. Partial matches are allowed for the top level only. This is useful for AC rewriting.

If any AC terms are in t1 or t2, then both t1 and t2 should be in `ac_canonical()' form before the call, that is, AC terms are right associated and sorted. C terms are in t1 or t2 need not be c_canonical. (Commutatvie matching is primitive, and you can get duplicate unifiers.)

Get first matching substitution. Return position for match_bt_next() calls. Here is an example. Assume we have terms t1 and t2.

  {
    Context c1 = get_context();
    Btm_state bt = match_bt_first(t1, c1, t2, 0);
    while (bt != NULL) {
        Term t3 = apply(t1, c1);
        zap_term(t3);
        bt = match_bt_next(bt);
        }
    free_context(c1);
  }
If you quit before NULL is returned, call match_bt_cancel(bt) to clear substitutions and free memory.
Btm_state match_bt_next(Btm_state bt1);
This routine gets the next matching substitution. See match_bt_first() for details.
void p_btm_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the btm package.
void p_btm_state(Btm_state bt);
This routine prints (to stdout) a Btm_state. It is not pretty.

Public Definitions in File btm.h

typedef struct btm_state * Btm_state;


Introduction

This package handles "backtrack matching", that is, matching that allows more than one unifier for a pair of terms, and computes the unifiers incrementally by backtracking. As I write this, we support associative commutative (AC) operations and commutative/symmetric (C) operations. Symbols are declared to be AC with set_assoc_comm() and C with set_commutative(). The use of Terms and Contexts is similar to ordinary matching, except that the means for undoing substitutions is different.
LADR-2009-11A/ladr/html/maximal.html0000644000175000017500000000650510775516357016250 0ustar mccunemccune maximal.h

#include "maximal.h"

This page has information from files maximal.h and maximal.c.

Contents


Public Routines in File maximal.c

Index

copy_selected_literal_marksmark_maximal_literalsmax_lit_testmaximal_signed_literal
exists_selected_literalmark_selected_literalmax_signed_lit_testnumber_of_maximal_literals
init_maximalmark_selected_literalsmaximal_literalselected_literal

Details


void copy_selected_literal_marks(Literals a, Literals b);

BOOL exists_selected_literal(Literals lits);

void init_maximal(void);

void mark_maximal_literals(Literals lits);

void mark_selected_literal(Literals lit);

void mark_selected_literals(Literals lits, char *selection);

BOOL max_lit_test(Literals lits, Literals lit);
Test if a literal is maximal in a clause (w.r.t. others literals of the either sign). This version does not use a flag.
BOOL max_signed_lit_test(Literals lits, Literals lit);
Test if a literal is maximal in a clause (w.r.t. others literals of the same sign). This version does not use a flag.
BOOL maximal_literal(Literals lits, Literals lit, int check);
Check if a literal is maximal in the clause that contains it. The argument "check" should be FLAG_CHECK (check the flag only) or FULL_CHECK (do the full comparicon).
BOOL maximal_signed_literal(Literals lits, Literals lit, int check);
Check if a literal is maximal in the clause that contains it. This only checks a flag. It does not compute maximality.
int number_of_maximal_literals(Literals lits, int check);
Return the number of maximal literals. This checks a flag only.
BOOL selected_literal(Literals lit);

Public Definitions in File maximal.h

enum {  /* how to check for maximal literals */
  FLAG_CHECK,
  FULL_CHECK
};


Introduction


LADR-2009-11A/ladr/html/lindex.html0000644000175000017500000001030610775516357016075 0ustar mccunemccune lindex.h

#include "lindex.h"

This page has information from files lindex.h and lindex.c.

Contents


Public Routines in File lindex.c

Index

fprint_lindex_memlindex_destroylindex_initlindex_update_first
lindex_backtracklindex_emptylindex_updatep_lindex_mem

Details


void fprint_lindex_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the lindex package. The Boolean argument heading tells whether to print a heading on the table.
BOOL lindex_backtrack(Lindex idx);
This Boolean function checks if either of the Mindex components (pos, neg) uses backtrack unification.
void lindex_destroy(Lindex ldx);
This frees all the memory associated with a Lindex. Do not refer to the Lindex after calling this routine.
BOOL lindex_empty(Lindex idx);
This Boolean routine checks if an Lindex is empty, that is, has no atoms. It must exist (be non-NULL).
Lindex lindex_init(Mindextype pos_mtype, Uniftype pos_utype, int pos_fpa_depth,
		   Mindextype neg_mtype, Uniftype neg_utype, int neg_fpa_depth);
This routine allocates and returns a literal index (Lindex), which is a pair of Mindexes, one for positive literals, and one for negative literals. The first three parameters are for the positive literal Mindex, and the second three are for the negative.

  • Mindextype: {LINEAR, FPA, DISCRIM, DISCRIM_BIND}
  • Uniftype: {ORDINARY_UNIF, BACKTRACK_UNIF}
  • fpa_depth: depth of FPA indexing (ignored for other index types).
See the routine mindex_init() for further information.
void lindex_update(Lindex ldx, Topform c, Indexop op);
This routine indexes (or unindexes) all literals of a clause.
void lindex_update_first(Lindex ldx, Topform c, Indexop op);
This routine indexes (or unindexes) the first literal of a clause.
void p_lindex_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the lindex package.

Public Definitions in File lindex.h

typedef struct lindex * Lindex;

struct lindex {
  Mindex pos;   /* index for positive literals */
  Mindex neg;   /* index for negative literals */
  Lindex next;  /* for avail list */
};


Introduction

This is a simple package that can be used when you need a pair of indexes (Mindexes), one for positive literals, and one for negative literals. The name Lindex means "literal index".

When you allocate the Lindex (lindex_init()), you specify the parameters as you would for two separate Mindexes. When you insert into or delete from the Lindex, you give a clause, and each literal of the clause is indexed: positive literals go into the positive component of the Lindex, and negative literals go into the negative component.

There are no retrieval operations in this package. Instead, use the retrieval operations from the Mindex package on the appropriate member (positive or negative) of the pair.

See the package "mindex" for information on the initialization parameters and retrieval operations.


LADR-2009-11A/ladr/html/int_code.html0000644000175000017500000000217510775516357016403 0ustar mccunemccune int_code.h

#include "int_code.h"

This page has information from files int_code.h and int_code.c.

Contents


Public Routines in File int_code.c

Index

check_ibuf_clauseget_clause_from_ibufput_clause_to_ibuf

Details


void check_ibuf_clause(Topform c);

Topform get_clause_from_ibuf(Ibuffer ibuf);

void put_clause_to_ibuf(Ibuffer ibuf, Topform c);

Public Definitions in File int_code.h


Introduction


LADR-2009-11A/ladr/html/ivy.html0000644000175000017500000000226610775516360015421 0ustar mccunemccune ivy.h

#include "ivy.h"

This page has information from files ivy.h and ivy.c.

Contents


Public Routines in File ivy.c

Index

expand_proof_ivysb_ivy_write_clause_jmapsb_ivy_write_just

Details


Plist expand_proof_ivy(Plist proof);

void sb_ivy_write_clause_jmap(String_buf sb, Topform c, I3list map);

void sb_ivy_write_just(String_buf sb, Ivyjust j, I3list map);

Public Definitions in File ivy.h


Introduction


LADR-2009-11A/ladr/html/ac_redun.html0000644000175000017500000000642410775516360016372 0ustar mccunemccune ac_redun.h

#include "ac_redun.h"

This page has information from files ac_redun.h and ac_redun.c.

Contents


Public Routines in File ac_redun.c

Index

associativityassociativity4cac_redundancycommutativity
associativity3c_associativitycac_tautologysame_top

Details


int associativity(Term atom);
If the atom is associativity, f(f(x,y),z) = f(x,f(y,z)), return the symnum of the operation; otherwise return 0 (which is never a symnum).
int associativity3(Term atom);
If the atom is any of the following (ab)c = a(bc) (ab)c = a(cb) (ab)c = b(ac) (ab)c = b(ca) return the symnum of the operation; otherwise return 0 (which is never a symnum).
int associativity4(Term atom);
If the atom is any of the following a(bc) = b(ac) a(bc) = b(ca) a(bc) = c(ab) a(bc) = c(ba) return the symnum of the operation; otherwise return 0 (which is never a symnum).
int c_associativity(Term atom);
If the atom is c_associativity, f(x,f(y,z)) = f(y,f(x,z)), return the symnum of the operation; otherwise return 0 (which is never a symnum).
BOOL cac_redundancy(Topform c, BOOL print);
This routine checks if the clause is commutativity or "c-associativity" x(yz)=y(xz); if so, it stores that information for later calls to cac_redundancy(). If an operation is found to C or AC, return TRUE; if found to be just A, return FALSE;

Otherwise, if any positive literal is an instance of x=x (mod C and AC as previously noted), it is rewritten to $T. Then return FALSE.

Motivation: If we know that * is commutative, and we derive an equation f(a,b*c)=f(a,c*b), we can delete that equation, because commutativity can do anything that equation can do. The same goes for AC operations.


BOOL cac_tautology(Literals lits);

int commutativity(Term atom);
If the atom is commutativity, return the symnum of the operation; otherwise return 0 (which is never a symnum).
BOOL same_top(Term t1, Term t2);
Do the two terms have the same top symbol?

Public Definitions in File ac_redun.h


Introduction


LADR-2009-11A/ladr/html/ioutil.html0000644000175000017500000002425010775516360016114 0ustar mccunemccune ioutil.h

#include "ioutil.h"

This page has information from files ioutil.h and ioutil.c.

Contents


Public Routines in File ioutil.c

Index

clause_readerfwrite_clauseparse_clause_from_stringread_term_list
clause_writerfwrite_clause_clistread_clausesb_write_clause
end_of_commands_termfwrite_clause_jmapread_clause_clistsb_write_clause_jmap
end_of_list_clausefwrite_clause_listread_clause_listsb_xml_write_clause_jmap
end_of_list_formulafwrite_demod_clistread_clause_or_formulaterm_reader
end_of_list_termfwrite_formularead_clause_or_formula_listterm_to_topform2
f_clausefwrite_formula_listread_formulaterm_writer
f_clausesfwrite_term_listread_formula_listzap_formula_list

Details


Topform clause_reader(BOOL fast);
If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A clause is read from stdin (NULL if there are none). Errors are fatal.
void clause_writer(Topform c, BOOL fast);
If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The clause is written to stdout, with a period and newline.
BOOL end_of_commands_term(Term t);
Check if a term is the constant "end_of_commands".
BOOL end_of_list_clause(Topform c);

BOOL end_of_list_formula(Formula f);

BOOL end_of_list_term(Term t);
Check if a term is the constant "end_of_list".
void f_clause(Topform c);
Write a clause to stdout, with id, with justification last.
void f_clauses(Plist p);

void fwrite_clause(FILE *fp, Topform c, int format);
This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n".
void fwrite_clause_clist(FILE *fp, Clist lst, int format);
This routine prints (to FILE *fp) a Clist of clauses in mixfix form. Example:
list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous).
void fwrite_clause_jmap(FILE *fp, Topform c, int format, I3list map)
			;
This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n".
void fwrite_clause_list(FILE *fp, Plist lst, char *name, int format);
This routine prints (to FILE *fp) a Plist of clauses in mixfix form. Example:
list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous).
void fwrite_demod_clist(FILE *fp, Clist lst, int format);
Similar to fwirte_clause_clist, except that lex-dep demodulators are noted.
void fwrite_formula(FILE *fp, Formula f);
This routine prints a formula, followed by ".\n" to a file. This version does not print extra parentheses (it first translates the formula to a term, then prints the term, then frees the term). To print the formula directly, with extra parentheses, call fprint_formula() instead.
void fwrite_formula_list(FILE *fp, Plist lst, char *name);
This routine prints (to FILE *fp) a list of formulas in mixfix form. Example:
list(sos).
a = b.
end_of_list.
If the name of the list is "", it is written as list(anonymous).
void fwrite_term_list(FILE *fp, Plist lst, char *name);
This routine prints (to FILE *fp) a list of terms in mixfix form. Example:
list(sos).
a = b.
end_of_list.
If the name of the list is "" or NULL, it is written as list(anonymous).
Topform parse_clause_from_string(char *s);

Topform read_clause(FILE *fin, FILE *fout);
This routine reads a clause from FILE *fin. If there are no more clauses in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.

Variables are "set", and upward links are made from all subterms to the clause.


Clist read_clause_clist(FILE *fin, FILE *fout, char *name, BOOL assign_id);
This routine reads a list of clauses from FILE *fin. If you wish the list to have a name, send a string; othersize send NULL. (You can name the list later with name_clist().) If there are no more clauses in *fin, an empty Clist is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.


Plist read_clause_list(FILE *fin, FILE *fout, BOOL assign_id);
Read clauses, up to end_of_list (or EOF), and return them in a Plist.
Topform read_clause_or_formula(FILE *fin, FILE *fout);

Plist read_clause_or_formula_list(FILE *fin, FILE *fout);

Formula read_formula(FILE *fin, FILE *fout);
This routine reads a formula from FILE *fin. If there are no more formulas in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.


Plist read_formula_list(FILE *fin, FILE *fout);
This routine reads a list of formulas from FILE *fin. If there are no more formulas in *fin, NULL is returned.

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.


Plist read_term_list(FILE *fin, FILE *fout);
This routine reads a list of terms from FILE *fin. If there are no more terms in *fin, NULL is returned.

None of the returned terms or their subterms will have type VARIABLE, even if it looks like a variable (e.g., x).

If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.


void sb_write_clause(String_buf sb, Topform c, int format);
This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n".
void sb_write_clause_jmap(String_buf sb, Topform c,
			  int format,
			  I3list map);
This routine writes a clause (in mixfix form, with ".\n") to a String_buf.
void sb_xml_write_clause_jmap(String_buf sb, Topform c, I3list map);
This routine writes a clause (in mixfix form, with ".\n") to a String_buf. It is written in XML format.
Term term_reader(BOOL fast);
If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A term is read from stdin (NULL if there are none). Errors are fatal.
Topform term_to_topform2(Term t);

void term_writer(Term t, BOOL fast);
If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The term is written to stdout, with a period and newline.
void zap_formula_list(Plist lst);
Free a Plist of formulas.

Public Definitions in File ioutil.h

enum { CL_FORM_STD,
       CL_FORM_BARE,
       CL_FORM_PARENTS,
       CL_FORM_XML,
       CL_FORM_IVY};  /* clause print format */


Introduction


LADR-2009-11A/ladr/html/order.html0000644000175000017500000000555410775516356015735 0ustar mccunemccune order.h

#include "order.h"

This page has information from files order.h and order.c.

Contents


Public Routines in File order.c

Index

compare_vecscopy_vecmerge_sortmerge_sort_recurse

Details


Ordertype compare_vecs(int *a, int *b, int n);

void copy_vec(int *a, int *b, int n);

void merge_sort(void *a[],   /* array to sort */
		int n,       /* size of array */
		Ordertype (*comp_proc) (void *, void *));
This is a general-purpose sorting routine. You give it an array of pointers to sort, the size of the array, and a comparison function.

Here is an example of how to use it.

  {
    Term args[MAX_ACM_ARGS];
    int n;

    < set n and put the n terms you wish to sort into args[] >

    merge_sort((void **) args, n, (Ordertype (*)(void*,void*)) term_compare_ncv);

    < args[] is now ordered by term_compare_ncv() >
  }

void merge_sort_recurse(void *a[],    /* array to sort */
			void *w[],    /* work array */
			int start,    /* index of first element */
			int end,      /* index of last element */
			Ordertype (*comp_proc) (void *, void *));
This is the recursive part of a general-purpose merge sort. You won't ordinarily call this (use merge_sort instead). Use this only if you manage allocation of the work array.

Here is an example of how to use it.

  {
    Term args[MAX_ACM_ARGS], work[MAX_ACM_ARGS];
    int n;

    < put the n terms you wish to sort into args[] >

    merge_sort_recurse((void **) args, (void **) work, 0, n-1,
               (Ordertype (*)(void*,void*)) term_compare_ncv);

    < args[] is now ordered by term_compare_ncv() >
  }

Public Definitions in File order.h

/* basic order relations */

typedef enum { NOT_COMPARABLE,
	       SAME_AS,
	       LESS_THAN,
	       GREATER_THAN,
	       LESS_THAN_OR_SAME_AS,
	       GREATER_THAN_OR_SAME_AS,
	       NOT_LESS_THAN,
	       NOT_GREATER_THAN
             } Ordertype;


Introduction

This package defines Ordertype and has a generic sorting routine merge_sort() that can be used to sort any kind of data.
LADR-2009-11A/ladr/html/parautil.html0000644000175000017500000001271410775516357016440 0ustar mccunemccune parautil.h

#include "parautil.h"

This page has information from files parautil.h and parautil.c.

Contents


Public Routines in File parautil.c

Index

build_reflex_eqfold_denialnew_constantsame_term_structure
eq_tautologyinit_paramodorient_equalitiestop_flip
equational_defliteral_fliporiented_equnfold_order
equational_def_2mark_oriented_eqrenamable_flip_eqzap_literal_flip
flip_eqmark_renamable_fliprenamable_flip_eq_testzap_top_flip

Details


Topform build_reflex_eq(void);

BOOL eq_tautology(Topform c);
This routine returns TRUE if the clause has any literals of the form t=t.
int equational_def(Topform c);

BOOL equational_def_2(Term alpha, Term beta);

void flip_eq(Term atom, int n);
Flip an equality and update the justification of the containing clause.
Topform fold_denial(Topform c, int alpha_max);

void init_paramod(void);

Literals literal_flip(Literals a);

void mark_oriented_eq(Term atom);
This routine marks an atom as an oriented equality.
void mark_renamable_flip(Term atom);
This routine marks an atom as "renamable_flip".
Topform new_constant(Topform c, int new_sn);
If the Topform is a positive equality unit a(x) = b(y) with two variables in which one variable occurs in each side, infer a clause a(x) = c with a new constant c. We could also infer b(y)=c, but that will come by other inference mechanisms.

If new_sn == INT_MAX, a new symbol will be generated; otherwise, new_sn will be used as the symbol number of the new symbol.


void orient_equalities(Topform c, BOOL allow_flips);
For each equality literal (positive or negative) of Topform c, compare the arguments; if the left is greater, mark the atom as oriented, and if the the right is greater, flip the arguments (add an entry to the justification), and mark the atom as oriented.
BOOL oriented_eq(Term atom);
This function checks if an atom is an oriented equality atom. (The terms are not actually compared. Only the mark is checked.)
BOOL renamable_flip_eq(Term atom);
This function checks if an atom is a renamable_flip equality atom. (The terms are not actually compared. Only the mark is checked.)
BOOL renamable_flip_eq_test(Term atom);
Test if a term is a renamable-flip equality atom. This does not check the flag; it does the complete test.
BOOL same_term_structure(Term t1, Term t2);
Do terms t1 and t2 have the same structure? That is, if we rename all variables to x, are t1 and t2 identical?
Term top_flip(Term a);
Given a binary term (or atom), return the flip. The two arguments are not copied. When done with it, call zap_top_flip(t) instead of zap_term so that the arguments are not zapped.
Ordertype unfold_order(Term alpha, Term beta);

void zap_literal_flip(Literals a);
Free a literal created by literal_flip.
void zap_top_flip(Term a);
Free a term created by top_flip.

Public Definitions in File parautil.h


Introduction

This package contains a few utilites for paramodulation and demodulation.
LADR-2009-11A/ladr/html/clock.html0000644000175000017500000001401010775516356015700 0ustar mccunemccune clock.h

#include "clock.h"

This page has information from files clock.h and clock.c.

Contents


Public Routines in File clock.c

Index

absolute_wallclockclock_secondsenable_clockssystem_seconds
clock_initclock_startfprint_clocksystem_time
clock_millisecondsclock_stopfree_clockuser_seconds
clock_resetclocks_enabledget_dateuser_time
clock_runningdisable_clocksinit_wallclockwallclock

Details


unsigned absolute_wallclock(void);

Clock clock_init(char *str);
This routine initializes a clock. You give it a string (which is not copied), representing the name of the new clock, and it returns a Clock to be used for all operations on the clock.

The clock operations are clock_start(), clock_stop(), clock_seconds(), clock_milliseconds(), and clock_reset().


unsigned clock_milliseconds(Clock p);
This routine returns the current value of a clock, in milliseconds. The value is in milliseconds.
void clock_reset(Clock p);
This routine resets a clock, as if it had just been initialized. (You should not need this routine under normal circumstances.)
BOOL clock_running(Clock p);
This routine tells you whether or not a clock is running.
double clock_seconds(Clock p);
This routine returns the current value of a clock, in seconds. The clock need not be stopped.
void clock_start(Clock p);
This routine starts clock n. It is okay if the clock is already going.
void clock_stop(Clock p);
This routine stops clock n and adds the time to the accumulated total, unless there have been too many starts and not enough stops. See the introduction.
BOOL clocks_enabled(void);

void disable_clocks(void);

void enable_clocks(void);

void fprint_clock(FILE *fp, Clock p);
This routine
void free_clock(Clock p);

char * get_date(void);
This routine returns a string representation of the current date and time.
void init_wallclock();
This routine initializes the wall-clock timer.
double system_seconds();
This routine returns the system CPU time, in seconds, that has been spent on the current process. (System time measures low-level operations such as system calls, paging, and I/O that the operating systems does on behalf of the process.)
unsigned system_time();
This routine returns the system CPU time, in milliseconds, that has been spent on the current process. (System time measures low-level operations such as system calls, paging, and I/O that the operating systems does on behalf of the process.)
double user_seconds();
This routine returns the user CPU time, in seconds, that the current process has used so far.
unsigned user_time();
This routine returns the user CPU time, in milliseconds, that the current process has used so far.
unsigned wallclock();
This routine returns the number of wall-clock seconds since init_wallclock() was called. The result is unsigned.

Public Definitions in File clock.h

typedef struct clock * Clock;


Introduction

This package is for timing various operations. Say you need to time an operation P. You first call clock_init() to set up a clock, then you can start and stop the clock as you wish, then you can get the accumulated time with clock_value(). These clocks measure the user CPU time.

An unusual feature of these clocks is that they can be used inside of recursive routines. For example, you can start the clock at the beginning of a recursive routine and stop it at the end. If you start it 3 times then stop it three times, it will really stop only on the third call. This works by a counter of the number of extra times the clock has been started, and clock_stop() will stop the clock only when the count is 0. (This feature probably isn't very useful, and most people can ignore it.)

Also here are some routines for getting process system/user CPU time, elapsed wall-clock time, and the time/date.


LADR-2009-11A/ladr/html/di_tree.html0000644000175000017500000000656110775516357016235 0ustar mccunemccune di_tree.h

#include "di_tree.h"

This page has information from files di_tree.h and di_tree.c.

Contents


Public Routines in File di_tree.c

Index

back_feature_subsumefprint_di_tree_memmega_sub_callsp_di_tree_mem
di_tree_deletefree_di_treenonunit_bsub_testszap_di_tree
di_tree_insertget_di_treenonunit_fsub_tests
forward_feature_subsumeinit_di_treep_di_tree

Details


Plist back_feature_subsume(Topform c, Di_tree root);

BOOL di_tree_delete(Ilist vec, Di_tree node, void *datum);

void di_tree_insert(Ilist vec, Di_tree node, void *datum);

Topform forward_feature_subsume(Topform d, Di_tree root);

void fprint_di_tree_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the di_tree package. The Boolean argument heading tells whether to print a heading on the table.
void free_di_tree(Di_tree p);

Di_tree get_di_tree(void);

Di_tree init_di_tree(void);
This routine allocates and returns an empty integer-vector discrimination index.
unsigned mega_sub_calls(void);

int nonunit_bsub_tests(void);

int nonunit_fsub_tests(void);

void p_di_tree(Ilist vec, Di_tree node, int depth);

void p_di_tree_mem(void);
This routine prints (to stdout) memory usage statistics for data types associated with the di_tree package.
void zap_di_tree(Di_tree node, int depth);

Public Definitions in File di_tree.h

typedef struct di_tree * Di_tree;

struct di_tree {       /* node in an integer vector discrimination tree */
  int label;           /* label of node */
  Di_tree   next;      /* sibling */
  union {
    Di_tree kids;      /* for internal nodes */
    Plist data;        /* for leaves */
  } u;
};


Introduction


LADR-2009-11A/ladr/html/backdemod.html0000644000175000017500000000425610775516360016524 0ustar mccunemccune backdemod.h

#include "backdemod.h"

This page has information from files backdemod.h and backdemod.c.

Contents


Public Routines in File backdemod.c

Index

back_demod_indexedback_demod_linearindex_clause_back_demodrewritable_clause

Details


Plist back_demod_indexed(Topform demod, int type, Mindex idx,
			 BOOL lex_order_vars);
This routine returns a Plist: the set clauses that have terms that can be rewritten with Topform demod.

If demod is oriented, demodulation is assumed to be left-to-right. If demod is not oriented, either way is allowed.

The Plist which is returned is ordered by decreasing clause ID.


Plist back_demod_linear(Topform demod, Clist lst, Plist rewritables);
This routine returns a Plist: the subset of Clist lst that can be rewritten with Topform demod (which is assumed to be an oriented equation). The Plist which is returned is ordered by decreasing clause ID.
void index_clause_back_demod(Topform c, Mindex idx, Indexop op);
This routine indexes or unindexes a clause for back demodulation.
BOOL rewritable_clause(Topform demod, Topform c);
This Boolean function checks if Topform c is can be rewritten by Topform demod, which is assumed to be an oriented (left-to-right) equation.

Public Definitions in File backdemod.h


Introduction


LADR-2009-11A/ladr/html/dioph.html0000644000175000017500000001355010775516357015721 0ustar mccunemccune dioph.h

#include "dioph.h"

This page has information from files dioph.h and dioph.c.

Contents


Public Routines in File dioph.c

Index

dionext_combo_bnext_combo_ss
next_combo_anext_combo_cp_ac_basis

Details


int dio(int ab[MAX_COEF],
	int m, int n,
	int constraints[MAX_COEF],
	int basis[MAX_BASIS][MAX_COEF],
	int *num_basis);
This routine generates the basis of solutions to the homogeneous linear diophantine equation given by ab, m, n. It uses Huet's algorithm (Information Processing Letters 7(3) 1978).

The equation has the form a1x1 + ... + amxm = b1y1 + ... + bnyn.

  • ab[] - the vector of coefficients. 1..m is a1..am, m+1..m+n is b1..bn.
  • m, n - the number of a and b coefficients.
  • constraints[] - rigid symbol (constant/function)restrictions.
  • basis[][] (output) - vector of minimal solutions.
  • num_basis (output) - number of minimal solutions.
Return value:
  • 0 - no solution within constraints
  • 1 - ok, solutions returned
  • -1 - too many (> MAX_BASIS) base solutions exist

int next_combo_a(int length, int basis[MAX_BASIS][MAX_COEF],
		 int num_basis, int constraints[MAX_COEF],
		 int combo[MAX_BASIS], int sum[MAX_COEF],
		 int start_flag);
This routine gets the first or next appropriate subset of the basis of solutions. "Appropriate" means that each variable gets instantiated to something, and there are no top-level rigid symbol clashes. I think of this as a potential unifier, because he caller still has to worry about recursive unification of subterms.
  • length -- total number of coefficients (m+n).
  • basis[][] -- basis of solutions.
  • num_basis -- number of basis solutions.
  • constraints[] -- rigid symbol constraints.
  • combo[] (input and output) -- current subset of the basis.
  • sum[] (intput and output) -- sum corresponding to combo[].
  • start_flag -- 1 for first call, 0 for subsequent calls.
We have several algorithms to do this. This implements algorithm A. (For most practical work, the differences in performance are small.)
int next_combo_b(int length, int basis[MAX_BASIS][MAX_COEF],
		 int num_basis, int constraints[MAX_COEF],
		 int combo[MAX_BASIS], int sum[MAX_COEF],
		 int start_flag);
This routine gets the first or next appropriate subset of the basis of solutions. This implements algorithm B. See next_combo_a() for a description.
int next_combo_c(int length, int basis[MAX_BASIS][MAX_COEF],
		 int num_basis, int constraints[MAX_COEF],
		 int combo[MAX_BASIS], int sum[MAX_COEF],
		 int start_flag);
This routine gets the first or next appropriate subset of the basis of solutions. This implements algorithm C. See next_combo_a() for a description.
int next_combo_ss(int length, int basis[MAX_BASIS][MAX_COEF],
		  int num_basis, int constraints[MAX_COEF],
		  int combo[MAX_BASIS], int sum[MAX_COEF],
		  int start_flag,
		  int combos[MAX_COMBOS][MAX_BASIS],
		  int *np,
		  int ss_parm);
This routine gets the first or next appropriate subset of the basis of solutions, subject to the "supserset restriction". It appears to work like the other next_combo routines, but it is not really incremental. To implement the superset restriction, we collect, in combos[] during the first call, up to MAX_COMBOS subsets satisfying the restriction, then give them out in the subsequent calls. The first bunch of parameters are the same as for the other next_combo routines.
  • length -- total number of coefficients (m+n).
  • basis[][] -- basis of solutions.
  • num_basis -- number of basis solutions.
  • constraints[] -- rigid symbol constraints.
  • combo[] (input and output) -- current subset of the basis.
  • sum[] (intput and output) -- sum corresponding to combo[].
  • start_flag -- 1 for first call, 0 for subsequent calls.
The rest of the parameters are added for the supserset restriction.
  • combos[][] (input and output) -- this is really just temp storage.
  • *np (input and output) -- temp storage (# of combos remaining).
  • ss_parm (input) -- supserset parameter [0...]

void p_ac_basis(int basis[MAX_BASIS][MAX_COEF],
		int num_basis, int m, int n);
This routine prints (to stdout) a basis of solutions.

Public Definitions in File dioph.h

#define MAX_COEF   250  /* total # of coef. from both sides */
#define MAX_BASIS  100  /* must be <= MAX_VARS, because rows are indexed */
#define MAX_COMBOS 200  /* for superset-restricted AC unif. */


Introduction

This package solves linear homogeneous Diophantine equations, which can be used to compute the set of associative-commutative unifiers for a pair of first-order terms. The way this usually works is that you first call dio() to get a basis of solutions, then call one of the the next_combo routines to (incrementally) get the relevant solutions.

The file dioph.c has a main() program, and it can be compiled and linked by itself for testing. The command for doing so is "gcc -DSOLO dioph.c".


LADR-2009-11A/ladr/html/clausify.html0000644000175000017500000000601510775516357016433 0ustar mccunemccune clausify.h

#include "clausify.h"

This page has information from files clausify.h and clausify.c.

Contents


Public Routines in File clausify.c

Index

clause_to_formulaformula_to_clauseformula_to_literal
clausify_formulaformula_to_clausesformula_to_literals

Details


Formula clause_to_formula(Topform c);
Return an entirely new formula.
Plist clausify_formula(Formula f);
This routine translates a Formula f into a Plist of clauses. The translation includes Skolemization, so the result should be unsatisfiable iff f is unsatisfiable. The variables in each clause are renumbered. If there are more than MAX_VARS variables in a clause, a fatal error occurs.

Formula f is not changed.


Topform formula_to_clause(Formula f);
This routine takes a Formula f and returns a Topform representation. If f is not an atom, literal, or disjunction of literals, the returned clause will be NULL or not well formed.

The returned clause is an entirely new copy, and the given formula is not changed.


Plist formula_to_clauses(Formula f);
This routine takes a Formula f and returns a Plist of clauses representation. If f is not an atom, literal, or disjunction of literals, or a conjunction of those things, the clauses in the returned list may be NULL or not well formed.

The returned clauses are entirely new copies, and the given formula is not changed.


Literals formula_to_literal(Formula f);
This routine takes a Formula f and returns a Literals representation. If the formula is not an ATOM_FORM or the negation of an ATOM_FORM, NULL is returned.

The returned literal is an entirely new copy, and the given formula is not changed.


Literals formula_to_literals(Formula f);

Public Definitions in File clausify.h


Introduction


LADR-2009-11A/ladr/html/strbuf.html0000644000175000017500000001524010775516356016120 0ustar mccunemccune strbuf.h

#include "strbuf.h"

This page has information from files strbuf.h and strbuf.c.

Contents


Public Routines in File strbuf.c

Index

fprint_sbp_strbuf_memsb_cat_copysb_to_malloc_string
fprint_strbuf_memsb_appendsb_charzap_string_buf
get_string_bufsb_append_charsb_replace_char
init_string_bufsb_append_intsb_size
p_sbsb_catsb_to_malloc_char_array

Details


void fprint_sb(FILE *fp, String_buf sb);
This routine prints String_buf sb to FILE *fp.
void fprint_strbuf_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the strbuf package. The Boolean argument heading tells whether to print a heading on the table.
String_buf get_string_buf(void);

String_buf init_string_buf(char *s);
This routine allocates and returns a String_buf, initialized to string s. Don't forget to call zap_string_buf(sb) when finished with it. Also see get_string_buf().
void p_sb(String_buf sb);
This routine prints String_buf sb, followed by '\n' and fflush, to stdout. If you don't want the newline, use fprint_sb() instead.
void p_strbuf_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the strbuf package.
void sb_append(String_buf sb, char *s);
This routine appends string s to String_buf sb. The NULL character that marks the end of s does not go into the String_buf.
void sb_append_char(String_buf sb, char c);
This routine appends character c to String_buf sb.
void sb_append_int(String_buf sb, int i);
Convert an integer to a string and append the string to a String_buf.
void sb_cat(String_buf sb1, String_buf sb2);
This routine appends a copy of sb2 to sb1, then deallocates sb2. Do not refer to sb2 after calling this rouine because it won't exist. You can use sb_cat_copy() instead if you need to save sb2.
void sb_cat_copy(String_buf sb1, String_buf sb2);
This routine appends a copy of sb2 to sb1. String_buf sb2 is not changed. You can use sb_cat() instead if you won't be needing sb2.
char sb_char(String_buf sb, int n);
This routine returns the n-th character (counting from 0) of String_buf sb. If index n is out of range, the NULL character '\0' is returned.
void sb_replace_char(String_buf sb, int i, char c);
This routine replaces a character in a String_buf. If the index i is out of range, nothing happens.
int sb_size(String_buf sb);

char *sb_to_malloc_char_array(String_buf sb);
This routine is similar to sb_to_malloc_string(), except that null characters are copied to the new string.
char *sb_to_malloc_string(String_buf sb);
This routine returns a new, ordinary C string corresponding to the String_buf argument sb. WARNING: the new string, say s, is dynamically allocated (malloced), so don't forget to call free(s) when you are finished with the string. (This routine is not intended for printing String_bufs; use fprint_sb() instead.)

String_bufs do not have a NULL character marking the end; instead, they keep a count of the number of characters.

If the String_buf contains NULL characters, they do NOT mark the end of the string. Instead, they are simply ignored when constructing the ordinary string.


void zap_string_buf(String_buf sb);
This routine deallocates a String_buf and frees all memory associated with it.

Public Definitions in File strbuf.h

typedef struct string_buf * String_buf;


Introduction

A String_buf is a kind of string that can grow as big as you need. This is implemented as a list of dynamically allocated character arrays of fixed size. The only problem with using String_bufs is that you have to remember to free a String_buf when you are finished with it.

This is similar to the StringBuffer class in Java, and the cstrings of our old theorem prover LMA/ITP. We didn't have anything like this in Otter, but there were times when I wish we had, so here it is.


LADR-2009-11A/ladr/html/parse.html0000644000175000017500000001614310775516357015731 0ustar mccunemccune parse.h

#include "parse.h"

This page has information from files parse.h and parse.c.

Contents


Public Routines in File parse.c

Index

declare_parse_typeget_cons_charread_termsplit_string
declare_quantifier_precedenceget_quote_charredeclare_symbol_and_copy_parsetypesread_term
declare_standard_parse_typesordinary_constant_stringsb_write_termtranslate_neg_equalities
fprint_parse_memp_parse_memset_cons_char
fwrite_termparenthesizeset_quote_char
fwrite_term_nlparse_term_from_stringskip_to_nl

Details


void declare_parse_type(char *str, int precedence, Parsetype type);

void declare_quantifier_precedence(int prec);

void declare_standard_parse_types(void);

void fprint_parse_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the parse package. The Boolean argument heading tells whether to print a heading on the table.
void fwrite_term(FILE *fp, Term t);
This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type().


void fwrite_term_nl(FILE *fp, Term t);
This routine prints a term (to FILE *fp) in readable form, that is, infix where appropriate and without extra parentheses. Also printed is ".\n".

See the documentation on mixfix terms and the routine set_parse_type().


char get_cons_char(void);

char get_quote_char(void);

BOOL ordinary_constant_string(char *s);

void p_parse_mem(void);
This routine prints (to stdout) memory usage statistics for data types associated with the parse package.
void parenthesize(BOOL setting);

Term parse_term_from_string(char *s);

Term read_term(FILE *fin, FILE *fout);
This routine reads a term (from FILE *fin). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type().


BOOL redeclare_symbol_and_copy_parsetype(char *operation, char *str,
					 BOOL echo, FILE *fout);

void sb_write_term(String_buf sb, Term t);
This routine prints a term to a String_buf in readable form, that is, infix where appropriate and without extra parentheses. A period and newline are not printed.

See the documentation on mixfix terms and the routine set_parse_type().


void set_cons_char(char c);

void set_quote_char(char c);

void skip_to_nl(FILE *fp);
Read characters up to the first newline (or EOF).
Plist split_string(char *onlys);
This splits a string of symbols, separated by whitespace, into a list of strings. A Plist of (malloced) strings is returned.
Term sread_term(String_buf sb, FILE *fout);
This routine reads a term (from String_buf *sb). The term may be in readable form, that is with infix operations and without extra parentheses.

If there is no term to be read, NULL is returned. If an error occurs, a message is sent to FILE *fout, and fatal error occurs.

See the documentation on mixfix terms and the routine set_parse_type().


void translate_neg_equalities(BOOL flag);
This routine sets or clears the flag which tells the parser to automatically translate alpha!=beta to ~(alpha=beta). This happens in read_term(), which is called by read_clause(), read_formula(), and read_term_list().

Public Definitions in File parse.h


Introduction

This package has routines for reading and writing terms in human-readable form. Binary function symbols can be declared to be infix with a precedence and left or right association, so that many parentheses can be omitted. Unary symbols can be declared to be prefix or postfix. In addition, prolog-style list-notation and quantified formulas are supported.

The symbol declarations and parse rules are similar to the method used by many Prolog systems (although we use mnemonic names instead of xfy, yfx, yf, etc.). The symbol declarations are made with set_parse_type().

This package is based on code taked form Otter and EQP, but there are some important differences. Detailed documentation should be available elsewhere.

The intension is to use this package for reading and writing all types of data (terms, clauses, formulas, control information, etc.), with outside routines to translate to/from the appropriate internal data structure when necessary.


LADR-2009-11A/ladr/html/flatterm.html0000644000175000017500000001041210775516357016426 0ustar mccunemccune flatterm.h

#include "flatterm.h"

This page has information from files flatterm.h and flatterm.c.

Contents


Public Routines in File flatterm.c

Index

copy_flattermflatterm_count_without_varsfprint_flatterm_memprint_flatterm
flat_multiset_varsflatterm_identget_flattermterm_to_flatterm
flat_occurs_inflatterm_symbol_countp_flattermzap_flatterm
flat_variables_multisubsetflatterm_to_termp_flatterm_mem

Details


Flatterm copy_flatterm(Flatterm f);

I2list flat_multiset_vars(Flatterm f);

BOOL flat_occurs_in(Flatterm t1, Flatterm t2);

BOOL flat_variables_multisubset(Flatterm a, Flatterm b);

int flatterm_count_without_vars(Flatterm f);

BOOL flatterm_ident(Flatterm a, Flatterm b);

int flatterm_symbol_count(Flatterm f);

Term flatterm_to_term(Flatterm f);

void fprint_flatterm_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the flatterm package. The Boolean argument heading tells whether to print a heading on the table.
Flatterm get_flatterm(void);

void p_flatterm(Flatterm f);

void p_flatterm_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the flatterm package.
void print_flatterm(Flatterm f);

Flatterm term_to_flatterm(Term t);

void zap_flatterm(Flatterm f);

Public Definitions in File flatterm.h

typedef struct flatterm * Flatterm;

struct flatterm {
  short         private_symbol; /* const/func/pred/var symbol ID */
  unsigned char arity;          /* number of auguments */
  Flatterm prev, next, end;

  /* The rest of the fields are for index retrieval and demodulation. */
  
  int size;                      /* symbol count */
  struct discrim *alternative;   /* subtree to try next */
  int varnum_bound_to;           /* -1 for not bound */
  BOOL reduced_flag;             /* fully demodulated */
};


Introduction

The Term macros VARIABLE(f), CONSTANT(f), COMPLEX(f), SYMNUM(f), VARNUM(f), ARITY(f) are used for Flatterms as well. The Term macro ARG(t,i) is NOT used for Flatterms.

Traversing Flatterms. It can be done recursively or iteratively. When building flatterms, recursive is better, because you have to make a Flatterm point to its end. Iterative: Flatterm fi; for (f = fi; fi != f->end->next; fi = fi->next) ... Recursive: int i; Flatterm fi = f->next; for (i = 0; i < ARITY(f); i++) { ... fi = fi->end->next; }


LADR-2009-11A/ladr/html/multiset.html0000644000175000017500000000217410775516357016464 0ustar mccunemccune multiset.h

#include "multiset.h"

This page has information from files multiset.h and multiset.c.

Contents


Public Routines in File multiset.c

Index

greater_multiset

Details


BOOL greater_multiset(Term a1[], int n1, Term a2[], int n2,
		      BOOL (*comp_proc) (Term, Term, BOOL),
		      BOOL lex_order_vars);
Given two arrays of terms, check if the first is greater in the multiset extension of the ordering given by comp_proc.

Public Definitions in File multiset.h


Introduction


LADR-2009-11A/ladr/html/discrimb.html0000644000175000017500000001120010775516357016400 0ustar mccunemccune discrimb.h

#include "discrimb.h"

This page has information from files discrimb.h and discrimb.c.

Contents


Public Routines in File discrimb.c

Index

discrim_bind_canceldiscrim_bind_retrieve_nextfprint_discrim_bind_indexp_discrim_bind_index
discrim_bind_retrieve_firstdiscrim_bind_updatefprint_discrimb_memp_discrimb_mem

Details


void discrim_bind_cancel(Discrim_pos pos);
This routine must be called if you get some, but not all answers to a tame discrimbintaion query. The Context (which was given to the discrim_bind_retrieve_first() call) is cleared, and the memory associated the retrieval state is freed.
void *discrim_bind_retrieve_first(Term t, Discrim root,
				  Context subst, Discrim_pos *ppos);
This routine, along with discrim_bind_retrieve_next(), gets answers from a tame discrimination index. This routine retrieves the first object associated with a term, say ft, more general than Term t. (NULL is returned if there is none.) The substitution for variables of ft is placed into Context subst.

If an object is returned, Discrim_pos *ppos is set to the retrieval state and is used for subsequent discrim_tame_retrieve_next() calls.

If you to get some, but not all answers, you must call discrim_tame_cancel() to clear the substitution and free memory associated with the Discrim_pos.


void *discrim_bind_retrieve_next(Discrim_pos pos);
This routine retrieves the next object in the sequence of answers to a query of a tame discrimbination tree. You must not explicitly clear the Context you gave to discrim_bind_retrieve_first()---that is handled internally. See discrim_bind_retrieve_first().
void discrim_bind_update(Term t, Discrim root, void *object, Indexop op);
This routine inserts (op==INSERT) or deletes (op==DELETE) an object into/from a tame discrimination index. Term t is the key, root is the root of the discrimination tree, and *object is a pointer (in many cases, *object will be t). See discrim_tame_retrieve_first().

A fatal error occurs if yout ry to delete an object that was not previouly inserted.


void fprint_discrim_bind_index(FILE *fp, Discrim d);
This routine prints (to FILE *fp) a tame discrimination index.
void fprint_discrimb_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the discrimb package. The Boolean argument heading tells whether to print a heading on the table.
void p_discrim_bind_index(Discrim d);
This routine prints (to stdout) a tame discrimination index.
void p_discrimb_mem(void);
This routine prints (to stdout) memory usage statistics for data types associated with the discrimb package.

Public Definitions in File discrimb.h


Introduction

Discrimination tree indexing in which variables are distinguished in the index and are bound as soon as possible during retrieval.
LADR-2009-11A/ladr/html/sos.html0000644000175000017500000001104410502077055015377 0ustar mccunemccune sos.h

#include "sos.h"

This page has information from files sos.h and sos.c.

Contents


Public Routines in File sos.c

Index

clauses_of_weightinsert_into_sosp_sos_treewt_of_clause_at
first_sos_clauselightest_sos_clauseremove_from_soszap_sos_index
index_sosp_sos_distworst_sos_clause

Details


int clauses_of_weight(int wt, int set);

Topform first_sos_clause(Clist lst);
Given a nonempty Clist, return the first clause. This does not remove the clause from any lists. (Call remove_from_sos(Topform) to do that.)
void index_sos(Topform c, int set);
This routine updates the (private) index for extracting sos clauses.
void insert_into_sos(Topform c, Clist sos, int set);
This routine appends a clause to the sos list and updates the (private) index for extracting sos clauses.
Topform lightest_sos_clause(int set);
Return the first (oldest) of the lightest sos clauses. This does not remove the clause from any lists. (Call remove_from_sos(Topform, Clist) to do that.)
void p_sos_dist(void);

void p_sos_tree(void);

void remove_from_sos(Topform c, Clist sos, int set);
This routine removes a clause from the sos list and updates the index for extracting the lightest and heaviest clauses.
Topform worst_sos_clause(Clist sos, int method);

int wt_of_clause_at(int set, double part);
Consider sos, ordered by weight. Assume 0 <= part <= 1; if not, we make it so. Return the weight of the clause at the part. If sos is empty, return INT_MAX.
void zap_sos_index(void);

Public Definitions in File sos.h

enum { BY_AGE, BY_WEIGHT, BY_RATIO };
enum { SOS1, SOS2 };


Introduction

This package has routines for efficiently managing selection of the given clause from the Sos list when using the given-clause algorithm.

We use a private index to quickly find the first, shortest clause in Sos. Here are the routines to use under ordinary circumstances.

  • insert_into_sos_lightest(Topform c, Clist sos);
  • remove_from_sos_lightest(Topform c);
  • extract_lightest_clause(Clist sos);
  • extract_first_clause(Clist lst);
Here's how it works (you probably don't need to know this).

We use an auxiliary Clist "Lightest" so that we don't have to scan Sos each time we need a new given clause. At any given time, Lightest is either empty or contains all of the Sos clauses of minimum weight, in the same order as in Sos.

To insert a newly kept clause c into Sos: If c is the same weight as clauses in Lightest, append it to Lightest as well as to Sos. If c is heaaver than Lightest, append it to Sos only. If c is lighter than Lightest, remove all clauses from Lightest, (leaving Lightest empty), and append c to Sos.

To get the first, lightest clause: If Lightest is empty, build a new Lightest list. Now just take the first member of Lightest.

Good performance of this scheme depends on the assumption that the Lightest list is farily stable; that is, as we go from given clause to given clause, the weight of the lightest clauses doesn't change often.


LADR-2009-11A/ladr/html/symbols.html0000644000175000017500000006254410775516357016315 0ustar mccunemccune symbols.h

#include "symbols.h"

This page has information from files symbols.h and symbols.c.

Contents


Public Routines in File symbols.c

Index

add_new_symbolsfunction_or_relation_snnot_symset_variable_style
add_skolems_to_preliminary_precedencefunction_symbolnot_symnumskolem_check
all_function_symbolsgen_new_symbolor_symskolem_reset
all_relation_symbolsget_operation_symbolor_symnumskolem_symbols
all_symget_symbol_typep_symsn_to_arity
all_symbols_lrpo_statusgreatest_symnump_symssn_to_kb_wt
and_symhas_greatest_precedenceparse_type_to_strsn_to_lex_val
arity_checkiff_sympreliminary_lex_comparesn_to_lrpo_status
assign_greatest_precedenceimp_symprint_fsym_precedencesn_to_occurrences
assoc_comm_symbolsimpby_symprint_kbo_weightssn_to_str
attrib_symis_assoc_commprint_rsym_precedencesort_by_lex_val
binary_parse_typeis_commutativeprocess_lex_listspecial_parse_type
clear_parse_typeis_eq_symbolprocess_skolem_listsprint_sym
clear_parse_type_for_all_symbolsis_skolemquant_symstr_exists
comm_symbolsis_symbolrelation_symbolstr_to_sn
current_fsym_precedenceis_unfold_symbolremove_variable_symbolssym_precedence
current_rsym_precedencelex_compare_arity_0123set_assoc_commsymbol_for_variable
declare_base_symbolslex_compare_arity_0213set_commutativesymbol_in_use
declare_functions_and_relationslex_insert_after_initial_constantsset_kb_weightsymbol_with_string
decommission_skolem_symbolslex_orderset_lex_valsymnums_of_arity
eq_symmark_for_new_symbolsset_lrpo_statussyms_with_lex_val
exists_preliminary_precedencemin_lex_valset_operation_symboltrue_sym
exists_symneq_symset_parse_typeunary_parse_type
false_symnew_constant_propertiesset_skolemvariable_name
fprint_symnew_symbols_since_markset_skolem_symbolsvariable_style
fprint_symsnext_skolem_symbolset_symbol_typevariable_symbols
fresh_symbolnot_in_preliminary_precedenceset_unfold_symbolzero_wt_kb

Details


void add_new_symbols(I2list syms);

void add_skolems_to_preliminary_precedence(void);
If there is a preliminary precedence, add the skolem symbols to it in the following way. For each Skolem symbol of arity-n, add it to Preliminary_precedence just before the first symbol of higher arity (else at the end).
Ilist all_function_symbols(void);

Ilist all_relation_symbols(void);

char *all_sym();

void all_symbols_lrpo_status(Lrpo_status status);
Assign all symbols the given lrpo status: LRPO_LR_STATUS or LRPO_MULTISET_STATUS.
char *and_sym();

Ilist arity_check(Ilist fsyms, Ilist rsyms);

void assign_greatest_precedence(int symnum);

BOOL assoc_comm_symbols(void);
This function tells you if any symbol has been declared to be associative-commutative;
char *attrib_sym();

BOOL binary_parse_type(char *str, int *precedence, Parsetype *type);
This routine gets the parse/print properties for a binary symbol. If *str is a binary symbol, TRUE is returned and the properties are filled in. If *str is a not a binary symbol, FALSE is returned.
void clear_parse_type(char *str);

void clear_parse_type_for_all_symbols(void);

BOOL comm_symbols(void);
This function tells you if any symbol has been declared to be commutative.
Ilist current_fsym_precedence();

Ilist current_rsym_precedence();

void declare_base_symbols(void);

void declare_functions_and_relations(Ilist fsyms, Ilist rsyms);

void decommission_skolem_symbols(void);
For each symbol in the symbol table, if it is marked "skolem", unmark it and set the type to "unspecified".
char *eq_sym();

BOOL exists_preliminary_precedence(Symbol_type type);

char *exists_sym();

char *false_sym();

void fprint_sym(FILE *fp, int symnum);
This routine prints (to FILE *fp) the string associated with a symbol ID. A newline is NOT printed.
void fprint_syms(FILE *fp);
This routine prints (to FILE *fp) the symbol table, including many of the attributes of each symbol.
int fresh_symbol(char *prefix, int arity);
This routine returns a symbol ID for a new symbol with the given arity. The symbol is made up of the given prefix followed by the smallest natural number that results in a new symbol (regardless of arity). The prefix must be less than MAX_NAME characters.
int function_or_relation_sn(char *str);
If there is a function or relation symbol in the table with the given string, return the symnum; otherwise return -1. (If there is more than one, the first one found is returned.)
BOOL function_symbol(int symnum);

int gen_new_symbol(char *prefix, int arity, Ilist syms);

char *get_operation_symbol(char *operation);

Symbol_type get_symbol_type(int symnum);

int greatest_symnum(void);
This function returns the greatest symnum (symbol ID) currently in use. This can be used if you need to dynamnically allocate an array of objects to be indexed by symnum.
BOOL has_greatest_precedence(int symnum);

char *iff_sym();

char *imp_sym();

char *impby_sym();

BOOL is_assoc_comm(int sn);
This function checks if a symbol ID has the associative-commutative property. Note that set_assoc_comm() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms.
BOOL is_commutative(int sn);
This function checks if a symbol ID has the commutative property. Note that set_commutative() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms.
BOOL is_eq_symbol(int symnum);
This Boolean routine checks if a given symbol ID is for eq_sym()/2. One could use is_symbol(symnum, eq_sym(), 2) instead, but this should be a bit faster.
BOOL is_skolem(int symnum);

BOOL is_symbol(int symnum, char *str, int arity);
This Boolean routine checks if a given symbol ID matches a given (string,arity) pair.
BOOL is_unfold_symbol(int symnum);

Ordertype lex_compare_arity_0123(Symbol s1, Symbol s2);

Ordertype lex_compare_arity_0213(Symbol s1, Symbol s2);

void lex_insert_after_initial_constants(Ilist syms);

void lex_order(Ilist fsyms, Ilist rsyms,
	       I2list fsyms_multiset, I2list rsyms_multiset,
	       Ordertype (*comp_proc) (Symbol, Symbol));
Assign a total order on lex_vals of (fsyms U rsyms). If a list of strings was previously given to set_preliminary_precedence, that order is maintained for symbols that have those strings. For the other rules, see *comp_proc (lex_compare*).
void mark_for_new_symbols(void);

int min_lex_val(void);

char *neq_sym();

void new_constant_properties(int sn);
In the symbol table entry for the given symbol number, set type=function, kb_weight=1, lex_val=(after initial constants)
I2list new_symbols_since_mark(void);

int next_skolem_symbol(int arity);
This routine returns a fresh symbol ID, which is intended to be used as a Skolem symbol. The symbols are c1, c2, c3, ... for arity 0 (constants) and f1, f2, f3, ... for arity != 0. If some of those symbols already exist in the symbol table (with any arity), they will be skipped.
Ilist not_in_preliminary_precedence(Ilist syms, Symbol_type type);

char *not_sym();

int not_symnum(void);
Return the symnum for not_sym()/1.
char *or_sym();

int or_symnum(void);
Return the symnum for or_sym()/2.
void p_sym(int symnum);
This routine prints (stdout) the string associated with a symbol ID. A newline is NOT printed.
void p_syms(void);
This routine prints (to stdout) the symbol table, including all of the attributes of each symbol.
char *parse_type_to_str(Parsetype type);

Ordertype preliminary_lex_compare(Symbol a, Symbol b);
Compare the given strings with respect to the list of strings given to the set_preliminary_precedence call. Strings without preliminary_precedence are smaller than those with. Two different strings without preliminary_precedence are NOT_COMPARABLE.

Return LESS_THAN, GREATER_THAN, SAME_AS, NOT_COMPARABLE.


void print_fsym_precedence(FILE *fp);

void print_kbo_weights(FILE *fp);

void print_rsym_precedence(FILE *fp);

void process_lex_list(Plist lex_strings, Ilist syms, Symbol_type type);

void process_skolem_list(Plist skolem_strings, Ilist fsyms);

char *quant_sym();

BOOL relation_symbol(int symnum);

Ilist remove_variable_symbols(Ilist syms);
Given a Plist of symbols (symnums), remove the ones that are correspond to variables.
void set_assoc_comm(char *str, BOOL set);
This routine declares a string to be a (binary) symbol with the logical property "associative-commutative". This property is used for AC unification/matching/identity. (If you wish to print AC expressions without parentheses, see set_parse_type().)
void set_commutative(char *str, BOOL set);
This routine declares a string to be a (binary) symbol with the logical property "commutative". This property is used for commutative unification/matching/identity.
void set_kb_weight(int symnum, int weight);

void set_lex_val(int symnum, int lex_val);
This routine is used to assign a lexical value to a symbol. The value can be retrieved later with sn_to_lex_val();
void set_lrpo_status(int symnum, Lrpo_status status);

void set_operation_symbol(char *operation, char *symbol);

void set_parse_type(char *str, int precedence, Parsetype type);
This routine sets the parse/print properties of a binary or unary symbol. The types for binary infix symbols are INFIX_LEFT, INFIX_RIGHT, INFIX. The types for prefix unary symbols are PREFIX, PREFIX_PAREN. The types for postfix unary symbols are POSTFIX, POSTFIX_PAREN.

If the precedence is out of range [MIN_PRECEDENCE ... MAX_PRECEDENCE], a fatal error occurs.


void set_skolem(int symnum);
This routine declares that a symbol is a Skolem function (or constant).
void set_skolem_symbols(Ilist symnums);

void set_symbol_type(int symnum, Symbol_type type);

void set_unfold_symbol(int symnum);
This routine declares that a symbol is a Skolem function (or constant).
void set_variable_style(Variable_style style);
This routine determines how variables are parsed and printed.
void skolem_check(BOOL flag);

void skolem_reset(void);
Reset the Skolem symbol counters (constant and function) to 1.
Ilist skolem_symbols(void);
Return the list of SYMNUMs (increasing) that have been declared to be Skolem symbols.
int sn_to_arity(int symnum);
This routine returns the arity associated with a symbol ID.
int sn_to_kb_wt(int symnum);
This routine returns the Knuth-Bendix weight associated with a symbol ID.
int sn_to_lex_val(int sn);
This routine returns the lexical value associated with a symbol ID. The default value is INT_MAX. If the symbol ID is not valid, INT_MIN is returned.
Lrpo_status sn_to_lrpo_status(int sn);
This routine returns the LRPO status associated with a symbol ID. The default value is LRPO_LR_STATUS. See order.h for the possible values. If the symbol ID is not valid, 0 is returned.
int sn_to_occurrences(int symnum);
This routine returns the occurrences associated with a symbol ID.
char *sn_to_str(int symnum);
This routine returns the string assocated with a symbol ID.
Ilist sort_by_lex_val(Ilist p);

int special_parse_type(char *str);
Is the string a unary or binary "special_parse_type" (e.g., PREFIX or INFIX)? If so, return the arity; otherwise return -1.
void sprint_sym(String_buf sb, int symnum);
This routine appends, to String_buf sb, the string associated with a symbol ID. A newline is NOT printed.
BOOL str_exists(char *str);
This function checks if the given string occurs in the symbol table (with any arity). This should be used judiciously, because the whole table is scanned.
int str_to_sn(char *str, int arity);
This routine takes a string and an arity, and returns an integer identifier for the pair. If the pair is not already in the symbol table, a new entry is inserted into the table. A pair, say ("f",2), is sometimes written as f/2, which is a different symbol from f/3. There is no limit on the length of the string (which is copied).
Ordertype sym_precedence(int symnum_1, int symnum_2);
This routine compares two symbol IDs by looking at their lex_val in the symbol table. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}.
void symbol_for_variable(char *str, int varnum);
Given a pointer to a string and a variable index, fill in the string with the variable symbol. The variable symbol is determined by the current variable style (standard, prolog, integer, etc.), which can be changed with set_variable_style().
BOOL symbol_in_use(char *str);

int symbol_with_string(Ilist syms, char *str);

Ilist symnums_of_arity(Ilist p, int i);

Ilist syms_with_lex_val(void);
Return an Ilist containing symnums of symbols to which lex_vals have been assigned.
char *true_sym(void);

BOOL unary_parse_type(char *str, int *precedence, Parsetype *type);
This routine gets the parse/print properties for a unary symbol. If *str is a unary symbol, TRUE is returned and the properties are filled in. If *str is a not a unary symbol, FALSE is returned.
BOOL variable_name(char *s);
Is the given name a variable? Formulas can have free variables (not explicitly quantified), so we have a rule to distinguish variables from constants. This is it.
Variable_style variable_style(void);
This routine gives the current variable style.
Ilist variable_symbols(Ilist syms);
Given a Plist of symbols (symnums), return a (new) list of the symnums that correspond to variables.
BOOL zero_wt_kb(void);
Is there already a symbol with KB weight 0?

Public Definitions in File symbols.h

/* maximum number of chars in string part of symbol (includes '\0') */

#define MAX_NAME      51

/* parse/print properties of symbols */

typedef enum {NOTHING_SPECIAL,
	      INFIX,         /* xfx */
	      INFIX_LEFT ,   /* yfx */
	      INFIX_RIGHT,   /* xfy */
	      PREFIX_PAREN,  /* fx  */
	      PREFIX,        /* fy  */
	      POSTFIX_PAREN, /* xf  */
	      POSTFIX        /* yf  */
             } Parsetype;

#define MIN_PRECEDENCE      1
#define MAX_PRECEDENCE    999

/* Function/relation properties of symbols */

typedef enum { UNSPECIFIED_SYMBOL,
	       FUNCTION_SYMBOL,
	       PREDICATE_SYMBOL
             } Symbol_type;

/* Unification properties of symbols */

typedef enum { EMPTY_THEORY,
	       COMMUTE,
	       ASSOC_COMMUTE
             } Unif_theory;

/* LRPO status */

typedef enum { LRPO_LR_STATUS,
	       LRPO_MULTISET_STATUS
             } Lrpo_status;

/* Variable style */

typedef enum { STANDARD_STYLE,      /* x,y,z,... */
	       PROLOG_STYLE,        /* A,B,C,... */
	       INTEGER_STYLE        /* 0,1,2,... */
             } Variable_style;

typedef struct symbol * Symbol;


Introduction

This collection of routines manages the global symbol table. Each symbol is a pair (string,arity) and has a unique ID number. For example, ("f",2), sometimes written f/2, is a different symbol from f/3.

These symbols are used mostly as constant, function, and predicate symbols, but they can be used for variables and other things as well.

The symbol table routines call malloc() and free() directly. The LADR memory package (tp_alloc()) is not used.


LADR-2009-11A/ladr/html/attrib.html0000644000175000017500000002715710775516357016113 0ustar mccunemccune attrib.h

#include "attrib.h"

This page has information from files attrib.h and attrib.c.

Contents


Public Routines in File attrib.c

Index

attribute_name_to_idcopy_term_attributeinheritable_att_instancesset_int_attribute
attributes_contain_variablesdeclare_term_attribute_inheritableinstantiate_inheritable_attributesset_string_attribute
attributes_to_termdelete_attributeslabel_attset_term_attribute
build_attr_termexists_attributep_attrib_memset_vars_attributes
cat_attfprint_attrib_memregister_attributestring_attribute_member
copy_attributesget_int_attributerenumber_vars_attributesterm_to_attributes
copy_int_attributeget_string_attributereplace_int_attributevars_in_attributes
copy_string_attributeget_term_attributereplace_term_attributezap_attributes

Details


int attribute_name_to_id(char *name);
Given an attribute name, return the attribute ID which is used for the "get" and "set" operations. Return -1 if the name has not been registered with "register_attribute".
BOOL attributes_contain_variables(Attribute a);
Does the list of attributes contain a Term attribute that contains a constant that looks like a variable?
Term attributes_to_term(Attribute a, char *operator);
This routine takes a list of attributes and constructs a term representation. It is a right-associated binary tree with Term forms of the attributes at the leaves.
Term build_attr_term(Attribute a);
Given an attribute, build (and return) a term representation of it. The name of the attribute will be the (unary) function symbol, and the value will be the argument.

This is typically used for printing attributes.


Attribute cat_att(Attribute a, Attribute b);
Concatenate two lists of attributes. Either may be NULL. Return the result.
Attribute copy_attributes(Attribute a);
This routine copies a list of attributes.
Attribute copy_int_attribute(Attribute source, Attribute dest, int attr_id);

Attribute copy_string_attribute(Attribute source, Attribute dest, int attr_id);

Attribute copy_term_attribute(Attribute source, Attribute dest, int attr_id);

void declare_term_attribute_inheritable(int id);
This routine makes a term attribute (which has already been registered) inheritable. This usually means that when the clause to which the attribute is attached begets a child, the child gets a copy of the instantiated attribute. This was designed for answer literals and ordering constraints.
Attribute delete_attributes(Attribute a, int id);
This routine frees all attributes of the given type.
BOOL exists_attribute(Attribute a, int id);
This routine checks if there are any attributes of the given type.
void fprint_attrib_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the attrib package. The Boolean argument heading tells whether to print a heading on the table.
int get_int_attribute(Attribute a, int id, int n);
This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, INT_MAX is returned.

A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute).


char *get_string_attribute(Attribute a, int id, int n);
This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute).


Term get_term_attribute(Attribute a, int id, int n);
This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute).


Attribute inheritable_att_instances(Attribute a, Context subst);
Given a list of attributes, this routine copies, instantiates, and returns the inheritable attributes. The Context can be NULL.
void instantiate_inheritable_attributes(Attribute a, Context subst);
This routine
int label_att(void);
Return the attribute identifier for label attributes. If it does not exist, return -1.
void p_attrib_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the attrib package.
int register_attribute(char *name, Attribute_type type);
This routine associates an attribute name and attribute type and returns an integer ID to be used with the attribute operations (set, get, etc).
void renumber_vars_attributes(Attribute attrs, int vmap[], int max_vars);
This routine renumbers the variables in the inheritable attribute terms.
void replace_int_attribute(Attribute a, int id, int val, int n);
This routine replaces that n-th int attribute for given attribute ID.

A fatal error occurs if the ID does not refer to an int type attribute (see register_attribute), or if there are not n attributes identified by ID.


void replace_term_attribute(Attribute a, int id, Term val, int n);
This routine replaces that n-th term attribute for given ID. The term that is already there is zapped, and the new term is NOT copied.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute), or if there are not n attributes identified by ID.


Attribute set_int_attribute(Attribute a, int id, int val);
This routine appends an pair to a list of attributes.

A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute).


Attribute set_string_attribute(Attribute a, int id, char *val);
This routine appends an pair to a list of attributes. If the string is not already in the symbol table, it is inserted (which copies the string).

A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute).


Attribute set_term_attribute(Attribute a, int id, Term val);
This routine appends an pair to a list of attributes. The term is not copied.

A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute).


void set_vars_attributes(Attribute attrs, char *vnames[], int max_vars);
This routine sets the variables in the inheritable attribute terms.
BOOL string_attribute_member(Attribute a, int id, char *s);
This routine checks of a list of attributes contains a particular attribute/value.

A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute).


Attribute term_to_attributes(Term t, char *operator);
This routine takes a term representing a list of attributes and builds list of attributes. The input term form is a binary term, constructed with the given operator, with the attributes at the leaves. For example,
    label("hi there!") # answer(XGK(x,y,z)) # hint_wt(32)
If anuthing goes wrong, a fatal error occurs.
Plist vars_in_attributes(Attribute attrs);
This routine returns the set of variables (as a Plist) in the inheritable attributes.
void zap_attributes(Attribute a);
This routine frees a list of attributes and any associated memory. In particular, the terms in term attributes are zapped.

Public Definitions in File attrib.h

typedef enum { INT_ATTRIBUTE,
	       STRING_ATTRIBUTE,
               TERM_ATTRIBUTE
             } Attribute_type;

typedef struct attribute * Attribute;


Introduction

This package is about lists of attributes. Each attribute is a pair (attribute-id, attribute-value). Each attribute-id is associated with a data type.

To use an attribute, you first have to call register_attribute(), giving and ID, name, and type of the attribute. The ID is used with the "set" and "get" operations.

For example,

  register_attribute(label_attr, "label", STRING_ATTRIBUTE);
  ...
  Attribute a = set_string_attribute(NULL, label_attr, "clause_32");
  ...
  char *s = get_string_attribute(a, label_attr, 1);

LADR-2009-11A/ladr/html/cnf.html0000644000175000017500000001101510775516357015356 0ustar mccunemccune cnf.h

#include "cnf.h"

This page has information from files cnf.h and cnf.c.

Contents


Public Routines in File cnf.c

Index

clausify_preparednfminiscopeskolemize
cnfformula_copy_shareminiscope_formulaunique_quantified_vars
cnf_max_clausesformula_ident_shareremove_universal_quantifiers

Details


Formula clausify_prepare(Formula f);
This routine gets a formula all ready for translation into clauses. The sequence of transformations is
  • change to negation normal form;
  • propositional simplification;
  • make the universally quantified variables unique;
  • skolemize (nothing fancy here);
  • remove universal quantifiers, changing the constants-which-represent-variables into genuine variables;
  • change to conjunctive normal form (with basic propositional simplification).
The caller should not refer to the given formula f after the call; A good way to call is f = clausify_prepare(f)
Formula cnf(Formula f);

int cnf_max_clauses(Formula f);
Given an NNF formula, return the maximum number of clauses that it can produce. (The maximum happens if no simplification occurs.)
Formula dnf(Formula f);

Formula formula_copy_share(Formula f);
This function returns a copy of the given formula. All subformulas, including the atoms, are copied.
BOOL formula_ident_share(Formula f, Formula g);
This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality.


Formula miniscope(Formula f);

Formula miniscope_formula(Formula f, unsigned mega_fid_call_limit);

Formula remove_universal_quantifiers(Formula f);
For each universally quantified variable in the given formula,
Formula skolemize(Formula f);
This routine Skolemizes an NNF formula. The quantified variables need not be named in any particular way. If there are universally quantified variables with the same name, one in the scope of another, the inner variable will be renamed. (Existential nodes are removed.)
Formula unique_quantified_vars(Formula f);
Rename quantified variables, if necessary, so that each is unique. This works for any formula.

If you wish to rename a quantified variable only if it occurs in the scope of of a quantified variable with the same name, you can use the routine eliminate_rebinding() instead.

(This could be a void routine, because none of the formula nodes is changed.)


Public Definitions in File cnf.h


Introduction


LADR-2009-11A/ladr/html/clauseid.html0000644000175000017500000000573010775516357016410 0ustar mccunemccune clauseid.h

#include "clauseid.h"

This page has information from files clauseid.h and clauseid.c.

Contents


Public Routines in File clauseid.c

Index

assign_clause_idclause_plist_memberfprint_clause_id_tabp_clause_id_tab
clause_ids_assignedfind_clause_by_idinsert_clause_into_plistunassign_clause_id

Details


void assign_clause_id(Topform c);
This routine assigns a unique identifier to the id field of a clause. It also inserts the clause into a hash table so that given an id number, the corresponding clause can be retrieved quickly (see find_clause_by_id()).
int clause_ids_assigned(void);
What is the most recently assigned clause ID?
BOOL clause_plist_member(Plist p, Topform c, BOOL increasing);
This routine checks if a clause occurs in a sorted (by ID) Plist of clauses. Boolean paramemeter "increasing" tells whether the list is increasing or decreasing.
Topform find_clause_by_id(int id);
This routine retrieves the clause with the given ID number (or NULL, if there is no such clause).
void fprint_clause_id_tab(FILE *fp);
This routine prints (to FILE *fp) all the clauses in the ID hash table.
Plist insert_clause_into_plist(Plist p, Topform c, BOOL increasing);
This routine inserts a clause into a sorted (by ID) Plist of clauses. Boolean paramemeter "increasing" tells whether the list is increasing or decreasing. The updated Plist is returned. If the clause is already there, nothing happens.
void p_clause_id_tab();
This routine prints (to stdout) all the clauses in the ID hash table.
void unassign_clause_id(Topform c);
This routine removes a clause from the ID hash table and resets the ID of the clause to 0. A fatal error occurs if the clause has not been assigned an ID.

Public Definitions in File clauseid.h


Introduction


LADR-2009-11A/ladr/html/literals.html0000644000175000017500000003176210775516357016442 0ustar mccunemccune literals.h

#include "literals.h"

This page has information from files literals.h and literals.c.

Contents


Public Routines in File literals.c

Index

any_clausefalse_termlits_to_termpositive_literals
append_literalfirst_literal_of_signmixed_clauseremove_null_literals
atom_numberfprint_literals_memneg_eqsymbol_occurrences_in_clause
clause_depthfree_literalsneg_eq_unittautology
clause_identfree_lits_to_termnegative_clauseterm_at_position
clause_symbol_countget_literalsnegative_literalsterm_to_literals
constants_in_clausegreatest_variable_in_clausenew_literaltrue_clause
contains_eqground_clausenumber_of_literalstrue_term
contains_pos_eqhorn_clausenumber_of_variablesunit_clause
copy_literalith_literalonly_eqvarnums_in_clause
copy_literalsliteral_numberp_literals_memvars_in_clause
copy_literals_with_flagliteral_to_termpos_eqzap_literal
copy_literals_with_flagsliterals_depthpos_eq_unitzap_literals
definite_clauseliterals_to_termpositive_clause

Details


BOOL any_clause(Literals lits);
This function is always TRUE. (It it intended to be used as an argument.)
Literals append_literal(Literals lits, Literals lit);
This routine appends a literal to a list of literals.
int atom_number(Literals lits, Term atom);
Given a clause and an atom, return the position of the atom (counting from 1) in the clause. The check is by pointer only. If the atom does not occur in the clause, 0 is returned.
int clause_depth(Literals lits);
Disjunction and negation signs are not included in the count. That is, return the depth of the deepest atomic formula.
BOOL clause_ident(Literals lits1, Literals lits2);
Identical clauses, including order of literals and variable numbering.
int clause_symbol_count(Literals lits);
Disjunction and negation signs are not included in the count.
Ilist constants_in_clause(Literals lits);
Given a clause, return the set of symnums for constants therein.
BOOL contains_eq(Literals lits);
This function checks if a clause contains an equality literal (positive or negative) for the purposes of paramodulation and demodulation.
BOOL contains_pos_eq(Literals lits);
This function checks if a clause contains a positive equality literal for the purposes of paramodulation and demodulation.
Literals copy_literal(Literals lit);

Literals copy_literals(Literals lits);
This routine builds and returns a copy of a clause. The container field of each nonvariable subterm points to the clause.
Literals copy_literals_with_flag(Literals lits, int flag);
This routine builds and returns a copy of a clause. The given termflag is copied for all subterms (including atoms, excluding variables).
Literals copy_literals_with_flags(Literals lits);
This routine builds and returns a copy of a clause. All termflags are copied for all subterms (including atoms, excluding variables).
BOOL definite_clause(Literals lits);
This Boolean function checks if a clause has exactly one positive literal.
BOOL false_term(Term t);

Literals first_literal_of_sign(Literals lits, BOOL sign);

void fprint_literals_mem(FILE *fp, int heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the clause package. The Boolean argument heading tells whether to print a heading on the table.
void free_literals(Literals p);

void free_lits_to_term(Term t);
This routine is to be used with terms constructed by lits_to_term().
Literals get_literals(void);

int greatest_variable_in_clause(Literals lits);
This routine returns the greatest variable index in a clause. If the clause is ground, -1 is returned.
BOOL ground_clause(Literals lits);

BOOL horn_clause(Literals lits);
This function checks if a clause has at most one positive literal.
Literals ith_literal(Literals lits, int i);
Return the i-th literal of a clause, counting from 1. Return NULL if i is out of range.
int literal_number(Literals lits, Literals lit);
Given a clause and a literal, return the position of the literal (counting from 1) in the clause. The check is by pointer only. If the literal does not occur in the clause, 0 is returned.
Term literal_to_term(Literals l);

int literals_depth(Literals lits);
This function returns the maximum depth of a list of literals. Negation signs are not counted, and P(a) has depth 1.
Term literals_to_term(Literals l);

Term lits_to_term(Literals l);
This routine converts a nonempty list of literals into a term. This version does not copy atoms; it constructs new term nodes only for the NOT and OR structure at the top of the clause. Use free_lits_to_term() to free terms constructed with this routine.
BOOL mixed_clause(Literals lits);
This function checks if a clause has at least one positive and at least one negative literal.
BOOL neg_eq(Literals lit);
This function checks if a literal is a positive equality for the purposes of paramodulation and demodulation.
BOOL neg_eq_unit(Literals lits);
This function checks if a list of Literals is a negative equality unit.
BOOL negative_clause(Literals lits);
This function checks if all of the literals of a clause are negative.
int negative_literals(Literals lits);
This function returns the number of negative literals in a clause.
Literals new_literal(int sign, Term atom);
This routine takes a sign (Boolean) and a Term atom, and returns a literal. The atom is not copied.
int number_of_literals(Literals lits);
This function returns the number of literals in a clause.
int number_of_variables(Literals lits);
This routine returns number of (distinct) variables in a clause.
BOOL only_eq(Literals lits);
This function checks if a clause contains only equality literals (positive or negative).
void p_literals_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the clause package.
BOOL pos_eq(Literals lit);
This function checks if a literal is a positive equality for the purposes of paramodulation and demodulation.
BOOL pos_eq_unit(Literals lits);
This function checks if a list of Literals is a positive equality unit for the purposes of paramodulation and demodulation.
BOOL positive_clause(Literals lits);
This function checks if all of the literals of a clause are positive.
int positive_literals(Literals lits);
This function returns the number of positive literals in a clause.
Literals remove_null_literals(Literals l);

int symbol_occurrences_in_clause(Literals lits, int symnum);

BOOL tautology(Literals lits);
This routine returns TRUE if the clause has complementary literals or if it has any literals of the form $T, -$F. This dos not check for x=x.
Term term_at_position(Literals lits, Ilist pos);

Literals term_to_literals(Term t, Literals lits);

BOOL true_clause(Literals lits);
Does the clause contain a literal $T? (This does not check for complementary literals, -$F, or x=x.)
BOOL true_term(Term t);

BOOL unit_clause(Literals lits);
This function checks if a clause has exactly one literal.
Ilist varnums_in_clause(Literals lits);
This routine returns the set of variable indexes (as an Ilist) in a clause.
Plist vars_in_clause(Literals lits);
This routine returns the set of variables (as a Plist) in a clause.
void zap_literal(Literals l);
This routine frees a literal.
void zap_literals(Literals l);
This routine frees a list of literals.

Public Definitions in File literals.h

typedef struct literals * Literals;

struct literals {
  BOOL      sign;
  Term      atom;
  Literals  next;
};


Introduction


LADR-2009-11A/ladr/html/index.html0000644000175000017500000000610010775516360015710 0ustar mccunemccune LADR DOCS

LADR

Library of Automated Deduction Routines

Version August-2006A
Top functions Interpretations Inference Rules Formulas and Clauses Indexing and Unification Terms Basic Routines
LADR-2009-11A/ladr/html/glist.html0000644000175000017500000004364210775516357015745 0ustar mccunemccune glist.h

#include "glist.h"

This page has information from files glist.h and glist.c.

Contents


Public Routines in File glist.c

Index

alist2_inserti2list_memberilist_rem_dupsplist_last
alist2_removei2list_multimemberilist_remove_lastplist_member
alist_inserti2list_multisubsetilist_removeallplist_pop
associ2list_prependilist_setplist_prepend
assoc2ai2list_removeallilist_subsetplist_remove
assoc2bi3list_appendilist_subtractplist_remove_last
copy_i3listi3list_countilist_unionplist_subset
copy_ilisti3list_prependith_in_plistplist_subtract
copy_plistilist_appendlongest_string_in_plistposition_in_ilist
fprint_glist_memilist_catmultiset_addposition_of_string_in_plist
fprint_ilistilist_cat2multiset_add_nreverse_i3list
free_i2listilist_copymultiset_occurrencesreverse_ilist
free_i3listilist_countmultiset_to_setreverse_plist
free_ilistilist_insert_upmultiset_unionsort_plist
free_plistilist_intersectp_glist_memstring_member_plist
get_i2listilist_is_setp_i2listzap_i2list
get_i3listilist_lastp_ilistzap_i3list
get_ilistilist_memberplist_appendzap_ilist
get_plistilist_occurrencesplist_catzap_plist
i2list_appendilist_popplist_cat2
i2list_countilist_prependplist_count

Details


I3list alist2_insert(I3list p, int key, int a, int b);
Alist2 (association list) for pairs of integers. Insert key/ pairs. With assoc2a(key), retreive value-a. With assoc2b(key), retreive value-b. If a key has more than one value pair, the most recent is returned. It a key is not in the alist2, INT_MIN is returned. An alist2 can be freed with zap_i3list(alist2).
I3list alist2_remove(I3list p, int key);

I2list alist_insert(I2list p, int key, int val);
Alists (association list) for integers. Insert key/value pairs. With assoc(key), retreive value. If a key has more than one value, the most recent is returned. It an key is not in the alist, INT_MIN is returned. An alist can be freed with zap_i2list(alist). This is not efficient, because no hashing is done; lookups are linear.
int assoc(I2list p, int key);
See alist_insert.
int assoc2a(I3list p, int key);
See alist2_insert.
int assoc2b(I3list p, int key);
See alist2_insert.
I3list copy_i3list(I3list p);
This routine copies a I3list (the whole 3list) and returns the copy.
Ilist copy_ilist(Ilist p);
This routine copies a Ilist (the whole list) and returns the copy.
Plist copy_plist(Plist p);
This routine copies a Plist (the whole list) and returns the copy.
void fprint_glist_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the glist package. The Boolean argument heading tells whether to print a heading on the table.
void fprint_ilist(FILE *fp, Ilist p);
The list of integers is printed to FILE *fp like this: (4 5 1 3), without a newline.
void free_i2list(I2list p);

void free_i3list(I3list p);

void free_ilist(Ilist p);

void free_plist(Plist p);

I2list get_i2list(void);

I3list get_i3list(void);

Ilist get_ilist(void);

Plist get_plist(void);

I2list i2list_append(I2list lst, int i, int j);
This routine appends an integer to a I2list. The updated I2list is returned.
int i2list_count(I2list p);
This routine returns the length of a I2list.
I2list i2list_member(I2list lst, int i);

BOOL i2list_multimember(I2list b, int i, int n);
Is a multimember of multiset b?
BOOL i2list_multisubset(I2list a, I2list b);

I2list i2list_prepend(I2list lst, int i, int j);
This routine inserts an integer triple as the first member of a I2list. The updated I2list is returned.
I2list i2list_removeall(I2list p, int i);
Remove all occurrences of i.

The argument is "used up".


I3list i3list_append(I3list lst, int i, int j, int k);
This routine appends an integer to a I3list. The updated I3list is returned.
int i3list_count(I3list p);
This routine returns the length of a I3list.
I3list i3list_prepend(I3list lst, int i, int j, int k);
This routine inserts an integer triple as the first member of a I3list. The updated I3list is returned.
Ilist ilist_append(Ilist lst, int i);
This routine appends an integer to a Ilist. The updated Ilist is returned.
Ilist ilist_cat(Ilist p1, Ilist p2);
Concatenate two Ilists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both arguments are "used up".


Ilist ilist_cat2(Ilist p1, Ilist p2);
Concatenate two Ilists and return the result. In this version, the second ilist is copied and placed at the end of p1. That is, p1 is "used up", but p2 is not.
Ilist ilist_copy(Ilist p);

int ilist_count(Ilist p);
This routine returns the length of a Ilist.
Ilist ilist_insert_up(Ilist p, int i);

Ilist ilist_intersect(Ilist a, Ilist b);
Construct the intersection (as a new Ilist).

The arguments are not changed.


BOOL ilist_is_set(Ilist a);

Ilist ilist_last(Ilist lst);

BOOL ilist_member(Ilist lst, int i);
This function checks if an integer is a member of a Ilist. (If a node in the Ilist contains a pointer instead of an integer, the result is undefined.)
int ilist_occurrences(Ilist p, int i);
How many times does an integer occur in an ilist?
Ilist ilist_pop(Ilist p);
This routine takes a nonempty Ilist, removes and frees the first node (ignoring the contents), and returns the remainder of the list.
Ilist ilist_prepend(Ilist lst, int i);
This routine inserts an integer as the first member of a Ilist. The updated Ilist is returned.
Ilist ilist_rem_dups(Ilist m);
Take a list of integers and remove duplicates.

This version "uses up" the argument.


Ilist ilist_remove_last(Ilist p);

Ilist ilist_removeall(Ilist p, int i);
Remove all occurrences of i.

The argument is "used up".


Ilist ilist_set(Ilist m);
Take a list of integers and remove duplicates. This creates a new list and leave the old list as it was. Don't make any assumptions about the order of the result.
BOOL ilist_subset(Ilist a, Ilist b);

Ilist ilist_subtract(Ilist p1, Ilist p2);
Return the members of p1 that are not in p2.

The arguments are not changed.


Ilist ilist_union(Ilist a, Ilist b);
Construct the union (as a new Ilist).

The arguments need not be sets, the result is a set.

The arguments are not changed.


void *ith_in_plist(Plist p, int i);

int longest_string_in_plist(Plist p);
Return -1 if the Plist is empty.
I2list multiset_add(I2list a, int i);
Add 1 occurrence of i to multiset a.
I2list multiset_add_n(I2list a, int i, int n);
Add n occurrences of i to multiset a.
int multiset_occurrences(I2list m, int i);

Ilist multiset_to_set(I2list m);

I2list multiset_union(I2list a, I2list b);
The result is constructed from the arguments, so do not refer to either of the arguments after the call. That is, both arguments are "used up".
void p_glist_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the glist package.
void p_i2list(I2list p);
The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end.
void p_ilist(Ilist p);
The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end.
Plist plist_append(Plist lst, void *v);
This routine appends a pointer to a Plist. The updated Plist is returned.
Plist plist_cat(Plist p1, Plist p2);
Concatenate two Plists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both args are destroyed.


Plist plist_cat2(Plist p1, Plist p2);
Concatenate two Plists and return the result. In this version, the second plist is copied and placed at the end of p1.

That is, the first arg is destroyed, and the second is preserved.


int plist_count(Plist p);
This routine returns the length of a Plist.
void *plist_last(Plist p);

BOOL plist_member(Plist lst, void *v);
This function checks if a pointer is a member of a Plist.
Plist plist_pop(Plist p);
This routine takes a nonempty Plist, removes and frees the first node (ignoring the contents), and returns the remainder of the list.
Plist plist_prepend(Plist lst, void *v);
This routine inserts a pointer as the first member of a Plist. The updated Plist is returned.
Plist plist_remove(Plist p, void *v);
Remove the first occurrence of a pointer from a Plist.
Plist plist_remove_last(Plist p);

BOOL plist_subset(Plist a, Plist b);

Plist plist_subtract(Plist p1, Plist p2);
Return the members of p1 that are not in p2.

The arguments are not changed.


int position_in_ilist(int i, Ilist p);
Count from 1; return -1 if the int is not in the Ilist.
int position_of_string_in_plist(char *s, Plist p);
Count from 1; return -1 if the string is not in the Plist.
I3list reverse_i3list(I3list p);
This routine reverses a I3list. The 3list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:
p = reverse_i3list(p);

Ilist reverse_ilist(Ilist p);
This routine reverses a Ilist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:
p = reverse_ilist(p);

Plist reverse_plist(Plist p);
This routine reverses a Plist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:
p = reverse_plist(p);

Plist sort_plist(Plist objects,	Ordertype (*comp_proc) (void *, void *));

BOOL string_member_plist(char *s, Plist p);

void zap_i2list(I2list p);
This routine frees an I2list (the whole list).
void zap_i3list(I3list p);
This routine frees a I3list (the whole list).
void zap_ilist(Ilist p);
This routine frees a Ilist (the whole list).
void zap_plist(Plist p);
This routine frees a Plist (the whole list). The things to which the members point are not freed.

Public Definitions in File glist.h

typedef struct plist * Plist;

struct plist {
  void *v;
  Plist next;
};

typedef struct ilist * Ilist;

struct ilist {
  int i;
  Ilist next;
};

typedef struct i2list * I2list;

struct i2list {
  int i;
  int j;
  I2list next;
};

typedef struct i3list * I3list;

struct i3list {
  int i;
  int j;
  int k;
  I3list next;
};


Introduction

This package handles Plist (singly-linked list of void pointers), Ilist (singly-linked list of integers), I2list (singly-linked list of pairs), I3list (singly-linked list of triples).
LADR-2009-11A/ladr/html/clist.html0000644000175000017500000002721210775516357015734 0ustar mccunemccune clist.h

#include "clist.h"

This page has information from files clist.h and clist.c.

Contents


Public Routines in File clist.c

Index

clauses_in_clistclist_lengthclist_zapneg_clauses_in_clist
clist_appendclist_membercopy_clist_to_plist_shallowneg_nonunit_in_clist
clist_append_allclist_move_clausesequality_in_clistp_clist
clist_append_plistclist_number_of_weightfprint_clause_clistp_clist_mem
clist_checkclist_prependfprint_clistplist_to_clist
clist_emptyclist_removefprint_clist_mempos_in_clist
clist_freeclist_remove_allhorn_clistprepend_clist_to_plist
clist_initclist_remove_all_clausesmax_wt_in_clistsort_clist_by_id
clist_insert_afterclist_reversemove_clist_to_plistunit_clist
clist_insert_beforeclist_swapname_clist

Details


Plist clauses_in_clist(Plist p, Clist l);
Return the intersection of Plist p of clauses and Clist c of clauses.
void clist_append(Topform c, Clist l);
This routine appends a Topform to a Clist.
void clist_append_all(Clist l1, Clist l2);
Append each member of l2 to l1, then zap l2. Do not refer to l2 after the call.
void clist_append_plist(Clist lst, Plist clauses);

void clist_check(Clist l);
This routine checks the integrity of a Clist. If any errors are found, a message is sent to stdout. This is used for debugging.
BOOL clist_empty(Clist lst);
This function checks if a (non-NULL) Clist is empty.
void clist_free(Clist p);
This routine frees an empty Clist. If the Clist is not empty, nothing happens.
Clist clist_init(char *name);
This routine allocates and returns an empty Clist, which is a doubly-linked list of pointers to clauses. You give it a string (any length, which is copied), representing the name of the list. If don't wish to name the list, send NULL. (You can name the list later with name_clist().)
void clist_insert_after(Topform c, Clist_pos pos);
This routine inserts a Topform after a given position in a Clist.
void clist_insert_before(Topform c, Clist_pos pos);
This routine inserts a Topform before a given position in a Clist.
int clist_length(Clist l);

int clist_member(Topform c, Clist l);
This Boolean routine checks if a Topform is a member of a Clist.
void clist_move_clauses(Clist a, Clist b);
Move all clauses from a to the end of b.
int clist_number_of_weight(Clist lst, int weight);

void clist_prepend(Topform c, Clist l);
This routine inserts a Topform as the first member of a Clist.
void clist_remove(Topform c, Clist l);
This routine removes a clause from a Clist. If the Topform occurs more than once in the Clist, the most recently inserted occurrence is removed. A fatal error occurs if the Topform is not in the Clist.
int clist_remove_all(Topform c);
This routine removes a clause from all lists in which it occurs. The number of lists from which it was removed is returned.
void clist_remove_all_clauses(Clist l);
This routine removes all clauses from a clist. The clauses are NOT deleted, even if they occur nowhere else.
void clist_reverse(Clist l);
Reverse a Clist.
void clist_swap(Topform a, Topform b);
Every clause occurs in a set (maybe empty) of Clists. Given clauses A and B, this routine puts A into the lists in which B occurs and vice versa.
void clist_zap(Clist l);
For each Topform (occurrence) in a Clist, remove it, and if it occurs in no other Clist, call zap_topform() to delete the clause. Then, free the Clist.
Plist copy_clist_to_plist_shallow(Clist a);

BOOL equality_in_clist(Clist l);
Does the list contain a clause with a positive equality literal?
void fprint_clause_clist(FILE *fp, Clist lst);
This routine prints (to FILE *fp) a Clist of clauses in standard prefix form.
void fprint_clist(FILE *fp, Clist l);
This routine prints (to FILE *fp) each clause in a Clist. If the Clist has a non-empty name, say "usable", the string "list(usable).\n" is printed first. The string "end_of_list.\n" is always printed at the end.
void fprint_clist_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the clist package. The Boolean argument heading tells whether to print a heading on the table.
BOOL horn_clist(Clist l);
Is every clause in the list a Horn clause?
int max_wt_in_clist(Clist l);
Scan a Clist, and return the maximum clause weight seen.
Plist move_clist_to_plist(Clist a);

void name_clist(Clist p, char *name);
This routine names or renames a Clist. The string you supply can be any length and is copied.
Plist neg_clauses_in_clist(Clist a);

BOOL neg_nonunit_in_clist(Clist l);
Does the list contain a negative nonunit clause ?
void p_clist(Clist l);
This routine prints (to stdout) each clause in a Clist. See fprint_clist().
void p_clist_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the clist package.
Clist plist_to_clist(Plist p, char *name);

Clist_pos pos_in_clist(Clist lst, Topform c);
Return the Clist_pos of a Topform in a Clist.
Plist prepend_clist_to_plist(Plist p, Clist c);

void sort_clist_by_id(Clist lst);

BOOL unit_clist(Clist l);
Is every clause in the list a unit clause?

Public Definitions in File clist.h

typedef struct clist_pos * Clist_pos;
typedef struct clist * Clist;

struct clist {
  char       *name;
  Clist_pos  first, last;
  int        length;
};

struct clist_pos {
  Clist_pos  prev, next;  /* previous and next member of Clist */
  Clist_pos  nocc;        /* next member of containment list */
  Clist      list;        /* the head of the list */
  Topform     c;          /* pointer to the clause */
};


Introduction

This package handles Clists, which are doubly-linked lists of (pointers to) clauses. This is the "official" way of building lists of clauses. (If you need a temporary, singly linked list, you can use Plist instead.)

An important property of Clists is that each clause knows what Clists it is on. In particular, each clause has a (singly linked) list of containing Clists, constructed from the same nodes as the ordinary Clist (see the definition of struct clist_pos).


LADR-2009-11A/ladr/html/pindex.html0000644000175000017500000001166210775516357016107 0ustar mccunemccune pindex.h

#include "pindex.h"

This page has information from files pindex.h and pindex.c.

Contents


Public Routines in File pindex.c

Index

delete_pair_indexinsert_pair_indexpairs_exhausted
fprint_pindex_memp_pindex_memretrieve_pair
init_pair_indexpair_already_usedzap_pair_index

Details


void delete_pair_index(Topform c, int wt, Pair_index p);
This routine removes a clause from a Pair_index. The parameter wt must be the same as when the clause was inserted. A fatal error may occur if the clause was not previously inserted or if it was inserted with a different weight.
void fprint_pindex_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for data types associated with the pindex package. The Boolean argument heading tells whether to print a heading on the table.
Pair_index init_pair_index(int n);
This routine allocates and initializes a Pair_index. Parameter n specifies the range 0 .. n-1 of weights that will be used. If a clause is inserted with weight outside of that range, the effective weight for pair indexing will be set to 0 or n-1.
void insert_pair_index(Topform c, int wt, Pair_index p);
This routine inserts a clause into a Pair_index. If the given weight is out of range [0 ... n-1] (where n is the parameter given to init_pair_index()), weight 0 or n-1 will be used instead.
void p_pindex_mem();
This routine prints (to stdout) memory usage statistics for data types associated with the pindex package.
int pair_already_used(Topform c1, int weight1,
		      Topform c2, int weight2,
		      Pair_index p);
This Boolean routine checks if a pair of clauses (with corresponding weights) has already been retrieved.
int pairs_exhausted(Pair_index p);
This routine is TRUE if the previous call to retrieve_pair() returned nothing and no more pairs have been inserted since then. (Also, TRUE is returned if no pairs were ever inserted.)

Note that FALSE may be returned when there really no pairs available.


void retrieve_pair(Pair_index p, Topform *cp1, Topform *cp2);
This routine retrieves the next pair from a Pair_index. The caller gives addresses of clauses which are filled in with the answer. If no pair is available, NULLs are filled in.
void zap_pair_index(Pair_index p);
This routine frees a pair index. It need not be empty.

Public Definitions in File pindex.h

typedef struct pair_index * Pair_index;


Introduction

This package has code for indexing clauses that are to be retrieved in pairs. When a clause is inserted, its weight is given. Retrieval is by sum of the weights of the pair -- lowest first. Say we have clauses with weights 0--4. Then pairs will be returned in this order:
(0,0)
(0,1)
(1,1)  (0,2)
(1,2)  (0,3)
(2,2)  (1,3)  (0,4)
(2,3)  (1,4)
(3,3)  (2,4)
(3,4)
(4,4)
Clauses can be inserted or deleted after retrieval has begun; the smallest available pair will always be returned. When the index is initialized, the caller supplies a parameter N, and the actual weight range for indexing will be 0...N-1. If an inserted clause has weight outside of this range, the weight will be changed to 0 or N-1.

This is intended to be used for binary inference rules such as paramodulation and resolution. It is similar to the method in ``A Theorem-Proving Language for Experimentation'' by Henschen, Overbeek, Wos, CACM 17(6), 1974.


LADR-2009-11A/ladr/tlist.h0000644000175000017500000000260011151265363014251 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_TLIST_H #define TP_TLIST_H #include "term.h" /* INTRODUCTION This little package handles singly-linked lists of terms. The data type Plist is used to build the lists.

Note that there is another package, listterm, that does similar things, but constructing the lists from ordinary terms, as in Prolog. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from tlist.c */ void zap_tlist(Plist p); Plist tlist_remove(Term t, Plist p); Plist tlist_union(Plist a, Plist b); Ilist constants_in_term(Term t, Ilist p); Plist tlist_copy(Plist p); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/memory.h0000644000175000017500000000331711151265363014430 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_MEMORY_H #define TP_MEMORY_H #include "fatal.h" #include #include /* INTRODUCTION */ /* Public definitions */ /* The following definitions exist because the memory get/free routines measure memory by pointers instead of bytes. */ #define CEILING(n,d) ((n)%(d) == 0 ? (n)/(d) : (n)/(d) + 1) #define BYTES_POINTER sizeof(void *) /* bytes per pointer */ #define PTRS(n) CEILING(n, BYTES_POINTER) /* ptrs needed for n bytes */ /* End of public definitions */ /* Public function prototypes from memory.c */ void *get_cmem(unsigned n); void *get_mem(unsigned n); void free_mem(void *q, unsigned n); void memory_report(FILE *fp); int megs_malloced(void); void set_max_megs(int megs); void set_max_megs_proc(void (*proc)(void)); int bytes_palloced(void); void *tp_alloc(size_t n); unsigned mega_mem_calls(void); void disable_max_megs(void); void enable_max_megs(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clock.h0000644000175000017500000000501311151265363014206 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLOCK_H #define TP_CLOCK_H #include #include #include #include "string.h" /* INTRODUCTION This package is for timing various operations. Say you need to time an operation P. You first call clock_init() to set up a clock, then you can start and stop the clock as you wish, then you can get the accumulated time with clock_value(). These clocks measure the user CPU time.

An unusual feature of these clocks is that they can be used inside of recursive routines. For example, you can start the clock at the beginning of a recursive routine and stop it at the end. If you start it 3 times then stop it three times, it will really stop only on the third call. This works by a counter of the number of extra times the clock has been started, and clock_stop() will stop the clock only when the count is 0. (This feature probably isn't very useful, and most people can ignore it.)

Also here are some routines for getting process system/user CPU time, elapsed wall-clock time, and the time/date. */ /* Public definitions */ typedef struct clock * Clock; /* End of public definitions */ /* Public function prototypes from clock.c */ void free_clock(Clock p); Clock clock_init(char *str); void clock_start(Clock p); void clock_stop(Clock p); unsigned clock_milliseconds(Clock p); double clock_seconds(Clock p); BOOL clock_running(Clock p); void clock_reset(Clock p); void fprint_clock(FILE *fp, Clock p); char * get_date(void); unsigned user_time(); double user_seconds(); unsigned system_time(); double system_seconds(); unsigned absolute_wallclock(void); void init_wallclock(); unsigned wallclock(); void disable_clocks(void); void enable_clocks(void); BOOL clocks_enabled(void); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/clauses.h0000644000175000017500000000303211225461204014543 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_CLAUSES_H #define TP_CLAUSES_H #include "topform.h" /* INTRODUCTION This package contains various functions on Plists of clauses. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from clauses.c */ Topform clause_member_plist(Plist p, Topform c); Plist intersect_clauses(Plist a, Plist b); double max_clause_weight(Plist p); int max_clause_symbol_count(Plist p); Plist nonneg_clauses(Plist clauses); BOOL all_clauses_horn(Plist l); BOOL all_clauses_unit(Plist l); BOOL all_clauses_positive(Plist l); int neg_nonunit_clauses(Plist l); int negative_clauses(Plist l); int most_literals(Plist clauses); BOOL pos_equality_in_clauses(Plist clauses); BOOL equality_in_clauses(Plist clauses); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/fpalist.h0000644000175000017500000000570111151265364014562 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FPALIST_H #define TP_FPALIST_H #include "term.h" /* INTRODUCTION */ /* Public definitions */ /* We use the Term ID to order FPA lists. */ #define FPA_ID_TYPE unsigned #define FPA_ID_MAX UINT_MAX #define FPA_ID(t) (((Term) t)->u.id) /* I experimented with using the address of the term as the term ID for ordering FPA lists. Although not technically legal in C (because addresses in different arrays (malloced blocks) are compared), I believe it works correctly on all modern systems. (It didn't work in DOS.) However, there is a practical problem. On some systems, malloc() returns addresses in increasing order, and on others, they are decreasing, giving answers to queries in the reverse order, causing different searches. define FPA_ID_TYPE Term define FPA_ID_MAX ((Term) ULONG_MAX) // define FPA_ID(t) ((Term) t) */ #define FLT(x,y) (FPA_ID(x) < FPA_ID(y)) #define FGT(x,y) (FPA_ID(x) > FPA_ID(y)) #define FLE(x,y) (FPA_ID(x) <= FPA_ID(y)) #define FGE(x,y) (FPA_ID(x) >= FPA_ID(y)) #define FTERM(p) ((p).f == NULL ? NULL : (p).f->d[(p).i]) /* FPA lists */ typedef struct fpa_chunk *Fpa_chunk; typedef struct fpa_list *Fpa_list; struct fpa_chunk { int size; /* size of array */ Term *d; /* array for chunk */ int n; /* current number of items in chunk (right justified) */ Fpa_list head; /* beginning of list to which this chunk belongs */ Fpa_chunk next; /* list of chunks is singly-linked */ }; struct fpa_list { Fpa_chunk chunks; int num_chunks; int chunksize; int num_terms; }; /* to maintain a position in an FPA list while traversing for set operations */ struct fposition { Fpa_chunk f; int i; }; /* End of public definitions */ /* Public function prototypes from fpalist.c */ Fpa_list get_fpa_list(); void fprint_fpalist_mem(FILE *fp, BOOL heading); void p_fpalist_mem(); void fpalist_insert(Fpa_list p, Term t); void fpalist_delete(Fpa_list p, Term t); struct fposition first_fpos(Fpa_list f); struct fposition next_fpos(struct fposition p); void zap_fpa_chunks(Fpa_chunk p); void zap_fpalist(Fpa_list p); BOOL fpalist_empty(Fpa_list p); void p_fpa_list(Fpa_chunk c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/symbols.c~0000644000175000017500000016710011272052143014774 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "symbols.h" /* Private definitions and types*/ struct symbol { int symnum; /* unique identifier */ char *name; /* the print symbol */ int arity; /* 0 for constants */ Symbol_type type; /* function, relation, unspecified */ Parsetype parse_type; /* infix, prefix, etc. */ int parse_prec; /* precedence for parsing/printing */ Unif_theory unif_theory; /* e.g., associative-commutative */ int occurrences; /* how often it occurs somewhere */ int lex_val; /* precedence for term orderings */ int kb_weight; /* for Knuth-Bendix ordering */ Lrpo_status lrpo_status; /* for LRPO, LPO, RPO */ BOOL skolem; BOOL unfold; BOOL auxiliary; /* not part of theory, e.g., in hints only */ /* IF YOU ADD MORE FIELDS, MAKE SURE TO INITIALIZE THEM ! */ }; #define SYM_TAB_SIZE 50000 static Plist By_id[SYM_TAB_SIZE]; /* for access by symnum (ID) */ static Plist By_sym[SYM_TAB_SIZE]; /* for access by string/arity */ static unsigned Symbol_count; /* Logic symbols when in Term form */ static char *True_sym = "$T"; static char *False_sym = "$F"; static char *And_sym = "&"; static char *Or_sym = "|"; static char *Not_sym = "-"; static char *Iff_sym = "<->"; static char *Imp_sym = "->"; static char *Impby_sym = "<-"; static char *All_sym = "all"; static char *Exists_sym = "exists"; static char *Quant_sym = "$quantified"; /* Other symbols when in Term form */ static char *Attrib_sym = "#"; /* operator for attaching attributes */ static char *Eq_sym = "="; /* for equality inference rules */ static char *Neq_sym = "!="; /* abbreviation for negation of Eq_sym */ /************* * * true_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *true_sym(void) { return True_sym; } /* true_sym */ /************* * * false_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *false_sym() { return False_sym; } /* false_sym */ /************* * * and_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *and_sym() { return And_sym; } /* and_sym */ /************* * * or_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *or_sym() { return Or_sym; } /* or_sym */ /************* * * not_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *not_sym() { return Not_sym; } /* not_sym */ /************* * * iff_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *iff_sym() { return Iff_sym; } /* iff_sym */ /************* * * imp_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *imp_sym() { return Imp_sym; } /* imp_sym */ /************* * * impby_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *impby_sym() { return Impby_sym; } /* impby_sym */ /************* * * all_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *all_sym() { return All_sym; } /* all_sym */ /************* * * exists_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *exists_sym() { return Exists_sym; } /* exists_sym */ /************* * * quantified_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *quant_sym() { return Quant_sym; } /* quantified_sym */ /************* * * attrib_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *attrib_sym() { return Attrib_sym; } /* attrib_sym */ /************* * * eq_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *eq_sym() { return Eq_sym; } /* eq_sym */ /************* * * neq_sym() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *neq_sym() { return Neq_sym; } /* neq_sym */ /************* * * set_operation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_operation_symbol(char *operation, char *symbol) { if (str_ident(operation, "true")) True_sym = symbol; else if (str_ident(operation, "false")) False_sym = symbol; else if (str_ident(operation, "conjunction")) And_sym = symbol; else if (str_ident(operation, "disjunction")) Or_sym = symbol; else if (str_ident(operation, "negation")) Not_sym = symbol; else if (str_ident(operation, "implication")) Imp_sym = symbol; else if (str_ident(operation, "backward_implication")) Impby_sym = symbol; else if (str_ident(operation, "equivalence")) Iff_sym = symbol; else if (str_ident(operation, "universal_quantification")) All_sym = symbol; else if (str_ident(operation, "existential_quantification")) Exists_sym = symbol; else if (str_ident(operation, "quantification")) Quant_sym = symbol; else if (str_ident(operation, "attribute")) Attrib_sym = symbol; else if (str_ident(operation, "equality")) Eq_sym = symbol; else if (str_ident(operation, "negated_equality")) Neq_sym = symbol; else { printf("The unknown operation is %s\n", operation); fatal_error("set_operation_symbol, unknown operation"); } } /* set_operation_symbol */ /************* * * get_operation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *get_operation_symbol(char *operation) { if (str_ident(operation, "true")) return True_sym; else if (str_ident(operation, "false")) return False_sym; else if (str_ident(operation, "conjunction")) return And_sym; else if (str_ident(operation, "disjunction")) return Or_sym; else if (str_ident(operation, "negation")) return Not_sym; else if (str_ident(operation, "implication")) return Imp_sym; else if (str_ident(operation, "backward_implication")) return Impby_sym; else if (str_ident(operation, "equivalence")) return Iff_sym; else if (str_ident(operation, "universal_quantification")) return All_sym; else if (str_ident(operation, "existential_quantification")) return Exists_sym; else if (str_ident(operation, "quantification")) return Quant_sym; else if (str_ident(operation, "attribute")) return Attrib_sym; else if (str_ident(operation, "equality")) return Eq_sym; else if (str_ident(operation, "negated_equality")) return Neq_sym; else { printf("The unknown operation is %s\n", operation); fatal_error("get_operation_symbol, unknown operation"); return ""; } } /* get_operation_symbol */ /************* * * symbol_in_use() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL symbol_in_use(char *str) { if (str_ident(str, True_sym)) return TRUE; else if (str_ident(str, False_sym)) return TRUE; else if (str_ident(str, And_sym)) return TRUE; else if (str_ident(str, Or_sym)) return TRUE; else if (str_ident(str, Not_sym)) return TRUE; else if (str_ident(str, Imp_sym)) return TRUE; else if (str_ident(str, Impby_sym)) return TRUE; else if (str_ident(str, Iff_sym)) return TRUE; else if (str_ident(str, All_sym)) return TRUE; else if (str_ident(str, Exists_sym)) return TRUE; else if (str_ident(str, Quant_sym)) return TRUE; else if (str_ident(str, Attrib_sym)) return TRUE; else if (str_ident(str, Eq_sym)) return TRUE; else if (str_ident(str, Neq_sym)) return TRUE; else return FALSE; } /* symbol_in_use */ /****************************************************************************/ /* This section is about the symbol table. */ /****************************************************************************/ /************* * * Symbol get_symbol() * *************/ static Symbol get_symbol(void) { Symbol p = malloc(sizeof(struct symbol)); p->name = ""; p->symnum = 0; p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; p->arity = -1; p->unif_theory = EMPTY_THEORY; p->occurrences = -1; p->lex_val = INT_MAX; p->lrpo_status = LRPO_LR_STATUS; p->kb_weight = 1; p->type = UNSPECIFIED_SYMBOL; p->skolem = FALSE; p->unfold = FALSE; p->auxiliary = FALSE; return(p); } /* get_symbol */ /************* * * int new_symnum() * * Return the next available symbol number. It is always POSITIVE. * *************/ static int new_symnum(void) { Symbol_count++; return(Symbol_count); } /* new_symnum */ /************* * * hash_sym() * *************/ static unsigned hash_sym(char *s, int arity) { unsigned x = arity; while (*s != '\0') { unsigned c = *s; x = (x << 4) | c; s++; } return abs(x) % SYM_TAB_SIZE; } /* hash_sym */ /************* * * hash_id() * *************/ static unsigned hash_id(int id) { return abs(id) % SYM_TAB_SIZE; } /* hash_id */ /************* * * lookup_by_id() * *************/ static Symbol lookup_by_id(int symnum) { Plist p; for (p = By_id[hash_id(symnum)]; p; p = p->next) { Symbol s = p->v; if (s->symnum == symnum) return s; } return NULL; } /* lookup_by_id */ /************* * * lookup_by_sym() * *************/ static Symbol lookup_by_sym(char *name, int arity) { Plist p; for (p = By_sym[hash_sym(name,arity)]; p; p = p->next) { Symbol s = p->v; if (s->arity == arity && str_ident(s->name, name)) return s; } return NULL; } /* lookup_by_sym */ /************* * * int str_to_sn() * *************/ /* DOCUMENTATION This routine takes a string and an arity, and returns an integer identifier for the pair. If the pair is not already in the symbol table, a new entry is inserted into the table. A pair, say ("f",2), is sometimes written as f/2, which is a different symbol from f/3. There is no limit on the length of the string (which is copied). */ /* PUBLIC */ int str_to_sn(char *str, int arity) { Symbol s = lookup_by_sym(str, arity); if (s == NULL) { s = get_symbol(); s->name = new_str_copy(str); s->arity = arity; s->symnum = new_symnum(); /* printf("New Symbol: %s/%d, sn=%d\n", str, arity, s->symnum); */ /* insert into both hash tables */ { int hashval_id = hash_id(s->symnum); int hashval_sym = hash_sym(str, arity); By_sym[hashval_sym] = plist_prepend(By_sym[hashval_sym], s); By_id[hashval_id] = plist_prepend(By_id[hashval_id], s); } } return(s->symnum); } /* str_to_sn */ /************* * * fprint_syms(file_ptr) -- Display the symbol list. * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the symbol table, including many of the attributes of each symbol. */ /* PUBLIC */ void fprint_syms(FILE *fp) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; fprintf(fp, "%d %s/%d %s, lex_val=%d, kb_weight=%d\n", s->symnum, s->name, s->arity, s->type == FUNCTION_SYMBOL ? "function" : s->type == PREDICATE_SYMBOL ? "relation" : "", s->lex_val, s->kb_weight); } } } /* fprint_syms */ /************* * * p_syms() * *************/ /* DOCUMENTATION This routine prints (to stdout) the symbol table, including all of the attributes of each symbol. */ /* PUBLIC */ void p_syms(void) { fprint_syms(stdout); } /* p_syms */ /************* * * fprint_sym() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void fprint_sym(FILE *fp, int symnum) { fprintf(fp, "%s", sn_to_str(symnum)); } /* fprint_sym */ /************* * * sprint_sym() * *************/ /* DOCUMENTATION This routine appends, to String_buf sb, the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void sprint_sym(String_buf sb, int symnum) { sb_append(sb, sn_to_str(symnum)); } /* fprint_sym */ /************* * * p_sym() * *************/ /* DOCUMENTATION This routine prints (stdout) the string associated with a symbol ID. A newline is NOT printed. */ /* PUBLIC */ void p_sym(int symnum) { fprint_sym(stdout, symnum); } /* p_sym */ /************* * * str_exists() * *************/ /* DOCUMENTATION This function checks if the given string occurs in the symbol table (with any arity). This should be used judiciously, because the whole table is scanned. */ /* PUBLIC */ BOOL str_exists(char *str) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (str_ident(str, s->name)) return TRUE; } } return FALSE; } /* str_exists */ /************* * * greatest_symnum() * *************/ /* DOCUMENTATION This function returns the greatest symnum (symbol ID) currently in use. This can be used if you need to dynamnically allocate an array of objects to be indexed by symnum. */ /* PUBLIC */ int greatest_symnum(void) { return Symbol_count; } /* greatest_symnum */ /****************************************************************************/ /* This section is about miscellaneous properties of symbols. */ /****************************************************************************/ /************* * * char *sn_to_str(symnum) -- given a symbol number, return the name * *************/ /* DOCUMENTATION This routine returns the string assocated with a symbol ID. */ /* PUBLIC */ char *sn_to_str(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(""); else return(p->name); } /* sn_to_str */ /************* * * int is_symbol(symbol, str, arity) * *************/ /* DOCUMENTATION This Boolean routine checks if a given symbol ID matches a given (string,arity) pair. */ /* PUBLIC */ BOOL is_symbol(int symnum, char *str, int arity) { Symbol n = lookup_by_id(symnum); if (n == NULL) return FALSE; else return (n->arity == arity && str_ident(n->name, str)); } /* is_symbol */ /************* * * int sn_to_arity(symnum) -- given a symbol number, return the arity * *************/ /* DOCUMENTATION This routine returns the arity associated with a symbol ID. */ /* PUBLIC */ int sn_to_arity(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->arity); } /* sn_to_arity */ /************* * * int sn_to_occurrences(symnum) * *************/ /* DOCUMENTATION This routine returns the occurrences associated with a symbol ID. */ /* PUBLIC */ int sn_to_occurrences(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->occurrences); } /* sn_to_occurrences */ /************* * * set_unfold_symbol() * *************/ /* DOCUMENTATION This routine declares that a symbol is a Skolem function (or constant). */ /* PUBLIC */ void set_unfold_symbol(int symnum) { Symbol p = lookup_by_id(symnum); p->unfold = TRUE; } /* set_unfold_symbol */ /************* * * is_unfold_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL is_unfold_symbol(int symnum) { Symbol p = lookup_by_id(symnum); return p->unfold; } /* is_unfold_symbol */ /************* * * declare_aux_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_aux_symbols(Ilist syms) { Ilist p; for (p = syms; p; p = p->next) { Symbol s = lookup_by_id(p->i); s->auxiliary = TRUE; } } /* declare_aux_symbols */ /****************************************************************************/ /* This section is about parse properties of symbols. */ /****************************************************************************/ /************* * * parse_type_to_str() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *parse_type_to_str(Parsetype type) { switch (type) { case INFIX_LEFT: return "infix_left"; case INFIX_RIGHT: return "infix_right"; case INFIX: return "infix"; case PREFIX: return "prefix"; case PREFIX_PAREN: return "prefix_paren"; case POSTFIX: return "postfix"; case POSTFIX_PAREN: return "postfix_paren"; case NOTHING_SPECIAL: return "ordinary"; } return "???"; } /* parse_type_to_str */ /************* * * clear_parse_type_for_all_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clear_parse_type_for_all_symbols(void) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; s->parse_type = NOTHING_SPECIAL; s->parse_prec = 0; } } } /* clear_parse_type_for_all_symbols */ /************* * * clear_parse_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void clear_parse_type(char *str) { Symbol p; p = lookup_by_sym(str, 1); if (p != NULL) { p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; } p = lookup_by_sym(str, 2); if (p != NULL) { p->parse_type = NOTHING_SPECIAL; p->parse_prec = 0; } } /* clear_parse_type */ /************* * * check_diff_type_same_prec() * *************/ static void check_diff_type_same_prec(char *str, int prec, Parsetype type) { if (type != NOTHING_SPECIAL) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; Parsetype type2 = s->parse_type; int prec2 = s->parse_prec; char *name = s->name; if (type2 != type && prec == prec2 && !str_ident(name, str)) { printf("\nConflicting declarations (the first may be built in):\n"); printf(" op(%d, %s, \"%s\").\n", prec2,parse_type_to_str(type2),name); printf(" op(%d, %s, \"%s\").\n", prec,parse_type_to_str(type),str); fatal_error("cannot declare different parse types with same " "precedence (see output file)"); } } } } } /* check_diff_type_same_prec */ /************* * * set_parse_type() * *************/ /* DOCUMENTATION This routine sets the parse/print properties of a binary or unary symbol. The types for binary infix symbols are INFIX_LEFT, INFIX_RIGHT, INFIX. The types for prefix unary symbols are PREFIX, PREFIX_PAREN. The types for postfix unary symbols are POSTFIX, POSTFIX_PAREN.

If the precedence is out of range [MIN_PRECEDENCE ... MAX_PRECEDENCE], a fatal error occurs. */ /* PUBLIC */ void set_parse_type(char *str, int precedence, Parsetype type) { if (precedence < MIN_PRECEDENCE || precedence > MAX_PRECEDENCE) fatal_error("set_parse_type: precedence out of range"); else { Symbol p = NULL; clear_parse_type(str); /* in case it has parse type of diff. arity */ check_diff_type_same_prec(str, precedence, type); switch (type) { case INFIX_LEFT: case INFIX_RIGHT: case INFIX: p = lookup_by_id(str_to_sn(str, 2)); p->parse_type = type; p->parse_prec = precedence; break; case PREFIX: case PREFIX_PAREN: case POSTFIX: case POSTFIX_PAREN: p = lookup_by_id(str_to_sn(str, 1)); p->parse_type = type; p->parse_prec = precedence; break; case NOTHING_SPECIAL: /* already cleared above */ break; } } } /* set_parse_type */ /************* * * binary_parse_type() * *************/ /* DOCUMENTATION This routine gets the parse/print properties for a binary symbol. If *str is a binary symbol, TRUE is returned and the properties are filled in. If *str is a not a binary symbol, FALSE is returned. */ /* PUBLIC */ BOOL binary_parse_type(char *str, int *precedence, Parsetype *type) { Symbol p = lookup_by_sym(str, 2); if (p == NULL || p->parse_type == NOTHING_SPECIAL) return FALSE; else { *precedence = p->parse_prec; *type = p->parse_type; return TRUE; } } /* binary_parse_type */ /************* * * unary_parse_type() * *************/ /* DOCUMENTATION This routine gets the parse/print properties for a unary symbol. If *str is a unary symbol, TRUE is returned and the properties are filled in. If *str is a not a unary symbol, FALSE is returned. */ /* PUBLIC */ BOOL unary_parse_type(char *str, int *precedence, Parsetype *type) { Symbol p = lookup_by_sym(str, 1); if (p == NULL || p->parse_type == NOTHING_SPECIAL) return FALSE; else { *precedence = p->parse_prec; *type = p->parse_type; return TRUE; } } /* unary_parse_type */ /************* * * special_parse_type() * *************/ /* DOCUMENTATION Is the string a unary or binary "special_parse_type" (e.g., PREFIX or INFIX)? If so, return the arity; otherwise return -1. */ /* PUBLIC */ int special_parse_type(char *str) { int prec; Parsetype type; if (binary_parse_type(str, &prec, &type)) return 2; else if (unary_parse_type(str, &prec, &type)) return 1; else return -1; } /* special_parse_type */ /****************************************************************************/ /* This section is about associativity-commutativity properties. */ /****************************************************************************/ static int Assoc_comm_symbols = 0; /* number declared */ static int Comm_symbols = 0; /* number decoared */ /************* * * set_assoc_comm() * *************/ /* DOCUMENTATION This routine declares a string to be a (binary) symbol with the logical property "associative-commutative". This property is used for AC unification/matching/identity. (If you wish to print AC expressions without parentheses, see set_parse_type().) */ /* PUBLIC */ void set_assoc_comm(char *str, BOOL set) { int sn = str_to_sn(str, 2); Symbol p = lookup_by_id(sn); if (set) { p->unif_theory = ASSOC_COMMUTE; Assoc_comm_symbols++; } else { p->unif_theory = EMPTY_THEORY; Assoc_comm_symbols--; } } /* set_assoc_comm */ /************* * * set_commutative() * *************/ /* DOCUMENTATION This routine declares a string to be a (binary) symbol with the logical property "commutative". This property is used for commutative unification/matching/identity. */ /* PUBLIC */ void set_commutative(char *str, BOOL set) { int sn = str_to_sn(str, 2); Symbol p = lookup_by_id(sn); if (set) { p->unif_theory = COMMUTE; Comm_symbols++; } else { p->unif_theory = EMPTY_THEORY; Comm_symbols--; } } /* set_commutative */ /************* * * assoc_comm_symbols() * *************/ /* DOCUMENTATION This function tells you if any symbol has been declared to be associative-commutative; */ /* PUBLIC */ BOOL assoc_comm_symbols(void) { return Assoc_comm_symbols != 0; } /* assoc_comm_symbols */ /************* * * comm_symbols() * *************/ /* DOCUMENTATION This function tells you if any symbol has been declared to be commutative. */ /* PUBLIC */ BOOL comm_symbols(void) { return Comm_symbols != 0; } /* comm_symbols */ /************* * * is_assoc_comm * * NOTE: may wish to avoid hash if no AC symbols exist. * *************/ /* DOCUMENTATION This function checks if a symbol ID has the associative-commutative property. Note that set_assoc_comm() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms. */ /* PUBLIC */ BOOL is_assoc_comm(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->unif_theory == ASSOC_COMMUTE); } /* is_assoc_comm */ /************* * * is_commutative * * NOTE: may wish to avoid hash if no C symbols exist. * *************/ /* DOCUMENTATION This function checks if a symbol ID has the commutative property. Note that set_commutative() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms. */ /* PUBLIC */ BOOL is_commutative(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->unif_theory == COMMUTE); } /* is_commutative */ /****************************************************************************/ /* This section is about some built-in logic symbols. */ /****************************************************************************/ static int Eq_symnum = 0; static int Or_symnum = 0; static int Not_symnum = 0; /************* * * int is_eq_symbol(symbol) * *************/ /* DOCUMENTATION This Boolean routine checks if a given symbol ID is for eq_sym()/2. One could use is_symbol(symnum, eq_sym(), 2) instead, but this should be a bit faster. */ /* PUBLIC */ BOOL is_eq_symbol(int symnum) { if (Eq_symnum == 0) { Eq_symnum = str_to_sn(eq_sym(), 2); } return (symnum == Eq_symnum ? TRUE : FALSE); } /* is_eq_symbol */ /************* * * not_symnum() * *************/ /* DOCUMENTATION Return the symnum for not_sym()/1. */ /* PUBLIC */ int not_symnum(void) { if (Not_symnum == 0) Not_symnum = str_to_sn(not_sym(), 1); return Not_symnum; } /* not_symnum */ /************* * * or_symnum() * *************/ /* DOCUMENTATION Return the symnum for or_sym()/2. */ /* PUBLIC */ int or_symnum(void) { if (Or_symnum == 0) Or_symnum = str_to_sn(or_sym(), 2); return Or_symnum; } /* or_symnum */ /************* * * declare_base_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_base_symbols(void) { int sn; sn = str_to_sn(false_sym(), 0); sn = str_to_sn(true_sym(), 0); sn = str_to_sn("false", 0); sn = str_to_sn("true", 0); } /* declare_base_symbols */ /****************************************************************************/ /* This section is about variables. */ /****************************************************************************/ static Variable_style Var_style = STANDARD_STYLE; /************* * * set_variable_style() * *************/ /* DOCUMENTATION This routine determines how variables are parsed and printed. */ /* PUBLIC */ void set_variable_style(Variable_style style) { Var_style = style; } /* set_variable_style */ /************* * * variable_style() * *************/ /* DOCUMENTATION This routine gives the current variable style. */ /* PUBLIC */ Variable_style variable_style(void) { return Var_style; } /* set_variable_style */ /************* * * variable_name() * *************/ /* DOCUMENTATION Is the given name a variable? Formulas can have free variables (not explicitly quantified), so we have a rule to distinguish variables from constants. This is it. */ /* PUBLIC */ BOOL variable_name(char *s) { if (variable_style() == PROLOG_STYLE) return (*s >= 'A' && *s <= 'Z'); else if (variable_style() == INTEGER_STYLE) return (*s >= '0' && *s <= '9'); else return (*s >= 'u' && *s <= 'z'); } /* variable_name */ /************* * * symbol_for_variable() * *************/ /* DOCUMENTATION Given a pointer to a string and a variable index, fill in the string with the variable symbol. The variable symbol is determined by the current variable style (standard, prolog, integer, etc.), which can be changed with set_variable_style(). */ /* PUBLIC */ void symbol_for_variable(char *str, int varnum) { if (variable_style() == INTEGER_STYLE) /* 0,1,2,3,4,5,6,7,... */ sprintf(str, "%d", varnum); else if (variable_style() == PROLOG_STYLE) { /* A,B,C,D,E,F,V6,V7,V8,... */ if (varnum < 6) sprintf(str, "%c", 'A' + varnum); else sprintf(str, "V%d", varnum); } else { /* x,y,z,u,w,v5,v6,v7,v8,... */ if (varnum < 3) sprintf(str, "%c", 'x' + varnum); else if (varnum == 3) sprintf(str, "%c", 'u'); else if (varnum == 4) sprintf(str, "%c", 'w'); else sprintf(str, "v%d", varnum); } } /* symbol_for_variable */ /************* * * variable_symbols() * *************/ /* DOCUMENTATION Given a Plist of symbols (symnums), return a (new) list of the symnums that correspond to variables. */ /* PUBLIC */ Ilist variable_symbols(Ilist syms) { if (syms == NULL) return NULL; else { Ilist work = variable_symbols(syms->next); if (sn_to_arity(syms->i) == 0 && variable_name(sn_to_str(syms->i))) work = ilist_prepend(work, syms->i); return work; } } /* variable_symbols */ /************* * * remove_variable_symbols() * *************/ /* DOCUMENTATION Given a Plist of symbols (symnums), remove the ones that correspond to variables. */ /* PUBLIC */ Ilist remove_variable_symbols(Ilist syms) { Ilist vars = variable_symbols(syms); Ilist result = ilist_subtract(syms,vars); zap_ilist(syms); zap_ilist(vars); return result; } /* remove_variable_symbols */ /****************************************************************************/ /* This section is about FUNCTION/RELATION distinction. */ /****************************************************************************/ /************* * * set_symbol_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_symbol_type(int symnum, Symbol_type type) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("set_symbol_type: bad symnum"); p->type = type; } /* set_symbol_type */ /************* * * get_symbol_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Symbol_type get_symbol_type(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("get_symbol_type: bad symnum"); return p->type; } /* get_symbol_type */ /************* * * function_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL function_symbol(int symnum) { return get_symbol_type(symnum) == FUNCTION_SYMBOL; } /* function_symbol */ /************* * * relation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL relation_symbol(int symnum) { return get_symbol_type(symnum) == PREDICATE_SYMBOL; } /* relation_symbol */ /************* * * function_or_relation_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL function_or_relation_symbol(int symnum) { Symbol_type t = get_symbol_type(symnum); return t == PREDICATE_SYMBOL || t == FUNCTION_SYMBOL; } /* function_or_relation_symbol */ /************* * * declare_functions_and_relations() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_functions_and_relations(Ilist fsyms, Ilist rsyms) { Ilist p; for (p = fsyms; p; p = p->next) set_symbol_type(p->i, FUNCTION_SYMBOL); for (p = rsyms; p; p = p->next) set_symbol_type(p->i, PREDICATE_SYMBOL); } /* declare_functions_and_relations */ /************* * * function_or_relation_sn() * *************/ /* DOCUMENTATION If there is a function or relation symbol in the table with the given string, return the symnum; otherwise return -1. (If there is more than one, the first one found is returned.) */ /* PUBLIC */ int function_or_relation_sn(char *str) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if ((s->type == FUNCTION_SYMBOL || s->type == PREDICATE_SYMBOL) && str_ident(str, s->name)) return s->symnum; } } return -1; } /* function_or_relation_sn */ /************* * * all_function_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist all_function_symbols(void) { Ilist syms = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->type == FUNCTION_SYMBOL) syms = ilist_append(syms, s->symnum); } } return syms; } /* all_function_symbols */ /************* * * all_relation_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist all_relation_symbols(void) { Ilist syms = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->type == PREDICATE_SYMBOL) syms = ilist_append(syms, s->symnum); } } return syms; } /* all_relation_symbols */ /****************************************************************************/ /* This section is all about LRPO status. */ /****************************************************************************/ /************* * * set_lrpo_status() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_lrpo_status(int symnum, Lrpo_status status) { Symbol p = lookup_by_id(symnum); p->lrpo_status = status; } /* set_lrpo_status */ /************* * * all_symbols_lrpo_status() * *************/ /* DOCUMENTATION Assign all symbols the given lrpo status: LRPO_LR_STATUS or LRPO_MULTISET_STATUS. */ /* PUBLIC */ void all_symbols_lrpo_status(Lrpo_status status) { int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; s->lrpo_status = status; } } } /* all_symbols_lrpo_status */ /************* * * sn_to_lrpo_status * *************/ /* DOCUMENTATION This routine returns the LRPO status associated with a symbol ID. The default value is LRPO_LR_STATUS. See order.h for the possible values. If the symbol ID is not valid, 0 is returned. */ /* PUBLIC */ Lrpo_status sn_to_lrpo_status(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? 0 : p->lrpo_status); } /* sn_to_lrpo_status */ /****************************************************************************/ /* This section is all about KB weights. */ /****************************************************************************/ static BOOL Zero_wt_kb = FALSE; /* is there symbol with kb_weight=0? */ /************* * * set_kb_weight() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_kb_weight(int symnum, int weight) { Symbol p = lookup_by_id(symnum); if (p == NULL) { fatal_error("set_kb_weight, symbol not found"); } if (weight == 0) { if (Zero_wt_kb) fatal_error("set_kb_weight, more than one symbol of weight 0"); else if (p->arity != 1 || p->type != FUNCTION_SYMBOL) fatal_error("set_kb_weight, weight 0 symbols must be unary" " function symbols"); else Zero_wt_kb = TRUE; } p->kb_weight = weight; } /* set_kb_weight */ /************* * * zero_wt_kb() * *************/ /* DOCUMENTATION Is there already a symbol with KB weight 0? */ /* PUBLIC */ BOOL zero_wt_kb(void) { return Zero_wt_kb; } /* zero_wt_kb */ /************* * * int sn_to_kb_wt() * *************/ /* DOCUMENTATION This routine returns the Knuth-Bendix weight associated with a symbol ID. */ /* PUBLIC */ int sn_to_kb_wt(int symnum) { Symbol p = lookup_by_id(symnum); if (p == NULL) return(-1); else return(p->kb_weight); } /* sn_to_kb_wt */ /************* * * print_kbo_weights() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_kbo_weights(FILE *fp) { Ilist fsyms = current_fsym_precedence(); Ilist p; fprintf(fp, "Function symbol KB weights: "); for (p = fsyms; p; p = p->next) fprintf(fp, " %s=%d.", sn_to_str(p->i), sn_to_kb_wt(p->i)); fprintf(fp, "\n"); zap_ilist(fsyms); } /* print_kbo_weights */ /****************************************************************************/ /* This section is all about Skolem symbols. */ /****************************************************************************/ static char *Skolem_constant_prefix = "c"; static char *Skolem_function_prefix = "f"; static int Next_skolem_constant = 1; /* counter for c1, c2, ... */ static int Next_skolem_function = 1; /* counter for f1, f2, ... */ static BOOL Skolem_check = TRUE; /* make sure Skolem symbols are unique */ /************* * * set_skolem() * *************/ /* DOCUMENTATION This routine declares that a symbol is a Skolem function (or constant). */ /* PUBLIC */ void set_skolem(int symnum) { Symbol p = lookup_by_id(symnum); p->skolem = TRUE; p->type = FUNCTION_SYMBOL; } /* set_skolem */ /************* * * skolem_check() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void skolem_check(BOOL flag) { Skolem_check = flag; } /* skolem_check */ /************* * * skolem_ok() * *************/ static BOOL skolem_ok(char *name, int arity) { if (!Skolem_check) return TRUE; else { Symbol s = lookup_by_sym(name, arity); if (s == NULL) return TRUE; else return s->auxiliary; } } /* skolem_ok */ /************* * * next_skolem_symbol() * *************/ /* DOCUMENTATION This routine returns a fresh symbol ID, which is intended to be used as a Skolem symbol. The symbols are c1, c2, c3, ... for arity 0 (constants) and f1, f2, f3, ... for arity != 0. If some of those symbols already exist in the symbol table (with any arity), they will be skipped. */ /* PUBLIC */ int next_skolem_symbol(int arity) { char name[20]; do { if (arity == 0) { sprintf(name, "%s%d", Skolem_constant_prefix, Next_skolem_constant); Next_skolem_constant++; } else { sprintf(name, "%s%d", Skolem_function_prefix, Next_skolem_function); Next_skolem_function++; } } while (!skolem_ok(name,arity)); { int symnum = str_to_sn(name, arity); set_skolem(symnum); return symnum; } } /* next_skolem_symbol */ /************* * * skolem_symbols() * *************/ /* DOCUMENTATION Return the list of SYMNUMs (increasing) that have been declared to be Skolem symbols. */ /* PUBLIC */ Ilist skolem_symbols(void) { Ilist g = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->skolem) g = ilist_prepend(g, s->symnum); } } return reverse_ilist(g); } /* skolem_symbols */ /************* * * is_skolem() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL is_skolem(int symnum) { Symbol p = lookup_by_id(symnum); return p->skolem; } /* is_skolem */ /************* * * skolem_reset() * *************/ /* DOCUMENTATION Reset the Skolem symbol counters (constant and function) to 1. */ /* PUBLIC */ void skolem_reset(void) { Next_skolem_constant = 1; Next_skolem_function = 1; } /* skolem_reset */ /************* * * decommission_skolem_symbols() * *************/ /* DOCUMENTATION For each symbol in the symbol table, if it is marked "skolem", unmark it and set the type to "unspecified". */ /* PUBLIC */ void decommission_skolem_symbols(void) { Ilist fsyms = all_function_symbols(); Ilist p; for (p = fsyms; p; p = p->next) { Symbol n = lookup_by_id(p->i); if (n->skolem) { n->skolem = FALSE; n->type = UNSPECIFIED_SYMBOL; } } zap_ilist(fsyms); } /* decommission_skolem_symbols */ /************* * * set_skolem_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void set_skolem_symbols(Ilist symnums) { Ilist p; for (p = symnums; p; p = p->next) { Symbol sym = lookup_by_id(p->i); if (sym == NULL) fatal_error("set_skolem_symbols, symbol not found"); sym->skolem = TRUE; } } /* set_skolem_symbols */ /****************************************************************************/ /* This section is all about lex_val and symbol precedence. */ /****************************************************************************/ static Ilist Preliminary_prec_func = NULL; static Ilist Preliminary_prec_pred = NULL; /************* * * set_lex_val() * *************/ /* DOCUMENTATION This routine is used to assign a lexical value to a symbol. The value can be retrieved later with sn_to_lex_val(); */ /* PUBLIC */ void set_lex_val(int symnum, int lex_val) { Symbol p = lookup_by_id(symnum); if (p == NULL) fatal_error("set_lex_val, invalid symnum"); p->lex_val = lex_val; /* printf("set_lex_val %s/%d, %d\n", p->name, p->arity, lex_val); */ } /* set_lex_val */ /************* * * sn_to_lex_val * *************/ /* DOCUMENTATION This routine returns the lexical value associated with a symbol ID. The default value is INT_MAX. If the symbol ID is not valid, INT_MIN is returned. */ /* PUBLIC */ int sn_to_lex_val(int sn) { Symbol p = lookup_by_id(sn); return (p == NULL ? INT_MIN : p->lex_val); } /* sn_to_lex_val */ /************* * * int sym_precedence(symnum_1, symnum_2) * *************/ /* DOCUMENTATION This routine compares two symbol IDs by looking at their lex_val in the symbol table. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}. */ /* PUBLIC */ Ordertype sym_precedence(int symnum_1, int symnum_2) { int p1, p2; if (symnum_1 == symnum_2) return SAME_AS; else { p1 = sn_to_lex_val(symnum_1); p2 = sn_to_lex_val(symnum_2); if (p1 == INT_MAX || p2 == INT_MAX) return NOT_COMPARABLE; else if (p1 > p2) return GREATER_THAN; else if (p1 < p2) return LESS_THAN; else return SAME_AS; } } /* sym_precedence */ /************* * * syms_with_lex_val() * *************/ /* DOCUMENTATION Return an Ilist containing symnums of symbols to which lex_vals have been assigned. */ /* PUBLIC */ Ilist syms_with_lex_val(void) { Ilist g = NULL; int i; for (i = 0; i < SYM_TAB_SIZE; i++) { Plist p; for (p = By_id[i]; p; p = p->next) { Symbol s = p->v; if (s->lex_val != INT_MAX) g = ilist_append(g, s->symnum); } } return g; } /* syms_with_lex_val */ /************* * * exists_preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL exists_preliminary_precedence(Symbol_type type) { if (type == FUNCTION_SYMBOL) return Preliminary_prec_func != NULL; else if (type == PREDICATE_SYMBOL) return Preliminary_prec_pred != NULL; else return FALSE; } /* exists_preliminary_precedence */ /************* * * preliminary_lex_compare() * *************/ /* DOCUMENTATION Compare the given strings with respect to the list of strings given to the set_preliminary_precedence call. Strings without preliminary_precedence are smaller than those with. Two different strings without preliminary_precedence are NOT_COMPARABLE.

Return LESS_THAN, GREATER_THAN, SAME_AS, NOT_COMPARABLE. */ /* PUBLIC */ Ordertype preliminary_lex_compare(Symbol a, Symbol b) { int ai = -1; int bi = -1; if (a->type != b->type) return NOT_COMPARABLE; else if (a->type == UNSPECIFIED_SYMBOL) return NOT_COMPARABLE; else if (a->type == FUNCTION_SYMBOL) { ai = position_in_ilist(a->symnum, Preliminary_prec_func); bi = position_in_ilist(b->symnum, Preliminary_prec_func); } else if (a->type == PREDICATE_SYMBOL) { ai = position_in_ilist(a->symnum, Preliminary_prec_pred); bi = position_in_ilist(b->symnum, Preliminary_prec_pred); } /* printf("%s=%d, %s=%d\n", a, ai, b, bi); */ if (ai == -1) ai = INT_MIN; if (bi == -1) bi = INT_MIN; if (ai < bi) return LESS_THAN; else if (ai > bi) return GREATER_THAN; else if (ai == INT_MIN) return NOT_COMPARABLE; /* neither in preliminary_precedence */ else return SAME_AS; } /* preliminary_lex_compare */ /************* * * lex_compare_base() * *************/ static Ordertype lex_compare_base(Symbol s1, Symbol s2) { if (s1 == s2) return SAME_AS; else if (s1 == NULL) return LESS_THAN; else if (s2 == NULL) return GREATER_THAN; /* FUNCTION < RELATION < others (don't know if there can be others) */ else if (s1->type == FUNCTION_SYMBOL && s2->type != FUNCTION_SYMBOL) return LESS_THAN; else if (s1->type != FUNCTION_SYMBOL && s2->type == FUNCTION_SYMBOL) return GREATER_THAN; else if (s1->type == PREDICATE_SYMBOL && s2->type != PREDICATE_SYMBOL) return LESS_THAN; else if (s1->type != PREDICATE_SYMBOL && s2->type == PREDICATE_SYMBOL) return GREATER_THAN; /* Now they have the same type (FUNCTION, RELATION, other). */ /* Check for preliminary order (lex command). */ else if (preliminary_lex_compare(s1, s2) == LESS_THAN) return LESS_THAN; else if (preliminary_lex_compare(s1, s2) == GREATER_THAN) return GREATER_THAN; /* = < other relations */ else if (s1->type == PREDICATE_SYMBOL && is_eq_symbol(s2->symnum)) return GREATER_THAN; else if (s1->type == PREDICATE_SYMBOL && is_eq_symbol(s1->symnum)) return LESS_THAN; /* if arities same: (1) Skolems > non-Skolems (2) if both Skolems, use sumnum (3) more-occurrences < fewer-occurrences (4) Use UNIX's strcomp, which is lexical ascii ordering. */ else if (s1->arity == s2->arity) { if (s1->skolem || s2->skolem) { if (!s2->skolem) return GREATER_THAN; else if (!s1->skolem) return LESS_THAN; else if (s1->symnum > s2->symnum) return GREATER_THAN; else if (s1->symnum < s2->symnum) return LESS_THAN; else return SAME_AS; } else if (s1->occurrences < s2->occurrences) return GREATER_THAN; else if (s1->occurrences > s2->occurrences) return LESS_THAN; else { int i = strcmp(s1->name, s2->name); if (i < 0) return LESS_THAN; else if (i > 0) return GREATER_THAN; else return SAME_AS; } } /* the type is the same, but arities are different */ else return NOT_COMPARABLE; /* code for "not yet decided" */ } /* lex_compare_base */ /************* * * lex_compare_arity_0123() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype lex_compare_arity_0123(Symbol s1, Symbol s2) { Ordertype base = lex_compare_base(s1, s2); if (base != NOT_COMPARABLE) return base; else /* symbols same type, but with different arities */ return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; } /* lex_compare_arity_0123 */ /************* * * lex_compare_arity_0213() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ordertype lex_compare_arity_0213(Symbol s1, Symbol s2) { Ordertype base = lex_compare_base(s1, s2); if (base != NOT_COMPARABLE) return base; else { /* Symbols same type, but with different arities. Relations: order by arity. Functions: constants < arity-2 < arity-1 < arity-3 < arity-4 ... . */ if (s1->type == PREDICATE_SYMBOL) return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; else if (s1->arity == 1) return s2->arity >= 3 ? LESS_THAN : GREATER_THAN; else if (s2->arity == 1) return s1->arity < 3 ? LESS_THAN : GREATER_THAN; else return s1->arity < s2->arity ? LESS_THAN : GREATER_THAN; } } /* lex_compare_arity_0213 */ /************* * * lex_order() * *************/ /* DOCUMENTATION Assign a total order on lex_vals of (fsyms U rsyms). If a list of strings was previously given to set_preliminary_precedence, that order is maintained for symbols that have those strings. For the other rules, see *comp_proc (lex_compare*). */ /* PUBLIC */ void lex_order(Ilist fsyms, Ilist rsyms, I2list fsyms_multiset, I2list rsyms_multiset, Ordertype (*comp_proc) (Symbol, Symbol)) { int n = ilist_count(fsyms) + ilist_count(rsyms); Symbol *a = malloc(n * sizeof(void *)); Ilist p; int i = 0; for (p = fsyms; p; p = p->next, i++) { a[i] = lookup_by_id(p->i); a[i]->occurrences = multiset_occurrences(fsyms_multiset, p->i); } for (p = rsyms; p; p = p->next, i++) { a[i] = lookup_by_id(p->i); a[i]->occurrences = multiset_occurrences(rsyms_multiset, p->i); } add_skolems_to_preliminary_precedence(); merge_sort((void **) a, n, (Ordertype (*)(void*, void*)) comp_proc); for (i = 0; i < n; i++) a[i]->lex_val = i; free(a); } /* lex_order */ /************* * * insert_by_lex_val() * *************/ static Ilist insert_by_lex_val(Ilist head, Ilist tail) { if (tail == NULL) { head->next = NULL; return head; } else if (sn_to_lex_val(head->i) < sn_to_lex_val(tail->i)) { head->next = tail; return head; } else { tail->next = insert_by_lex_val(head, tail->next); return tail; } } /* insert_by_lex_val */ /************* * * sort_by_lex_val() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist sort_by_lex_val(Ilist p) { if (p == NULL) return NULL; else { return insert_by_lex_val(p, sort_by_lex_val(p->next)); } } /* sort_by_lex_val */ /************* * * remove_syms_without_lex_val() * *************/ static Ilist remove_syms_without_lex_val(Ilist syms) { if (syms == NULL) return NULL; else { syms->next = remove_syms_without_lex_val(syms->next); if (sn_to_lex_val(syms->i) == INT_MAX) { Ilist rest = syms->next; free_ilist(syms); return rest; } else return syms; } } /* remove_syms_without_lex_val */ /************* * * current_fsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist current_fsym_precedence() { Ilist syms = all_function_symbols(); syms = remove_syms_without_lex_val(syms); syms = sort_by_lex_val(syms); return syms; } /* current_fsym_precedence */ /************* * * current_rsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist current_rsym_precedence() { Ilist syms = all_relation_symbols(); syms = remove_syms_without_lex_val(syms); syms = sort_by_lex_val(syms); return syms; } /* current_rsym_precedence */ /************* * * not_in_preliminary_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist not_in_preliminary_precedence(Ilist syms, Symbol_type type) { Ilist missing = NULL; Ilist p; for (p = syms; p; p = p->next) { if (type == FUNCTION_SYMBOL && position_in_ilist(p->i, Preliminary_prec_func) == -1) missing = ilist_append(missing, p->i); else if (type == PREDICATE_SYMBOL && position_in_ilist(p->i, Preliminary_prec_pred) == -1) missing = ilist_append(missing, p->i); } return missing; } /* not_in_preliminary_precedence */ /************* * * print_fsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_fsym_precedence(FILE *fp) { Ilist fsyms = current_fsym_precedence(); Ilist p; printf("Function symbol precedence: function_order(["); for (p = fsyms; p; p = p->next) printf(" %s%s", sn_to_str(p->i), p->next ? "," : ""); printf(" ]).\n"); zap_ilist(fsyms); } /* print_fsym_precedence */ /************* * * print_rsym_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void print_rsym_precedence(FILE *fp) { Ilist rsyms = current_rsym_precedence(); Ilist p; printf("Predicate symbol precedence: predicate_order(["); for (p = rsyms; p; p = p->next) printf(" %s%s", sn_to_str(p->i), p->next ? "," : ""); printf(" ]).\n"); zap_ilist(rsyms); } /* print_rsym_precedence */ /************* * * min_lex_val() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int min_lex_val(void) { Ilist a = syms_with_lex_val(); Ilist p; int min = INT_MAX; for (p = a; p; p = p->next) { int x = sn_to_lex_val(p->i); min = IMIN(min, x); } zap_ilist(a); return min; } /* min_lex_val */ /************* * * max_lex_val() * *************/ static int max_lex_val(void) { Ilist a = syms_with_lex_val(); Ilist p; int max = INT_MIN; for (p = a; p; p = p->next) { int x = sn_to_lex_val(p->i); max = IMAX(max, x); } zap_ilist(a); return max; } /* min_lex_val */ /************* * * assign_greatest_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void assign_greatest_precedence(int symnum) { set_lex_val(symnum, max_lex_val() + 1); } /* assign_greatest_precedence */ /************* * * has_greatest_precedence() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL has_greatest_precedence(int symnum) { return sn_to_lex_val(symnum) == max_lex_val(); } /* has_greatest_precedence */ /************* * * lex_insert_after_initial_constants() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void lex_insert_after_initial_constants(Ilist syms) { if (syms) { Ilist all = current_fsym_precedence(); Ilist a, s; int val = 1; for (a = all; a && sn_to_arity(a->i) == 0; a = a->next) { if (!ilist_member(syms, a->i)) set_lex_val(a->i, val++); } syms = sort_by_lex_val(syms); /* so that relative order is unchanged */ for (s = syms; s; s = s->next) set_lex_val(s->i, val++); for (; a; a = a->next) { if (!ilist_member(syms, a->i)) set_lex_val(a->i, val++); } } } /* lex_insert_after_initial_constants */ /************* * * skolem_insert() * *************/ static Ilist skolem_insert(Ilist prec, int i) { if (prec == NULL) return ilist_append(NULL, i); else if (sn_to_arity(prec->i) > sn_to_arity(i)) return ilist_prepend(prec, i); else { prec->next = skolem_insert(prec->next, i); return prec; } } /* skolem_insert */ /************* * * add_skolems_to_preliminary_precedence() * *************/ /* DOCUMENTATION If there is a preliminary precedence, add the skolem symbols to it in the following way. For each Skolem symbol of arity-n, add it to Preliminary_precedence just before the first symbol of higher arity (else at the end). */ /* PUBLIC */ void add_skolems_to_preliminary_precedence(void) { if (Preliminary_prec_func != NULL) { Ilist skolems = skolem_symbols(); Ilist p; /* printf("Before adding skolems: "); p_ilist(Preliminary_precedence); */ for (p = skolems; p; p = p->next) { if (!ilist_member(Preliminary_prec_func, p->i)) Preliminary_prec_func = skolem_insert(Preliminary_prec_func, p->i); } /* printf("After adding skolems: "); p_ilist(Preliminary_precedence); */ zap_ilist(skolems); } } /* add_skolems_to_preliminary_precedence */ /****************************************************************************/ /* This section is all about symbols generated on the fly. */ /****************************************************************************/ static unsigned Mark_for_new_symbols = 0; /* */ /************* * * fresh_symbol() * *************/ /* DOCUMENTATION This routine returns a symbol ID for a new symbol with the given arity. The symbol is made up of the given prefix followed by the smallest natural number that results in a new symbol (regardless of arity). The prefix must be less than MAX_NAME characters. */ /* PUBLIC */ int fresh_symbol(char *prefix, int arity) { char name[MAX_NAME+20]; int i = 0; if (strlen(prefix) > MAX_NAME) { fatal_error("fresh_symbol, prefix is too big."); } do { sprintf(name, "%s%d", prefix, i); i++; } while (str_exists(name)); return str_to_sn(name, arity); } /* fresh_symbol */ /************* * * gen_new_symbol() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int gen_new_symbol(char *prefix, int arity, Ilist syms) { char name[MAX_NAME+20]; int symnum; int i = 0; if (strlen(prefix) > MAX_NAME) fatal_error("gen_new_symbol, prefix is too big."); sprintf(name, "%s%d", prefix, i); symnum = str_to_sn(name, arity); while (ilist_member(syms, symnum)) { i++; sprintf(name, "%s%d", prefix, i); symnum = str_to_sn(name, arity); } return symnum; } /* gen_new_symbol */ /************* * * mark_for_new_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_for_new_symbols(void) { Mark_for_new_symbols = Symbol_count + 1; /* next symnum */ } /* mark_for_new_symbols */ /************* * * new_symbols_since_mark() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list new_symbols_since_mark(void) { I2list p = NULL; int sn; for (sn = Mark_for_new_symbols; sn <= Symbol_count; sn++) { if (TRUE || function_or_relation_symbol(sn)) { p = i2list_append(p, sn, sn_to_arity(sn)); } } return p; } /* new_symbols_since_mark */ /************* * * add_new_symbols() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void add_new_symbols(I2list syms) { I2list p; for (p = syms; p; p = p->next) { int sn; int symnum = p->i; int arity = p->j; if (symnum != Symbol_count+1) fatal_error("add_new_symbols, bad symnum"); sn = fresh_symbol("child_symbol_", arity); if (sn != symnum) fatal_error("add_new_symbols, symnums do not match"); } } /* add_new_symbols */ /************* * * new_constant_properties() * *************/ /* DOCUMENTATION In the symbol table entry for the given symbol number, set type=function, kb_weight=1, lex_val=(after initial constants) */ /* PUBLIC */ void new_constant_properties(int sn) { Symbol s = lookup_by_id(sn); if (s == NULL || s->arity != 0) fatal_error("new_constant_properties, bad symbol number"); s->type = FUNCTION_SYMBOL; s->kb_weight = 1; { Ilist syms = ilist_append(NULL, sn); lex_insert_after_initial_constants(syms); zap_ilist(syms); } } /* new_constant_properties */ /************* * * collect_multiples() * *************/ static Ilist collect_multiples(Ilist syms) { /* Example: Given (f/0, f/1, g/0, h/2), return (f/0, f/1). */ Ilist p1; Ilist p2; Ilist bad_syms = NULL; for (p1 = syms; p1; p1 = p1->next) { char *s1 = sn_to_str(p1->i); for (p2 = p1->next; p2; p2 = p2->next) { char *s2 = sn_to_str(p2->i); if (str_ident(s1, s2)) { if (!ilist_member(bad_syms, p1->i)) bad_syms = ilist_prepend(bad_syms, p1->i); if (!ilist_member(bad_syms, p2->i)) bad_syms = ilist_prepend(bad_syms, p2->i); } } } return bad_syms; } /* collect_multiples */ /************* * * arity_check() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist arity_check(Ilist fsyms, Ilist rsyms) { Ilist syms = ilist_cat(ilist_copy(fsyms), ilist_copy(rsyms)); Ilist bad_syms = collect_multiples(syms); return bad_syms; } /* arity_check */ /************* * * symbol_with_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int symbol_with_string(Ilist syms, char *str) { if (syms == NULL) return -1; else if (str_ident(str, sn_to_str(syms->i))) return syms->i; else return symbol_with_string(syms->next, str); } /* symbol_with_string */ /************* * * process_skolem_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_skolem_list(Plist skolem_strings, Ilist fsyms) { Ilist skolems = NULL; Plist p; for (p = skolem_strings; p; p = p->next) { int sn = symbol_with_string(fsyms, p->v); if (sn == -1) fprintf(stderr, "WARNING, declared Skolem symbol not found in formulas: %s\n", (char *) p->v); else skolems = ilist_append(skolems, sn); } set_skolem_symbols(skolems); zap_ilist(skolems); } /* process_skolem_list */ /************* * * process_lex_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void process_lex_list(Plist lex_strings, Ilist syms, Symbol_type type) { Ilist lexs = NULL; Plist p; Plist not_in_formulas = NULL; for (p = lex_strings; p; p = p->next) { int sn = symbol_with_string(syms, p->v); if (sn == -1) not_in_formulas = plist_append(not_in_formulas, p->v); else lexs = ilist_append(lexs, sn); } if (not_in_formulas) { char *s = (type == FUNCTION_SYMBOL ? "function" : "predicate"); fprintf(stderr, "WARNING, %s symbols in %s_order (lex) command not found in formulas: ", s, s); fprintf(stdout, "WARNING, %s symbols in %s_order (lex) command not found in formulas: ", s, s); for (p = not_in_formulas; p; p = p->next) { fprintf(stderr, "%s%s", (char *) p->v, p->next ? ", " : ".\n"); fprintf(stdout, "%s%s", (char *) p->v, p->next ? ", " : ".\n"); } } if (type == FUNCTION_SYMBOL) Preliminary_prec_func = lexs; else Preliminary_prec_pred = lexs; zap_plist(not_in_formulas); } /* process_lex_list */ /************* * * symnums_of_arity() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist symnums_of_arity(Ilist p, int i) { if (p == NULL) return NULL; else if (sn_to_arity(p->i) != i) { Ilist r = p->next; free_ilist(p); return symnums_of_arity(r, i); } else { p->next = symnums_of_arity(p->next, i); return p; } } /* symnums_of_arity */ LADR-2009-11A/ladr/unify.h0000644000175000017500000001533111151265364014252 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_UNIFY_H #define TP_UNIFY_H #include "listterm.h" #include "termflag.h" /* INTRODUCTION This package handles ordinary unification and matching of terms. The methods are probably different from what you learned in your logic course, so pay close attention.

In situations where you consider instantiating the variables of a term t, you will have an associated Context c. The Context keeps track of the terms that are substituted for the variables--- think of it as a substitution table indexed by the variable number.

Contexts allow you to separate variables of two terms without creating a renamed copy of one of the terms. Say we have two terms with different Contexts: (t1,c1) and (t2,c2). If t1 and t2 share a variable, say v3, occurrences in t1 are a different variable from occurrences in t2, because the contexts are different. Think of the those variables as (v3,c1) and (v3,c2). In fact, when an instantiation is recorded in a Context, the variable in question is set to a pair, say (t4,c4) rather than just t4, because we have to know how to interpret the variables of t4.

There are situations where the terms being unified really do share variables, for example when factoring the literals of a clause; in those cases, you simply use the same context for both terms.

When you call unify(), match(), or any other routine that tries to make terms identical by instantiation, the terms you give are not changed---all of the action happens in their contexts (and in the trail, see below). So you do not have to copy terms before calling the routine.

When a unify or match routine succeeds, the Contexts are updated to reflect the common instance of the terms. Also, a Trail is returned. A Trail is a linked list of (variable,context) pairs telling exactly which variables were instantiated during the operation. Its purpose is to quickly restore the Contexts to their previous states.

You must explicitly allocate and free Contexts. To save time, we don't initialize the arrays each time a Context is re-allocated, and we don't check that Contexts are clear when they are freed. Therefore, you must make sure that a Context is clear before freeing it. See undo_subst(). Also, if you forget to clear the Context with undo_subst(), you will have a memory leak, because the Trail will be lost. (If you suspect that you have a bug which causes a non-empty context to be freed, you can enable a run-time check in free_context() and recompile unify.c.)

When you wish to find out what a context does to a term t, you can call apply(), which builds a new copy of the term with all of the instantiations of the context applied to the term t. But I wrote above that (v3,c1) is a different variable from (v3,c2)---what does apply do with uninstantiated variables? Each context has a unique multiplier (a small natural number); When apply() gets to an uninstantiated variable v, it returns a variable with index (multiplier*MAX_VARS)+VARNUM(v). Of course, this can give you VARNUMs > MAX_VARS, so you may have to rename variables of the result before calling a unification routine on the result.

Unification and matching can be used incrementally. For example, you can all unify() with a context which has entries from a previous call to unify(). Hyperresolution can be implemented by backtracking through the negative literals of a nucleus and the satellites that unify with a given literal of the nucleus, constructing and undoing partial substitutions along the way. Another example is subsumption. Checking whether one clause subsumes another can be done by incremental matching, backtracking through the literals of the potential subsumer, trying to map them to the literals of the other clause.

Associative-commutative unification and matching, and commutative unification and matching, use different unification code, because they have to deal with multiple unifiers for a pair of terms. (These other kinds of unification and matching may use the Context data type defined here.) */ /* Public definitions */ /* Dereference a variable. */ #define DEREFERENCE(t, c) { int i; \ while (c!=NULL && VARIABLE(t) && c->terms[i=VARNUM(t)]) \ { t = c->terms[i]; c = c->contexts[i]; } } /* A Context records a substitution of terms for variables. */ typedef struct context * Context; struct context { Term terms[MAX_VARS]; /* terms substituted for variables */ Context contexts[MAX_VARS]; /* Contexts corresponding to terms */ int multiplier; /* for getting separate vars in apply */ Term partial_term; /* for AC matching */ }; typedef struct trail * Trail; /* The following type is for backtrack unification and matching. */ typedef enum { NO_ALT = 0, AC_ALT, COMM_ALT } Unif_alternative; /* End of public definitions */ /* Public function prototypes from unify.c */ Context get_context(void); void free_context(Context p); void fprint_unify_mem(FILE *fp, BOOL heading); void p_unify_mem(); BOOL unify(Term t1, Context c1, Term t2, Context c2, Trail *trp); BOOL variant(Term t1, Context c1, Term t2, Trail *trp); BOOL occur_check(int vn, Context vc, Term t, Context c); BOOL match(Term t1, Context c1, Term t2, Trail *trp); Term apply(Term t, Context c); Term apply_substitute(Term t, Term beta, Context c_from, Term into_term, Context c_into); Term apply_substitute2(Term t, Term beta, Context c_from, Ilist into_pos, Context c_into); Term apply_demod(Term t, Context c, int flag); void undo_subst(Trail tr); void undo_subst_2(Trail tr, Trail sub_tr); void fprint_context(FILE *fp, Context c); void p_context(Context c); void fprint_trail(FILE *fp, Trail t); void p_trail(Trail t); BOOL match_weight(Term t1, Context c1, Term t2, Trail *trp, int var_sn); Ilist vars_in_trail(Trail tr); Plist context_to_pairs(Ilist varnums, Context c); BOOL empty_substitution(Context s); BOOL variable_substitution(Context s); BOOL subst_changes_term(Term t, Context c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/formula.c.work0000644000175000017500000011450011140424624015531 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "formula.h" /* Private definitions and types */ /* * memory management */ #define PTRS_FORMULA PTRS(sizeof(struct formula)) static unsigned Formula_gets, Formula_frees; static unsigned Arg_mem; /* memory (pointers) for arrays of args */ /************* * * Formula get_formula() * *************/ static Formula get_formula(int arity) { Formula p = get_cmem(PTRS_FORMULA); p->kids = get_cmem(arity); p->arity = arity; Formula_gets++; Arg_mem += arity; return(p); } /* get_formula */ /************* * * free_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_formula(Formula p) { if (p->excess_refs != 0) fatal_error("free_formula: freeing shared formula"); free_mem(p->kids, p->arity); Arg_mem -= p->arity; free_mem(p, PTRS_FORMULA); Formula_frees++; } /* free_formula */ /************* * * fprint_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the formula package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_formula_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct formula); fprintf(fp, "formula (%4d) %11u%11u%11u%9.1f K\n", n, Formula_gets, Formula_frees, Formula_gets - Formula_frees, ((Formula_gets - Formula_frees) * n) / 1024.); fprintf(fp, " formula arg arrays: %9.1f K\n", Arg_mem * BYTES_POINTER / 1024.); } /* fprint_formula_mem */ /************* * * p_formula_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the formula package. */ /* PUBLIC */ void p_formula_mem() { fprint_formula_mem(stdout, TRUE); } /* p_formula_mem */ /* * end of memory management */ /************* * * formula_megs() * *************/ /* DOCUMENTATION Return the approximate number of megabytes in use for storage of formulas. */ /* PUBLIC */ unsigned formula_megs(void) { unsigned bytes = (Formula_gets - Formula_frees) * sizeof(struct formula) + Arg_mem * BYTES_POINTER; return bytes / (1024 * 1024); } /* formula_megs */ /************* * * formula_get() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula formula_get(int arity, Ftype type) { Formula f = get_formula(arity); f->type = type; return f; } /* formula_get */ /************* * * zap_formula() * *************/ /* DOCUMENTATION Free a formula, including all of its subformulas, including its atoms. If a subformula as excess references, the refcount is decremented instead. */ /* PUBLIC */ void zap_formula(Formula f) { if (f == NULL) return; else if (f->excess_refs > 0) f->excess_refs--; else { if (f->type == ATOM_FORM) zap_term(f->atom); else { int i; for (i = 0; i < f->arity; i++) zap_formula(f->kids[i]); } if (f->attributes) zap_attributes(f->attributes); free_formula(f); } } /* zap_formula */ /************* * * logic_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL logic_term(Term t) { return (is_term(t, true_sym(), 0) || is_term(t, false_sym(), 0) || is_term(t, not_sym(), 1) || is_term(t, and_sym(), 2) || is_term(t, or_sym(), 2) || is_term(t, imp_sym(), 2) || is_term(t, impby_sym(), 2) || is_term(t, iff_sym(), 2) || is_term(t, quant_sym(), 3)); } /* logic_term */ /************* * * symbols_in_term_if() * *************/ static I2list symbols_in_term_if(Term t, I2list g) { if (VARIABLE(t)) return g; else if (is_term(t, "if", 3)) { /* special case: don't include "if" or the first argument */ g = symbols_in_term(ARG(t,1), g); g = symbols_in_term(ARG(t,2), g); } else { int i; g = multiset_add(g, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) g = symbols_in_term_if(ARG(t,i), g); } return g; } /* symbols_in_term_if */ /************* * * function_symbols_in_formula() * *************/ /* DOCUMENTATION Collect the multiset of function symbols in a formula. */ /* PUBLIC */ I2list function_symbols_in_formula(Formula f, I2list g) { if (f->type == ATOM_FORM) { if (is_term(f->atom, "if", 3)) { } else { int i; for (i = 0; i < ARITY(f->atom); i++) g = symbols_in_term_if(ARG(f->atom,i), g); } } else if (f->type == ALL_FORM || f->type == EXISTS_FORM) { I2list p = function_symbols_in_formula(f->kids[0], NULL); p = i2list_removeall(p, str_to_sn(f->qvar, 0)); g = multiset_union(g, p); } else { int i; for (i = 0; i < f->arity; i++) g = function_symbols_in_formula(f->kids[i], g); } return g; } /* function_symbols_in_formula */ /************* * * function_symbols_in_formulas() * *************/ /* DOCUMENTATION Collect the multiset of function symbols (including constants) in formulas in a Plist. An I2list of SYMNUMs is returned. */ /* PUBLIC */ I2list function_symbols_in_formulas(Plist lst) { I2list syms = NULL; Plist p; for (p = lst; p; p = p->next) { syms = function_symbols_in_formula(p->v, syms); #if 1 { I2list x; fprint_formula(stdout, p->v); for (x = syms; x; x = x->next) printf(" %s:%d", sn_to_str(x->i), x->j); printf(" FSYMS\n"); } #endif } return syms; } /* function_symbols_in_formulas */ /************* * * relation_symbols_in_formula_term() * *************/ static I2list relation_symbols_in_formula_term(Term t, I2list g) { if (VARIABLE(t)) return g; else if (logic_term(t)) { int i; for (i = 0; i < ARITY(t); i++) { if (quant_sym(t) && i != 3) ; /* skip quantifier & quantified var */ else g = relation_symbols_in_formula_term(ARG(t,i), g); } return g; } else { g = multiset_add(g, SYMNUM(t)); return g; } } /* relation_symbols_in_formula_term */ /************* * * include_conditions() * *************/ static I2list include_conditions(Term t, I2list g) { if (VARIABLE(t)) return g; else if (is_term(t, "if", 3)) { g = relation_symbols_in_formula_term(ARG(t,0), g); g = include_conditions(ARG(t,1), g); g = include_conditions(ARG(t,2), g); return g; } else { int i; for (i = 0; i < ARITY(t); i++) g = include_conditions(ARG(t,i), g); return g; } } /* include_conditions */ /************* * * relation_symbols_in_formula() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols in a formula. */ /* PUBLIC */ I2list relation_symbols_in_formula(Formula f, I2list g) { if (f->type == ATOM_FORM) { if (is_term(f->atom, "if", 3)) { /* special case: treat args as formulas */ g = relation_symbols_in_formula_term(ARG(f->atom,0), g); g = relation_symbols_in_formula_term(ARG(f->atom,1), g); g = relation_symbols_in_formula_term(ARG(f->atom,2), g); } else { g = multiset_add(g, SYMNUM(f->atom)); g = include_conditions(f->atom, g); } } else { int i; for (i = 0; i < f->arity; i++) g = relation_symbols_in_formula(f->kids[i], g); } return g; } /* relation_symbols_in_formula */ /************* * * relation_symbols_in_formulas() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols (including constants) in formulas in a Plist. An I2list of SYMNUMs is returned. */ /* PUBLIC */ I2list relation_symbols_in_formulas(Plist lst) { I2list syms = NULL; Plist p; for (p = lst; p; p = p->next) { syms = relation_symbols_in_formula(p->v, syms); #if 1 { I2list x; fprint_formula(stdout, p->v); for (x = syms; x; x = x->next) printf(" %s:%d", sn_to_str(x->i), x->j); printf(" RSYMS\n"); } #endif } return syms; } /* relation_symbols_in_formulas */ /************* * * term_to_formula() * *************/ /* DOCUMENTATION Assume that no subterm (of t) representing a formula is a term of type VARIABLE. The given Term is not changed. */ /* PUBLIC */ Formula term_to_formula(Term t) { Formula f = NULL; Ftype type; Attribute attributes = NULL; if (is_term(t, attrib_sym(), 2)) { attributes = term_to_attributes(ARG(t,1), attrib_sym()); t = ARG(t,0); } if (is_term(t, quant_sym(), 3)) { /* example: $quantified(all,x,p) */ Term quant = ARG(t,0); Term var = ARG(t,1); Ftype qtype = (is_term(quant, all_sym(), 0) ? ALL_FORM : EXISTS_FORM); f = formula_get(1, qtype); f->kids[0] = term_to_formula(ARG(t,2)); f->qvar = sn_to_str(SYMNUM(var)); } else { if (is_term(t, true_sym(), 0)) type = AND_FORM; else if (is_term(t, false_sym(), 0)) type = OR_FORM; else if (is_term(t, not_sym(), 1)) type = NOT_FORM; else if (is_term(t, and_sym(), 2)) type = AND_FORM; else if (is_term(t, or_sym(), 2)) type = OR_FORM; else if (is_term(t, iff_sym(), 2)) type = IFF_FORM; else if (is_term(t, imp_sym(), 2)) type = IMP_FORM; else if (is_term(t, impby_sym(), 2)) type = IMPBY_FORM; else type = ATOM_FORM; if (type == ATOM_FORM) { f = formula_get(0, ATOM_FORM); f->atom = copy_term(t); } else if (type == NOT_FORM) { f = formula_get(1, NOT_FORM); f->kids[0] = term_to_formula(ARG(t,0)); } else if (ARITY(t) == 0) { f = formula_get(0, type); } else { f = formula_get(2, type); f->kids[0] = term_to_formula(ARG(t,0)); f->kids[1] = term_to_formula(ARG(t,1)); } } f = flatten_top(f); f->attributes = attributes; return f; } /* term_to_formula */ /************* * * formula_to_term() * *************/ /* DOCUMENTATION Returns an entirely new term. */ /* PUBLIC */ Term formula_to_term(Formula f) { Term t = NULL; switch (f->type) { case ATOM_FORM: t = copy_term(f->atom); break; case NOT_FORM: t = get_rigid_term(not_sym(), 1); ARG(t,0) = formula_to_term(f->kids[0]); break; case IFF_FORM: t = get_rigid_term(iff_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case IMP_FORM: t = get_rigid_term(imp_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case IMPBY_FORM: t = get_rigid_term(impby_sym(), 2); ARG(t,0) = formula_to_term(f->kids[0]); ARG(t,1) = formula_to_term(f->kids[1]); break; case AND_FORM: case OR_FORM: if (f->arity == 0) t = get_rigid_term(f->type == AND_FORM ? true_sym() : false_sym(), 0); else { int i = f->arity-1; t = formula_to_term(f->kids[i]); for (i--; i >= 0; i--) { Term t1 = get_rigid_term(f->type == AND_FORM ? and_sym() : or_sym(), 2); ARG(t1,0) = formula_to_term(f->kids[i]); ARG(t1,1) = t; t = t1; } } break; case ALL_FORM: case EXISTS_FORM: { /* transform to: $quantified(all,x,f) */ t = get_rigid_term(quant_sym(), 3); ARG(t,0) = get_rigid_term(f->type == ALL_FORM ? all_sym() : exists_sym(), 0); ARG(t,1) = get_rigid_term(f->qvar, 0); ARG(t,2) = formula_to_term(f->kids[0]); } break; } if (f->attributes) t = build_binary_term(str_to_sn(attrib_sym(), 2), t, attributes_to_term(f->attributes, attrib_sym())); return t; } /* formula_to_term */ /************* * * fprint_formula() * *************/ /* DOCUMENTATION This routine prints a formula to a file. If you wish to have a formula printed without extra parentheses, you can call fprint_formula_term() instead. */ /* PUBLIC */ void fprint_formula(FILE *fp, Formula f) { if (f->type == ATOM_FORM) { /* fprintf(fp, "("); */ fprint_term(fp, f->atom); /* fprintf(fp, ")"); */ } else if (f->type == NOT_FORM) { /* fprintf(fp, "(%s ", not_sym()); */ fprintf(fp, "%s ", not_sym()); fprint_formula(fp, f->kids[0]); /* fprintf(fp, ")"); */ } else if (f->type == IFF_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", iff_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMP_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", imp_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (f->type == IMPBY_FORM) { fprintf(fp, "("); fprint_formula(fp, f->kids[0]); fprintf(fp, " %s ", impby_sym()); fprint_formula(fp, f->kids[1]); fprintf(fp, ")"); } else if (quant_form(f)) { fprintf(fp, "(%s %s ", f->type==ALL_FORM ? all_sym() : exists_sym(), f->qvar); fprint_formula(fp, f->kids[0]); fprintf(fp, ")"); } else if (f->type == AND_FORM || f->type == OR_FORM) { if (f->arity == 0) fprintf(fp, "%s", f->type == AND_FORM ? true_sym() : false_sym()); else { int i; fprintf(fp, "("); for (i = 0; i < f->arity; i++) { fprint_formula(fp, f->kids[i]); if (i < f->arity-1) fprintf(fp, " %s ", f->type == AND_FORM ? and_sym() : or_sym()); } fprintf(fp, ")"); } } } /* fprint_formula */ /************* * * p_formula() * *************/ /* DOCUMENTATION This routine prints a formula, followed by ".\n" and fflush, to stdout. If you wish to have a formula printed without extra parentheses, you can call p_formula_term() instead. If you don't want the newline, use fprint_formula() instead. */ /* PUBLIC */ void p_formula(Formula c) { fprint_formula(stdout, c); printf(".\n"); fflush(stdout); } /* p_formula */ /************* * * hash_formula() * *************/ /* DOCUMENTATION This is a simple hash function for formulas. It shifts symbols by 3 bits and does exclusive ORs. */ /* PUBLIC */ unsigned hash_formula(Formula f) { if (f->type == ATOM_FORM) return hash_term(f->atom); else if (quant_form(f)) return (f->type << 3) ^ (unsigned) f->qvar[0]; else { unsigned x = f->type; int i; for (i = 0; i < f->arity; i++) x = (x << 3) ^ hash_formula(f->kids[i]); return x; } } /* hash_formula */ /************* * * formula_ident() * *************/ /* DOCUMENTATION This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.

The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality. */ /* PUBLIC */ BOOL formula_ident(Formula f, Formula g) { if (f->type != g->type || f->arity != g->arity) return FALSE; else if (f->type == ATOM_FORM) return term_ident(f->atom, g->atom); else if (quant_form(f)) return (str_ident(f->qvar,g->qvar) && formula_ident(f->kids[0],g->kids[0])); else { int i; for (i = 0; i < f->arity; i++) if (!formula_ident(f->kids[i], g->kids[i])) return FALSE; return TRUE; } } /* formula_ident */ /************* * * formula_copy() * *************/ /* DOCUMENTATION This function returns a copy of the given formula. All subformulas, including the atoms, are copied. */ /* PUBLIC */ Formula formula_copy(Formula f) { Formula g = formula_get(f->arity, f->type); if (f->type == ATOM_FORM) g->atom = copy_term(f->atom); else { int i; if (quant_form(f)) g->qvar = f->qvar; for (i = 0; i < f->arity; i++) g->kids[i] = formula_copy(f->kids[i]); } return g; } /* formula_copy */ /************* * * dual_type() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL dual_type(int op) { switch (op) { case AND_FORM: return OR_FORM; case OR_FORM: return AND_FORM; case ALL_FORM: return EXISTS_FORM; case EXISTS_FORM: return ALL_FORM; default: return op; } } /* dual */ /************* * * dual() * *************/ /* DOCUMENTATION Change a formula into its dual. This is destructive. */ /* PUBLIC */ Formula dual(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = dual(f->kids[i]); f->type = dual_type(f->type); return f; } /* dual */ /************* * * and() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula and(Formula a, Formula b) { Formula f = formula_get(2, AND_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* and */ /************* * * or() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula or(Formula a, Formula b) { Formula f = formula_get(2, OR_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* or */ /************* * * imp() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula imp(Formula a, Formula b) { Formula f = formula_get(2, IMP_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* imp */ /************* * * impby() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula impby(Formula a, Formula b) { Formula f = formula_get(2, IMPBY_FORM); f->kids[0] = a; f->kids[1] = b; return f; } /* impby */ /************* * * not() * *************/ static Formula not(Formula a) { Formula f = formula_get(1, NOT_FORM); f->kids[0] = a; return f; } /* not */ /************* * * negate() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula negate(Formula a) { return not(a); } /* negate */ /************* * * quant_form() -- is it a quantified formula? * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL quant_form(Formula f) { return (f->type == ALL_FORM || f->type == EXISTS_FORM); } /* quant_form */ /************* * * flatten_top() -- applies to AND and OR. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula flatten_top(Formula f) { if (f->type != AND_FORM && f->type != OR_FORM) return f; else { BOOL operate = FALSE; int n = 0; /* count new arity */ int i; for (i = 0; i < f->arity; i++) { if (f->type != f->kids[i]->type) n++; else { n += (f->kids[i]->arity); operate = TRUE; } } if (!operate) return f; else { Formula g = formula_get(n, f->type); int i, j; j = 0; for (i = 0; i < f->arity; i++) { if (f->kids[i]->type != f->type) g->kids[j++] = f->kids[i]; else { int k; for (k = 0; k < f->kids[i]->arity; k++) g->kids[j++] = f->kids[i]->kids[k]; free_formula(f->kids[i]); } } free_formula(f); /* If the new formula has just one argument, return that argument. */ if (g->arity == 1) { Formula h = g->kids[0]; free_formula(g); return h; } else return g; } } } /* flatten_top */ /************* * * formula_flatten() * *************/ /* DOCUMENTATION This routine (recursively) flattens all AND and OR subformulas. */ /* PUBLIC */ Formula formula_flatten(Formula f) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = formula_flatten(f->kids[i]); return flatten_top(f); } /* flatten */ /************* * * nnf2() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

The argument "pref" should be either CONJUNCTION or DISJUNCTION, and it specifies the preferred form to use when translating IFFs.

This rouine is destructive; a good way to call it is f = nnf2(f, CONJUNCTION). */ /* PUBLIC */ Formula nnf2(Formula f, Fpref pref) { if (f->type == ATOM_FORM) return f; else if (quant_form(f)) { f->kids[0] = nnf2(f->kids[0], pref); return f; } else if (f->type == AND_FORM || f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) f->kids[i] = nnf2(f->kids[i], pref); return f; } else if (f->type == IMP_FORM) { Formula g = nnf2(or(not(f->kids[0]), f->kids[1]), pref); free_formula(f); return g; } else if (f->type == IMPBY_FORM) { Formula g = nnf2(or(f->kids[0], not(f->kids[1])), pref); free_formula(f); return g; } else if (f->type == IFF_FORM) { Formula g; Formula a = f->kids[0]; Formula b = f->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(imp(a,b), impby(ac,bc)), pref); else g = nnf2(or(and(a,b),and(not(ac),not(bc))), pref); free_formula(f); return g; } /* NOT */ else if (f->type == NOT_FORM) { Formula h = f->kids[0]; if (h->type == ATOM_FORM) return f; else if (h->type == NOT_FORM) { Formula g = nnf2(h->kids[0], pref); free_formula(h); free_formula(f); return g; } else if (quant_form(h)) { Formula g = formula_get(1, dual_type(h->type)); g->qvar = h->qvar; g->kids[0] = nnf2(not(h->kids[0]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == AND_FORM || h->type == OR_FORM) { Formula g = formula_get(h->arity, dual_type(h->type)); int i; for (i = 0; i < h->arity; i++) g->kids[i] = nnf2(not(h->kids[i]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMP_FORM) { Formula g = nnf2(and(h->kids[0], not(h->kids[1])), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IMPBY_FORM) { Formula g = nnf2(and(not(h->kids[0]), h->kids[1]), pref); free_formula(h); free_formula(f); return g; } else if (h->type == IFF_FORM) { Formula g; Formula a = h->kids[0]; Formula b = h->kids[1]; Formula ac = formula_copy(a); Formula bc = formula_copy(b); if (pref == CONJUNCTION) g = nnf2(and(or(a,b),or(not(ac),not(bc))), pref); else g = nnf2(or(and(a,not(b)),and(not(ac),bc)), pref); free_formula(h); free_formula(f); return g; } else return f; } /* NOT */ else return f; } /* nnf2 */ /************* * * nnf() * *************/ /* DOCUMENTATION Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).

This routine is destructive; a good way to call it is f = nnf(f). */ /* PUBLIC */ Formula nnf(Formula f) { return nnf2(f, CONJUNCTION); } /* nnf */ /************* * * make_conjunction() * *************/ /* DOCUMENTATION If the formula is not a conjunction, make it so. */ /* PUBLIC */ Formula make_conjunction(Formula f) { if (f->type == AND_FORM) return f; else { Formula h = formula_get(1, AND_FORM); h->kids[0] = f; return h; } } /* make_conjunction */ /************* * * make_disjunction() * *************/ /* DOCUMENTATION If the formula is not a dismunction, make it so. */ /* PUBLIC */ Formula make_disjunction(Formula f) { if (f->type == OR_FORM) return f; else { Formula h = formula_get(1, OR_FORM); h->kids[0] = f; return h; } } /* make_disjunction */ /************* * * formula_canon_eq() * *************/ /* DOCUMENTATION For each equality in the formula, if the right side greater according to "term_compare_ncv", flip the equality. */ /* PUBLIC */ void formula_canon_eq(Formula f) { if (f->type == ATOM_FORM) { Term a = f->atom; if (eq_term(a)) { Term left = ARG(a,0); Term right = ARG(a,1); if (term_compare_ncv(left, right) == LESS_THAN) { ARG(a,0) = right; ARG(a,1) = left; } } } else { int i; for (i = 0; i < f->arity; i++) formula_canon_eq(f->kids[i]); } } /* formula_canon_eq */ /************* * * formula_size() * *************/ /* DOCUMENTATION How many nodes are in the formula. (Atomic formulae count as 1.) */ /* PUBLIC */ int formula_size(Formula f) { if (f->type == ATOM_FORM) return 1; else { int i; int n = 0; for (i = 0; i < f->arity; i++) n += formula_size(f->kids[i]); return n+1; } } /* formula_size */ /************* * * greatest_qvar() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a quantified variable in Formula f.

Recall that in Formulas, a quantified variable is represented as a constant (which is bound by the quantifier). If the formula has no quantified variables, return -1. */ /* PUBLIC */ int greatest_qvar(Formula f) { if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_qvar(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_qvar(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_qvar */ /************* * * greatest_symnum_in_formula() * *************/ /* DOCUMENTATION Return the greatest SYMNUM of a any subterm. This includes quantifed variables that don't occur in any term.

This routine is intended to be used if you need malloc an array for indexing by SYMNUM. */ /* PUBLIC */ int greatest_symnum_in_formula(Formula f) { if (f->type == ATOM_FORM) { return greatest_symnum_in_term(f->atom); } if (quant_form(f)) { int sn = str_to_sn(f->qvar, 0); int max_sub = greatest_symnum_in_formula(f->kids[0]); return (sn > max_sub ? sn : max_sub); } else { int max = -1; int i; for (i = 0; i < f->arity; i++) { int max_sub = greatest_symnum_in_formula(f->kids[i]); max = (max_sub > max ? max_sub : max); } return max; } } /* greatest_symnum_in_formula */ /************* * * subst_free_var() * *************/ /* DOCUMENTATION In formula f, substitute free occurrences of target with replacement. The function term_ident() is used, and the target can be any term. */ /* PUBLIC */ void subst_free_var(Formula f, Term target, Term replacement) { if (f->type == ATOM_FORM) f->atom = subst_term(f->atom, target, replacement); else if (quant_form(f) && str_ident(sn_to_str(SYMNUM(target)), f->qvar)) { ; /* Do nothing, because we have a quantified variable of the same name. */ } else { int i; for (i = 0; i < f->arity; i++) subst_free_var(f->kids[i], target, replacement); } } /* subst_free_var */ /************* * * elim_rebind() * *************/ static Formula elim_rebind(Formula f, Ilist uvars) { if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Ilist uvars_plus; if (ilist_member(uvars, SYMNUM(var))) { /* We are in the scope of another variable with this name, so * rename this variable. */ int sn = gen_new_symbol("y", 0, uvars); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); var = newvar; } uvars_plus = ilist_prepend(uvars, SYMNUM(var)); f->kids[0] = elim_rebind(f->kids[0], uvars_plus); free_term(var); free_ilist(uvars_plus); /* frees first node only; uvars still good */ return f; } else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = elim_rebind(f->kids[i], uvars); return f; } } /* elim_rebind */ /************* * * eliminate_rebinding() * *************/ /* DOCUMENTATION This routine renames quantified variables so that no quantified variable occurs in the scope of a quantified variable with the same name.

If you wish to rename variables so that each quantifer has a unique variable, you can use the routine unique_quantified_vars() instead.

The argument f is "used up" during the procedure.

(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.) */ /* PUBLIC */ Formula eliminate_rebinding(Formula f) { f = elim_rebind(f, NULL); return f; } /* eliminate_rebinding */ /************* * * free_vars() * *************/ static Plist free_vars(Formula f, Plist vars) { if (f->type == ATOM_FORM) vars = free_vars_term(f->atom, vars); else if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); Plist vars2 = free_vars(f->kids[0], NULL); vars2 = tlist_remove(var, vars2); vars = tlist_union(vars, vars2); zap_term(var); } else { int i; for (i = 0; i < f->arity; i++) vars = free_vars(f->kids[i], vars); } return vars; } /* free_vars */ /************* * * closed_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL closed_formula(Formula f) { Plist vars = free_vars(f, NULL); /* deep (returns new terms) */ BOOL ok = (vars == NULL); zap_tlist(vars); return ok; } /* closed_formula */ /************* * * get_quant_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula get_quant_form(Ftype type, char *qvar, Formula subformula) { Formula f = formula_get(1, type); f->qvar = qvar; f->kids[0] = subformula; return f; } /* get_quant_form */ /************* * * uni_close() * *************/ static Formula uni_close(Formula f, Plist vars) { if (vars == NULL) return f; else { Formula g = uni_close(f, vars->next); Term v = vars->v; return get_quant_form(ALL_FORM, sn_to_str(SYMNUM(v)), g); } } /* uni_close */ /************* * * universal_closure() * *************/ /* DOCUMENTATION Construct the universal closure of Formula f. The Formula is consumed during the construction. */ /* PUBLIC */ Formula universal_closure(Formula f) { Plist vars = free_vars(f, NULL); /* deep (returns new terms) */ f = uni_close(f, vars); zap_tlist(vars); return f; } /* universal_closure */ /************* * * free_var() * *************/ static BOOL free_var(char *svar, Term tvar, Formula f) { if (f->type == ATOM_FORM) return occurs_in(tvar, f->atom); else if (quant_form(f) && str_ident(svar, f->qvar)) { return FALSE; } else { int i; for (i = 0; i < f->arity; i++) { if (free_var(svar, tvar, f->kids[i])) return TRUE; } return FALSE; } } /* free_var */ /************* * * free_variable() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL free_variable(char *svar, Formula f) { Term tvar = get_rigid_term(svar, 0); BOOL free = free_var(svar, tvar, f); free_term(tvar); return free; } /* free_variable */ /************* * * formulas_to_conjunction * *************/ /* DOCUMENTATION Given a Plist of formulas, form a conjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty conjunction is TRUE. */ /* PUBLIC */ Formula formulas_to_conjunction(Plist formulas) { Plist p; int n = plist_count(formulas); Formula f = formula_get(n, AND_FORM); int i = 0; for (p = formulas; p; p = p->next) { f->kids[i++] = p->v; } return f; } /* formulas_to_conjunction */ /************* * * formulas_to_disjunction * *************/ /* DOCUMENTATION Given a Plist of formulas, form a disjunction of the members. The formulas are not copied, and the Plist is not freed, so you may wish to call zap_plist after the call to this routine.

Note that the empty disjunction is FALSE. */ /* PUBLIC */ Formula formulas_to_disjunction(Plist formulas) { Plist p; int n = plist_count(formulas); Formula f = formula_get(n, OR_FORM); int i = 0; for (p = formulas; p; p = p->next) { f->kids[i++] = p->v; } return f; } /* formulas_to_disjunction */ /************* * * copy_plist_of_formulas() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist copy_plist_of_formulas(Plist formulas) { if (formulas == NULL) return NULL; else { Plist tail = copy_plist_of_formulas(formulas->next); Plist head = get_plist(); head->v = formula_copy(formulas->v); head->next = tail; return head; } } /* copy_plist_of_formulas */ /************* * * literal_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL literal_formula(Formula f) { if (f->type == ATOM_FORM) return TRUE; else if (f->type == NOT_FORM) return f->kids[0]->type == ATOM_FORM; else return FALSE; } /* literal_formula */ /************* * * clausal_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL clausal_formula(Formula f) { if (f->type == OR_FORM) { int i; for (i = 0; i < f->arity; i++) { if (!clausal_formula(f->kids[i])) return FALSE; } return TRUE; } else return literal_formula(f); } /* clausal_formula */ /************* * * formula_set_vars_recurse() * *************/ static void formula_set_vars_recurse(Formula f, char *vnames[], int max_vars) { if (f->type == ATOM_FORM) f->atom = set_vars_recurse(f->atom, vnames, max_vars); else { int i; for (i = 0; i < f->arity; i++) formula_set_vars_recurse(f->kids[i], vnames, max_vars); } } /* formula_set_vars_recurse */ /************* * * formula_set_variables() * *************/ /* DOCUMENTATION This routine traverses a formula and changes the constants that should be variables, into variables. On input, the formula should have no variables. The new variables are numbered 0, 1, 2 ... according the the first occurrence, reading from the left.

A fatal error occurs if there are more than max_vars variables.

The intended is use is for input formulas that are built without regard to variable/constant distinction. */ /* PUBLIC */ void formula_set_variables(Formula f, int max_vars) { char *a[MAX_VARS], **vmap; int i; if (max_vars > MAX_VARS) vmap = malloc((max_vars * sizeof(char *))); else vmap = a; for (i = 0; i < max_vars; i++) vmap[i] = NULL; formula_set_vars_recurse(f, vmap, max_vars); /* Now do any answer attributes (with the same vmap). */ if (f->attributes) { set_vars_attributes(f->attributes, vmap, max_vars); #if 0 /* Make sure that answer vars also occur in formula. */ Plist attr_vars = vars_in_attributes(c->attributes); Plist formula_vars = vars_in_formula(c); if (!plist_subset(attr_vars, formula_vars)) { Plist p; printf("Variables in answers must also occur ordinary literals:\n"); p_formula(c); for (p = attr_vars; p; p = p->next) { if (!plist_member(formula_vars, p->v)) { Term t = p->v; printf("Answer variable not in ordinary literal: %s.\n", vmap[VARNUM(t)]); } } fatal_error("formula_set_variables, answer variable not in literal"); } zap_plist(formula_vars); zap_plist(attr_vars); #endif } if (max_vars > MAX_VARS) free(vmap); } /* formula_set_variables */ /************* * * positive_formula() * *************/ /* DOCUMENTATION Ignoring quantifiers, does the formula consist of an atomic formula or the conjunction of atomic formulas? */ /* PUBLIC */ BOOL positive_formula(Formula f) { Formula g = f; while (quant_form(g)) g = g->kids[0]; if (g->type == ATOM_FORM) return TRUE; else if (g->type != AND_FORM) return FALSE; else { int i; for (i = 0; i < g->arity; i++) if (!positive_formula(g->kids[i])) return FALSE; return TRUE; } } /* positive_formula */ /************* * * formula_contains_attributes() * *************/ /* DOCUMENTATION Does the formula or any of its subformulas contain attributes? */ /* PUBLIC */ BOOL formula_contains_attributes(Formula f) { if (f->attributes != NULL) return TRUE; else if (f->type == ATOM_FORM) return FALSE; else { int i; for (i = 0; i < f->arity; i++) if (formula_contains_attributes(f->kids[i])) return TRUE; return FALSE; } } /* formula_contains_attributes */ /************* * * subformula_contains_attributes() * *************/ /* DOCUMENTATION Does any proper subformula contain attributes? */ /* PUBLIC */ BOOL subformula_contains_attributes(Formula f) { if (f->type == ATOM_FORM) return FALSE; else { int i; for (i = 0; i < f->arity; i++) if (formula_contains_attributes(f->kids[i])) return TRUE; return FALSE; } } /* subformula_contains_attributes */ /************* * * constants_in_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist constants_in_formula(Formula f) { Ilist p; I2list p2 = NULL; p2 = function_symbols_in_formula(f, p2); p = multiset_to_set(p2); zap_i2list(p2); p = symnums_of_arity(p, 0); return p; } /* constants_in_formula */ /************* * * relation_in_formula() * *************/ /* DOCUMENTATION Collect the multiset of relation symbols in a formula. */ /* PUBLIC */ BOOL relation_in_formula(Formula f, int symnum) { if (f->type == ATOM_FORM) return SYMNUM(f->atom) == symnum; else { int i; for (i = 0; i < f->arity; i++) if (relation_in_formula(f->kids[i], symnum)) return TRUE; return FALSE; } } /* relation_in_formula */ /************* * * rename_all_bound_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void rename_all_bound_vars(Formula f) { if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); free_term(newvar); } else { int i; for (i = 0; i < f->arity; i++) rename_all_bound_vars(f->kids[i]); } } /* rename_all_bound_vars */ /************* * * rename_these_bound_vars() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void rename_these_bound_vars(Formula f, Ilist vars) { /* Rename each quantified variable in "vars" to a new symbol. */ if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); if (ilist_member(vars, SYMNUM(var))) { /* Rename this variable. */ int sn = fresh_symbol("x", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); } rename_these_bound_vars(f->kids[0], vars); } else { int i; for (i = 0; i < f->arity; i++) rename_these_bound_vars(f->kids[i], vars); } } /* rename_these_bound_vars */ LADR-2009-11A/ladr/dioph.c0000644000175000017500000005042110637466321014221 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "dioph.h" /************* * * gcd(x,y) - greatest common divisor * *************/ static int gcd(int x, int y) { int r; if (x < y) {r = x; x = y; y = r;} r = x % y; while (r != 0) {x = y; y = r; r = x % y;} return y; } /* gcd */ /************* * * lcm(x,y) - least common multiple * *************/ static int lcm(int x, int y) { return (x * y) / gcd(x,y); } /* lcm */ /************* * * less_vec(a1, a2, length) - true iff each component of a1 is <= * the corresponding component of a2 * *************/ static int less_vec(int *a1, int *a2, int length) { int i; for (i = 0; i < length; i++) { if (a1[i] > a2[i]) return 0; } return 1; } /* less_vec */ /************* * * var_check_1(constraints, xy, start, stop) * * true iff for i=start,...,stop, constraints[i] implies xy[i] <= 1; * For checking basis solutions and combinations of basis solutions. * * Otherwise, AC symbol would have to unify with another rigid symbol. * *************/ static int var_check_1(int *constraints, int *xy, int start, int stop) { int i; for (i = start; i <= stop; i++) { if (constraints[i] && xy[i] > 1) return 0; } return 1; } /* var_check_1 */ /************* * * var_check_2(constraints, xy, start, stop) * * TRUE iff for i,j=start,...,stop, * * constraints[i] && xy[i] && constraints[j] && xy[j] * implies constraints[i] = constraints[j] . * * Otherwise, variable would have to unify with 2 different symbols. * * For checking basis solutions only. * *************/ static int var_check_2(int *constraints, int *xy, int start, int stop) { int i, j; for (i = start; i <= stop; i++) { if (constraints[i] && xy[i]) { for (j = i+1; j <= stop; j++) { if (constraints[j] && xy[j]) { if (constraints[j] != constraints[i]) return 0; } } } } return 1; } /* var_check_2 */ /************* * * add_solution(xy, length, num_basis, basis) * If no solution in basis is less than xy, then append xy to basis * If there is not enough room, return 0. * *************/ static int add_solution(int *xy, int length, int *num_basis, int (*basis)[MAX_COEF]) { int i; for (i = 0; i < *num_basis; i++) if (less_vec(basis[i], xy, length)) return 1; if (*num_basis >= MAX_BASIS) { return 0; } for (i = 0; i < length; i++) basis[*num_basis][i] = xy[i]; (*num_basis)++; return 1; } /* add_solution */ /************* * * a_in_bounds(ab,xy,max_y,d,e,m,n,xypos,max_a,max_b,suma,constraints) * Check if a[0],...,a[xypos] is ok: * 1. check Huet's (a) condition; * 2. check that xy vector is compatible with and constants/functions; * 3. set up the max_y vector; * 4. check Huet's (b) condition; * *************/ static int a_in_bounds(int *ab, int *xy, int *max_y, int (*d)[MAX_COEF], int (*e)[MAX_COEF], int m, int n, int xypos, int max_a, int max_b, int suma, int *constraints) { int i, j, f, bsum; if (xy[xypos] > max_b) /* Huet's (a) condition */ return 0; if (var_check_1(constraints, xy, 0, m-1) == 0 || var_check_2(constraints, xy, 0, m-1) == 0) return 0; for (j = m; j < m+n; j++) /* build max_y vector */ { max_y[j] = max_a; for (i = 0; i < m; i++) if (xy[i] >= d[i][j]) { f = e[i][j] - 1; if (f < max_y[j]) max_y[j] = f; } } bsum = 0; for (j = m; j < m+n; j++) bsum = bsum + ab[j] * max_y[j]; if (suma <= bsum) /* Huet's (b) condition */ return 1; else return 0; } /* a_in_bounds */ /************* * * b_in_bounds(xy,max_y,constraints,xypos,suma,sumb,m,n,d,e) * Check if b[0],...,b[xypos] is ok: * 1. check Huet's (c) and (d) conditions; * 2. check that xy vector is compatible with and constants/functions; * *************/ static int b_in_bounds(int *xy, int *max_y, int *constraints, int xypos, int suma, int sumb, int m, int n) { /* Huet (d) and (c) conditions */ if (sumb <= suma && xy[xypos] <= max_y[xypos]) /* check constant/function symbol condition */ if (var_check_1(constraints, xy, 0, m+n-1) && var_check_2(constraints, xy, 0, m+n-1)) return 1; else return 0; else return 0; } /* b_in_bounds */ /************* * * int dio() * *************/ /* DOCUMENTATION This routine generates the basis of solutions to the homogeneous linear diophantine equation given by ab, m, n. It uses Huet's algorithm (Information Processing Letters 7(3) 1978).

The equation has the form a1x1 + ... + amxm = b1y1 + ... + bnyn.

  • ab[] - the vector of coefficients. 1..m is a1..am, m+1..m+n is b1..bn.
  • m, n - the number of a and b coefficients.
  • constraints[] - rigid symbol (constant/function)restrictions.
  • basis[][] (output) - vector of minimal solutions.
  • num_basis (output) - number of minimal solutions.
Return value:
  • 0 - no solution within constraints
  • 1 - ok, solutions returned
  • -1 - too many (> MAX_BASIS) base solutions exist
*/ /* PUBLIC */ int dio(int ab[MAX_COEF], int m, int n, int constraints[MAX_COEF], int basis[MAX_BASIS][MAX_COEF], int *num_basis) { /* max_a, max_b - the maximums of the a's and b's. * xy - the vector used to construct solutions. * xypos - the current position in the xy vector. * suma, sumb - accumulate the sums as the soutions are constructed. * max_y - used to hold maximums for the y values. * d, e - d[i,j] = lcm(ai,bj) / ai, e[i,j] = lcm(ai,bj) / bj, they * are used to construct solutions and for bounds checking. */ int xy[MAX_COEF], max_y[MAX_COEF]; int d[MAX_COEF][MAX_COEF], e[MAX_COEF][MAX_COEF]; int xypos, max_a, max_b, suma, sumb; int i, j, a, b, t, go_a, go_b, backup; if (m == 0 || n == 0) { *num_basis = 0; return 1; } max_a = 0; max_b = 0; for (i = 0; i < m; i++) for (j = m; j < m+n; j++) { a = ab[i]; b = ab[j]; t = lcm(a,b); d[i][j] = t / a; e[i][j] = t / b; } for (i = 0; i < m; i++) if (ab[i] > max_a) max_a = ab[i]; for (i = m; i < m+n; i++) if (ab[i] > max_b) max_b = ab[i]; for (i = 0; i < m+n; i++) xy[i] = 0; xypos = m - 1; go_a = 1; suma = 0; *num_basis = 0; while(go_a) { xy[xypos]++; suma = suma + ab[xypos]; if (a_in_bounds(ab,xy,max_y,d,e,m,n,xypos,max_a,max_b, suma,constraints)) { sumb = 0; xypos = m + n - 1; go_b = 1; while (go_b) { xy[xypos]++; sumb = sumb + ab[xypos]; if (b_in_bounds(xy,max_y,constraints,xypos, suma,sumb,m,n)) { if (suma == sumb) { if (add_solution(xy, m+n, num_basis, basis)) backup = 1; else return -1; } else backup = 0; } else backup = 1; if (backup) { sumb = sumb - xy[xypos] * ab[xypos]; xy[xypos] = 0; xypos--; if (xypos < m) go_b = 0; } else xypos = m + n - 1; } xypos = m - 1; } else { suma = suma - xy[xypos] * ab[xypos]; xy[xypos] = 0; xypos--; if (xypos < 0) go_a = 0; } } /* Add the special solutions Sij */ for (i = 0; i < m+n; i++) xy[i] = 0; for (i = 0; i < m; i++) for (j = m; j < m+n; j++) { xy[i] = d[i][j]; xy[j] = e[i][j]; if (var_check_1(constraints,xy,0,m+n-1) && var_check_2(constraints,xy,0,m+n-1)) if (!add_solution(xy, m+n, num_basis, basis)) return -1; xy[i] = 0; xy[j] = 0; } return 1; } /* dio */ /* Following macros are for following next_combo routines. */ #define ADD_TO_SUM(sum,basis,i,len) \ {int j,*p; for (j=0,p=basis[i];j
  • length -- total number of coefficients (m+n).
  • basis[][] -- basis of solutions.
  • num_basis -- number of basis solutions.
  • constraints[] -- rigid symbol constraints.
  • combo[] (input and output) -- current subset of the basis.
  • sum[] (intput and output) -- sum corresponding to combo[].
  • start_flag -- 1 for first call, 0 for subsequent calls. We have several algorithms to do this. This implements algorithm A. (For most practical work, the differences in performance are small.) */ /* PUBLIC */ int next_combo_a(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag) { int go, pos, i, success; if (start_flag) { for (i = 0; i < length; i++) sum[i] = 0; for (i = 0; i < num_basis; i++) combo[i] = 0; } success = 0; pos = num_basis-1; go = (pos >= 0); while (go && !success) { int backup = 1; if (!combo[pos]) { combo[pos] = 1; /* All following positions 0. */ ADD_TO_SUM(sum, basis, pos, length); if (var_check_1(constraints, sum, 0, length-1)) { /* OK if no component is 0. */ success = 1; for (i = 0; i < length && success; i++) if (sum[i] == 0) success = 0; backup = 0; } } if (backup) { combo[pos] = 0; SUBTRACT_FROM_SUM(sum, basis, pos, length); pos--; go = (pos >= 0); } else pos = num_basis-1; } return success; } /* next_combo_a */ /************* * * next_combo_b * * Find the first or next appropriate subset of the basis. * combo is the current subset, and * sum is the solution corresponding to combo. * *************/ /* DOCUMENTATION This routine gets the first or next appropriate subset of the basis of solutions. This implements algorithm B. See next_combo_a() for a description. */ /* PUBLIC */ int next_combo_b(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag) { int go, pos, i, success; if (start_flag) { for (i = 0; i < length; i++) sum[i] = 0; for (i = 0; i < num_basis; i++) combo[i] = 0; pos = -1; } else { pos = num_basis-1; while (pos >= 0 && !combo[pos]) pos--; combo[pos] = 0; SUBTRACT_FROM_SUM(sum, basis, pos, length); } success = 0; go = 1; while (go && !success) { if (pos == num_basis-1) { success = 1; for (i = 0; i < length && success; i++) if (sum[i] == 0) success = 0; if (!success) { while (pos >= 0 && !combo[pos]) pos--; if (pos < 0) go = 0; else { combo[pos] = 0; SUBTRACT_FROM_SUM(sum, basis, pos, length); } } } else { pos++; combo[pos] = 1; ADD_TO_SUM(sum, basis, pos, length); if (!var_check_1(constraints, sum, 0, length-1)) { combo[pos] = 0; SUBTRACT_FROM_SUM(sum, basis, pos, length); } } } return success; } /* next_combo_b */ /************* * * next_combo_c -- Hullot's algorithm * * Find the first or next appropriate subset of the basis. * *************/ #define DOWN 1 #define OVER 2 #define BACKUP 3 #define SUCCESS 4 #define FAILURE 5 /* DOCUMENTATION This routine gets the first or next appropriate subset of the basis of solutions. This implements algorithm C. See next_combo_a() for a description. */ /* PUBLIC */ int next_combo_c(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag) { int pos, i, status, ok; if (start_flag) { for (i = 0; i < length; i++) sum[i] = 0; /* set combo[] to root pattern */ for (i = 0; i < num_basis; i++) { combo[i] = 1; ADD_TO_SUM(sum, basis, i, length); } pos = -1; /* pos, which is index into combo[], also = level-1 */ /* Fail if a column of basis is all 0 (if not big enough). */ for (i = 0, ok = 1; i < length && ok; i++) if (sum[i] == 0) ok = 0; status = (ok ? DOWN : FAILURE); } else { /* use combo[] from previous call */ pos = num_basis-1; /* leaf */ status = BACKUP; } while (status != SUCCESS && status != FAILURE) { if (status == DOWN) { /* go to left child */ if (pos == -1 || combo[pos] == 0) { /* parent is a left child */ pos++; combo[pos] = 0; SUBTRACT_FROM_SUM(sum, basis, pos, length); } else { pos++; for (i = pos+1; i < num_basis; i++) { combo[i] = 1; ADD_TO_SUM(sum, basis, i, length); } } /* if big enough */ for (i = 0, ok = 1; i < length && ok; i++) if (sum[i] == 0) ok = 0; if (ok) status = (pos == num_basis-1) ? SUCCESS : DOWN; else status = OVER; } else if (status == OVER) { /* go to (right) sibling */ combo[pos] = 1; ADD_TO_SUM(sum, basis, pos, length); for (i = pos+1; i < num_basis; i++) { if (combo[i]) { combo[i] = 0; SUBTRACT_FROM_SUM(sum, basis, i, length); } } /* if small enough */ if (var_check_1(constraints, sum, 0, length-1)) status = (pos == num_basis-1) ? SUCCESS : DOWN; else status = BACKUP; } else if (status == BACKUP) { /* go to nearest ancestor that has a right sibling */ while (pos >= 0 && combo[pos]) pos--; status = (pos < 0 ? FAILURE : OVER); } } return status == SUCCESS ? 1 : 0; } /* next_combo_c */ /************* * * superset_degree * * If a is not a superset of b, return -1, else return |a-b|. * *************/ static int superset_degree(int *a, int *b, int n) { int i, c; for (i=0, c=0; i=0; i++) { if (b[i] && !a[i]) c = -1; else if (a[i] && !b[i]) c++; } return c; } /* superset_degree */ /************* * * next_combo_ss * *************/ /* DOCUMENTATION This routine gets the first or next appropriate subset of the basis of solutions, subject to the "supserset restriction". It appears to work like the other next_combo routines, but it is not really incremental. To implement the superset restriction, we collect, in combos[] during the first call, up to MAX_COMBOS subsets satisfying the restriction, then give them out in the subsequent calls. The first bunch of parameters are the same as for the other next_combo routines.
    • length -- total number of coefficients (m+n).
    • basis[][] -- basis of solutions.
    • num_basis -- number of basis solutions.
    • constraints[] -- rigid symbol constraints.
    • combo[] (input and output) -- current subset of the basis.
    • sum[] (intput and output) -- sum corresponding to combo[].
    • start_flag -- 1 for first call, 0 for subsequent calls.
    The rest of the parameters are added for the supserset restriction.
    • combos[][] (input and output) -- this is really just temp storage.
    • *np (input and output) -- temp storage (# of combos remaining).
    • ss_parm (input) -- supserset parameter [0...]
    */ /* PUBLIC */ int next_combo_ss(int length, int basis[MAX_BASIS][MAX_COEF], int num_basis, int constraints[MAX_COEF], int combo[MAX_BASIS], int sum[MAX_COEF], int start_flag, int combos[MAX_COMBOS][MAX_BASIS], int *np, int ss_parm) { int i, go, ok; if (start_flag) { *np = 0; go = next_combo_a(length,basis,num_basis,constraints,combo,sum,1); while (go) { for (i=0, ok = 1; i < *np && ok; i++) /* 0 means basic superset test */ /* n means allow supersets that have n more elements. */ if (superset_degree(combo, combos[i], num_basis) > ss_parm) ok = 0; if (ok) { if (*np == MAX_COMBOS) { printf("next_combo_ss: MAX_COMBOS.\n"); go = 0; } else { for (i=0; i 0) { (*np)--; for (i=0; i ", i); for (j = 0; j < num_basis; j++) if (combo[j]) for (k = 0; k < basis[j][i]; k++) printf("z%d ", j); printf("\n"); } } #endif #endif ok = (*proc)(m+n, basis, num_basis, constraints, combo, sum, 0); } return count; } /* all_combos */ #endif #ifdef SOLO /************* * * main * *************/ int main(int argc, char **argv) { int m, n, num_basis; int ab[MAX_COEF], constraints[MAX_COEF], basis[MAX_BASIS][MAX_COEF]; int i; unsigned long t0, t1, t2, t3; printf("\nThe equation is A1X1 + ... + AmXm = B1Y1 + ... + BnYn.\n\n"); printf("Enter m and n, the number of terms on each side: "); scanf("%d %d", &m, &n); if (m+n > MAX_COEF) { printf("maximum m+n is %d\n", MAX_COEF); exit(2); } printf("Enter the %d A coefficients and the %d B coefficients: ", m, n); for (i=0; i 0) { t2 = clock(); i = all_combos(m, n, basis, num_basis, constraints, next_combo_a); t3 = clock(); printf("\nNumber of unifiers is %d\n", i); printf("next_combo_a time = %.2f\n", (t3-t2)/1000000.); #if 0 t2 = clock(); t2 = clock(); i = all_combos(m, n, basis, num_basis, constraints, next_combo_b); t3 = clock(); printf("\nNumber of unifiers is %d\n", i); printf("next_combo_b time = %.2f\n", (t3-t2)/1000000.); t2 = clock(); i = all_combos(m, n, basis, num_basis, constraints, next_combo_c); t3 = clock(); printf("\nNumber of unifiers is %d\n", i); printf("next_combo_c time = %.2f\n", (t3-t2)/1000000.); #endif } return 0; } /* main */ #endif LADR-2009-11A/ladr/util/0000755000175000017500000000000010707171107013716 5ustar mccunemccuneLADR-2009-11A/ladr/util/init-package0000755000175000017500000000471310573346174016216 0ustar mccunemccune#!/usr/bin/perl $this_file = __FILE__; if (scalar(@ARGV) != 1) { print "Usage: $this_file filename (without .c or .h)\n"; exit 1; } if (-e "$ARGV[0].h") { print "File $ARGV[0].h already exists.\n"; exit 1; } if (-e "$ARGV[0].c") { print "File $ARGV[0].c already exists.\n"; exit 1; } open(FH, ">$ARGV[0].h"); open(FC, ">$ARGV[0].c"); print FC <; @includes = grep(/^#include\s+\"/, @lines); foreach $includeline (@includes) { ($junk,$kid) = split("\"", $includeline); if (!defined($Kids{$hfile})) { $Kids{$hfile} = $kid; } else { $Kids{$hfile} = $Kids{$hfile} . " $kid"; } } close(FH); } foreach $hfile (@hfiles) { @desc = &descendents($hfile); } `/bin/mv Makefile Makefile.bak`; print "\nMakefile has been backed up to Makefile.bak\n"; open(FIN, "Makefile"); $line = ; while (!$done) { $done = ($line =~ /rest of the file/); print FOUT "$line"; $line = ; } foreach $hfile (@hfiles) { $ofile = $hfile; $ofile =~ s/\.h/.o/; print FOUT "\n$ofile: \t$hfile $Desc{$hfile}\n"; } LADR-2009-11A/ladr/util/temp0000644000175000017500000000367510215336545014624 0ustar mccunemccune #define PTRS_T2 CEILING(sizeof(struct t2),BYTES_POINTER) static unsigned T2_gets, T2_frees; #define PTRS_T3 CEILING(sizeof(struct t3),BYTES_POINTER) static unsigned T3_gets, T3_frees; /************* * * T2 get_t2() * *************/ static T2 get_t2(void) { T2 p = get_mem(PTRS_T2); T2 xxx_gets++; return(p); } /* get_t2 */ /************* * * free_t2() * *************/ static void free_t2(T2 p) { free_mem(p, PTRS_T2); T2 xxx_frees++; } /* free_t2 */ /************* * * T3 get_t3() * *************/ static T3 get_t3(void) { T3 p = get_mem(PTRS_T3); T3 xxx_gets++; return(p); } /* get_t3 */ /************* * * free_t3() * *************/ static void free_t3(T3 p) { free_mem(p, PTRS_T3); T3 xxx_frees++; } /* free_t3 */ /************* * * fprint_t1 xxx_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the t1 package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_t1 xxx_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct t2); fprintf(fp, "t2 (%4d) %11u%11u%11u%9.1f K\n", n, T2 xxx_gets, T2 xxx_frees, T2 xxx_gets - T2 xxx_frees, ((T2 xxx_gets - T2 xxx_frees) * n) / 1024.); n = sizeof(struct t3); fprintf(fp, "t3 (%4d) %11u%11u%11u%9.1f K\n", n, T3 xxx_gets, T3 xxx_frees, T3 xxx_gets - T3 xxx_frees, ((T3 xxx_gets - T3 xxx_frees) * n) / 1024.); } /* fprint_t1 xxx_mem */ /************* * * p_t1 xxx_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the t1 package. */ /* PUBLIC */ void p_t1 xxx_mem() { fprint_t1 xxx_mem(stdout, TRUE); } /* p_t1 xxx_mem */ /* * end of memory management */ LADR-2009-11A/ladr/util/options-for-gui.py0000755000175000017500000000171110707171107017334 0ustar mccunemccune#!/usr/bin/python import re, sys print ' dependencies = [' for line in sys.stdin.readlines(): line = line.replace('automatic', 'auto') line = line.replace('TRUE', 'True') line = line.replace('FALSE', 'False') line = line.replace('INT_MAX', 'sys.maxint') line = line.replace('"', "'") (_,type,opt,a,b,c,_) = re.split('_dependency\(\w+->|,\s*\w+->|,\s*|\);\n|\s*', line) if (opt in ['default_parts', 'default_output'] or b in ['lrs_ticks', 'echo_input', 'quiet']): com = '#' else: com = '' if type in ['flag_flag', 'flag_parm', 'flag_stringparm']: print "%s (('%s', %s), ('%s', %s))," % (com, opt, a, b, c) elif type == 'parm_parm': if c == 'True': v2 = "('multiply', %s)" % b else: v2 = b print "%s (('%s', 'any'), ('%s', %s))," % (com, opt, a, v2) else: print '# not handled: line' print ' ]' LADR-2009-11A/ladr/util/backup0000755000175000017500000000022006536020661015106 0ustar mccunemccune#!/bin/csh # h option says to follow symlinks (html directory) tar cvhf go.tar *.h *.c Makefile util html */*.in gzip go.tar ls -l go.tar.gz LADR-2009-11A/ladr/util/new-type0000755000175000017500000000161710140532443015414 0ustar mccunemccune#!/usr/bin/perl $this_file = __FILE__; if (scalar(@ARGV) != 1) { print "Usage: $this_file type\n"; exit 1; } $arg = $ARGV[0]; $upp = uc $arg; $cap = ucfirst $arg; $low = lc $arg; printf "#define PTRS_$upp CEILING(sizeof(struct $low), BYTES_POINTER)\n"; printf "static unsigned %s_gets, %s_frees;\n", $cap, $cap; print <$type<\/A>/g; } } return $line; } # Main program starts here. $this_file = __FILE__; if (scalar(@ARGV) != 1) { print "Usage: $this_file filename (without .h or .c)\n"; exit 1; } $cfile = $ARGV[0] . ".c"; $hfile = $ARGV[0] . ".h"; if (! open(FC, $cfile)) { print "Cannot open file $cfile\n"; die; } if (! open(FH, $hfile)) { print "Cannot open file $hfile\n"; die; } # Get stuff from .h file and put it in @definitions. push(@definitions, "
    ");
    $pub = 0;
    while ($line = ) {
        if ($intro && $line =~ /\*\//) {
    	$intro = 0;
        }
        elsif ($pub && $line =~ "End of public definitions") {
    	$pub = 0;
        }
    
        if ($pub) {
    	$line = &type_links($line);
    	push(@definitions, $line);
        }
        elsif ($intro) {
    	push(@intro_lines, $line);
        }
    
        if ($line =~ "INTRODUCTION") {
    	$intro = 1;
    	undef @intro_lines;
        }
        elsif ($line =~ "Public definitions") {
    	$pub = 1;
        }
    }  # each line of .h file
    push(@definitions, "
    "); # Get prototypes and documentation from .c file and put in @routines. $doc = 0; $pub = 0; while ($line = ) { if ($doc && $line =~ /\*\//) { $doc = 0; } if ($pub && $line =~ "{") { $pub = 0; # Now we have a prototype (pub_lines) , and possibly doc_lines. # Get the function name from pub_lines and add to @functions. $function = $pub_lines[0]; $function =~ s/.*(\b\w+\b)\(.*/\1/; chop($function); push(@functions, "$function"); # Put a ; at the end of the prototype $pub_lines[$#pub_lines] =~ s/\n/;\n/; $document{$function} = join("", @doc_lines); $prototype{$function} = join("", @pub_lines); undef @doc_lines; # in case a routine has no doc } if ($doc) { $line = &type_links($line); push(@doc_lines, $line); } if ($pub) { $line = &type_links($line); push(@pub_lines, $line); } if ($line =~ "DOCUMENTATION") { $doc = 1; undef @doc_lines; } if ($line =~ "PUBLIC") { $pub = 1; undef @pub_lines; } } # each line of .c file # Create 4-column function index and put in @index. @functions = sort(@functions); $n = scalar(@functions); if ($n % 4 == 0) {$rows = $n / 4;} else {$rows = int($n / 4) + 1;} @x1 = @functions[0 .. $rows-1]; @x2 = @functions[$rows .. 2*$rows-1]; @x3 = @functions[2*$rows .. 3*$rows-1]; @x4 = @functions[3*$rows .. $n-1]; push(@index, "\n"); foreach $i (0 .. $rows-1) { push(@index, ""); push(@index, "\n"); push(@index, "\n"); } push(@index, "
    $x1[$i]$x2[$i]$x3[$i]$x4[$i]
    \n"); # Insert function links into %document. foreach $func (keys(%document)) { foreach $func2 (keys(%document)) { $document{$func2} =~ s/\b$func\(/$func<\/A>(/g; } } # OK, now we can print the HTML. print < $hfile

    #include "$hfile"

    This page has information from files
    $hfile and $cfile.

    Contents

    END_OF_HEAD print "


    Public Routines in File $cfile

    \n"; print "

    Index

    \n"; print @index; print "

    Details

    \n"; foreach $func (sort keys(%prototype)) { print ""; print "
    "; 
        print $prototype{$func};
        print "
    "; print $document{$func}; } print "

    Public Definitions in File $hfile

    \n"; print @definitions; print "

    Introduction

    \n"; print @intro_lines; print < END_OF_TAIL LADR-2009-11A/ladr/util/proto0000755000175000017500000000104106465656225015022 0ustar mccunemccune#!/bin/csh if ($#argv != 1) then echo "need one arg: filename without .h or .c" exit 1 endif if (! -e $1.c || ! -e $1.h) then echo "Both $1.c and $1.h must exist." exit 1 endif /bin/mv $1.h $1.h.bak sed '/Public function prototypes/,$d' $1.h.bak > $1.h echo "/* Public function prototypes from $1.c */" >> $1.h echo "" >> $1.h awk '/PUBLIC/,/^{/' < $1.c | sed -e '/PUBLIC/d' -e 's/{//' -e 's/) *$/);/' >> $1.h echo "#endif /* conditional compilation of whole file */" >> $1.h echo "$1.h has been updated; old version is $1.h.bak." LADR-2009-11A/ladr/util/options-for-gui.py~0000755000175000017500000000170510706017404017533 0ustar mccunemccune#!/usr/bin/python import re, sys print ' dependencies = [' for line in sys.stdin.readlines(): line = line.replace('automatic', 'auto') line = line.replace('TRUE', 'True') line = line.replace('FALSE', 'False') line = line.replace('INT_MAX', 'sys.maxint') line = line.replace('"', "'") (_,type,opt,a,b,c,_) = re.split('_dependency\(p->|,\s*p->|,\s*|\);\n|\s*', line) if (opt in ['default_parts', 'default_output'] or b in ['lrs_ticks', 'echo_input', 'quiet']): com = '#' else: com = '' if type in ['flag_flag', 'flag_parm', 'flag_stringparm']: print "%s (('%s', %s), ('%s', %s))," % (com, opt, a, b, c) elif type == 'parm_parm': if c == 'True': v2 = "('multiply', %s)" % b else: v2 = b print "%s (('%s', 'any'), ('%s', %s))," % (com, opt, a, v2) else: print '# not handled: line' print ' ]' LADR-2009-11A/ladr/util/to-html0000755000175000017500000000017507426523730015242 0ustar mccunemccune#!/bin/csh if ($#argv != 1) then echo "need 1 arg: filename without .h or .c" exit(1) endif util/doc5 $1 > html/$1.html LADR-2009-11A/ladr/ibuffer.h0000644000175000017500000000323311151265363014537 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_IBUFFER_H #define TP_IBUFFER_H #include "fatal.h" /* INTRODUCTION */ /* Public definitions */ #define IBUF_INIT_SIZE 40000 #define IBUF_EOF INT_MIN struct ibuffer { int write_position; /* current number of ints in buf (next pos to write) */ int read_position; /* next pos to read */ int size; /* size of buf */ int *buf; /* the buffer */ }; typedef struct ibuffer * Ibuffer; /* End of public definitions */ /* Public function prototypes from ibuffer.c */ Ibuffer ibuf_init(void); void ibuf_free(Ibuffer ibuf); void ibuf_write(Ibuffer ibuf, int i); void ibuf_write_block(Ibuffer ibuf, int *a, int n); void ibuf_rewind(Ibuffer ibuf); int ibuf_read(Ibuffer ibuf); int ibuf_xread(Ibuffer ibuf); int ibuf_length(Ibuffer ibuf); int *ibuf_buffer(Ibuffer ibuf); Ibuffer fd_read_to_ibuf(int fd); void p_ibuf(Ibuffer ibuf); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/attrib.c0000644000175000017500000005535411074677627014426 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "attrib.h" /* Private definitions and types */ /* Attribute: a list of these can be attached to clauses. */ struct attribute { /* to form lists of attributes */ int id; /* attribute ID (index into Attribute_names array) */ union { /* attribute value */ int i; char *s; Term t; } u; Attribute next; }; /* Attribute_names: data about types of attributes. */ #define MAX_ATTRIBUTE_NAMES 50 static struct { /* array, indexed by attribute id */ char *name; /* name of attribute, e.g., label, answer */ Attribute_type type; /* INT_ATTRIBUTE STRING_ATTRIBUTE TERM_ATTRIBUTE etc */ BOOL inheritable; /* child gets instance (for term attributes only) */ } Attribute_names[MAX_ATTRIBUTE_NAMES]; static int Next_attribute_name = 0; /* * memory management */ #define PTRS_ATTRIBUTE PTRS(sizeof(struct attribute)) static unsigned Attribute_gets, Attribute_frees; /************* * * Attribute get_attribute() * *************/ static Attribute get_attribute(void) { Attribute p = get_cmem(PTRS_ATTRIBUTE); Attribute_gets++; return(p); } /* get_attribute */ /************* * * free_attribute() * *************/ static void free_attribute(Attribute p) { free_mem(p, PTRS_ATTRIBUTE); Attribute_frees++; } /* free_attribute */ /************* * * fprint_attrib_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the attrib package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_attrib_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct attribute); fprintf(fp, "attribute (%4d) %11u%11u%11u%9.1f K\n", n, Attribute_gets, Attribute_frees, Attribute_gets - Attribute_frees, ((Attribute_gets - Attribute_frees) * n) / 1024.); } /* fprint_attrib_mem */ /************* * * p_attrib_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the attrib package. */ /* PUBLIC */ void p_attrib_mem() { fprint_attrib_mem(stdout, TRUE); } /* p_attrib_mem */ /* * end of memory management */ /************* * * attribute_type() * *************/ static Attribute_type attribute_type(Attribute a) { return Attribute_names[a->id].type; } /* attribute_type */ /************* * * attribute_name() * *************/ static char *attribute_name(Attribute a) { return Attribute_names[a->id].name; } /* attribute_name */ /************* * * register_attribute() * *************/ /* DOCUMENTATION This routine associates an attribute name and attribute type and returns an integer ID to be used with the attribute operations (set, get, etc). */ /* PUBLIC */ int register_attribute(char *name, Attribute_type type) { int id = -1; if (Next_attribute_name == MAX_ATTRIBUTE_NAMES) fatal_error("register_attribute: too many attribute names"); else { id = str_to_sn(name, 1); /* insert into symbol table */ id = Next_attribute_name++; Attribute_names[id].name = new_str_copy(name); Attribute_names[id].type = type; } return id; } /* register_attribute */ /************* * * declare_term_attribute_inheritable() * *************/ /* DOCUMENTATION This routine makes a term attribute (which has already been registered) inheritable. This usually means that when the clause to which the attribute is attached begets a child, the child gets a copy of the instantiated attribute. This was designed for answer literals and ordering constraints. */ /* PUBLIC */ void declare_term_attribute_inheritable(int id) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("declare_term_attribute_inheritable, bad id"); Attribute_names[id].inheritable = TRUE; } /* declare_term_attribute_inheritable */ /************* * * inheritable() * *************/ static BOOL inheritable(Attribute a) { return Attribute_names[a->id].inheritable; } /* inheritable */ /************* * * set_int_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes.

    A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_int_attribute(Attribute a, int id, int val) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("set_int_attribute, bad id"); if (a == NULL) { Attribute b = get_attribute(); b->id = id; b->u.i = val; return b; } else { a->next = set_int_attribute(a->next, id, val); return a; } } /* set_int_attribute */ /************* * * get_int_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, INT_MAX is returned.

    A fatal error occurs if the ID does not refer to an integer type attribute (see register_attribute). */ /* PUBLIC */ int get_int_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("get_int_attribute, bad id"); if (a == NULL) return INT_MAX; else if (a->id == id && n == 1) return a->u.i; else if (a->id == id) return get_int_attribute(a->next, id, n-1); else return get_int_attribute(a->next, id, n); } /* get_int_attribute */ /************* * * exists_attribute() * *************/ /* DOCUMENTATION This routine checks if there are any attributes of the given type. */ /* PUBLIC */ BOOL exists_attribute(Attribute a, int id) { if (a == NULL) return FALSE; else if (a->id == id) return TRUE; else return exists_attribute(a->next, id); } /* exists_attribute */ /************* * * set_term_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes. The term is not copied.

    A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_term_attribute(Attribute a, int id, Term val) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("set_term_attribute, bad ID"); if (a == NULL) { Attribute b = get_attribute(); b->id = id; b->u.t = val; return b; } else { a->next = set_term_attribute(a->next, id, val); return a; } } /* set_term_attribute */ /************* * * replace_term_attribute() * *************/ /* DOCUMENTATION This routine replaces that n-th term attribute for given ID. The term that is already there is zapped, and the new term is NOT copied.

    A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute), or if there are not n attributes identified by ID. */ /* PUBLIC */ void replace_term_attribute(Attribute a, int id, Term val, int n) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("replace_term_attribute, bad ID"); if (a == NULL) fatal_error("replace_term_attribute, attribute not found"); else if (a->id == id && n == 1) { zap_term(a->u.t); a->u.t = val; } else if (a->id == id) replace_term_attribute(a->next, id, val, n-1); else replace_term_attribute(a->next, id, val, n); } /* replace_term_attribute */ /************* * * replace_int_attribute() * *************/ /* DOCUMENTATION This routine replaces that n-th int attribute for given attribute ID.

    A fatal error occurs if the ID does not refer to an int type attribute (see register_attribute), or if there are not n attributes identified by ID. */ /* PUBLIC */ void replace_int_attribute(Attribute a, int id, int val, int n) { if (Attribute_names[id].type != INT_ATTRIBUTE) fatal_error("replace_int_attribute, bad ID"); if (a == NULL) fatal_error("replace_int_attribute, attribute not found"); else if (a->id == id && n == 1) { a->u.i = val; } else if (a->id == id) replace_int_attribute(a->next, id, val, n-1); else replace_int_attribute(a->next, id, val, n); } /* replace_int_attribute */ /************* * * get_term_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

    A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute). */ /* PUBLIC */ Term get_term_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("get_term_attribute, bad ID"); if (a == NULL) return NULL; else if (a->id == id && n == 1) return a->u.t; else if (a->id == id) return get_term_attribute(a->next, id, n-1); else return get_term_attribute(a->next, id, n); } /* get_term_attribute */ /************* * * get_term_attributes() * *************/ /* DOCUMENTATION This routine gets all attribute values (connect by symnum) associated with an attribute ID. If nothing matches, NULL is returned.

    A fatal error occurs if the ID does not refer to a Term type attribute (see register_attribute). */ /* PUBLIC */ Term get_term_attributes(Attribute a, int id) { if (Attribute_names[id].type != TERM_ATTRIBUTE) fatal_error("get_term_attribute, bad ID"); if (a == NULL) return NULL; else { Term t = get_term_attributes(a->next, id); if (a->id == id) { Term head = copy_term(a->u.t); if (t == NULL) t = head; else t = build_binary_term_safe(attrib_sym(), head, t); } return t; } } /* get_term_attributes */ /************* * * set_string_attribute() * *************/ /* DOCUMENTATION This routine appends an pair to a list of attributes. If the string is not already in the symbol table, it is inserted (which copies the string).

    A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute). */ /* PUBLIC */ Attribute set_string_attribute(Attribute a, int id, char *val) { if (Attribute_names[id].type != STRING_ATTRIBUTE) fatal_error("set_string_attribute, bad ID"); if (a == NULL) { int sn = str_to_sn(val, 0); /* insert into symbol table */ char *str = sn_to_str(sn); /* get the symbol table copy of string */ Attribute b = get_attribute(); b->id = id; b->u.s = str; return b; } else { a->next = set_string_attribute(a->next, id, val); return a; } } /* set_string_attribute */ /************* * * get_string_attribute() * *************/ /* DOCUMENTATION This routine gets the n-th (counting from 1) attribute value associated with an attribute ID. If nothing matches, NULL is returned.

    A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute). */ /* PUBLIC */ char *get_string_attribute(Attribute a, int id, int n) { if (Attribute_names[id].type != STRING_ATTRIBUTE) fatal_error("get_string_attribute, bad ID"); if (a == NULL) return NULL; else if (a->id == id && n == 1) return a->u.s; else if (a->id == id) return get_string_attribute(a->next, id, n-1); else return get_string_attribute(a->next, id, n); } /* get_string_attribute */ /************* * * string_attribute_member() * *************/ /* DOCUMENTATION This routine checks of a list of attributes contains a particular attribute/value.

    A fatal error occurs if the ID does not refer to a string type attribute (see register_attribute). */ /* PUBLIC */ BOOL string_attribute_member(Attribute a, int id, char *s) { if (Attribute_names[id].type != STRING_ATTRIBUTE) fatal_error("string_attribute_member, bad ID"); if (a == NULL) return FALSE; else if (a->id == id && str_ident(s, a->u.s)) return TRUE; else return string_attribute_member(a->next, id, s); } /* string_attribute_member */ /************* * * zap_attributes() * *************/ /* DOCUMENTATION This routine frees a list of attributes and any associated memory. In particular, the terms in term attributes are zapped. */ /* PUBLIC */ void zap_attributes(Attribute a) { if (a != NULL) { zap_attributes(a->next); /* If there is any memory associted with the attribure, free it here. */ if (attribute_type(a) == TERM_ATTRIBUTE) zap_term(a->u.t); free_attribute(a); } } /* zap_attributes */ /************* * * delete_attributes() * *************/ /* DOCUMENTATION This routine frees all attributes of the given type. */ /* PUBLIC */ Attribute delete_attributes(Attribute a, int id) { if (a == NULL) return NULL; else { a->next = delete_attributes(a->next, id); if (a->id == id) { Attribute b = a->next; /* If there is any memory associted with the attribure, free it here. */ if (attribute_type(a) == TERM_ATTRIBUTE) zap_term(a->u.t); free_attribute(a); return b; } else return a; } } /* delete_attributes */ /************* * * cat_att() * *************/ /* DOCUMENTATION Concatenate two lists of attributes. Either may be NULL. Return the result. */ /* PUBLIC */ Attribute cat_att(Attribute a, Attribute b) { if (a == NULL) return b; else { a->next = cat_att(a->next, b); return a; } } /* cat_att */ /************* * * build_attr_term() * *************/ /* DOCUMENTATION Given an attribute, build (and return) a term representation of it. The name of the attribute will be the (unary) function symbol, and the value will be the argument.

    This is typically used for printing attributes. */ /* PUBLIC */ Term build_attr_term(Attribute a) { char *name = attribute_name(a); Attribute_type type = attribute_type(a); Term t = get_rigid_term(name, 1); /* e.g., label(cl_32), answer(assoc) */ switch (type) { case INT_ATTRIBUTE: { char s[25]; if (a->u.i < 0) { ARG(t,0) = get_rigid_term("-", 1); ARG(ARG(t,0),0) = get_rigid_term(int_to_str(-(a->u.i), s, 25), 0); } else { ARG(t,0) = get_rigid_term(int_to_str(a->u.i, s, 25), 0); } break; } case STRING_ATTRIBUTE: ARG(t,0) = get_rigid_term(a->u.s, 0); break; case TERM_ATTRIBUTE: ARG(t,0) = copy_term(a->u.t); break; default: fatal_error("build_attr_term: bad attribute type"); } return t; } /* build_attr_term */ /************* * * attributes_to_term() * *************/ /* DOCUMENTATION This routine takes a list of attributes and constructs a term representation. It is a right-associated binary tree with Term forms of the attributes at the leaves. */ /* PUBLIC */ Term attributes_to_term(Attribute a, char *operator) { if (a == NULL) return NULL; /* should happen only on top call */ else if (a->next == NULL) return build_attr_term(a); else { return build_binary_term(str_to_sn(operator, 2), build_attr_term(a), attributes_to_term(a->next, operator)); } } /* attributes_to_term */ /************* * * cat_attributes() * *************/ static Attribute cat_attributes(Attribute a0, Attribute a1) { if (a0 == NULL) return a1; else { a0->next = cat_attributes(a0->next, a1); return a0; } } /* cat_attributes */ /************* * * attribute_name_to_id() * *************/ /* DOCUMENTATION Given an attribute name, return the attribute ID which is used for the "get" and "set" operations. Return -1 if the name has not been registered with "register_attribute". */ /* PUBLIC */ int attribute_name_to_id(char *name) { int i; for (i = 0; i < MAX_ATTRIBUTE_NAMES; i++) { if (Attribute_names[i].name != NULL && str_ident(Attribute_names[i].name, name)) return i; } return -1; } /* attribute_name_to_id */ /************* * * term_to_attributes() * *************/ /* DOCUMENTATION This routine takes a term representing a list of attributes and builds list of attributes. The input term form is a binary term, constructed with the given operator, with the attributes at the leaves. For example,

        label("hi there!") # answer(XGK(x,y,z)) # hint_wt(32)
    
    If anuthing goes wrong, a fatal error occurs. */ /* PUBLIC */ Attribute term_to_attributes(Term t, char *operator) { if (is_term(t, operator, 2)) { Attribute a0 = term_to_attributes(ARG(t,0), operator); Attribute a1 = term_to_attributes(ARG(t,1), operator); return cat_attributes(a0, a1); } else { int id; Attribute a; if (ARITY(t) != 1) fatal_error("term_to_attributes, arity not 1"); id = attribute_name_to_id(sn_to_str(SYMNUM(t))); if (id == -1) fatal_error("term_to_attributes, attribute name not found"); a = get_attribute(); a->id = id; switch (Attribute_names[id].type) { case INT_ATTRIBUTE: { int i; if (!term_to_int(ARG(t,0), &i)) fatal_error("term_to_attributes, bad integer"); a->u.i = i; break; } case STRING_ATTRIBUTE: if (!CONSTANT(ARG(t,0))) fatal_error("term_to_attributes, bad string"); else a->u.s = sn_to_str(SYMNUM(ARG(t,0))); break; case TERM_ATTRIBUTE: a->u.t = copy_term(ARG(t,0)); break; } return a; } } /* term_to_attributes */ /************* * * inheritable_att_instances() * *************/ /* DOCUMENTATION Given a list of attributes, this routine copies, instantiates, and returns the inheritable attributes. The Context can be NULL. */ /* PUBLIC */ Attribute inheritable_att_instances(Attribute a, Context subst) { if (a == NULL) return NULL; else if (!inheritable(a)) return inheritable_att_instances(a->next, subst); else { Attribute new = get_attribute(); new->id = a->id; new->u.t = subst ? apply(a->u.t, subst) : copy_term(a->u.t); new->next = inheritable_att_instances(a->next, subst); return new; } } /* inheritable_att_instances */ /************* * * copy_attributes() * *************/ /* DOCUMENTATION This routine copies a list of attributes. */ /* PUBLIC */ Attribute copy_attributes(Attribute a) { if (a == NULL) return NULL; else { Attribute new = get_attribute(); new->id = a->id; switch (attribute_type(a)) { case INT_ATTRIBUTE: new->u.i = a->u.i; break; case STRING_ATTRIBUTE: new->u.s = a->u.s; break; case TERM_ATTRIBUTE: new->u.t = copy_term(a->u.t); break; default: fatal_error("copy_attribute: unknown attribute"); } new->next = copy_attributes(a->next); return new; } } /* copy_attributes */ /************* * * instantiate_inheritable_attributes() * *************/ /* DOCUMENTATION This routine */ /* PUBLIC */ void instantiate_inheritable_attributes(Attribute a, Context subst) { Attribute b; for (b = a; b; b = b->next) { if (attribute_type(b) == TERM_ATTRIBUTE && inheritable(b)) { Term t = apply(b->u.t, subst); zap_term(b->u.t); b->u.t = t; } } } /* instantiate_inheritable_attributes */ /************* * * renumber_vars_attributes() * *************/ /* DOCUMENTATION This routine renumbers the variables in the inheritable attribute terms. */ /* PUBLIC */ void renumber_vars_attributes(Attribute attrs, int vmap[], int max_vars) { Attribute a; for (a = attrs; a; a = a->next) { if (inheritable(a)) { a->u.t = renum_vars_recurse(a->u.t, vmap, max_vars); } } } /* renumber_vars_attributes */ /************* * * set_vars_attributes() * *************/ /* DOCUMENTATION This routine sets the variables in the inheritable attribute terms. */ /* PUBLIC */ void set_vars_attributes(Attribute attrs, char *vnames[], int max_vars) { Attribute a; for (a = attrs; a; a = a->next) { if (inheritable(a)) { a->u.t = set_vars_recurse(a->u.t, vnames, max_vars); } } } /* set_vars_attributes */ /************* * * vars_in_attributes(attrs) * *************/ /* DOCUMENTATION This routine returns the set of variables (as a Plist) in the inheritable attributes. */ /* PUBLIC */ Plist vars_in_attributes(Attribute attrs) { Plist vars = NULL; Attribute a; for (a = attrs; a; a = a->next) { if (inheritable(a)) { vars = set_of_vars(a->u.t, vars); } } return vars; } /* vars_in_attributes */ /************* * * label_att() * *************/ /* DOCUMENTATION Return the attribute identifier for label attributes. If it does not exist, return -1. */ /* PUBLIC */ int label_att(void) { int i; for (i = 0; i < MAX_ATTRIBUTE_NAMES; i++) { if (Attribute_names[i].type == STRING_ATTRIBUTE && str_ident(Attribute_names[i].name, "label")) return i; } return -1; } /* label_att */ /************* * * attributes_contain_variables() * *************/ /* DOCUMENTATION Does the list of attributes contain a Term attribute that contains a constant that looks like a variable? */ /* PUBLIC */ BOOL attributes_contain_variables(Attribute a) { if (a == NULL) return FALSE; else if (attributes_contain_variables(a->next)) return TRUE; else if (attribute_type(a) != TERM_ATTRIBUTE) return FALSE; else { Term t = a->u.t; Plist p = free_vars_term(t, NULL); BOOL contains_vars = (p != NULL); zap_plist(p); return contains_vars; } } /* attributes_contain_variables */ /************* * * copy_int_attribute() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Attribute copy_int_attribute(Attribute source, Attribute dest, int attr_id) { int i = 1; int val; while ((val = get_int_attribute(source, attr_id, i)) != INT_MAX) { dest = set_int_attribute(dest, attr_id, val); i++; } return dest; } /* copy_int_attribute */ /************* * * copy_string_attribute() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Attribute copy_string_attribute(Attribute source, Attribute dest, int attr_id) { int i = 1; char *val; while ((val = get_string_attribute(source, attr_id, i))) { dest = set_string_attribute(dest, attr_id, val); i++; } return dest; } /* copy_string_attribute */ /************* * * copy_term_attribute() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Attribute copy_term_attribute(Attribute source, Attribute dest, int attr_id) { int i = 1; Term val; while ((val = get_term_attribute(source, attr_id, i))) { dest = set_term_attribute(dest, attr_id, copy_term(val)); i++; } return dest; } /* copy_term_attribute */ LADR-2009-11A/ladr/tptp_trans.c0000644000175000017500000005377711222177600015323 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "tptp_trans.h" /* Private definitions and types */ /* From Geoff Sutcliffe, Feb 13, 2008: %----These are used in the TPTP and need to exist before the %----transformations and formats are loaded. They are also declared at %----runtime in tptp2X/4. :-op(99,fx,'$'). :-op(100,fx,++). :-op(100,fx,--). %----Postfix for != :-op(100,xf,'!'). %---- .. used for range in tptp2X. Needs to be stronger than : :-op(400,xfx,'..'). %----! and ? are of higher precedence than : so ![X]:p(X) is :(![X],p(X)) %----Otherwise ![X]:![Y]:p(X,Y) cannot be parsed. %----! is fy so Prolog can read !! (blah) as !(!(blah)) and it gets fixed :-op(400,fy,!). :-op(400,fx,?). :-op(400,fx,^). :-op(400,fx,:=). :-op(400,fx,'!!'). :-op(400,fx,'??'). %----= must bind more tightly than : for ! [X] : a = X. = must binder looser %----than quantifiers for otherwise X = ! [Y] : ... is a syntax error (the = %----grabs the quantifier). That means for thf it is necessary to bracket %----formula terms, e.g., a = (! [X] : p(X)) :-op(405,xfx,'='). %---!= not possible because ! is special - see postfix cheat :-op(405,xfx,'!='). :-op(440,xfy,>). %----Type arrow %----Need : stronger than binary connectives for ! [X] : p(X) <=> !Y ... %----Need ~ and : equal and right-assoc for ![X] : ~p and for ~![X] : ... :-op(450,xfy,:). :-op(450,fy,~). :-op(501,yfx,@). :-op(502,xfy,'|'). :-op(502,xfy,'~|'). :-op(502,xfy,'+'). %----Fision for rfof :-op(503,xfy,&). :-op(503,xfy,~&). :-op(503,xfy,'*'). %----Fusion for rfof :-op(504,xfy,=>). :-op(504,xfy,<=). :-op(505,xfy,<=>). :-op(505,xfy,<~>). %----Must be weak to allow any formulae on RHS :-op(550,xfy,:=). -------------------------------------------------------- Correction from Geoff, May 14, 2008: op(502,xfx,'~|'), op(503,xfx,~&), op(504,xfx,=>), op(504,xfx,<=), op(505,xfx,<=>), op(505,xfx,<~>), op(550,xfx,:=). -------------------------------------------------------- From Geoff, October 6, 2008: I would be quite happy if both [input and output] were equally strict, conforming to the TPTP BNF. However, your other users might be happier if the input were a little more forgiving, and that's why my Prolog operator defs are like they are - more forgiving than the BNF. I guess you have the following at the moment, which are the "forgiving" operator defs ... op(400,fy,!), op(400,fx,?), op(405,xfx,'='), op(450,xfy,:), op(450,fy,~), op(502,xfy,'|'), op(502,xfx,'~|'), op(503,xfy,&), op(503,xfx,~&), op(504,xfx,=>), op(504,xfx,<=), op(505,xfx,<=>), op(505,xfx,<~>), Indeed, I solved the current issue by reading your output with my Prolog tool, whose parsing uses those defs, but whose output routines are hand rolled to output in strict TPTP format. For output, or generally strict, you can set all the binary connectives to the same precedence, e.g., ... op(502,xfy,'|'), op(502,xfx,'~|'), op(502,xfy,&), op(502,xfx,~&), op(502,xfx,=>), op(502,xfx,<=), op(502,xfx,<=>), op(502,xfx,<~>), Note the | and & are xfy, which allows, e.g., (a | b | c | d). -------------------------------------------------------- WWM: Ok, I'll separate the types for parsing TPTP and printing TPTP. Parsing TPTP will be flexible, pretty much as before. Printing will be conservative, using Geoff's second set of op defs above, with the exception that & and | will be INFIX instead of INFIX_RIGHT, (because LADR does not allow different parse types with same precedence). So we'll print, e.g., (a & (b & c)) => (d | (e | f)), whereas the TPTP string a & b & c => d | e | f wil be parsed correctly as the same term. Also, for ladr_to_tptp, I'll add an command-line option -p that will cause ALL expressions to be parenthesized. */ /************* * * declare_tptp_input_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_tptp_input_types(void) { check_for_illegal_symbols(FALSE); /* get around the "--" problem */ /* We do not support all of the TPTP operations listed above. */ declare_parse_type(",", 999, INFIX_RIGHT); /* LADR requirement */ declare_parse_type("++", 100, PREFIX_PAREN); declare_parse_type("--", 100, PREFIX_PAREN); declare_parse_type("!", 400, PREFIX_PAREN); declare_parse_type("?", 400, PREFIX_PAREN); declare_parse_type("!=", 405, INFIX); /* added by McCune */ declare_parse_type("=", 405, INFIX); declare_parse_type("~", 410, PREFIX); /* changed by McCune */ declare_parse_type(":", 450, INFIX_RIGHT); declare_parse_type("|", 502, INFIX_RIGHT); declare_parse_type("&", 503, INFIX_RIGHT); declare_parse_type("=>", 504, INFIX); declare_parse_type("<=", 504, INFIX); declare_parse_type("<=>", 505, INFIX); declare_parse_type("<~>", 505, INFIX); /* Other things */ set_cons_char('\0'); /* Don't recognize list cons */ } /* declare_tptp_input_types */ /************* * * declare_tptp_output_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_tptp_output_types(void) { check_for_illegal_symbols(FALSE); /* get around the "--" problem */ /* We do not support all of the TPTP operations listed above. */ declare_parse_type(",", 999, INFIX_RIGHT); /* LADR requirement */ declare_parse_type("++", 100, PREFIX_PAREN); declare_parse_type("--", 100, PREFIX_PAREN); declare_parse_type("!", 400, PREFIX_PAREN); declare_parse_type("?", 400, PREFIX_PAREN); declare_parse_type("!=", 405, INFIX); /* added by McCune */ declare_parse_type("=", 405, INFIX); declare_parse_type("~", 410, PREFIX); /* changed by McCune */ declare_parse_type(":", 450, INFIX_RIGHT); declare_parse_type("|", 502, INFIX); /* NOTE: not INFIX_RIGHT (xfy) */ declare_parse_type("&", 502, INFIX); /* NOTE: not INFIX_RIGHT (xfy) */ declare_parse_type("=>", 502, INFIX); declare_parse_type("<=", 502, INFIX); declare_parse_type("<=>", 502, INFIX); declare_parse_type("<~>", 502, INFIX); /* Other things */ set_cons_char('\0'); /* Don't recognize list cons */ } /* declare_tptp_output_types */ /***************************************************************************** This first part is for the TPTP to LADR transformation *****************************************************************************/ /************* * * tptp2_to_ladr_term() * * Take a TPTP "input_clause" transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp2_to_ladr_term(Term t) { Term f = NULL; if (!proper_listterm(t)) { p_term(t); fatal_error("tptp2_to_ladr_term, expected list of literals"); } t = listterm_reverse(t); /* so the result is in the same order */ while (cons_term(t)) { Term a0 = ARG(t,0); Term lit = NULL; if (is_term(a0, "++", 1) || is_term(a0, "--", 1)) { Term atom = ARG(a0, 0); if (is_term(atom, "equal", 2)) { Term tmp = build_binary_term_safe(eq_sym(), ARG(atom,0), ARG(atom,1)); free_term(atom); /* shallow */ atom = tmp; } if (is_term(a0, "++", 1)) lit = atom; else lit = build_unary_term_safe(not_sym(), atom); } else { p_term(a0); fatal_error("tptp2_to_ladr_term, unknown literal"); } if (f == NULL) f = lit; else f = build_binary_term_safe(or_sym(), lit, f); t = ARG(t,1); } return f; } /* tptp2_to_ladr_term */ /************* * * tptp3_to_ladr_term() * * Take a TPTP "cnf" or "fof", and transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp3_to_ladr_term(Term t) { if (is_term(t, "$true", 0)) { free_term(t); return get_rigid_term(true_sym(), 0); } else if (is_term(t, "$false", 0)) { free_term(t); return get_rigid_term(false_sym(), 0); } else if (is_term(t, "~", 1)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term t2 = build_unary_term_safe(not_sym(), a0); free_term(t); return t2; } else if (is_term(t, "|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(imp_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(impby_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "~&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "~|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "<~>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, ":", 2)) { /* Assume it's well formed (don't check for errors). */ Term q = ARG(t,0); Term form = tptp3_to_ladr_term(ARG(t,1)); Term vars = listterm_reverse(ARG(q,0)); char *quant; if (!proper_listterm(vars)) fatal_error("tptp_to_ladr: bad quantified variable(s)"); quant = (is_term(q,"!",1) ? all_sym() : exists_sym()); while (cons_term(vars)) { Term v = ARG(vars, 0); Term new = get_rigid_term(quant_sym(), 3); ARG(new,0) = get_rigid_term(quant, 0); ARG(new,1) = copy_term(v); ARG(new,2) = form; form = new; vars = ARG(vars, 1); } zap_term(vars); free_term(t); free_term(q); return form; } else return t; } /* tptp3_to_ladr_term */ /************* * * tptp_input_to_ladr_formula() * * The input Term t is not modified by the call. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula tptp_input_to_ladr_formula(Term t) { char *type = sn_to_str(SYMNUM(t)); Term name = ARG(t,0); Term role = ARG(t,1); Term form = NULL; Term a, b; Formula f; if (str_ident(type, "fof") || str_ident(type, "cnf")) form = tptp3_to_ladr_term(copy_term(ARG(t,2))); else if (str_ident(type, "input_clause")) form = tptp2_to_ladr_term(copy_term(ARG(t,2))); else { p_term(t); fatal_error("tptp_formlua: unknown type"); } a = build_binary_term_safe(attrib_sym(), build_unary_term_safe("label", copy_term(name)), build_unary_term_safe("label", copy_term(role))); b = build_binary_term_safe(attrib_sym(), form, a); f = term_to_formula(b); zap_term(b); return f; } /* tptp_input_to_ladr_formula */ /***************************************************************************** This first part is for the LADR to TPTP transformation *****************************************************************************/ /************* * * rename_vars_to_upper() * *************/ static void rename_vars_to_upper(Formula f) { int i; if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); int sn = fresh_symbol("X", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); free_term(newvar); } for (i = 0; i < f->arity; i++) rename_vars_to_upper(f->kids[i]); } /* rename_vars_to_upper */ /************* * * ladr_term_to_tptp_term() * *************/ static Term ladr_term_to_tptp_term(Term t) { if (is_term(t, true_sym(), 0)) { free_term(t); return get_rigid_term("$true", 0); } else if (is_term(t, false_sym(), 0)) { free_term(t); return get_rigid_term("$false", 0); } else if (is_term(t, not_sym(), 1)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term t2 = build_unary_term_safe("~", a0); free_term(t); return t2; } else if (is_term(t, or_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("|", a0, a1); free_term(t); return t2; } else if (is_term(t, and_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("&", a0, a1); free_term(t); return t2; } else if (is_term(t, imp_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("=>", a0, a1); free_term(t); return t2; } else if (is_term(t, impby_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=", a0, a1); free_term(t); return t2; } else if (is_term(t, iff_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=>", a0, a1); free_term(t); return t2; } else if (is_term(t, quant_sym(), 3)) { Term quant = ARG(t,0); Term var = ARG(t,1); Term form = ladr_term_to_tptp_term(ARG(t,2)); char *q = is_term(quant, "all", 0) ? "!" : "?"; /* build the term :(quant([var]),form) */ Term vlist = listterm_cons(var, get_nil_term()); Term qterm = build_unary_term_safe(q, vlist); Term top = build_binary_term_safe(":", qterm, form); free_term(quant); /* shallow */ return top; } else return t; } /* ladr_term_to_tptp_term */ /************* * * ladr_list_to_tptp_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist ladr_list_to_tptp_list(Plist in, char *name, char *type) { BOOL goal = str_ident(type, "conjecture"); /* goals always become fof */ Plist out = NULL; Plist p; for (p = in; p; p = p->next) { Formula f = p->v; f->attributes = NULL; /* always remove all attributes */ if (clausal_formula(f) && !goal) { Term t, cnf; Topform c = formula_to_clause(f); zap_formula(f); clause_set_variables(c, MAX_VARS); t = ladr_term_to_tptp_term(topform_to_term(c)); zap_topform(c); cnf = get_rigid_term("cnf", 3); ARG(cnf,0) = get_rigid_term(name, 0); ARG(cnf,1) = get_rigid_term(type, 0); ARG(cnf,2) = t; out = plist_prepend(out, cnf); } else { /* f is a non-clausal formula */ Term t, fof; f = universal_closure(f); rename_vars_to_upper(f); t = ladr_term_to_tptp_term(formula_to_term(f)); fof = get_rigid_term("fof", 3); ARG(fof,0) = get_rigid_term(name, 0); ARG(fof,1) = get_rigid_term(type, 0); ARG(fof,2) = t; out = plist_prepend(out, fof); } } return reverse_plist(out); } /* ladr_list_to_tptp_list */ /************* * * syms_in_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist syms_in_form(Term t, BOOL clausal) { if (clausal) { if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), TRUE); else if (is_term(t, "|", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else if (is_term(t, "$true", 0) || is_term(t, "$false", 0)) return NULL; else return fsym_set_in_term(t); } else { /* non-clausal */ if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), FALSE); else if (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else if (is_term(t, ":", 2)) { /* This assumes exactly one universally quantified variable! */ Ilist a = syms_in_form(ARG(t,1), FALSE); a = ilist_removeall(a, SYMNUM(ARG(ARG(ARG(t,0),0),0))); return a; } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else if (is_term(t, "$true", 0) || is_term(t, "$false", 0)) return NULL; else return fsym_set_in_term(t); } } /* syms_in_form */ /************* * * good_tptp_sym() * *************/ static BOOL good_tptp_sym(char *s) { if (strlen(s) == 0) return FALSE; else { /* [a-z][a-zA-Z0-9_]* */ if (!(s[0] >= 'a' && s[0] <= 'z')) return FALSE; else { int i; for (i = 1; i < strlen(s); i++) { char c = s[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) return FALSE; } return TRUE; } } } /* good_tptp_sym */ /************* * * good_ladr_sym() * *************/ static BOOL good_ladr_sym(char *s) { return s[0] != '\''; } /* good_ladr_sym */ /************* * * map_for_bad_tptp_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list map_for_bad_tptp_syms(Ilist syms, BOOL quote_bad_syms) { if (syms == NULL) return NULL; else { I2list map = map_for_bad_tptp_syms(syms->next, quote_bad_syms); int old_sn = syms->i; char *s = sn_to_str(old_sn); if (!good_tptp_sym(s)) { int new_sn; if (quote_bad_syms) { char *escaped = escape_char(s, '\''); int n = strlen(escaped); char *new_str = malloc(n+3); new_str[0] = '\''; strcpy(new_str+1, escaped); new_str[n+1] = '\''; new_str[n+2] = '\0'; new_sn = str_to_sn(new_str, sn_to_arity(old_sn)); free(new_str); free(escaped); } else new_sn = fresh_symbol("tptp", sn_to_arity(old_sn)); map = i2list_append(map, old_sn, new_sn); } return map; } } /* map_for_bad_tptp_syms */ /************* * * map_for_bad_ladr_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list map_for_bad_ladr_syms(Ilist syms, BOOL quote_bad_syms) { if (syms == NULL) return NULL; else { I2list map = map_for_bad_ladr_syms(syms->next, quote_bad_syms); int old_sn = syms->i; char *s = sn_to_str(old_sn); if (!good_ladr_sym(s)) { int new_sn; if (quote_bad_syms) { char *escaped = escape_char(s, '"'); int n = strlen(escaped); char *new_str = malloc(n+3); new_str[0] = '"'; strcpy(new_str+1, escaped); new_str[n+1] = '"'; new_str[n+2] = '\0'; new_sn = str_to_sn(new_str, sn_to_arity(old_sn)); free(new_str); free(escaped); } else new_sn = fresh_symbol("ladr", sn_to_arity(old_sn)); map = i2list_append(map, old_sn, new_sn); } return map; } } /* map_for_bad_ladr_syms */ /************* * * replace_bad_syms_term() * *************/ /* DOCUMENTATION The given term is used up. */ /* PUBLIC */ Term replace_bad_syms_term(Term t, I2list map) { if (VARIABLE(t)) return t; else { int i; int old_sn = SYMNUM(t); int new_sn = assoc(map, old_sn); if (new_sn != INT_MIN) { Term new = get_rigid_term(sn_to_str(new_sn), sn_to_arity(new_sn)); for (i = 0; i < ARITY(t); i++) ARG(new,i) = ARG(t,i); free_term(t); /* shallow */ t = new; } for (i = 0; i < ARITY(t); i++) ARG(t,i) = replace_bad_syms_term(ARG(t,i), map); return t; } } /* replace_bad_syms_term */ /************* * * replace_bad_tptp_syms_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term replace_bad_tptp_syms_form(Term t, BOOL clausal, I2list map) { if (is_term(t, "~", 1)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), clausal, map); return t; } else if (clausal && is_term(t, "|", 2)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), TRUE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), TRUE, map); return t; } else if (!clausal && (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2))) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), FALSE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else if (!clausal && is_term(t, ":", 2)) { /* We do not have to worry about quantified variables being replaced---they are disjoint from all other symbols, because they were generted by fresh_symbol(). */ ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else return replace_bad_syms_term(t, map); } /* replace_bad_tptp_syms_form */ LADR-2009-11A/ladr/multiset.h0000644000175000017500000000216111151265363014762 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_MULTISET_H #define TP_MULTISET_H #include "term.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from multiset.c */ BOOL greater_multiset(Term a1[], int n1, Term a2[], int n2, BOOL (*comp_proc) (Term, Term, BOOL), BOOL lex_order_vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/btu.c0000644000175000017500000010555410637466321013720 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "btu.h" /* Private definitions and types */ #define MAX_ACU_ARGS 500 typedef struct ac_position * Ac_position; struct ac_position { int m, n, num_basis; /* # of coefficients and size of basis */ int basis[MAX_BASIS][MAX_COEF]; int constraints[MAX_COEF]; /* 0 for vars, else symbol number */ Term args[MAX_COEF]; Context arg_contexts[MAX_COEF]; Term new_terms[MAX_COEF]; /* substitution terms */ int combo[MAX_BASIS]; /* current subset of basis solutions */ int sum[MAX_COEF]; /* solution corresponding to combo */ Term basis_terms[MAX_BASIS][MAX_COEF]; Context c3; /* table for new variables */ Btu_state sub_position; /* position in sub-unification problem */ int superset_limit; /* for superset-restricted AC unif. */ int combos[MAX_COMBOS][MAX_BASIS];/* for superset-restricted AC unif. */ int combos_remaining; /* for superset-restricted AC unif. */ Ac_position next; /* for avail list only */ }; struct btu_state { Btu_state parent, next, prev, first_child, last_child; Term t1, t2; /* terms being unified or matched */ Context c1, c2; /* respective contexts for variables */ int varnum; /* for unbinding when backtracking */ Context cb; /* for unbinding when backtracking */ Unif_alternative alternative; /* type of alternative (position) */ /* for commutative unification */ int flipped; Btu_state position_bt; /* in sequence of alternatives */ /* for AC unification */ Ac_position ac; /* in sequence of AC unifiers */ }; /* #define DEBUG */ #define GO 1 #define SUCCESS 2 #define EXHAUSTED 4 #define FAILURE 3 #define POP 5 #define BACKTRACK 6 /******** bind a variable, record binding in a bt_node ********/ #define BIND_BT(i, c1, t2, c2, bt) { \ c1->terms[i] = t2; c1->contexts[i] = c2; \ bt->varnum = i; bt->cb = c1; } /* reference for mutual recursion */ static Btu_state unify_bt_guts(Btu_state bt1); /* * memory management */ #define PTRS_BTU_STATE PTRS(sizeof(struct btu_state)) static unsigned Btu_state_gets, Btu_state_frees; #define PTRS_AC_POSITION PTRS(sizeof(struct ac_position)) static unsigned Ac_position_gets, Ac_position_frees; /************* * * Btu_state get_btu_state() * *************/ static Btu_state get_btu_state(void) { Btu_state p = get_cmem(PTRS_BTU_STATE); p->varnum = -1; Btu_state_gets++; return(p); } /* get_btu_state */ /************* * * free_btu_state() * *************/ static void free_btu_state(Btu_state p) { free_mem(p, PTRS_BTU_STATE); Btu_state_frees++; } /* free_btu_state */ /************* * * Ac_position get_ac_position() * *************/ static Ac_position get_ac_position(void) { Ac_position p = get_cmem(PTRS_AC_POSITION); Ac_position_gets++; return(p); } /* get_ac_position */ /************* * * free_ac_position() * *************/ static void free_ac_position(Ac_position p) { free_mem(p, PTRS_AC_POSITION); Ac_position_frees++; } /* free_ac_position */ /************* * * fprint_btu_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the btu package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_btu_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct btu_state); fprintf(fp, "btu_state (%4d) %11u%11u%11u%9.1f K\n", n, Btu_state_gets, Btu_state_frees, Btu_state_gets - Btu_state_frees, ((Btu_state_gets - Btu_state_frees) * n) / 1024.); n = sizeof(struct ac_position); fprintf(fp, "ac_position (%4d)%11u%11u%11u%9.1f K\n", n, Ac_position_gets, Ac_position_frees, Ac_position_gets - Ac_position_frees, ((Ac_position_gets - Ac_position_frees) * n) / 1024.); } /* fprint_btu_mem */ /************* * * p_btu_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the btu package. */ /* PUBLIC */ void p_btu_mem() { fprint_btu_mem(stdout, TRUE); } /* p_btu_mem */ /* * end of memory management */ /************* * * p_binding() * *************/ #if 0 static void p_binding(int vnum, Context vc, Term t, Context tc) { Term vt, ti; vt = get_variable_term(vnum); ti = apply(vt, vc); printf("["); fprint_term(stdout,vt); printf(",0x%x:%d] -> [", (unsigned) vc, vc->multiplier); fprint_term(stdout,t); printf(",0x%x:%d] (", (unsigned) tc, tc->multiplier); fprint_term(stdout,ti); printf(")\n"); free_term(vt); free_term(ti); } /* p_binding */ #endif /************* * * flatten_deref * * Given a term (t) with AC symbol and a context (tc), fill in an * array (a) with the flattened arguments. Variable arguments are * dereferenced, and a second array (ac) is filled in with the * corresponding contexts. The given term is not changed. * The index (*ip) must be initialized by the calling routine. * * Note: the objects being manipulated are pairs , * where the context determines the values of the variables in the term. * If context is NULL, the variables are treated as constants. * *************/ static void flatten_deref(Term t, Context tc, Term *a, Context *ac, int *ip) { Term t1; Context c1; int sn, i; sn = SYMNUM(t); for (i = 0; i < ARITY(t); i++) { t1 = ARG(t,i); c1 = tc; DEREFERENCE(t1, c1); if (SYMNUM(t1) == sn) flatten_deref(t1, c1, a, ac, ip); else { if (*ip >= MAX_ACU_ARGS) { p_term(t1); fatal_error("flatten_deref, too many arguments."); } else { a[*ip] = t1; ac[*ip] = c1; } (*ip)++; } } } /* flatten_deref(t) */ /************* * * compare_ncv_context -- compare terms, taking context into account. * * Compare terms. NAME < COPMLEX < VARIABLE. * Constants by symbol; complex lexicographically; vars by (context,varnum) * Ignore AC symbols. * * Return LESS_THAN, SAME_AS, or GREATER_THAN. * *************/ static int compare_ncv_context(Term t1, Term t2, Context c1, Context c2) { int rc, m1, m2; if (CONSTANT(t1) && !CONSTANT(t2)) rc = LESS_THAN; else if (!CONSTANT(t1) && CONSTANT(t2)) rc = GREATER_THAN; else if (COMPLEX(t1) && VARIABLE(t2)) rc = LESS_THAN; else if (VARIABLE(t1) && COMPLEX(t2)) rc = GREATER_THAN; /* Now we know they are the same type. */ else if VARIABLE(t1) { /* both variables */ m1 = (c1 ? c1->multiplier : INT_MIN); m2 = (c2 ? c2->multiplier : INT_MIN); if (m1 < m2) rc = LESS_THAN; else if (m1 > m2) rc = GREATER_THAN; else if (VARNUM(t1) < VARNUM(t2)) rc = LESS_THAN; else if (VARNUM(t1) > VARNUM(t2)) rc = GREATER_THAN; else rc = SAME_AS; } else { if (SYMNUM(t1) < SYMNUM(t2)) rc = LESS_THAN; else if (SYMNUM(t1) > SYMNUM(t2)) rc = GREATER_THAN; else { int i; for (i = 0, rc = SAME_AS; i < ARITY(t1) && rc == SAME_AS; i++) rc = compare_ncv_context(ARG(t1,i), ARG(t2,i), c1, c2); } } return(rc); } /* compare_ncv_context */ /************* * * sort_ac(a, c, n) * * Sort an array of terms and their associated contexts. * I intend for the number of terms to be small, so this is * a quadratic sort. * *************/ static void sort_ac(Term *a, Context *c, int n) { int i, j, min_i; Term min_t; Context min_c; for (i = 0; i < n-1; i++) { min_t = a[i]; min_c = c[i]; min_i = i; for (j = i+1; j < n; j++) { if (compare_ncv_context(a[j], min_t, c[j], min_c) == LESS_THAN) { min_t = a[j]; min_c = c[j]; min_i = j; } } if (min_i != i) { a[min_i] = a[i]; a[i] = min_t; c[min_i] = c[i]; c[i] = min_c; } } } /* sort_ac */ /************* * * void elim_con_context * * Eliminate common terms, taking context into account. * Eliminated terms are just set to NULL. * *************/ static void elim_con_context(Term *a1, Term *a2, Context *c1, Context *c2, int n1, int n2) { int i1, i2, rc; i1 = i2 = 0; while (i1 < n1 && i2 < n2) { rc = compare_ncv_context(a1[i1], a2[i2], c1[i1], c2[i2]); if (rc == SAME_AS) { a1[i1] = NULL; c1[i1] = NULL; i1++; a2[i2] = NULL; c2[i2] = NULL; i2++; } else if (rc == LESS_THAN) i1++; else i2++; } } /* elim_con_context */ /************* * * void ac_mult_context * * With an array of terms, eliminate NULL positions, and collapse * duplicates into one, building a corresponding array of multiplicities. * *************/ static void ac_mult_context(Term *a, Context *c, int *mults, int *np) { int it, im, i, m, j, n; n = *np; im = 0; it = 0; while (it < n) { if (!a[it]) it++; else { i = it+1; m = 1; while (i < n && a[i] && compare_ncv_context(a[it], a[i], c[it], c[i]) == SAME_AS) { a[i] = NULL; c[i] = NULL; m++; i++; } mults[im++] = m; it = i; } } for (i = n-1; i >= 0; i--) { if (!a[i]) { for (j = i; j < n-1; j++) { a[j] = a[j+1]; c[j] = c[j+1]; } n--; } } if (n != im) { fatal_error("in ac_mult_context, n!=im."); } *np = n; } /* ac_mult_context */ /************* * * ac_prepare * * Final preparation for diophantine solver. Fill in the arrays: * * ab - coefficients for both terms * constraints - 0 for variable with context * -(varnum+1) for variable w/o context (unbindable) * else symbol number * terms the arguments * contexts contexts for arguments * *************/ static void ac_prepare(Term *a1, Term *a2, Context *c1, Context *c2, int *mults1, int *mults2, int n1, int n2, int *ab, int *constraints, Term *terms, Context *contexts) { int i; if (n1+n2 > MAX_COEF) { fatal_error("ac_prepare, too many arguments."); } for (i = 0; i < n1; i++) { ab[i] = mults1[i]; if (VARIABLE(a1[i])) constraints[i] = (c1[i] ? 0 : (-VARNUM(a1[i])) - 1); else constraints[i] = SYMNUM(a1[i]); terms[i] = a1[i]; contexts[i] = c1[i]; } for (i = 0; i < n2; i++) { ab[i+n1] = mults2[i]; if (VARIABLE(a2[i])) constraints[i+n1] = (c2[i] ? 0 : (-VARNUM(a2[i])) - 1); else constraints[i+n1] = SYMNUM(a2[i]); terms[i+n1] = a2[i]; contexts[i+n1] = c2[i]; } } /* ac_prepare */ /************* * * set_up_basis_terms * * Given the basis solutions, fill in a corresponding array of * partial terms to be used for building substitutions. * This is done once for the basis, to avoid rebuilding the terms * for each subset. * * NOTE: the terms are not well-formed. Each has form f(ti,NULL), * so that it's quick to make, e.g., f(t1,f(t2,f(t3,t4))). * *************/ static void set_up_basis_terms(int sn, int (*basis)[MAX_COEF], int num_basis, int length, Term (*basis_terms)[MAX_COEF]) { Term t1, t2, t3; int i, j, k; for (i = 0; i < num_basis; i++) for (j = 0; j < length; j++) { if (basis[i][j] == 0) basis_terms[i][j] = NULL; else { t1 = get_variable_term(i); for (k = 2; k <= basis[i][j]; k++) { t2 = get_variable_term(i); t3 = get_rigid_term_dangerously(sn, 2); ARG(t3,0) = t2; ARG(t3,1) = t1; t1 = t3; } t2 = get_rigid_term_dangerously(sn, 2); ARG(t2,0) = t1; ARG(t2,1) = NULL; basis_terms[i][j] = t2; } } } /* set_up_basis_terms */ /************* * * unify_ac * * Associative-commutative Unification. t1 and t2 have the same ac symbol. * (t1, c1, t2, c2, are dereferenced terms from bt.) * * If c1 and c2 are different they must have different multipliers!!! * *************/ /* DOCUMENTATION This routine gets the first or next AC unifier for a pair of terms. This is mutually recursive with unify_bt_guts() and unify_bt_next() for sub-unification problems. The top calls are made to the backtrack unification routines unify_bt_first(), and unify_bt_next(). */ static int unify_ac(Term t1, Context c1, Term t2, Context c2, struct btu_state *bt) { Term t3, t4, ti; Btu_state sub_problems, bt2, bt3; Ac_position ac; Term a1[MAX_ACU_ARGS], a2[MAX_ACU_ARGS]; Context ac1[MAX_ACU_ARGS], ac2[MAX_ACU_ARGS], ci; int mults1[MAX_ACU_ARGS], mults2[MAX_ACU_ARGS]; int ab[MAX_COEF], num_basis, n1, n2; int i, j, length, vn, ok, status; Unif_alternative continuation; num_basis = length = 0; /* to quiet compiler */ continuation = bt->alternative; if (continuation == NO_ALT) { /* If first call, set up dioph eq and solve. */ /* Stats[AC_INITIATIONS]++; */ bt->alternative = AC_ALT; ac = get_ac_position(); bt->ac = ac; ac->c3 = get_context(); ac->superset_limit = -1; /* Parms[AC_SUPERSET_LIMIT].val; */ #ifdef DEBUG printf("\nunify_ac, new problem:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); #endif n1 = 0; flatten_deref(t1,c1,a1,ac1,&n1); /* put args in a1, incl. deref */ sort_ac(a1, ac1, n1); /* sort args */ n2 = 0; flatten_deref(t2,c2,a2,ac2,&n2); sort_ac(a2, ac2, n2); elim_con_context(a1, a2, ac1, ac2, n1, n2); /* elim. common terms */ ac_mult_context(a1, ac1, mults1, &n1); /* get multiplicity */ ac_mult_context(a2, ac2, mults2, &n2); if (n1 == 0 && n2 == 0) { /* Input terms are identical modulo AC. */ /* Succeed with no alternatives. */ free_context(ac->c3); free_ac_position(bt->ac); bt->ac = NULL; bt->alternative = NO_ALT; status = SUCCESS; } else { ac_prepare(a1, a2, ac1, ac2, mults1, mults2, n1, n2, ab, ac->constraints, ac->args, ac->arg_contexts); ok = dio(ab,n1,n2,ac->constraints,ac->basis,&(ac->num_basis)); num_basis = ac->num_basis; length = n1 + n2; if (ok == 1 && num_basis > 0) { /* if solutions, store data in ac_position */ ac->m = n1; ac->n = n2; /* prepare for combination search */ set_up_basis_terms(SYMNUM(t1), ac->basis, num_basis, n1+n2, ac->basis_terms); status = GO; } else { status = FAILURE; if (ok == -1) { printf("basis too big for %d %d.\n", n1, n2); #if 0 fprint_term(stdout, t1); printf(" "); fprint_term(stdout, t2); printf("\n"); p_ac_basis(ac->basis, ac->num_basis, n1, n2); /* print out args2 */ for (i = 0; i < n2; i++) fprint_term(stdout, a2[i]); exit(34); #endif } } } } else { /* continuation */ /* Stats[AC_CONTINUATIONS]++; */ ac = bt->ac; #ifdef DEBUG printf("\nunify_ac, continuation:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); #endif if (ac->sub_position) { /* if subproblems pending */ ac->sub_position = unify_bt_next(ac->sub_position); status = (ac->sub_position ? SUCCESS : GO); } else status = GO; num_basis = ac->num_basis; length = ac->m + ac->n; } while (status == GO) { if (continuation) { /* Undo bindings from previous combination. */ for (i = length-1; i >= 0; i--) { ti = ARG(ac,i); ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ti); #ifdef DEBUG printf("<-<-<- clearing (ci) "); fflush(stdout); p_binding(vn, ci, ci->terms[vn], ci->contexts[vn]); #endif ci->terms[vn] = NULL; ci->contexts[vn] = NULL; } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { #ifdef DEBUG printf("<-<-<- clearing (c3)"); fprint_term(stdout, ac->new_terms[i]); p_binding(SYMNUM(ac->new_terms[i]), ac->c3, ac->c3->terms[VARNUM(ac->new_terms[i])], ac->c3->contexts[VARNUM(ac->new_terms[i])]); #endif ac->c3->terms[VARNUM(ac->new_terms[i])] = NULL; ac->c3->contexts[VARNUM(ac->new_terms[i])] = NULL; } } } /* Get first or next relevant subset of the basis solutions. * A parameter limits the number of combinations (and makes AC * unification incomplete). -1 means that there is no limit. * 0 means that no supsersets are allowed, 1 means that supersets * with one additional element are allowed, etc.. Also, if there * is a limit, then at most MAX_COMBOS combinations will be returned. */ if (ac->superset_limit < 0) ok = next_combo_a(length, ac->basis, num_basis, ac->constraints, ac->combo, ac->sum, !continuation); else ok = next_combo_ss(length, ac->basis, num_basis, ac->constraints, ac->combo, ac->sum, !continuation, ac->combos, &(ac->combos_remaining), ac->superset_limit); #ifdef DEBUG printf(" ----Combination? %s\n", ok ? "YES" : "NO"); #endif if (ok) { /* We now have a potential unifier. It's not guaranteed, * because it may have subterms to be unified. */ sub_problems = bt3 = NULL; /* A variable is associated with each row of the basis. * ac->combo is the current subst of the rows. * * Loop through columns, building a term (t4) for each. */ for (i = 0; i < length; i++) { t4 = NULL; /* Loop through rows, building t4. */ for (j = 0; j < num_basis; j++) { if (ac->combo[j]) { t3 = ac->basis_terms[j][i]; if (t3) { if (!t4) t4 = ARG(t3,0); else { ARG(t3,1) = t4; t4 = t3; } } } } ac->new_terms[i] = t4; #ifdef DEBUG printf(" ---- arg %d goes with ", i); p_term(t4); #endif /* t4 must now be unified with args[i]. * switch args[i] * variable: just bind it. * constant: bind t4 (which is a variable in this case). * complex: add t4=args[i] to the set of subproblems. */ ti = ARG(ac,i); ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ti); ci->terms[vn] = t4; ci->contexts[vn] = ac->c3; #ifdef DEBUG printf("->->->-> binding (ci) "); p_binding(vn, ci, t4, ac->c3); #endif } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { ac->c3->terms[VARNUM(t4)] = ti; ac->c3->contexts[VARNUM(t4)] = ci; #ifdef DEBUG printf("->->->-> binding (c3)"); p_binding(VARNUM(t4), ac->c3, ti, ci); #endif } else { bt2 = get_btu_state(); bt2->prev = bt3; if (bt3) bt3->next = bt2; else sub_problems = bt2; bt2->t1 = t4; bt2->c1 = ac->c3; bt2->t2 = ti; bt2->c2 = ci; bt3 = bt2; #ifdef DEBUG printf("->->->-> subproblem ["); fprint_term(stdout,t4); printf(",0x%x:%d] :: [", (unsigned) ac->c3, ac->c3->multiplier); fprint_term(stdout,ti); printf(",0x%x:%d]\n", (unsigned) ci, ci->multiplier); #endif } } /* for each arg */ if (sub_problems) { ac->sub_position = unify_bt_guts(sub_problems); if (ac->sub_position) status = SUCCESS; else { #ifdef DEBUG printf(" subproblems failed; continuing\n"); #endif continuation = 1; status = GO; } } else { ac->sub_position = NULL; status = SUCCESS; } } /* if (ok) */ else /* There are no more combinations, so stop. */ status = EXHAUSTED; } /* while (STATUS == go) */ if (status == SUCCESS) { #ifdef DEBUG printf("\nunify_ac, success:\n"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x:%d]\n", (unsigned) ac->c3, ac->c3->multiplier); { Term s1, s2; s1 = apply(t1, c1); s2 = apply(t2, c2); printf(" t1 instance: "); fprint_term_nl(stdout, s1); printf(" t2 instance: "); fprint_term_nl(stdout, s2); zap_term(s1); zap_term(s2); } #endif return(1); } else { /* Free memory, clean up, and fail. */ #ifdef DEBUG printf("\nunify_ac, %s:\n", status == EXHAUSTED ? "finished" : "fail"); printf(" "); fprint_term(stdout, t1); printf(" [0x%x:%d]\n", (unsigned) c1, c1->multiplier); printf(" "); fprint_term(stdout, t2); printf(" [0x%x:%d]\n", (unsigned) c2, c2->multiplier); printf(" c3 context is [0x%x]\n", (unsigned) ac->c3); #endif if (status == EXHAUSTED) { /* Delete all terms in basis_terms. */ for (i = 0; i < num_basis; i++) for (j = 0; j < length; j++) if (ac->basis_terms[i][j]) { t2 = ac->basis_terms[i][j]; zap_term(ARG(t2,0)); free_term(t2); } } free_context(ac->c3); free_ac_position(bt->ac); bt->ac = NULL; bt->alternative = NO_ALT; return(0); } } /* unify_ac */ /************* * * unify_ac_cancel * *************/ /* DOCUMENTATION This routine should be called if the rest of a sequence of AC unifiers is not called for. It clears substitutions as well frees memory. */ static void unify_ac_cancel(Ac_position ac) { int i, j, length, vn; Context ci; Term t2, ti; Btu_state bt; length = ac->m + ac->n; /* Undo bindings from previous combination. */ for (i = 0; i < length; i++) { ti = ARG(ac,i); ci = ac->arg_contexts[i]; if (ci && VARIABLE(ti)) { vn = VARNUM(ARG(ac,i)); ci->terms[vn] = NULL; ci->contexts[vn] = NULL; } else if (CONSTANT(ti) || (!ci && VARIABLE(ti))) { ac->c3->terms[VARNUM(ac->new_terms[i])] = NULL; ac->c3->contexts[VARNUM(ac->new_terms[i])] = NULL; } } /* Delete all terms in basis_terms. */ for (i = 0; i < ac->num_basis; i++) for (j = 0; j < length; j++) if (ac->basis_terms[i][j]) { t2 = ac->basis_terms[i][j]; zap_term(ARG(t2,0)); free_term(t2); } if (ac->sub_position) { /* unity_bt leaves you at the end of the list, so get to the start. */ for (bt = ac->sub_position; bt->prev; bt = bt->prev); unify_bt_cancel(bt); } free_context(ac->c3); free_ac_position(ac); } /* unify_ac_cancel */ /************* * * p_ac_position() - print ac_position * *************/ /* DOCUMENTATION This routine prints (to stdout) some of the data in an Ac_position. */ static void p_ac_position(Ac_position ac, int n) { if (!ac) printf("\nac_position is NULL.\n"); else { printf("\nac_position, context c3:\n"); p_context(ac->c3); printf("\nSub problems:\n"); if (!ac->sub_position) printf("none.\n"); else { Btu_state bt; /* Get to the beginning of the list of subproblems. */ for (bt = ac->sub_position; bt->prev; bt = bt->prev); for (; bt; bt = bt->next) p_bt_tree(bt, n); } printf("end of ac_position, context c3:\n"); } } /* p_ac_position */ /************* * * Btu_state unify_bt_backup(bt) * * Back up (freeing nodes) to the most recent node with an alternative. * *************/ static Btu_state unify_bt_backup(Btu_state bt1) { Btu_state bt2, bt3; while (bt1 != NULL && bt1->alternative == NO_ALT) { if (bt1->cb) { /* unbind variable */ #ifdef DEBUG printf("CLEAR: v%d, c%d\n", bt1->varnum, bt1->cb->multiplier); fflush(stdout); #endif bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; bt1->cb = NULL; } if (bt1->prev) { bt1 = bt1->prev; while (bt1->last_child) bt1 = bt1->last_child; } else { bt2 = bt1; bt1 = bt1->parent; while (bt2) { bt3 = bt2; bt2 = bt2->next; free_btu_state(bt3); } if (bt1) bt1->first_child = bt1->last_child = NULL; } } return(bt1); } /* unify_bt_backup */ /************* * * unify_commute() * * Commutative unification. t1 and t2 have the same commutative symbol. * t1, c1, t2, c2, are dereferenced terms from bt. * * This simply tries to unify both ways. * We can get redundant unifiers if both ways unify, for example, * f(a,x) and f(a,a) unify twice, both times with the same substitution. * *************/ static int unify_commute(Term t1, Context c1, Term t2, Context c2, Btu_state bt) { Btu_state bt1, bt2; if (bt->alternative == NO_ALT) { /* first call */ bt->alternative = COMM_ALT; bt->flipped = 0; /* Set up 2 subproblems, then unify guts. */ bt1 = get_btu_state(); bt2 = get_btu_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt1->c2 = c2; bt2->c1 = c1; bt2->c2 = c2; bt1->t1=ARG(t1,0); bt1->t2=ARG(t2,0); bt2->t1=ARG(t1,1); bt2->t2=ARG(t2,1); bt->position_bt = unify_bt_guts(bt1); } else /* continuation */ bt->position_bt = unify_bt_next(bt->position_bt); if (!bt->position_bt && !bt->flipped) { /* Set up 2 subproblems, with t2 flipped, then unify guts. */ bt1 = get_btu_state(); bt2 = get_btu_state(); bt1->next = bt2; bt2->prev = bt1; bt1->c1 = c1; bt1->c2 = c2; bt2->c1 = c1; bt2->c2 = c2; bt1->t1=ARG(t1,0); bt1->t2=ARG(t2,1); bt2->t1=ARG(t1,1); bt2->t2=ARG(t2,0); bt->flipped = 1; bt->position_bt = unify_bt_guts(bt1); } if (bt->position_bt) return(1); else { bt->alternative = NO_ALT; return(0); } } /* unify_commute */ /************* * * unify_bt_first * * This is backtracking unification, to be used when there * can be more than one unifier. This version handles (any number of) * commutative and associative-commutative function symbols. * * Get first unifier. Return position for unify_bt_next calls. * This procedure can also be used for matching, because a NULL * context causes the corresponding term to be treated as ground. * * Here is an example of its use: * * c1 = get_context(); * c2 = get_context(); * bt = unify_bt_first(t1, c1, t2, c2); * while (bt) { * t3 = apply(t1, c1); * t4 = apply(t2, c2); * zap_term(t3); * zap_term(t4); * bt = unify_bt_next(bt); * } * free_context(c1); * free_context(c2); * *************/ /* DOCUMENTATION This routine gets the first unifier for a pair of terms and returns a Btu_state (or NULL if there are no unifiers) to be used for calls to unify_bt_next() to get the rest of the unifiers. This unification handles associative-commutative (AC) and commutative (C) symbols, so there can be more than one unifier. (Commutatvie unification is primitive, and you can get duplicate unifiers.)

    This is called "backtrack unification", because the unifiers are constructed incrementally, as needed. Here is an example of how to do it. Assume we have Terms t1 and t2.

      {
        Context c1 = get_context();
        Context c2 = get_context();
        bt = unify_bt_first(t1, c1, t2, c2);
        while (bt != NULL) {
          t3 = apply(t1, c1);
          t4 = apply(t2, c2);
          
          zap_term(t4);
          bt = unify_bt_next(bt);
          }
        free_context(c1);
        free_context(c2);
      }
    
    The routine unify_bt_next() takes care of clearing the substitutions before getting the next unifier. If you decide not to get all of the unifiers, you should call unify_bt_cancel() to free the memory used by the Btu_state.

    If there are no AC or C symbols, it is a little bit faster to use unify() (ordinary unification) instead of backtrack unification. */ /* PUBLIC */ Btu_state unify_bt_first(Term t1, Context c1, Term t2, Context c2) { Btu_state bt = get_btu_state(); bt->t1 = t1; bt->t2 = t2; bt->c1 = c1; bt->c2 = c2; /* p_term(t1); p_term(t2); printf("\n"); */ return(unify_bt_guts(bt)); } /* unify_bt */ /************* * * unify_bt_next * * Get next unifier. Return position for subsequent calls. * *************/ /* DOCUMENTATION This routine gets the next unifier for "backtrack unification". See unify_bt_first() for an explanation. */ /* PUBLIC */ Btu_state unify_bt_next(Btu_state bt1) { /* Go to last node in tree, then back up to a node with an alternative. */ while (bt1->next != NULL) bt1 = bt1->next; while (bt1->last_child != NULL) bt1 = bt1->last_child; bt1 = unify_bt_backup(bt1); if (bt1 != NULL) return(unify_bt_guts(bt1)); else return(NULL); } /* unify_bt_next */ /************* * * unify_bt_cancel * * This routine should be called if the rest of a sequence of * unifiers is not called for. It clears substitutions as well * frees memory. * *************/ /* DOCUMENTATION This routine frees the memory associated with a state in backtrack unification. This should be called if you decide to get some, but not all, unifiers from unify_bt_first() and unify_bt_next(). */ /* PUBLIC */ void unify_bt_cancel(Btu_state bt) { Btu_state bt1, bt2; for (bt1 = bt; bt1 != NULL; ) { unify_bt_cancel(bt1->first_child); if (bt1->alternative == COMM_ALT) unify_bt_cancel(bt1->position_bt); else if (bt1->alternative == AC_ALT) { unify_ac_cancel(bt1->ac); } else if (bt1->cb != NULL) { bt1->cb->terms[bt1->varnum] = NULL; bt1->cb->contexts[bt1->varnum] = NULL; } bt2 = bt1; bt1 = bt1->next; free_btu_state(bt2); } } /* unify_bt_cancel */ /************* * * unify_bt_guts * * Main loop for backtracking unification. * *************/ /* DOCUMENTATION This routine (mutually recursive with unify_ac()), does the important work of backtrack unification. It is called bt unify_bt_first() and unify_bt_next(). */ static Btu_state unify_bt_guts(Btu_state bt1) { Term t1, t2; Context c1, c2; int vn1, vn2, status; Btu_state bt2, bt3; status = GO; while (status == GO) { t1 = bt1->t1; t2 = bt1->t2; c1 = bt1->c1; c2 = bt1->c2; DEREFERENCE(t1, c1) DEREFERENCE(t2, c2) #ifdef DEBUG printf("guts loop (derefed) "); fprint_term(stdout, t1); printf(" %d ", c1 ? c1->multiplier : -2); fprint_term(stdout, t2); printf(" %d \n", c2 ? c2->multiplier : -2); #endif if (bt1->alternative == COMM_ALT) { if (unify_commute(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (bt1->alternative == AC_ALT) { if (unify_ac(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (c1 && VARIABLE(t1)) { vn1 = VARNUM(t1); if (VARIABLE(t2)) { if (vn1 == VARNUM(t2) && c1 == c2) status = POP; else { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn1, c1->multiplier); fflush(stdout); #endif BIND_BT(vn1, c1, t2, c2, bt1) status = POP; } } else { /* t1 variable, t2 not variable */ /* Stats[BT_OCCUR_CHECKS]++; */ if (occur_check(vn1, c1, t2, c2)) { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn1, c1->multiplier); fflush(stdout); #endif BIND_BT(vn1, c1, t2, c2, bt1) status = POP; } else status = BACKTRACK; } } else if (c2 && VARIABLE(t2)) { /* t2 variable, t1 not variable */ vn2 = VARNUM(t2); /* Stats[BT_OCCUR_CHECKS]++; */ if (occur_check(vn2, c2, t1, c1)) { #ifdef DEBUG printf("BIND: v%d, c%d\n", vn2, c2->multiplier); fflush(stdout); #endif BIND_BT(vn2, c2, t1, c1, bt1) status = POP; } else status = BACKTRACK; } else if (SYMNUM(t1) != SYMNUM(t2)) status = BACKTRACK; else if (CONSTANT(t1)) status = POP; else { /* both COMPLEX with same symbol (and same arity) */ if (is_commutative(SYMNUM(t1))) { if (unify_commute(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else if (is_assoc_comm(SYMNUM(t1))) { if (unify_ac(t1, c1, t2, c2, bt1)) status = POP; else status = BACKTRACK; } else { /* Set up children corresponding to args of . * Order not important for correctness. * AC kids last for efficiency, but keep in order otherwise. */ int i; bt3 = NULL; for (i = 0; i < ARITY(t1); i++) { bt2 = get_btu_state(); bt2->t1 = ARG(t1,i); bt2->t2 = ARG(t2,i); bt2->c1 = c1; bt2->c2 = c2; bt2->parent = bt1; if (is_assoc_comm(SYMNUM(ARG(t1,i)))) { /* insert at end */ bt2->prev = bt1->last_child; if (bt1->last_child) bt1->last_child->next = bt2; else bt1->first_child = bt2; bt1->last_child = bt2; } else { if (bt3) { /* insert after bt3 */ bt2->next = bt3->next; bt2->prev = bt3; bt3->next = bt2; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; } else { /* insert at beginning */ bt2->next = bt1->first_child; if (bt2->next) bt2->next->prev = bt2; else bt1->last_child = bt2; bt1->first_child = bt2; } bt3 = bt2; } } bt1 = bt1->first_child; status = GO; } } if (status == POP) { while (!bt1->next && bt1->parent) bt1 = bt1->parent; if (!bt1->next) status = SUCCESS; else { bt1 = bt1->next; status = GO; } } else if (status == BACKTRACK) { bt1 = unify_bt_backup(bt1); if (bt1) status = GO; else status = FAILURE; } } return(bt1); } /* unify_bt_guts */ /************* * * p_bt_tree -- print a bt tree (This could be improved!) * *************/ /* DOCUMENTATION This (recursive) routine prints (to stdout) a backtrack unification state. Parameter n should be 0 on the top call. */ /* PUBLIC */ void p_bt_tree(Btu_state bt, int n) { int i; Btu_state curr, prev; if (bt == NULL) printf("bt tree NULL.\n"); else { printf("\n" ); for (i = 0; i < n%100; i++) printf("----"); printf(" bt_tree: %d\n", n); fprint_term(stdout, bt->t1); printf(" [ %p ]\n", bt->c1); fprint_term(stdout, bt->t2); printf(" [ %p ]\n", bt->c2); p_context(bt->c1); p_context(bt->c2); if (bt->alternative == AC_ALT) { p_ac_position(bt->ac, n+100); } prev = NULL; for (curr = bt->first_child; curr; curr = curr->next) { if (curr->parent != bt) printf("parent error\n"); if (curr->prev != prev) printf("prev error\n"); p_bt_tree(curr, n+1); prev = curr; } if (bt->last_child != prev) printf("last error\n"); printf(" end of bt_tree: %d\n", n); } } /* p_bt_tree */ LADR-2009-11A/ladr/README.kbo0000644000175000017500000000104410224550430014364 0ustar mccunemccuneEach function (including constant) symbol has a positive weight. exception: there can be a unary function with weight 0 (think group inverse) There is a symbol precedence, independent of the symbol weight. exception: if there is a unary of weight 0, it is greatest in the precedence. The exceptions are so that equations like g(f(x,y)) = f(g(y),g(x)) can be demodulators (in that orientation). The weight of a term is simply the sym of the weights of the function and constant symbols. Is alpha > beta in KBO? See kbo() in termorder.c. LADR-2009-11A/ladr/test.c0000644000175000017500000000223410637466323014076 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #define N 5 void compute_args(int *a, int arity, int n, int i) { int x = i; int r; for (r = arity-1; r >= 0; r--) { a[r] = x % n; x = x - a[r]; x = x / n; } } /* lkj */ main() { int a[4]; int i; for (i = 0; i < 81; i++) { int j; compute_args(a, 4, 3, i); for (j = 0; j < 4; j++) printf(" %d", a[j]); printf("\n"); } } /* main */ LADR-2009-11A/ladr/weighttest0000755000175000017500000002451511112717360015063 0ustar mccunemccuneELF°ƒ4”4 (&#44€4€àà€€8888˜8˜ LL˜L˜ÐÐ((( Qåtd/lib/ld-linux.so.2GNU €( ¬KãÀgUa ;yH²A¯49)úˆ.P™__gmon_start__libc.so.6_IO_stdin_usedexitstdinprintffgetsstrlen__libc_start_mainGLIBC_2.0ii Z™P™,™0™4™8™<™@™U‰åSƒìè[Ë“üÿÿÿ…ÒtèèÝè˜X[ÉÃÿ5$™ÿ%(™ÿ%,™héàÿÿÿÿ%0™héÐÿÿÿÿ%4™héÀÿÿÿÿ%8™hé°ÿÿÿÿ%<™h é ÿÿÿÿ%@™h(éÿÿÿ1í^‰áƒäðPTRh`‡hp‡QVh’†è›ÿÿÿôU‰åƒì€=T™t ëƒÀ£L™ÿÒ¡L™‹…ÒuëÆT™ÉÃU‰åƒì¡H˜…Àt¸…Àt Ç$H˜ÿÐÉÃU‰åƒìÇEüë#‹EüE¶‹EüE ¶8Ât ÇEìëƒEü‹Eü;E|ÕÇEì‹EìÉÃU‰åƒì ‹E ;EHÇEüë.‹Eü‰ÂU‹E ‰D$‹E‰D$‰$è…ÿÿÿ…Àt‹Eü‰EìëƒEü‹E ‹U‰Ñ)Á‰È;Eü}ÁÇEìÿÿÿÿ‹EìÉÃU‰åƒìH‹E‰$èþÿÿ‰EüÇEø‹Eø‰EôÇEðƒ}ü“ÙîÝ]Èé®ÇEì‹Uô‹Eü)ЉEè‹Eè;Eô~‹Eô‰Eè‹Eø‰Eäë>‹EôE‰Eà‹Eü‰D$ ‹E‰D$‹Eä‰D$‹Eà‰$èÿÿÿ‰EÜ‹EÜ;Eô}‹Eä‰EìƒEä‹EèƒÀ;Eä·ƒ}ìuƒEôë ‹EìEô‹EìEð‹Eüƒè;EôhÿÿÿÛEð‹EüƒèPÛ$d$ÞùÝ]ÈÝEÈÉÃU‰åƒì8‹E‰$è ýÿÿ‰EüÇEøÇEôÇEè‹Eè‰Eì‹Eì‰Eðëw‹EìEðE¶‹EìEôE¶8ÂuƒEìëU‹Eì‰EØ‹Eè‰EÜ‹EØ9EÜ}‹E؉EÜ‹E܉EèƒEð‹Eð;Eôt ÇEìë ƒEø‹EèƒÀEôÇEè‹Eè‰Eì‹Eì‰Eð‹EìEô;EüŒzÿÿÿÛEøÛEüÞùÉÃL$ƒäðÿqüU‰åQì‹A‰…üÿÿe¡‰Eø1À¡P™‰D$ÇD$è…üÿÿ‰$èƒüÿÿ‰… üÿÿƒ½ üÿÿu Ç$è¨üÿÿ…üÿÿ¶„Àt…üÿÿ‰$èmüÿÿƒèÆ„üÿÿ…üÿÿ‰$è´ýÿÿÙèÞáÝ\$Ç$ ˆèPüÿÿ…üÿÿ‰$èþÿÿÝ\$Ç$%ˆè2üÿÿé[ÿÿÿU‰å]Ãt&¼'U‰åWVSèOÃ¥ƒì èƒûÿÿ»ÿÿÿƒÿÿÿ)ÇÁÿ…ÿt$1ö‹E‰D$‹E ‰D$‹E‰$ÿ”³ÿÿÿƒÆ9÷uÞƒÄ [^_]Ë$ÃU‰åSƒì¡8˜ƒøÿt1ÛÿЋƒ4˜ƒëƒøÿuðƒÄ[]ÃU‰åSƒìè[ÃèÌûÿÿY[ÉÃ%.5f %.5f ÿÿÿÿÿÿÿÿ ƒ ü‡Hõþÿo€4‚¤ d  ™0܂̂þÿÿo¬‚ÿÿÿoðÿÿo˜‚L˜Rƒbƒrƒ‚ƒ’ƒ¢ƒD˜GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu1)$ ƒ"ü‡4„+$8ƒˆ!u_IO_stdin_usedmain‰Q¦uÔƒÔƒC61Eint­,²L‡ˆO‰K'/build/buildd/glibc-2.7/build-tree/i386-libc/csu/crti.S/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuGNU AS 2.18.0€ü]GNU C 4.2.3 (Ubuntu 4.2.3-2ubuntu7)weight2.c/home/mccune/LADR/ladr4„_‡­size_tÖlunsigned intunsigned charshort unsigned intlong unsigned intsigned charshort intintlong long intlong long unsigned int__quad_t8Û__off_t%long int__off64_tŽMchar_IO_FILE”-Õ_flagsÔ#_IO_read_ptrG#_IO_read_endG#_IO_read_baseG# _IO_write_baseG#_IO_write_ptrG#_IO_write_endG#_IO_buf_baseG#_IO_buf_endG# _IO_save_baseG#$_IO_backup_baseG#(_IO_save_end G#,_markers"&#0_chain$,#4_fileno&Ô#8_flags2*Ô#<_old_offset,#@_cur_column0#D_vtable_offset1¸#F_shortbuf22#G_lock6B#H_offset?1#L__pad1HE#T__pad2IE#X__pad3JE#\__pad4KE#`__pad5L^#d_modeNÔ#h_unused2PH#l _IO_lock_t´_IO_marker º& _next»&# _sbuf¼,# _posÀÔ#ãU MB BÕ MX B' char_array_ident5Ô4„z„²s4G‘t4G‘n4Ô‘i6Ô‘t char_array_findFÔz„Ü„,#bEG‘nbEÔ‘aEG‘naEÔ‘ ˆ„ЄiHÔ‘t complexity_1Yú܄˅XúsXG‘length[Ô‘tmin\Ô‘pindex]Ô‘ltotal^Ô‘h…¡…flendÔ‘dmaxlookeÔ‘`windowfÔ‘\@…z…tocheckmG‘XindnÔ‘Tdouble complexity_2ŒúË…’†„s‹G‘nÔ‘tcŽÔ‘pbÔ‘laÔ‘hoÔ‘domaxÔ‘`mainÕÔ’†_‡°ÙargcÔÔqargvÔÙ‘€xsÖß‘ˆxt×G‘„xG MðBçstdin‘,‰]Ä /build/buildd/glibc-2.7/build-tree/i386-libc/csu/crtn.S/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuGNU AS 2.18.0€% $ > $ > $ > 4: ; I?  &IU%% : ; I$ > $ >   I : ;  : ;I8 : ; : ; I8 I !I/ .: ; ' I@: ; I 4: ; I  .? : ; ' I@!I/4: ; I? < U%#û init.c‚Nû /build/buildd/glibc-2.7/build-tree/i386-libc/csucrti.S ƒ!/!=Z!gg//ü‡(!/!=Z!–û /usr/lib/gcc/i486-linux-gnu/4.2.3/include/usr/include/bits/usr/includeweight2.cstddef.htypes.hlibio.hstdio.h4„4h‘Y޽Ÿ .g„‘"€OŸ .h×ugvŸ¡u¯ƒiƒ‘#ƒxf äghghfä„ .g×uv//­iåKƒ’K‘t.äƒ2.º³%‘¼É†"ÊxNû /build/buildd/glibc-2.7/build-tree/i386-libc/csucrtn.S8ƒ !!!ˆ!!!ÿÿÿÿ| ˆ4„F… z„b… Ü„ï… Ë…Ç… 8’†Í   … „short unsigned intshort int_IO_stdin_usedlong long unsigned intunsigned charGNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu1)/build/buildd/glibc-2.7/build-tree/glibc-2.7/csuinit.clong long intttFuFGtGItI¨u¨©t©«t«—u—˜t˜štš^u^btbhQhitiktk+uÿÿÿÿ ƒ.ƒü‡ˆÿÿÿÿ8ƒ<ƒˆˆ.symtab.strtab.shstrtab.interp.note.ABI-tag.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.eh_frame.ctors.dtors.jcr.dynamic.got.got.plt.data.bss.comment.debug_aranges.debug_pubnames.debug_info.debug_abbrev.debug_line.debug_frame.debug_str.debug_loc.debug_ranges#(( 5HH81öÿÿo€€$; ¤¤C4‚4dKÿÿÿo˜‚˜Xþÿÿo¬‚¬ g Ì‚Ìp Ü‚Ü0 y ƒ 0t<ƒ<p°ƒ°L…ü‡ü‹ˆ“4ˆ48˜8¤@˜@«H˜H°L˜Lй™ ¾ ™ $ÇD™D ÍP™P ÒP &Ûx pêè @ú( §Ïo>@ €Ð-0P»8 óC@@Q„!@%= Ä&‰(H€¤4‚˜‚¬‚Ì‚ Ü‚ ƒ <ƒ °ƒ ü‡ˆ4ˆ8˜@˜H˜L˜™ ™D™P™ !"ñÿñÿñÿ8˜,@˜:H˜Gàƒ ]T™lL™s„ ñÿ<˜ŒD˜™4ˆ§H˜³Ð‡ ñÿÉñÿÓ4„F äz„b ôÜ„ï Ë…Ç  ™$8˜58˜HL˜QD™ \`‡ l°ƒ s ‚ –ˆü‡£y´²ÑˆàD™í¯ÿH™ p‡Z 9.P™ñÿ:P™KX™ñÿPP™ñÿWúgʇ ~’†Í ƒ ƒ init.cinitfini.ccrtstuff.c__CTOR_LIST____DTOR_LIST____JCR_LIST____do_global_dtors_auxcompleted.5843p.5841frame_dummy__CTOR_END____DTOR_END____FRAME_END____JCR_END____do_global_ctors_auxweight2.cchar_array_identchar_array_findcomplexity_1complexity_2_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICdata_start__libc_csu_fini_start__gmon_start___Jv_RegisterClasses_fp_hw_finifgets@@GLIBC_2.0__libc_start_main@@GLIBC_2.0_IO_stdin_used__data_startstrlen@@GLIBC_2.0__dso_handle__libc_csu_initprintf@@GLIBC_2.0__bss_startstdin@@GLIBC_2.0_end_edataexit@@GLIBC_2.0__i686.get_pc_thunk.bxmain_initLADR-2009-11A/ladr/fastparse.h0000644000175000017500000000433711151265364015114 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FASTPARSE_H #define TP_FASTPARSE_H #include "topform.h" /* INTRODUCTION This package is meant for use when there are a great number of terms to be read and written. I wrote it when I was looking for a single axiom for lattice theory and was filtering trillions (really) of equations.

    The ordinary parsing is very general and rather slow.

    This package reads and writes prefix terms, without parentheses commas, or spaces. Each symbol is one character. Each term to be read starts on a new line and ends with a period. The user has to declare the arities of symbols by calling fast_set_symbol().

    Here's an example to read lattice equations in fast-parse form and write them in ordinary form.

    int main(int argc, char **argv)
    {
      Term t;
      fast_set_symbol('=', 2);
      fast_set_symbol('m', 2);
      fast_set_symbol('j', 2);
      t = fast_read_term(stdin, stderr);
      while (t != NULL) {
        fwrite_term_nl(stdout, t);
        zap_term(t);
        t = fast_read_term(stdin, stderr);
      }
      exit(0);
    }
    

    There are also routines for reading and writing fast-parse clauses. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from fastparse.c */ void fast_set_symbol(char c, int arity); void fast_set_defaults(void); Term fast_read_term(FILE *fin, FILE *fout); void fast_fwrite_term_nl(FILE *fp, Term t); Topform fast_read_clause(FILE *fin, FILE *fout); void fast_fwrite_clause(FILE *fp, Topform c); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/compress.h0000644000175000017500000000223411151265364014751 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_COMPRESS_H #define TP_COMPRESS_H #include "parautil.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from compress.c */ Term uncompress_term(char *s, int *ip); char *compress_term(Term t); void compress_clause(Topform c); void uncompress_clause(Topform c); void uncompress_clauses(Plist p); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/int_code.c0000644000175000017500000001735211261157532014703 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "int_code.h" /* Private definitions and types */ /************* * * put_ilist_to_ibuf() * *************/ static void put_ilist_to_ibuf(Ibuffer ibuf, Ilist p) { /* size of Ilist, then members */ ibuf_write(ibuf, ilist_count(p)); for (; p; p = p->next) ibuf_write(ibuf, p->i); } /* put_ilist_to_ibuf */ /************* * * get_ilist_from_ibuf() * *************/ static Ilist get_ilist_from_ibuf(Ibuffer ibuf) { /* size of Ilist, then members */ int i; Ilist p = NULL; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) p = ilist_append(p, ibuf_xread(ibuf)); return p; } /* get_ilist_from_ibuf */ /************* * * put_i3list_to_ibuf() * *************/ static void put_i3list_to_ibuf(Ibuffer ibuf, I3list p) { /* size of I3list, then members */ ibuf_write(ibuf, i3list_count(p)); for (; p; p = p->next) { ibuf_write(ibuf, p->i); ibuf_write(ibuf, p->j); ibuf_write(ibuf, p->k); } } /* put_i3list_to_ibuf */ /************* * * get_i3list_from_ibuf() * *************/ static I3list get_i3list_from_ibuf(Ibuffer ibuf) { /* size of I3list, then members */ int i; I3list p = NULL; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) { int i1 = ibuf_xread(ibuf); int i2 = ibuf_xread(ibuf); int i3 = ibuf_xread(ibuf); p = i3list_append(p, i1, i2, i3); } return p; } /* get_i3list_from_ibuf */ /************* * * put_term_to_ibuf() * *************/ static void put_term_to_ibuf(Ibuffer ibuf, Term t) { if (VARIABLE(t)) ibuf_write(ibuf, -VARNUM(t)); else { int i; ibuf_write(ibuf, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) { put_term_to_ibuf(ibuf, ARG(t,i)); } } } /* put_term_to_ibuf */ /************* * * get_term_from_ibuf() * *************/ static Term get_term_from_ibuf(Ibuffer ibuf) { int a = ibuf_xread(ibuf); if (a <= 0) return get_variable_term(-a); else { Term t; int i; int arity = sn_to_arity(a); if (arity == -1) { printf("bad symnum: %d\n", a); fatal_error("get_term_from_ibuf, symbol not in symbol table"); } t = get_rigid_term_dangerously(a, arity); for (i = 0; i < ARITY(t); i++) ARG(t,i) = get_term_from_ibuf(ibuf); return t; } } /* get_term_from_ibuf */ /************* * * put_just_to_ibuf() * *************/ static void put_just_to_ibuf(Ibuffer ibuf, Just j) { /* size of Just, then members */ ibuf_write(ibuf, just_count(j)); for (; j; j = j->next) { ibuf_write(ibuf, j->type); switch (j->type) { case INPUT_JUST: case GOAL_JUST: /* nothing */ break; case CLAUSIFY_JUST: case DENY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case NEW_SYMBOL_JUST: /* integer */ ibuf_write(ibuf, j->u.id); break; case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: /* list of integers */ put_ilist_to_ibuf(ibuf, j->u.lst); break; case DEMOD_JUST: /* list of integer triples */ put_i3list_to_ibuf(ibuf, j->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: ibuf_write(ibuf, j->u.para->from_id); put_ilist_to_ibuf(ibuf, j->u.para->from_pos); ibuf_write(ibuf, j->u.para->into_id); put_ilist_to_ibuf(ibuf, j->u.para->into_pos); break; default: fatal_error("put_just_to_ibuf, unknown type"); } } } /* put_just_to_ibuf */ /************* * * get_just_from_ibuf() * *************/ static Just get_just_from_ibuf(Ibuffer ibuf) { /* size of Just, then members */ Just j_collect = NULL; int i; int n = ibuf_xread(ibuf); for (i = 0; i < n; i++) { int type = ibuf_xread(ibuf); Just j = get_just(); j->type = type; switch (type) { case INPUT_JUST: case GOAL_JUST: /* nothing */ break; case CLAUSIFY_JUST: case DENY_JUST: case COPY_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: case NEW_SYMBOL_JUST: /* integer */ j->u.id = ibuf_xread(ibuf); break; case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: /* list of integers */ j->u.lst = get_ilist_from_ibuf(ibuf); break; case DEMOD_JUST: /* list of integer triples */ j->u.demod = get_i3list_from_ibuf(ibuf); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: j->u.para = get_parajust(); j->u.para->from_id = ibuf_xread(ibuf); j->u.para->from_pos = get_ilist_from_ibuf(ibuf); j->u.para->into_id = ibuf_xread(ibuf); j->u.para->into_pos = get_ilist_from_ibuf(ibuf); break; default: printf("unknown just type: %d\n", type); fatal_error("get_just_from_ibuf, unknown just"); } j_collect = append_just(j_collect, j); } return j_collect; } /* get_just_from_ibuf */ /************* * * put_clause_to_ibuf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void put_clause_to_ibuf(Ibuffer ibuf, Topform c) { /* id is_formula weight number-of-justs justs lits/atts [atomflags] */ ibuf_write(ibuf, c->id); ibuf_write(ibuf, c->is_formula); ibuf_write(ibuf, c->weight); put_just_to_ibuf(ibuf, c->justification); /* literals and attributes */ { Term t = topform_to_term(c); put_term_to_ibuf(ibuf, t); zap_term(t); } if (!c->is_formula) { /* flags on atoms (maximal, oriented, etc.) */ Literals l; for (l = c->literals; l; l = l->next) ibuf_write(ibuf, l->atom->private_flags); } } /* put_clause_to_ibuf */ /************* * * get_clause_from_ibuf() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform get_clause_from_ibuf(Ibuffer ibuf) { /* id is_formula weight number-of-justs justs lits/atts [atomflags] */ int id = ibuf_xread(ibuf); int is_formula = ibuf_xread(ibuf); int weight = ibuf_xread(ibuf); Just j = get_just_from_ibuf(ibuf); Term t = get_term_from_ibuf(ibuf); Topform c = term_to_topform(t, is_formula); zap_term(t); c->id = id; c->is_formula = is_formula; c->weight = weight; c->justification = j; if (!is_formula) { Literals l; for (l = c->literals; l; l = l->next) l->atom->private_flags = ibuf_xread(ibuf); } return c; } /* get_clause_from_ibuf */ /************* * * check_ibuf_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void check_ibuf_clause(Topform c) { Ibuffer ibuf = ibuf_init(); put_clause_to_ibuf(ibuf, c); p_ibuf(ibuf); ibuf_rewind(ibuf); { Topform d = get_clause_from_ibuf(ibuf); fprint_clause(stdout, c); fprint_clause(stdout, d); if (!clause_ident(c->literals, d->literals)) fatal_error("check_ibuf_clause, clasues not ident"); zap_topform(d); } ibuf_free(ibuf); } /* check_ibuf_clause */ LADR-2009-11A/ladr/avltree.c0000644000175000017500000003421011100130671014534 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "avltree.h" #include /* Private definitions and types */ struct avl_node { void *item; /* data (including key) */ int size; /* number of nodes */ int height; /* leaf has height 1 */ Avl_node left, right; /* subtrees */ }; static BOOL Debug = FALSE; /* * memory management */ #define PTRS_AVL_NODE PTRS(sizeof(struct avl_node)) static unsigned Avl_node_gets, Avl_node_frees; /************* * * Avl_node get_avl_node() * *************/ static Avl_node get_avl_node(void) { Avl_node p = get_mem(PTRS_AVL_NODE); Avl_node_gets++; return(p); } /* get_avl_node */ /************* * * free_avl_node() * *************/ static void free_avl_node(Avl_node p) { free_mem(p, PTRS_AVL_NODE); Avl_node_frees++; } /* free_avl_node */ /************* * * fprint_avltree_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the avltree package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_avltree_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct avl_node); fprintf(fp, "avl_node (%4d) %11u%11u%11u%9.1f K\n", n, Avl_node_gets, Avl_node_frees, Avl_node_gets - Avl_node_frees, ((Avl_node_gets - Avl_node_frees) * n) / 1024.); } /* fprint_avltree_mem */ /************* * * p_avltree_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the avltree package. */ /* PUBLIC */ void p_avltree_mem() { fprint_avltree_mem(stdout, TRUE); } /* p_avltree_mem */ /* * end of memory management */ /************* * * avl_height() * *************/ /* DOCUMENTATION Return the height of an AVL tree. Leaves have height 1. */ /* PUBLIC */ int avl_height(Avl_node p) { return (p == NULL ? 0 : p->height); } /* avl_height */ /************* * * avl_size() * *************/ /* DOCUMENTATION Return the number of nodes in an AVL tree. */ /* PUBLIC */ int avl_size(Avl_node p) { return (p == NULL ? 0 : p->size); } /* avl_size */ /************* * * set_height_and_size() * *************/ static void set_height_and_size(Avl_node p) { p->height = IMAX(avl_height(p->left), avl_height(p->right)) + 1; p->size = (avl_size(p->left) + avl_size(p->right)) + 1; } /* set_height_and_size */ /************* * * balance_ok() * *************/ static BOOL balance_ok(Avl_node p) { return (abs(avl_height(p->left) - avl_height(p->right)) <= 1); } /* balance_ok */ /************* * * rotate_left() * *************/ static Avl_node rotate_left(Avl_node p) { Avl_node b = p; Avl_node c = p->right->left; Avl_node d = p->right; if (Debug) printf("rotate left\n"); b->right = c; set_height_and_size(b); d->left = b; set_height_and_size(d); return d; } /* rotate_left */ /************* * * rotate_right() * *************/ static Avl_node rotate_right(Avl_node p) { Avl_node b = p->left; Avl_node c = p->left->right; Avl_node d = p; if (Debug) printf("rotate right\n"); d->left = c; set_height_and_size(d); b->right = d; set_height_and_size(b); return b; } /* rotate_right */ /************* * * avl_fix() * *************/ static Avl_node avl_fix(Avl_node p) { if (balance_ok(p)) { set_height_and_size(p); return p; } else { if (avl_height(p->left) < avl_height(p->right)) { if (avl_height(p->right->left) <= avl_height(p->right->right)) return rotate_left(p); else { p->right = rotate_right(p->right); return rotate_left(p); } } else { if (avl_height(p->left->right) <= avl_height(p->left->left)) return rotate_right(p); else { p->left = rotate_left(p->left); return rotate_right(p); } } } } /* avl_fix */ /************* * * avl_insert() * *************/ /* DOCUMENTATION Insert an item into an AVL tree, and return the updated tree. The item is an arbitrary pointer, and the caller gives a function that takes two pointers and compares two items. The comparison function must return LESS_THAN, SAME_AS, or GREATER_THAN.

    If the item is already in the tree (that is, if the comparison function return SAME_AS for any item already in the tree), a fatal error occurs. */ /* PUBLIC */ Avl_node avl_insert(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { if (p == NULL) { Avl_node new = get_avl_node(); new->item = item; new->size = 1; new->height = 1; new->left = NULL; new->right = NULL; return new; } else { Ordertype relation = (*compare)(item, p->item); switch (relation) { case LESS_THAN: p->left = avl_insert(p->left, item, compare); break; case GREATER_THAN: p->right = avl_insert(p->right, item, compare); break; case SAME_AS: fatal_error("avl_insert, item already there"); break; default: fatal_error("avl_insert, not comparable"); break; } p = avl_fix(p); /* rebalance if necessary; set height, size */ return p; } } /* avl_insert */ /************* * * remove_and_return_largest() * *************/ static Avl_node remove_and_return_largest(Avl_node p, Avl_node *removed) { if (p->right == NULL) { *removed = p; return p->left; } else { p->right = remove_and_return_largest(p->right, removed); p = avl_fix(p); /* rebalance if necessary; set height, size */ return p; } } /* remove_and_return_largest */ /************* * * remove_and_return_smallest() * *************/ static Avl_node remove_and_return_smallest(Avl_node p, Avl_node *removed) { if (p->left == NULL) { *removed = p; return p->right; } else { p->left = remove_and_return_smallest(p->left, removed); p = avl_fix(p); /* rebalance if necessary; set height, size */ return p; } } /* remove_and_return_smallest */ /************* * * avl_delete() * *************/ /* DOCUMENTATION Delete an item from an AVL tree and return the updated tree. If the item is not in the tree (that is, if the comparison function does not return SAME_AS for any item in the tree), a fatal error occurs. */ /* PUBLIC */ Avl_node avl_delete(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { if (p == NULL) fatal_error("avl_delete, item not found"); else { Ordertype relation = (*compare)(item, p->item); if (relation == LESS_THAN) p->left = avl_delete(p->left, item, compare); else if (relation == GREATER_THAN) p->right = avl_delete(p->right, item, compare); else if (relation != SAME_AS) fatal_error("avl_find: not comparable"); else { Avl_node left = p->left; Avl_node right = p->right; free_avl_node(p); p = NULL; if (left == NULL && right == NULL) { return NULL; } else if (avl_height(left) < avl_height(right)) right = remove_and_return_smallest(right, &p); else left = remove_and_return_largest(left, &p); p->left = left; p->right = right; } p = avl_fix(p); } return p; } /* avl_delete */ /************* * * avl_lookup() * *************/ static Avl_node avl_lookup(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { if (p == NULL) return NULL; else { Ordertype relation = (*compare)(item, p->item); switch (relation) { case SAME_AS: return p; case LESS_THAN: return avl_lookup(p->left, item, compare); case GREATER_THAN: return avl_lookup(p->right, item, compare); default: fatal_error("avl_lookup: not comparable"); } return NULL; /* won't happen */ } } /* avl_lookup */ /************* * * avl_find() * *************/ /* DOCUMENTATION Look for an item in an AVL tree. That is, look for an item for which the comparison function returns SAME_AS. If it is found, return the item in the tree; otherwise return NULL; */ /* PUBLIC */ void *avl_find(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { Avl_node n = avl_lookup(p, item, compare); return (n == NULL ? NULL : n->item); } /* avl_find */ /************* * * avl_smallest() * *************/ /* DOCUMENTATION Return the smallest (leftmost) item in an AVL tree. */ /* PUBLIC */ void *avl_smallest(Avl_node p) { if (p == NULL) return NULL; /* happens at top only */ else if (p->left == NULL) return p->item; else return avl_smallest(p->left); } /* avl_smallest */ /************* * * avl_largest() * *************/ /* DOCUMENTATION Return the largest (rightmost) item in an AVL tree. */ /* PUBLIC */ void *avl_largest(Avl_node p) { if (p == NULL) return NULL; /* happens at top only */ else if (p->right == NULL) return p->item; else return avl_largest(p->right); } /* avl_largest */ /************* * * avl_place() * *************/ /* DOCUMENTATION How far (counting from 1) from the beginning of the tree is the item. If the item is not already in the tree, this function says how far it would be if it were inserted first. */ /* PUBLIC */ int avl_place(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { if (p == NULL) return 1; else { Ordertype relation = (*compare)(item, p->item); switch (relation) { case LESS_THAN: return avl_place(p->left, item, compare); case SAME_AS: return avl_size(p->left) + 1; case GREATER_THAN: return avl_size(p->left) + 1 + avl_place(p->right, item, compare); default: fatal_error("avl_place, not comparable"); } return INT_MAX; /* won't happen */ } } /* avl_place */ /************* * * avl_position() * *************/ /* DOCUMENTATION Return x, 0 < x <= 1, telling the position of the item in the tree. The last item always has position 1.0. The first item in a tree of size 10 has position 0.1.

    */ /* PUBLIC */ double avl_position(Avl_node p, void *item, Ordertype (*compare) (void *, void *)) { int place = avl_place(p, item, compare); return place / (double) avl_size(p); } /* avl_position */ /************* * * avl_nth_item() * *************/ /* DOCUMENTATION Return the n-th item (counting from 1) in an AVL tree. If n is out of range, NULL is returned. */ /* PUBLIC */ void *avl_nth_item(Avl_node p, int n) { if (p == NULL || n < 1 || n > p->size) return NULL; else if (n <= avl_size(p->left)) return avl_nth_item(p->left, n); else if (n == avl_size(p->left)+1) return p->item; else return avl_nth_item(p->right, n - (avl_size(p->left)+1)); } /* avl_nth_item */ /************* * * avl_item_at_position() * *************/ /* DOCUMENTATION Given an AVL tree and a position pos, 0.0 < pos <= 1.0, return the item at that position. If the tree is empty, or if pos is out of range, NULL is returned. The index (counting from 1) of the returned item is ceiling(pos * p->size). */ /* PUBLIC */ void *avl_item_at_position(Avl_node p, double pos) { if (p == NULL || pos <= 0.0 || pos > 1.0) return NULL; else { int n = (int) ceil(pos * p->size); /* It should be, but make sure that 1 <= n <= p->size. */ n = (n < 1 ? 1 : (n > p->size ? p->size : n)); return avl_nth_item(p, n); } } /* avl_item_at_position */ /************* * * avl_zap() * *************/ /* DOCUMENTATION Free an entire AVL tree. This does not affect any of the data to which the tree refers. */ /* PUBLIC */ void avl_zap(Avl_node p) { if (p != NULL) { avl_zap(p->left); avl_zap(p->right); free_avl_node(p); } } /* avl_zap */ /************* * * avl_check() * *************/ /* DOCUMENTATION Check that each node of an AVL tree has the following properties: (1) "size" and "height" fields are correct; (2) heights of the two children differ by at most 1. In addition, check that the inorder traversal of the whole tree really is in order. */ /* PUBLIC */ void avl_check(Avl_node p, Ordertype (*compare) (void *, void *)) { if (p != NULL) { avl_check(p->left, compare); avl_check(p->right, compare); if (p->left && (*compare)(p->left->item, p->item) != LESS_THAN) { printf("error: left not smaller: %p\n", p->item); fprintf(stderr, "error: left not smaller: %p\n", p->item); } if (p->right && (*compare)(p->right->item, p->item) != GREATER_THAN) { printf("error: right not greater: %p\n", p->item); fprintf(stderr, "error: right not greater: %p\n", p->item); } if (p->height != IMAX(avl_height(p->left), avl_height(p->right)) + 1) { printf("error: height wrong: %p\n", p->item); fprintf(stderr, "error: height wrong: %p\n", p->item); } if (p->size != (avl_size(p->left) + avl_size(p->right)) + 1) { printf("error: size wrong: %p\n", p->item); fprintf(stderr, "error: size wrong: %p\n", p->item); } if (!balance_ok(p)) { printf("error: unbalanced: %p\n", p->item); fprintf(stderr, "error: unbalanced: %p\n", p->item); } } } /* avl_check */ /************* * * p_avl() * *************/ /* DOCUMENTATION Print an AVL tree to stdout. The pointers to the items are printed as integers. */ /* PUBLIC */ void p_avl(Avl_node p, int level) { int i; if (p == NULL) { for (i = 0; i < level; i++) printf(" "); printf("----\n"); } else { p_avl(p->right, level+1); for (i = 0; i < level; i++) printf(" "); printf("%4d\n", (int) p->item); p_avl(p->left, level+1); } } /* p_avl */ LADR-2009-11A/ladr/literals.c0000644000175000017500000005212711136251633014733 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "literals.h" /* Private definitions and types */ /* * memory management */ #define PTRS_LITERALS PTRS(sizeof(struct literals)) static unsigned Literals_gets, Literals_frees; /************* * * Literals get_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals get_literals(void) { Literals p = get_cmem(PTRS_LITERALS); Literals_gets++; return(p); } /* get_literals */ /************* * * free_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_literals(Literals p) { free_mem(p, PTRS_LITERALS); Literals_frees++; } /* free_literals */ /************* * * fprint_literals_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clause package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_literals_mem(FILE *fp, int heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct literals); fprintf(fp, "literals (%4d) %11u%11u%11u%9.1f K\n", n, Literals_gets, Literals_frees, Literals_gets - Literals_frees, ((Literals_gets - Literals_frees) * n) / 1024.); } /* fprint_literals_mem */ /************* * * p_literals_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clause package. */ /* PUBLIC */ void p_literals_mem() { fprint_literals_mem(stdout, 1); } /* p_literals_mem */ /* * end of memory management */ /************* * * zap_literal(c) * *************/ /* DOCUMENTATION This routine frees a literal. */ /* PUBLIC */ void zap_literal(Literals l) { zap_term(l->atom); free_literals(l); } /* zap_literal */ /************* * * zap_literals(c) * *************/ /* DOCUMENTATION This routine frees a list of literals. */ /* PUBLIC */ void zap_literals(Literals l) { if (l) { zap_literals(l->next); zap_literal(l); } } /* zap_literals */ /************* * * new_literal() * *************/ /* DOCUMENTATION This routine takes a sign (Boolean) and a Term atom, and returns a literal. The atom is not copied. */ /* PUBLIC */ Literals new_literal(int sign, Term atom) { Literals lit = get_literals(); lit->sign = sign; lit->atom = atom; return lit; } /* new_literal */ /************* * * copy_literal() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals copy_literal(Literals lit) { return new_literal(lit->sign, copy_term(lit->atom)); } /* copy_literal */ /************* * * append_literal() * *************/ /* DOCUMENTATION This routine appends a literal to a list of literals. */ /* PUBLIC */ Literals append_literal(Literals lits, Literals lit) { if (lits == NULL) return lit; else { lits->next = append_literal(lits->next, lit); return lits; } } /* append_literal */ /************* * * term_to_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals term_to_literals(Term t, Literals lits) { Literals l; if (is_term(t, false_sym(), 0)) return lits; /* translates to nothing */ else if (is_term(t, or_sym(), 2)) { /* Traverse term right-to-left and add to the * front of the clause, so order is preserved. */ l = term_to_literals(ARG(t,1), lits); l = term_to_literals(ARG(t,0), l); } else { l = get_literals(); l->next = lits; l->sign = !(COMPLEX(t) && is_term(t, not_sym(), 1)); if (l->sign) l->atom = copy_term(t); else l->atom = copy_term(ARG(t,0)); } return(l); } /* term_to_literals */ /************* * * literal_to_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term literal_to_term(Literals l) { Term t; if (l->sign) t = copy_term(l->atom); else { t = get_rigid_term(not_sym(), 1); ARG(t,0) = copy_term(l->atom); } return t; } /* literal_to_term */ /************* * * literals_to_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term literals_to_term(Literals l) { Term t = literal_to_term(l); if (l->next) { Term d = get_rigid_term(or_sym(), 2); ARG(d,0) = t; ARG(d,1) = literals_to_term(l->next); return d; } else return t; } /* literals_to_term */ /************* * * lits_to_term() -- do not copy atoms! * *************/ /* DOCUMENTATION This routine converts a nonempty list of literals into a term. This version does not copy atoms; it constructs new term nodes only for the NOT and OR structure at the top of the clause. Use free_lits_to_term() to free terms constructed with this routine. */ /* PUBLIC */ Term lits_to_term(Literals l) { Term t; if (l->sign) t = l->atom; else { t = get_rigid_term_dangerously(not_symnum(), 1); ARG(t,0) = l->atom; } if (l->next) { Term d = get_rigid_term_dangerously(or_symnum(), 2); ARG(d,0) = t; ARG(d,1) = lits_to_term(l->next); t = d; } return t; } /* lits_to_term */ /************* * * free_lits_to_term() -- do not free atoms! * *************/ /* DOCUMENTATION This routine is to be used with terms constructed by lits_to_term(). */ /* PUBLIC */ void free_lits_to_term(Term t) { if (SYMNUM(t) == not_symnum()) free_term(t); else if (SYMNUM(t) == or_symnum()) { free_lits_to_term(ARG(t,0)); free_lits_to_term(ARG(t,1)); free_term(t); } } /* free_lits_to_term */ /************* * * positive_literals() * *************/ /* DOCUMENTATION This function returns the number of positive literals in a clause. */ /* PUBLIC */ int positive_literals(Literals lits) { if (lits == NULL) return 0; else if (lits->sign) return 1 + positive_literals(lits->next); else return positive_literals(lits->next); } /* positive_literals */ /************* * * negative_literals() * *************/ /* DOCUMENTATION This function returns the number of negative literals in a clause. */ /* PUBLIC */ int negative_literals(Literals lits) { if (lits == NULL) return 0; else if (!lits->sign) return 1 + negative_literals(lits->next); else return negative_literals(lits->next); } /* negative_literals */ /************* * * positive_clause() * *************/ /* DOCUMENTATION This function checks if all of the literals of a clause are positive. */ /* PUBLIC */ BOOL positive_clause(Literals lits) { return negative_literals(lits) == 0; } /* positive_clause */ /************* * * any_clause() * *************/ /* DOCUMENTATION This function is always TRUE. (It it intended to be used as an argument.) */ /* PUBLIC */ BOOL any_clause(Literals lits) { return TRUE; } /* any_clause */ /************* * * negative_clause() * *************/ /* DOCUMENTATION This function checks if all of the literals of a clause are negative. */ /* PUBLIC */ BOOL negative_clause(Literals lits) { return positive_literals(lits) == 0; } /* negative_clause */ /************* * * mixed_clause() * *************/ /* DOCUMENTATION This function checks if a clause has at least one positive and at least one negative literal. */ /* PUBLIC */ BOOL mixed_clause(Literals lits) { return (positive_literals(lits) >= 1 && negative_literals(lits) >= 1); } /* mixed_clause */ /************* * * number_of_literals() * *************/ /* DOCUMENTATION This function returns the number of literals in a clause. */ /* PUBLIC */ int number_of_literals(Literals lits) { if (lits == NULL) return 0; else return 1 + number_of_literals(lits->next); } /* number_of_literals */ /************* * * unit_clause() * *************/ /* DOCUMENTATION This function checks if a clause has exactly one literal. */ /* PUBLIC */ BOOL unit_clause(Literals lits) { return number_of_literals(lits) == 1; } /* unit_clause */ /************* * * horn_clause() * *************/ /* DOCUMENTATION This function checks if a clause has at most one positive literal. */ /* PUBLIC */ BOOL horn_clause(Literals lits) { return positive_literals(lits) <= 1; } /* horn_clause */ /************* * * definite_clause() * *************/ /* DOCUMENTATION This Boolean function checks if a clause has exactly one positive literal. */ /* PUBLIC */ BOOL definite_clause(Literals lits) { return positive_literals(lits) == 1; } /* definite_clause */ /************* * * greatest_variable_in_clause(c) * *************/ /* DOCUMENTATION This routine returns the greatest variable index in a clause. If the clause is ground, -1 is returned. */ /* PUBLIC */ int greatest_variable_in_clause(Literals lits) { if (lits == NULL) return -1; else { int max_this = greatest_variable(lits->atom); int max_rest = greatest_variable_in_clause(lits->next); return IMAX(max_this, max_rest); } } /* greatest_variable_in_clause */ /************* * * vars_in_clause(c) * *************/ /* DOCUMENTATION This routine returns the set of variables (as a Plist) in a clause. */ /* PUBLIC */ Plist vars_in_clause(Literals lits) { if (lits == NULL) return NULL; else return set_of_vars(lits->atom, vars_in_clause(lits->next)); } /* vars_in_clause */ /************* * * varnums_in_clause(c) * *************/ /* DOCUMENTATION This routine returns the set of variable indexes (as an Ilist) in a clause. */ /* PUBLIC */ Ilist varnums_in_clause(Literals lits) { Plist vars = vars_in_clause(lits); Ilist varnums = NULL; Plist p; for (p = vars; p; p = p->next) { Term var = p->v; varnums = ilist_append(varnums, VARNUM(var)); } zap_plist(vars); return varnums; } /* varnums_in_clause */ /************* * * number_of_variables(c) * *************/ /* DOCUMENTATION This routine returns number of (distinct) variables in a clause. */ /* PUBLIC */ int number_of_variables(Literals lits) { Plist vars = vars_in_clause(lits); int n = plist_count(vars); zap_plist(vars); return n; } /* number_of_variables */ /************* * * ground_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL ground_clause(Literals lits) { return greatest_variable_in_clause(lits) == -1; } /* ground_clause */ /************* * * copy_literals() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The container field of each nonvariable subterm points to the clause. */ /* PUBLIC */ Literals copy_literals(Literals lits) { if (lits == NULL) return NULL; else { Literals new = get_literals(); new->sign = lits->sign; new->atom = copy_term(lits->atom); new->next = copy_literals(lits->next); return new; } } /* copy_literals */ /************* * * copy_literals_with_flags() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. All termflags are copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Literals copy_literals_with_flags(Literals lits) { if (lits == NULL) return NULL; else { Literals new = get_literals(); new->sign = lits->sign; new->atom = copy_term_with_flags(lits->atom); new->next = copy_literals(lits->next); return new; } } /* copy_literals_with_flags */ /************* * * copy_literals_with_flag() * *************/ /* DOCUMENTATION This routine builds and returns a copy of a clause. The given termflag is copied for all subterms (including atoms, excluding variables). */ /* PUBLIC */ Literals copy_literals_with_flag(Literals lits, int flag) { if (lits == NULL) return NULL; else { Literals new = get_literals(); new->sign = lits->sign; new->atom = copy_term_with_flag(lits->atom, flag); new->next = copy_literals(lits->next); return new; } } /* copy_literals_with_flag */ /************* * * literal_number() * *************/ /* DOCUMENTATION Given a clause and a literal, return the position of the literal (counting from 1) in the clause. The check is by pointer only. If the literal does not occur in the clause, 0 is returned. */ /* PUBLIC */ int literal_number(Literals lits, Literals lit) { if (lits == NULL) return 0; else if (lits == lit) return 1; else { int n = literal_number(lits->next, lit); return n == 0 ? 0 : n+1; } } /* literal_number */ /************* * * atom_number() * *************/ /* DOCUMENTATION Given a clause and an atom, return the position of the atom (counting from 1) in the clause. The check is by pointer only. If the atom does not occur in the clause, 0 is returned. */ /* PUBLIC */ int atom_number(Literals lits, Term atom) { if (lits == NULL) return 0; else if (lits->atom == atom) return 1; else { int n = atom_number(lits->next, atom); return n == 0 ? 0 : n+1; } } /* atom_number */ /************* * * ith_literal() * *************/ /* DOCUMENTATION Return the i-th literal of a clause, counting from 1. Return NULL if i is out of range. */ /* PUBLIC */ Literals ith_literal(Literals lits, int i) { if (lits == NULL) return NULL; else if (i == 1) return lits; else return ith_literal(lits->next, i-1); } /* ith_literal */ /************* * * true_clause() * *************/ /* DOCUMENTATION Does the clause contain a literal $T? (This does not check for complementary literals, -$F, or x=x.) */ /* PUBLIC */ BOOL true_clause(Literals lits) { if (lits == NULL) return FALSE; else if (lits->sign && true_term(lits->atom)) return TRUE; else return true_clause(lits->next); } /* true_clause */ /************* * * complementary_scan() * *************/ static BOOL complementary_scan(Literals lits, Literals lit) { if (lits == NULL) return FALSE; else if (lits->sign != lit->sign && term_ident(lits->atom, lit->atom)) return TRUE; else return complementary_scan(lits->next, lit); } /* complementary_scan */ /************* * * tautology() * *************/ /* DOCUMENTATION This routine returns TRUE if the clause has complementary literals or if it has any literals of the form $T, -$F. This dos not check for x=x. */ /* PUBLIC */ BOOL tautology(Literals lits) { if (lits == NULL) return FALSE; else if (lits->sign && true_term(lits->atom)) return TRUE; else if (!lits->sign && false_term(lits->atom)) return TRUE; else if (complementary_scan(lits->next, lits)) return TRUE; else return tautology(lits->next); } /* tautology */ /************* * * symbol_occurrences_in_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int symbol_occurrences_in_clause(Literals lits, int symnum) { if (lits == NULL) return 0; else return symbol_occurrences(lits->atom, symnum) + symbol_occurrences_in_clause(lits->next, symnum); } /* symbol_occurrences_in_clause */ /************* * * remove_null_literals() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals remove_null_literals(Literals l) { if (l == NULL) return NULL; else { l->next = remove_null_literals(l->next); if (l->atom != NULL) return l; else { Literals m = l->next; free_literals(l); return m; } } } /* remove_null_literals */ /************* * * first_literal_of_sign() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Literals first_literal_of_sign(Literals lits, BOOL sign) { if (lits == NULL) return NULL; else if (lits->sign == sign) return lits; else return first_literal_of_sign(lits->next, sign); } /* first_literal_of_sign */ /************* * * constants_in_clause() * *************/ /* DOCUMENTATION Given a clause, return the set of symnums for constants therein. */ /* PUBLIC */ Ilist constants_in_clause(Literals lits) { if (lits == NULL) return NULL; else { Ilist p = constants_in_clause(lits->next); return constants_in_term(lits->atom, p); } } /* constants_in_clause */ /************* * * clause_ident() * *************/ /* DOCUMENTATION Identical clauses, including order of literals and variable numbering. */ /* PUBLIC */ BOOL clause_ident(Literals lits1, Literals lits2) { if (lits1 == NULL) return lits2 == NULL; else if (lits2 == NULL) return FALSE; else if (lits1->sign != lits2->sign) return FALSE; else if (!term_ident(lits1->atom, lits2->atom)) return FALSE; else return clause_ident(lits1->next, lits2->next); } /* clause_ident */ /************* * * clause_symbol_count() * *************/ /* DOCUMENTATION Disjunction and negation signs are not included in the count. */ /* PUBLIC */ int clause_symbol_count(Literals lits) { if (lits == NULL) return 0; else return symbol_count(lits->atom) + clause_symbol_count(lits->next); } /* clause_symbol_count */ /************* * * clause_depth() * *************/ /* DOCUMENTATION Disjunction and negation signs are not included in the count. That is, return the depth of the deepest atomic formula. */ /* PUBLIC */ int clause_depth(Literals lits) { if (lits == NULL) return 0; else { int depth_this = term_depth(lits->atom); int depth_rest = clause_depth(lits->next); return IMAX(depth_this, depth_rest); } } /* clause_depth */ /************* * * pos_eq() * *************/ /* DOCUMENTATION This function checks if a literal is a positive equality for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL pos_eq(Literals lit) { return lit->sign && eq_term(lit->atom); } /* pos_eq */ /************* * * neg_eq() * *************/ /* DOCUMENTATION This function checks if a literal is a positive equality for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL neg_eq(Literals lit) { return lit->sign == FALSE && eq_term(lit->atom); } /* neg_eq */ /************* * * pos_eq_unit() * *************/ /* DOCUMENTATION This function checks if a list of Literals is a positive equality unit for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL pos_eq_unit(Literals lits) { return (unit_clause(lits) && lits->sign && eq_term(lits->atom)); } /* pos_eq_unit */ /************* * * neg_eq_unit() * *************/ /* DOCUMENTATION This function checks if a list of Literals is a negative equality unit. */ /* PUBLIC */ BOOL neg_eq_unit(Literals lits) { return (unit_clause(lits) && !lits->sign && eq_term(lits->atom)); } /* neg_eq_unit */ /************* * * contains_pos_eq() * *************/ /* DOCUMENTATION This function checks if a clause contains a positive equality literal for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL contains_pos_eq(Literals lits) { if (lits == NULL) return FALSE; else if (pos_eq(lits)) return TRUE; else return contains_pos_eq(lits->next); } /* contains_pos_eq */ /************* * * contains_eq() * *************/ /* DOCUMENTATION This function checks if a clause contains an equality literal (positive or negative) for the purposes of paramodulation and demodulation. */ /* PUBLIC */ BOOL contains_eq(Literals lits) { if (lits == NULL) return FALSE; else if (eq_term(lits->atom)) return TRUE; else return contains_eq(lits->next); } /* contains_eq */ /************* * * only_eq() * *************/ /* DOCUMENTATION This function checks if a clause contains only equality literals (positive or negative). */ /* PUBLIC */ BOOL only_eq(Literals lits) { if (lits == NULL) return TRUE; else if (!eq_term(lits->atom)) return FALSE; else return only_eq(lits->next); } /* only_eq */ /************* * * literals_depth() * *************/ /* DOCUMENTATION This function returns the maximum depth of a list of literals. Negation signs are not counted, and P(a) has depth 1. */ /* PUBLIC */ int literals_depth(Literals lits) { if (lits == NULL) return 0; else { int m = literals_depth(lits->next); int n = term_depth(lits->atom); return IMAX(m, n); } } /* literals_depth */ /************* * * term_at_position() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term term_at_position(Literals lits, Ilist pos) { if (lits == NULL || pos == NULL) return NULL; else { Literals lit = ith_literal(lits, pos->i); Term t = term_at_pos(lit->atom, pos->next); return t; } } /* term_at_position */ /************* * * pos_predicates() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist pos_predicates(Ilist p, Literals lits) { Literals l; for (l = lits; l; l = l->next) { if (l->sign && ! ilist_member(p, SYMNUM(l->atom))) p = ilist_prepend(p, SYMNUM(l->atom)); } return p; } /* pos_predicates */ LADR-2009-11A/ladr/ioutil.h0000644000175000017500000000550311151265364014425 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_IOUTIL_H #define TP_IOUTIL_H #include "parse.h" #include "fastparse.h" #include "ivy.h" #include "clausify.h" /* INTRODUCTION */ /* Public definitions */ enum { CL_FORM_STD, CL_FORM_BARE, CL_FORM_PARENTS, CL_FORM_XML, CL_FORM_TAGGED, CL_FORM_IVY}; /* clause print format */ /* End of public definitions */ /* Public function prototypes from ioutil.c */ void fwrite_formula(FILE *fp, Formula f); Topform read_clause(FILE *fin, FILE *fout); Topform parse_clause_from_string(char *s); BOOL end_of_list_clause(Topform c); Clist read_clause_clist(FILE *fin, FILE *fout, char *name, BOOL assign_id); Plist read_clause_list(FILE *fin, FILE *fout, BOOL assign_id); void sb_write_clause_jmap(String_buf sb, Topform c, int format, I3list map); void sb_write_clause(String_buf sb, Topform c, int format); void sb_xml_write_clause_jmap(String_buf sb, Topform c, I3list map); void sb_tagged_write_clause_jmap(String_buf sb, Topform c, I3list map); void fwrite_clause_jmap(FILE *fp, Topform c, int format, I3list map); void fwrite_clause(FILE *fp, Topform c, int format); void f_clause(Topform c); void fwrite_clause_clist(FILE *fp, Clist lst, int format); void fwrite_demod_clist(FILE *fp, Clist lst, int format); void fwrite_clause_list(FILE *fp, Plist lst, char *name, int format); void f_clauses(Plist p); Formula read_formula(FILE *fin, FILE *fout); BOOL end_of_list_formula(Formula f); Plist read_formula_list(FILE *fin, FILE *fout); void fwrite_formula_list(FILE *fp, Plist lst, char *name); void zap_formula_list(Plist lst); BOOL end_of_list_term(Term t); BOOL end_of_commands_term(Term t); Plist read_term_list(FILE *fin, FILE *fout); void fwrite_term_list(FILE *fp, Plist lst, char *name); Term term_reader(BOOL fast); void term_writer(Term t, BOOL fast); Topform clause_reader(BOOL fast); void clause_writer(Topform c, BOOL fast); Topform term_to_topform2(Term t); Topform read_clause_or_formula(FILE *fin, FILE *fout); Plist read_clause_or_formula_list(FILE *fin, FILE *fout); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/listterm.c0000644000175000017500000001245310637466322014765 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "listterm.h" /* Private definitions and types */ #define CONS_SYM "$cons" #define NIL_SYM "$nil" /************* * * get_nil_term() * *************/ /* DOCUMENTATION Allocate and return an empty listterm. */ /* PUBLIC */ Term get_nil_term() { return get_rigid_term(NIL_SYM, 0); } /* get_nil_term */ /************* * * listterm_cons() * *************/ /* DOCUMENTATION This routine returns the "cons" of two terms. The two terms are not copied. */ /* PUBLIC */ Term listterm_cons(Term t1, Term t2) { Term c = get_rigid_term(CONS_SYM, 2); ARG(c,0) = t1; ARG(c,1) = t2; return c; } /* listterm_cons */ /************* * * cons_term() * *************/ /* DOCUMENTATION This function checks if a term is a "cons", that is, arity 2 with the official "cons" symbol. */ /* PUBLIC */ BOOL cons_term(Term t) { return is_symbol(SYMNUM(t), CONS_SYM, 2); } /* cons_term */ /************* * * nil_term() * *************/ /* DOCUMENTATION This function checks if a term is a "nil", that is, arity 0 with the official "nil" symbol. */ /* PUBLIC */ BOOL nil_term(Term t) { return is_symbol(SYMNUM(t), NIL_SYM, 0); } /* nil_term */ /************* * * proper_listterm() * *************/ /* DOCUMENTATION This function checks if a term is a proper listterm, that is, a nil_term(), or a cons_term() whose tail is a proper_listterm(). */ /* PUBLIC */ BOOL proper_listterm(Term t) { if (nil_term(t)) return TRUE; else if (cons_term(t)) return proper_listterm(ARG(t,1)); else return FALSE; } /* proper_listterm */ /************* * * listterm_append() * *************/ /* DOCUMENTATION This routine appends an element to a listterm. The resulting listterm is returned. Neither the list nor the element is copied. You should not refer to the argument "list" after calling this routine---a good way to call it is like this:

    list = listterm_append(list, element)

    If "list" is not a proper_listterm(), the result will be well-formed, but it might not be what you expect. */ /* PUBLIC */ Term listterm_append(Term list, Term element) { if (!cons_term(list)) return listterm_cons(element, list); else { ARG(list,1) = listterm_append(ARG(list,1), element); return list; } } /* listterm_append */ /************* * * listterm_length() * *************/ /* DOCUMENTATION This function returns the length of a listterm. */ /* PUBLIC */ int listterm_length(Term t) { if (!cons_term(t)) return 0; else { return 1 + listterm_length(ARG(t,1)); } } /* listterm_length */ /************* * * listterm_i() * *************/ /* DOCUMENTATION Return the i-th member, counting from 1, of a listterm. If there are less than i members, return NULL. */ /* PUBLIC */ Term listterm_i(Term lst, int i) { if (!cons_term(lst)) return NULL; else if (i == 1) return ARG(lst,0); else return listterm_i(ARG(lst,1), i-1); } /* listterm_i */ /************* * * listterm_member() * *************/ /* DOCUMENTATION This function checks if Term t is a member of a listterm (Term lst). */ /* PUBLIC */ BOOL listterm_member(Term t, Term lst) { if (cons_term(lst)) { if (term_ident(t, ARG(lst,0))) return TRUE; else return listterm_member(t, ARG(lst,1)); } else return FALSE; } /* listterm_member */ /************* * * listterm_to_tlist() * *************/ /* DOCUMENTATION Given a proper listterm (e.g, [a,b,c]), return a Plist of the members. The members are not copied. */ /* PUBLIC */ Plist listterm_to_tlist(Term t) { if (!proper_listterm(t)) return NULL; else { Plist p = NULL; while (cons_term(t)) { p = plist_append(p, ARG(t, 0)); t = ARG(t,1); } return p; } } /* listterm_to_tlist */ /************* * * listterm_zap() * *************/ /* DOCUMENTATION Free a list structure, but do not free its members. */ /* PUBLIC */ void listterm_zap(Term t) { if (!cons_term(t)) zap_term(t); else { listterm_zap(ARG(t,1)); free_term(t); } } /* listterm_zap */ /************* * * rev2() * *************/ static Term rev2(Term t, Term done) { if (!cons_term(t)) return done; else return rev2(ARG(t,1), listterm_cons(ARG(t,0), done)); } /* rev2 */ /************* * * listterm_reverse() * *************/ /* DOCUMENTATION Reverse a listterm. A new list structure is created, but the members are not copied. The old list structure is freed. */ /* PUBLIC */ Term listterm_reverse(Term t) { Term reversed = rev2(t, get_nil_term()); listterm_zap(t); return reversed; } /* listterm_reverse */ LADR-2009-11A/ladr/tptp_trans.c~0000644000175000017500000005352711150624042015507 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "tptp_trans.h" /* Private definitions and types */ /* From Geoff Sutcliffe, Feb 13, 2008: %----These are used in the TPTP and need to exist before the %----transformations and formats are loaded. They are also declared at %----runtime in tptp2X/4. :-op(99,fx,'$'). :-op(100,fx,++). :-op(100,fx,--). %----Postfix for != :-op(100,xf,'!'). %---- .. used for range in tptp2X. Needs to be stronger than : :-op(400,xfx,'..'). %----! and ? are of higher precedence than : so ![X]:p(X) is :(![X],p(X)) %----Otherwise ![X]:![Y]:p(X,Y) cannot be parsed. %----! is fy so Prolog can read !! (blah) as !(!(blah)) and it gets fixed :-op(400,fy,!). :-op(400,fx,?). :-op(400,fx,^). :-op(400,fx,:=). :-op(400,fx,'!!'). :-op(400,fx,'??'). %----= must bind more tightly than : for ! [X] : a = X. = must binder looser %----than quantifiers for otherwise X = ! [Y] : ... is a syntax error (the = %----grabs the quantifier). That means for thf it is necessary to bracket %----formula terms, e.g., a = (! [X] : p(X)) :-op(405,xfx,'='). %---!= not possible because ! is special - see postfix cheat :-op(405,xfx,'!='). :-op(440,xfy,>). %----Type arrow %----Need : stronger than binary connectives for ! [X] : p(X) <=> !Y ... %----Need ~ and : equal and right-assoc for ![X] : ~p and for ~![X] : ... :-op(450,xfy,:). :-op(450,fy,~). :-op(501,yfx,@). :-op(502,xfy,'|'). :-op(502,xfy,'~|'). :-op(502,xfy,'+'). %----Fision for rfof :-op(503,xfy,&). :-op(503,xfy,~&). :-op(503,xfy,'*'). %----Fusion for rfof :-op(504,xfy,=>). :-op(504,xfy,<=). :-op(505,xfy,<=>). :-op(505,xfy,<~>). %----Must be weak to allow any formulae on RHS :-op(550,xfy,:=). -------------------------------------------------------- Correction from Geoff, May 14, 2008: op(502,xfx,'~|'), op(503,xfx,~&), op(504,xfx,=>), op(504,xfx,<=), op(505,xfx,<=>), op(505,xfx,<~>), op(550,xfx,:=). -------------------------------------------------------- From Geoff, October 6, 2008: I would be quite happy if both [input and output] were equally strict, conforming to the TPTP BNF. However, your other users might be happier if the input were a little more forgiving, and that's why my Prolog operator defs are like they are - more forgiving than the BNF. I guess you have the following at the moment, which are the "forgiving" operator defs ... op(400,fy,!), op(400,fx,?), op(405,xfx,'='), op(450,xfy,:), op(450,fy,~), op(502,xfy,'|'), op(502,xfx,'~|'), op(503,xfy,&), op(503,xfx,~&), op(504,xfx,=>), op(504,xfx,<=), op(505,xfx,<=>), op(505,xfx,<~>), Indeed, I solved the current issue by reading your output with my Prolog tool, whose parsing uses those defs, but whose output routines are hand rolled to output in strict TPTP format. For output, or generally strict, you can set all the binary connectives to the same precedence, e.g., ... op(502,xfy,'|'), op(502,xfx,'~|'), op(502,xfy,&), op(502,xfx,~&), op(502,xfx,=>), op(502,xfx,<=), op(502,xfx,<=>), op(502,xfx,<~>), Note the | and & are xfy, which allows, e.g., (a | b | c | d). -------------------------------------------------------- WWM: Ok, I'll separate the types for parsing TPTP and printing TPTP. Parsing TPTP will be flexible, pretty much as before. Printing will be conservative, using Geoff's second set of op defs above, with the exception that & and | will be INFIX instead of INFIX_RIGHT, (because LADR does not allow different parse types with same precedence). So we'll print, e.g., (a & (b & c)) => (d | (e | f)), whereas the TPTP string a & b & c => d | e | f wil be parsed correctly as the same term. Also, for ladr_to_tptp, I'll add an command-line option -p that will cause ALL expressions to be parenthesized. */ /************* * * declare_tptp_input_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_tptp_input_types(void) { check_for_illegal_symbols(FALSE); /* get around the "--" problem */ /* We do not support all of the TPTP operations listed above. */ declare_parse_type(",", 999, INFIX_RIGHT); /* LADR requirement */ declare_parse_type("++", 100, PREFIX_PAREN); declare_parse_type("--", 100, PREFIX_PAREN); declare_parse_type("!", 400, PREFIX_PAREN); declare_parse_type("?", 400, PREFIX_PAREN); declare_parse_type("!=", 405, INFIX); /* added by McCune */ declare_parse_type("=", 405, INFIX); declare_parse_type("~", 410, PREFIX); /* changed by McCune */ declare_parse_type(":", 450, INFIX_RIGHT); declare_parse_type("|", 502, INFIX_RIGHT); declare_parse_type("&", 503, INFIX_RIGHT); declare_parse_type("=>", 504, INFIX); declare_parse_type("<=", 504, INFIX); declare_parse_type("<=>", 505, INFIX); declare_parse_type("<~>", 505, INFIX); /* Other things */ set_cons_char('\0'); /* Don't recognize list cons */ } /* declare_tptp_input_types */ /************* * * declare_tptp_output_types() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void declare_tptp_output_types(void) { check_for_illegal_symbols(FALSE); /* get around the "--" problem */ /* We do not support all of the TPTP operations listed above. */ declare_parse_type(",", 999, INFIX_RIGHT); /* LADR requirement */ declare_parse_type("++", 100, PREFIX_PAREN); declare_parse_type("--", 100, PREFIX_PAREN); declare_parse_type("!", 400, PREFIX_PAREN); declare_parse_type("?", 400, PREFIX_PAREN); declare_parse_type("!=", 405, INFIX); /* added by McCune */ declare_parse_type("=", 405, INFIX); declare_parse_type("~", 410, PREFIX); /* changed by McCune */ declare_parse_type(":", 450, INFIX_RIGHT); declare_parse_type("|", 502, INFIX); /* NOTE: not INFIX_RIGHT (xfy) */ declare_parse_type("&", 502, INFIX); /* NOTE: not INFIX_RIGHT (xfy) */ declare_parse_type("=>", 502, INFIX); declare_parse_type("<=", 502, INFIX); declare_parse_type("<=>", 502, INFIX); declare_parse_type("<~>", 502, INFIX); /* Other things */ set_cons_char('\0'); /* Don't recognize list cons */ } /* declare_tptp_output_types */ /***************************************************************************** This first part is for the TPTP to LADR transformation *****************************************************************************/ /************* * * tptp2_to_ladr_term() * * Take a TPTP "input_clause" transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp2_to_ladr_term(Term t) { Term f = NULL; if (!proper_listterm(t)) { p_term(t); fatal_error("tptp2_to_ladr_term, expected list of literals"); } t = listterm_reverse(t); /* so the result is in the same order */ while (cons_term(t)) { Term a0 = ARG(t,0); Term lit = NULL; if (is_term(a0, "++", 1) || is_term(a0, "--", 1)) { Term atom = ARG(a0, 0); if (is_term(atom, "equal", 2)) { Term tmp = build_binary_term_safe(eq_sym(), ARG(atom,0), ARG(atom,1)); free_term(atom); /* shallow */ atom = tmp; } if (is_term(a0, "++", 1)) lit = atom; else lit = build_unary_term_safe(not_sym(), atom); } else { p_term(a0); fatal_error("tptp2_to_ladr_term, unknown literal"); } if (f == NULL) f = lit; else f = build_binary_term_safe(or_sym(), lit, f); t = ARG(t,1); } return f; } /* tptp2_to_ladr_term */ /************* * * tptp3_to_ladr_term() * * Take a TPTP "cnf" or "fof", and transform it to a LADR formula * (in term form). The input formula is used up in the transformation. * *************/ static Term tptp3_to_ladr_term(Term t) { if (is_term(t, "$true", 0)) { free_term(t); return get_rigid_term(true_sym(), 0); } else if (is_term(t, "$false", 0)) { free_term(t); return get_rigid_term(false_sym(), 0); } else if (is_term(t, "~", 1)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term t2 = build_unary_term_safe(not_sym(), a0); free_term(t); return t2; } else if (is_term(t, "|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(imp_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(impby_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "<=>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); free_term(t); return t2; } else if (is_term(t, "~&", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(and_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "~|", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(or_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, "<~>", 2)) { Term a0 = tptp3_to_ladr_term(ARG(t,0)); Term a1 = tptp3_to_ladr_term(ARG(t,1)); Term t2 = build_binary_term_safe(iff_sym(), a0, a1); Term t3 = build_unary_term_safe(not_sym(), t2); free_term(t); return t3; } else if (is_term(t, ":", 2)) { /* Assume it's well formed (don't check for errors). */ Term q = ARG(t,0); Term form = tptp3_to_ladr_term(ARG(t,1)); Term vars = listterm_reverse(ARG(q,0)); char *quant; if (!proper_listterm(vars)) fatal_error("tptp_to_ladr: bad quantified variable(s)"); quant = (is_term(q,"!",1) ? all_sym() : exists_sym()); while (cons_term(vars)) { Term v = ARG(vars, 0); Term new = get_rigid_term(quant_sym(), 3); ARG(new,0) = get_rigid_term(quant, 0); ARG(new,1) = copy_term(v); ARG(new,2) = form; form = new; vars = ARG(vars, 1); } zap_term(vars); free_term(t); free_term(q); return form; } else return t; } /* tptp3_to_ladr_term */ /************* * * tptp_input_to_ladr_formula() * * The input Term t is not modified by the call. * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula tptp_input_to_ladr_formula(Term t) { char *type = sn_to_str(SYMNUM(t)); Term name = ARG(t,0); Term role = ARG(t,1); Term form = NULL; Term a, b; Formula f; if (str_ident(type, "fof") || str_ident(type, "cnf")) form = tptp3_to_ladr_term(copy_term(ARG(t,2))); else if (str_ident(type, "input_clause")) form = tptp2_to_ladr_term(copy_term(ARG(t,2))); else { p_term(t); fatal_error("tptp_formlua: unknown type"); } a = build_binary_term_safe(attrib_sym(), build_unary_term_safe("label", copy_term(name)), build_unary_term_safe("label", copy_term(role))); b = build_binary_term_safe(attrib_sym(), form, a); f = term_to_formula(b); zap_term(b); return f; } /* tptp_input_to_ladr_formula */ /***************************************************************************** This first part is for the LADR to TPTP transformation *****************************************************************************/ /************* * * rename_vars_to_upper() * *************/ static void rename_vars_to_upper(Formula f) { int i; if (quant_form(f)) { Term var = get_rigid_term(f->qvar, 0); int sn = fresh_symbol("X", 0); Term newvar = get_rigid_term(sn_to_str(sn), 0); subst_free_var(f->kids[0], var, newvar); f->qvar = sn_to_str(sn); free_term(var); free_term(newvar); } for (i = 0; i < f->arity; i++) rename_vars_to_upper(f->kids[i]); } /* rename_vars_to_upper */ /************* * * ladr_term_to_tptp_term() * *************/ static Term ladr_term_to_tptp_term(Term t) { if (is_term(t, true_sym(), 0)) { free_term(t); return get_rigid_term("$true", 0); } else if (is_term(t, false_sym(), 0)) { free_term(t); return get_rigid_term("$false", 0); } else if (is_term(t, not_sym(), 1)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term t2 = build_unary_term_safe("~", a0); free_term(t); return t2; } else if (is_term(t, or_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("|", a0, a1); free_term(t); return t2; } else if (is_term(t, and_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("&", a0, a1); free_term(t); return t2; } else if (is_term(t, imp_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("=>", a0, a1); free_term(t); return t2; } else if (is_term(t, impby_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=", a0, a1); free_term(t); return t2; } else if (is_term(t, iff_sym(), 2)) { Term a0 = ladr_term_to_tptp_term(ARG(t,0)); Term a1 = ladr_term_to_tptp_term(ARG(t,1)); Term t2 = build_binary_term_safe("<=>", a0, a1); free_term(t); return t2; } else if (is_term(t, quant_sym(), 3)) { Term quant = ARG(t,0); Term var = ARG(t,1); Term form = ladr_term_to_tptp_term(ARG(t,2)); char *q = is_term(quant, "all", 0) ? "!" : "?"; /* build the term :(quant([var]),form) */ Term vlist = listterm_cons(var, get_nil_term()); Term qterm = build_unary_term_safe(q, vlist); Term top = build_binary_term_safe(":", qterm, form); free_term(quant); /* shallow */ return top; } else return t; } /* ladr_term_to_tptp_term */ /************* * * ladr_list_to_tptp_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist ladr_list_to_tptp_list(Plist in, char *name, char *type) { BOOL goal = str_ident(type, "conjecture"); /* goals always become fof */ Plist out = NULL; Plist p; for (p = in; p; p = p->next) { Formula f = p->v; f->attributes = NULL; /* always remove all attributes */ if (clausal_formula(f) && !goal) { Term t, cnf; Topform c = formula_to_clause(f); zap_formula(f); clause_set_variables(c, MAX_VARS); t = ladr_term_to_tptp_term(topform_to_term(c)); zap_topform(c); cnf = get_rigid_term("cnf", 3); ARG(cnf,0) = get_rigid_term(name, 0); ARG(cnf,1) = get_rigid_term(type, 0); ARG(cnf,2) = t; out = plist_prepend(out, cnf); } else { /* f is a non-clausal formula */ Term t, fof; f = universal_closure(f); rename_vars_to_upper(f); t = ladr_term_to_tptp_term(formula_to_term(f)); fof = get_rigid_term("fof", 3); ARG(fof,0) = get_rigid_term(name, 0); ARG(fof,1) = get_rigid_term(type, 0); ARG(fof,2) = t; out = plist_prepend(out, fof); } } return reverse_plist(out); } /* ladr_list_to_tptp_list */ /************* * * syms_in_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Ilist syms_in_form(Term t, BOOL clausal) { if (clausal) { if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), TRUE); else if (is_term(t, "|", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), TRUE); Ilist b = syms_in_form(ARG(t,1), TRUE); return ilist_union(a,b); } else return fsym_set_in_term(t); } else { /* non-clausal */ if (is_term(t, "~", 1)) return syms_in_form(ARG(t,0), FALSE); else if (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else if (is_term(t, ":", 2)) { /* This assumes exactly one universally quantified variable! */ Ilist a = syms_in_form(ARG(t,1), FALSE); a = ilist_removeall(a, SYMNUM(ARG(ARG(ARG(t,0),0),0))); return a; } else if (is_term(t, "=", 2)) { Ilist a = syms_in_form(ARG(t,0), FALSE); Ilist b = syms_in_form(ARG(t,1), FALSE); return ilist_union(a,b); } else return fsym_set_in_term(t); } } /* syms_in_form */ /************* * * good_tptp_sym() * *************/ static BOOL good_tptp_sym(char *s) { /* [a-z][a-zA-Z0-9_]* */ if (strlen(s) == 0) return FALSE; else { if (!(s[0] >= 'a' && s[0] <= 'z')) return FALSE; else { int i; for (i = 1; i < strlen(s); i++) { char c = s[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) return FALSE; } return TRUE; } } } /* good_tptp_sym */ /************* * * good_ladr_sym() * *************/ static BOOL good_ladr_sym(char *s) { return s[0] != '\''; } /* good_ladr_sym */ /************* * * map_for_bad_tptp_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list map_for_bad_tptp_syms(Ilist syms, BOOL quote_bad_syms) { if (syms == NULL) return NULL; else { I2list map = map_for_bad_tptp_syms(syms->next, quote_bad_syms); int old_sn = syms->i; char *s = sn_to_str(old_sn); if (!good_tptp_sym(s)) { int new_sn; if (quote_bad_syms) { char *escaped = escape_char(s, '\''); int n = strlen(escaped); char *new_str = malloc(n+3); new_str[0] = '\''; strcpy(new_str+1, escaped); new_str[n+1] = '\''; new_str[n+2] = '\0'; new_sn = str_to_sn(new_str, sn_to_arity(old_sn)); free(new_str); free(escaped); } else new_sn = fresh_symbol("tptp", sn_to_arity(old_sn)); map = i2list_append(map, old_sn, new_sn); } return map; } } /* map_for_bad_tptp_syms */ /************* * * map_for_bad_ladr_syms() * *************/ /* DOCUMENTATION */ /* PUBLIC */ I2list map_for_bad_ladr_syms(Ilist syms, BOOL quote_bad_syms) { if (syms == NULL) return NULL; else { I2list map = map_for_bad_ladr_syms(syms->next, quote_bad_syms); int old_sn = syms->i; char *s = sn_to_str(old_sn); if (!good_ladr_sym(s)) { int new_sn; if (quote_bad_syms) { char *escaped = escape_char(s, '"'); int n = strlen(escaped); char *new_str = malloc(n+3); new_str[0] = '"'; strcpy(new_str+1, escaped); new_str[n+1] = '"'; new_str[n+2] = '\0'; new_sn = str_to_sn(new_str, sn_to_arity(old_sn)); free(new_str); free(escaped); } else new_sn = fresh_symbol("ladr", sn_to_arity(old_sn)); map = i2list_append(map, old_sn, new_sn); } return map; } } /* map_for_bad_ladr_syms */ /************* * * replace_bad_syms_term() * *************/ /* DOCUMENTATION The given term is used up. */ /* PUBLIC */ Term replace_bad_syms_term(Term t, I2list map) { if (VARIABLE(t)) return t; else { int i; int old_sn = SYMNUM(t); int new_sn = assoc(map, old_sn); if (new_sn != INT_MIN) { Term new = get_rigid_term(sn_to_str(new_sn), sn_to_arity(new_sn)); for (i = 0; i < ARITY(t); i++) ARG(new,i) = ARG(t,i); free_term(t); /* shallow */ t = new; } for (i = 0; i < ARITY(t); i++) ARG(t,i) = replace_bad_syms_term(ARG(t,i), map); return t; } } /* replace_bad_syms_term */ /************* * * replace_bad_tptp_syms_form() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term replace_bad_tptp_syms_form(Term t, BOOL clausal, I2list map) { if (is_term(t, "~", 1)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), clausal, map); return t; } else if (clausal && is_term(t, "|", 2)) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), TRUE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), TRUE, map); return t; } else if (!clausal && (is_term(t, "|", 2) || is_term(t, "&", 2) || is_term(t, "=>", 2) || is_term(t, "<=", 2) || is_term(t, "<=>", 2))) { ARG(t,0) = replace_bad_tptp_syms_form(ARG(t,0), FALSE, map); ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else if (!clausal && is_term(t, ":", 2)) { /* We do not have to worry about quantified variables being replaced---they are disjoint from all other symbols, because they were generted by fresh_symbol(). */ ARG(t,1) = replace_bad_tptp_syms_form(ARG(t,1), FALSE, map); return t; } else return replace_bad_syms_term(t, map); } /* replace_bad_tptp_syms_form */ LADR-2009-11A/ladr/unify.c0000644000175000017500000005072211136374301014243 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "unify.h" /* Private definitions and types */ /* A Trail records substitutions so that they can be easily undone. * Whenever a variable is instantiated (by making in entry in a * Context), one of these nodes is prepended to the current trail. */ struct trail { int varnum; /* index of instantiated variable */ Context context; /* context of instanteated variable */ Trail next; /* next (earlier) member of trail */ }; /* bind a variable, record binding in a trail */ #define BIND_TR(i, c1, t2, c2, trp) { struct trail *tr; \ c1->terms[i] = t2; c1->contexts[i] = c2; \ tr = get_trail(); tr->varnum = i; tr->context = c1; \ tr->next = *trp; *trp = tr; } #define MAX_MULTIPLIERS 500 /* Private variables */ static BOOL Multipliers[MAX_MULTIPLIERS]; /* (m[i]==FALSE) => i is available */ /************* * * next_available_multiplier() * *************/ static int next_available_multiplier() { int i; for (i = 0; i < MAX_MULTIPLIERS; i++) if (!Multipliers[i]) { Multipliers[i] = TRUE; return i; } fatal_error("next_available_multiplier, none available (infinite loop?)."); return -1; /* to quiet compiler */ } /* next_available_multiplier */ /* * memory management */ #define PTRS_CONTEXT PTRS(sizeof(struct context)) static unsigned Context_gets, Context_frees; #define PTRS_TRAIL PTRS(sizeof(struct trail)) static unsigned Trail_gets, Trail_frees; /************* * * Context get_context() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Context get_context(void) { Context p = get_cmem(PTRS_CONTEXT); p->multiplier = next_available_multiplier(); Context_gets++; return(p); } /* get_context */ /************* * * free_context() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void free_context(Context p) { if (Multipliers[p->multiplier] == FALSE) fatal_error("free_context, bad multiplier"); Multipliers[p->multiplier] = FALSE; free_mem(p, PTRS_CONTEXT); Context_frees++; } /* free_context */ /************* * * Trail get_trail() * *************/ static Trail get_trail(void) { Trail p = get_mem(PTRS_TRAIL); /* uninitialized */ Trail_gets++; return(p); } /* get_trail */ /************* * * free_trail() * *************/ static void free_trail(Trail p) { free_mem(p, PTRS_TRAIL); Trail_frees++; } /* free_trail */ /************* * * fprint_unify_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the unify package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_unify_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct context); fprintf(fp, "context (%4d) %11u%11u%11u%9.1f K\n", n, Context_gets, Context_frees, Context_gets - Context_frees, ((Context_gets - Context_frees) * n) / 1024.); n = sizeof(struct trail); fprintf(fp, "trail (%4d) %11u%11u%11u%9.1f K\n", n, Trail_gets, Trail_frees, Trail_gets - Trail_frees, ((Trail_gets - Trail_frees) * n) / 1024.); } /* fprint_unify_mem */ /************* * * p_unify_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the unify package. */ /* PUBLIC */ void p_unify_mem() { fprint_unify_mem(stdout, 1); } /* p_unify_mem */ /* * end of memory management */ /************* * * unify() * *************/ /* DOCUMENTATION This routine tries to unify two terms in their respective contexts. Trail * trp is the address of a Trail. If successful, the trail is extended (at its front) with substitutions that were made, and trp is updated to point to the new beginning of the trail. If unify fails, the Contexts and the Trail * are not changed.

    You must make sure, before calling unify(), that no variable v in t1 or t2 has VARNUM(v) >= MAXVARS. This is usually accomplished by calling a routine that renames variables.

    Here is an example how to use unify(), apply(), and undo_subst(). Assume we have terms t1 and t2. (Terms t1 and t2 may share variables, but we "separate" the variables by using different contexts. That is, variable v1 in context c1 is different from variable v1 in context c2.)

        {
            Context c1 = get_context();
            Context c2 = get_context();
            Trail tr = NULL;
            if (unify(t1, c1, t2, c2, &tr)) {
                Term t3 = apply(t1, c1);
                Term t4 = apply(t2, c2);
                if (term_ident(t3, t4))
                    printf("everything is OK\n");
                else
                    printf("something is broken\n");
                undo_subst(tr);
                zap_term(t3);
                zap_term(t4);
            }
            else
                printf("unify fails\n");
            free_context(c1);
            free_context(c2);
        }
    
    */ /* PUBLIC */ BOOL unify(Term t1, Context c1, Term t2, Context c2, Trail *trp) { Trail tpos, tp, t3; int vn1, vn2; DEREFERENCE(t1, c1) /* dereference macro */ DEREFERENCE(t2, c2) /* dereference macro */ /* Now, neither t1 nor t2 is a bound variable. */ if (VARIABLE(t1)) { vn1 = VARNUM(t1); if (VARIABLE(t2)) { /* both t1 and t2 are variables */ if (vn1 == VARNUM(t2) && c1 == c2) return TRUE; /* identical */ else { BIND_TR(vn1, c1, t2, c2, trp) return TRUE; } } else { /* t1 variable, t2 not variable */ if (occur_check(vn1, c1, t2, c2)) { BIND_TR(vn1, c1, t2, c2, trp) return TRUE; } else return FALSE; /* failed occur_check */ } } else if (VARIABLE(t2)) { /* t2 variable, t1 not variable */ vn2 = VARNUM(t2); if (occur_check(vn2, c2, t1, c1)) { BIND_TR(vn2, c2, t1, c1, trp) return TRUE; } else return FALSE; /* failed occur_check */ } else if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else if (ARITY(t1) == 0) return TRUE; else { /* both complex with same symbol */ int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = ARITY(t1); while (i < arity && unify(ARG(t1,i), c1, ARG(t2,i), c2, trp)) i++; if (i == arity) return TRUE; else { /* restore trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; tp->context->contexts[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } /* unify */ /************* * * int variant(t1, c1, t2, trail_address) * *************/ /* DOCUMENTATION This routine checks if Term t1 (in Context c1) and Term t2 (without a Context) are variants, that is, if each is an instance of the other. If successful, the unifying substitution is in Context c1. The calling sequence and the use of Contexts and Trails is the same as for unify(). */ /* PUBLIC */ BOOL variant(Term t1, Context c1, Term t2, Trail *trp) { /* If this gets used a lot, it should be recoded so that it won't * traverse the terms twice. */ BOOL ok; Trail tr = NULL; Context c2 = get_context(); if (match(t2, c2, t1, &tr)) { undo_subst(tr); ok = match(t1, c1, t2, trp); } else ok = 0; free_context(c2); return ok; } /* variant */ /************* * * int occur_check(varnum, var_context, term, term_context) * * Return 0 iff variable occurs in term under substitution * (including var==term). * *************/ /* DOCUMENTATION This function checks if a variable with index vn (in Context vc) occurs in Term t (in Context c), including the top case, where t is the variable in question. */ /* PUBLIC */ BOOL occur_check(int vn, Context vc, Term t, Context c) { if (!c) return TRUE; else if (VARIABLE(t)) { /* variable */ int tvn; tvn = VARNUM(t); if (tvn == vn && c == vc) return FALSE; /* fail occur_check here */ else if (c->terms[tvn] == NULL) return TRUE; /* uninstantiated variable */ else return occur_check(vn, vc, c->terms[tvn], c->contexts[tvn]); } else { /* constant or complex */ int i; for (i = 0; i < ARITY(t); i++) if (!occur_check(vn, vc, ARG(t,i), c)) return FALSE; return TRUE; } } /* occur_check */ /************* * * int match(t1, c1, t2, trail_address) -- one-way unification. * * Match returns 1 if t2 is an instance of {t1 in context c1}. * This is not a very general version, but it is useful for * demodulation and subsumption. It assumes that the variables * of t1 and t2 are separate, that none of the variables in t2 * have been instantiated, and that none of those t2's variables * will be instantiatied. Hence, there is no context for t2, * no need to dereference more than one level, and no need for * an occur_check. * * The use of the trail is the same as in `unify'. * *************/ /* DOCUMENTATION This routine checks if Term t2 (without a Context) is an instance of Term t1 (in Context c1). If successful, Context c1 and Trail * trp are updated. The calling sequence and the use of Contexts and Trails is similar to those for unify(). */ /* PUBLIC */ BOOL match(Term t1, Context c1, Term t2, Trail *trp) { int vn; if (VARIABLE(t1)) { vn = VARNUM(t1); if (c1->terms[vn] == NULL) { BIND_TR(vn, c1, t2, NULL, trp) return TRUE; } else return term_ident(c1->terms[vn], t2); } else if (VARIABLE(t2)) return FALSE; else { /* neither term is a variable */ if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else { Trail tpos, tp, t3; int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = ARITY(t1); while (i < arity && match(ARG(t1,i), c1, ARG(t2,i), trp)) i++; if (i == arity) return TRUE; else { /* restore from trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } } /* match */ /************* * * Term apply(term, context) -- Apply a substitution to a term. * * Apply always succeeds and returns a pointer to the * instantiated term. * *************/ /* DOCUMENTATION This routine applies the substitution in Context c to Term t. See the explanation of unify() for an example of the use of apply(). */ /* PUBLIC */ Term apply(Term t, Context c) { DEREFERENCE(t, c) /* A NULL context is ok. It happens when c is built by match. */ /* If the context is NULL, then apply just copies the term. */ if (VARIABLE(t)) { if (!c) return get_variable_term(VARNUM(t)); else return get_variable_term(c->multiplier * MAX_VARS + VARNUM(t)); } else { /* constant or complex term */ Term t2 = get_rigid_term_like(t); int i; for (i = 0; i < ARITY(t); i++) ARG(t2,i) = apply(ARG(t,i), c); return t2; } } /* apply */ /************* * * apply_substitute() * *************/ /* DOCUMENTATION This routine is like apply(), but when it reaches a particular subterm (into_term) of the source term (t), it continues with another source term (beta). This routine is intended to be used for paramodulation, to avoid unnecessary work. For example, when paramodulating alpha=beta into p[into_term], where alpha unifies with into_term, we construct the appropriate instance of p[beta] in one step by using this routine. */ /* PUBLIC */ Term apply_substitute(Term t, Term beta, Context c_from, Term into_term, Context c_into) { if (t == into_term) return apply(beta, c_from); else if (VARIABLE(t)) return apply(t, c_into); else { Term t2 = get_rigid_term_like(t); int i; for (i = 0; i < ARITY(t); i++) ARG(t2,i) = apply_substitute(ARG(t,i), beta, c_from, into_term, c_into); return t2; } } /* apply_substitute */ /************* * * apply_substitute2() * *************/ /* DOCUMENTATION Similar to apply_substitute, but the into_term is specified with a position vector instead of the term itself. This is so that the into term can be a variable. (Recall that variables are probably shared, and we have to specify an *occurrence*.) */ /* PUBLIC */ Term apply_substitute2(Term t, Term beta, Context c_from, Ilist into_pos, Context c_into) { if (into_pos == NULL) return apply(beta, c_from); else if (VARIABLE(t)) return apply(t, c_into); else { Term t2 = get_rigid_term_like(t); int arg_pos = into_pos->i - 1; /* Position vectors count from 1. */ int i; for (i = 0; i < ARITY(t); i++) { if (i == arg_pos) ARG(t2,i) = apply_substitute2(ARG(t,i), beta, c_from, into_pos->next, c_into); else ARG(t2,i) = apply(ARG(t,i), c_into); } return t2; } } /* apply_substitute2 */ /************* * * apply_demod() * * Special-purpose apply for ordinary demodulation. * Assume every variable in t is instantated by the * substitution. Terms that come from instantiating * variables get the flag set, indicating that the * term is fully demodulated (assuming inside-out * demodulation). * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term apply_demod(Term t, Context c, int flag) { Term b; if (VARIABLE(t)) { b = copy_term(c->terms[VARNUM(t)]); term_flag_set(b, flag); } else { int i; b = get_rigid_term_like(t); for (i = 0; i < ARITY(t); i++) ARG(b,i) = apply_demod(ARG(t,i), c, flag); } return b; } /* apply_demod */ /************* * * undo_subst(tr) -- Clear a substitution. * *************/ /* DOCUMENTATION This routine clears substitution entries recoded in Trail tr, and frees the corresponding Trail nodes. */ /* PUBLIC */ void undo_subst(Trail tr) { Trail t3; while (tr != NULL) { tr->context->terms[tr->varnum] = NULL; tr->context->contexts[tr->varnum] = NULL; t3 = tr; tr = tr->next; free_trail(t3); } } /* undo_subst */ /************* * * undo_subst_2(trail_1, trail_2) -- Clear part of a substitution. * * It is assumed that trail_2 (possibly NULL) is a subtrail * of trail_1. This routine clears entries starting at trail_1, * up to (but not including) trail_2. * *************/ /* DOCUMENTATION It is assumed that Trail sub_tr is a subtrail of Trail tr. This routine clears part (maybe all) of a substitution, by clearing the entries from tr up to, but not including sub_tr. The corresponding Trail nodes are deallocated, so the caller should no longer refer to tr. (This is useful for inference rules like hyperresolution, which backtrack, undoing parts of substitutions.) */ /* PUBLIC */ void undo_subst_2(Trail tr, Trail sub_tr) { Trail t3; while (tr != sub_tr) { tr->context->terms[tr->varnum] = NULL; tr->context->contexts[tr->varnum] = NULL; t3 = tr; tr = tr->next; free_trail(t3); } } /* undo_subst_2 */ /************* * * fprint_context(file_ptr, context) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Context. */ /* PUBLIC */ void fprint_context(FILE *fp, Context c) { int i; if (c == NULL) fprintf(fp, "Substitution NULL.\n"); else { fprintf(fp, "Substitution, multiplier %d\n", c->multiplier); for (i=0; i< MAX_VARS; i++) { if (c->terms[i] != NULL) { Term t = get_variable_term(i); fprint_term(fp, t); free_term(t); fprintf(fp, " [%p] -> ", c); fprint_term(fp, c->terms[i]); if (c->contexts[i] == NULL) fprintf(fp, " (NULL context)\n"); else fprintf(fp, " [%p:%d]\n", c->contexts[i], c->contexts[i]->multiplier); } } #if 0 if (c->partial_term) { printf("partial_term: "); print_term(fp, c->partial_term); printf("\n"); } #endif } } /* fprint_context */ /************* * * p_context(context) * *************/ /* DOCUMENTATION This routine prints (to stdout) a Context. */ /* PUBLIC */ void p_context(Context c) { fprint_context(stdout, c); } /* p_context */ /************* * * fprint_trail(file_ptr, context) * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Trail. The whole list is printed. */ /* PUBLIC */ void fprint_trail(FILE *fp, Trail t) { Trail t2; fprintf(fp, "Trail:"); t2 = t; while (t2 != NULL) { fprintf(fp, " <%d,%p>", t2->varnum, t2->context); t2 = t2->next; } fprintf(fp, ".\n"); } /* fprint_trail */ /************* * * p_trail(context) * *************/ /* DOCUMENTATION This routine prints (to stdout) a Trail. The whole list is printed. */ /* PUBLIC */ void p_trail(Trail t) { fprint_trail(stdout, t); } /* p_trail */ /************* * * match_weight() * *************/ /* DOCUMENTATION Special-purpose match for weighting. */ /* PUBLIC */ BOOL match_weight(Term t1, Context c1, Term t2, Trail *trp, int var_sn) { if (SYMNUM(t1) == var_sn) { return VARIABLE(t2); } else if (VARIABLE(t1)) { int vn = VARNUM(t1); if (c1->terms[vn] == NULL) { BIND_TR(vn, c1, t2, NULL, trp) return TRUE; } else return term_ident(c1->terms[vn], t2); } else if (VARIABLE(t2)) return FALSE; else { /* neither term is a variable */ if (SYMNUM(t1) != SYMNUM(t2)) return FALSE; /* fail because of symbol clash */ else { Trail tpos, tp, t3; int i, arity; tpos = *trp; /* save trail position in case of failure */ i = 0; arity = ARITY(t1); while (i < arity && match_weight(ARG(t1,i), c1, ARG(t2,i), trp, var_sn)) i++; if (i == arity) return TRUE; else { /* restore from trail and fail */ tp = *trp; while (tp != tpos) { tp->context->terms[tp->varnum] = NULL; t3 = tp; tp = tp->next; free_trail(t3); } *trp = tpos; return FALSE; } } } } /* match_weight */ /************* * * vars_in_trail() * *************/ /* DOCUMENTATION Return the list of variables (as integers) in a trail. Note that this ignores the contexts associated with the varibles. */ /* PUBLIC */ Ilist vars_in_trail(Trail tr) { if (tr == NULL) return NULL; else return ilist_append(vars_in_trail(tr->next), tr->varnum); } /* vars_in_trail */ /************* * * context_to_pairs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist context_to_pairs(Ilist varnums, Context c) { Plist pairs = NULL; int i; for (i = 0; i < MAX_VARS; i++) { if (ilist_member(varnums, i)) { Term var = get_variable_term(i); Term t = apply(var, c); if (!term_ident(var, t)) { Term pair = listterm_cons(var, t); pairs = plist_append(pairs, pair); } else { zap_term(var); zap_term(t); } } } return pairs; } /* context_to_pairs */ /************* * * empty_substitution() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL empty_substitution(Context s) { int i; for (i = 0; i < MAX_VARS; i++) { if (s->terms[i] != NULL) return FALSE; } return TRUE; } /* empty_substitution */ /************* * * variable_substitution() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL variable_substitution(Context s) { int i; for (i = 0; i < MAX_VARS; i++) { if (s->terms[i]) { Term t = s->terms[i]; Context c = s->contexts[i]; DEREFERENCE(t,c); if (!VARIABLE(t)) return FALSE; } } return TRUE; } /* variable_substitution */ /************* * * subst_changes_term(term, context) * *************/ /* DOCUMENTATION This routine checks if a subsitution would change a term, if applied. */ /* PUBLIC */ BOOL subst_changes_term(Term t, Context c) { if (VARIABLE(t)) { return c->terms[VARNUM(t)] != NULL; } else { int i; for (i = 0; i < ARITY(t); i++) if (subst_changes_term(ARG(t,i), c)) return TRUE; return FALSE; } } /* subst_changes_term */ LADR-2009-11A/ladr/hash.c0000644000175000017500000001252710637466322014047 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "hash.h" /* Private definitions and types */ struct hashtab { int size; Hashnode *table; }; struct hashnode { void *v; Hashnode next; }; /* * memory management */ #define PTRS_HASHTAB PTRS(sizeof(struct hashtab)) static unsigned Hashtab_gets, Hashtab_frees; #define PTRS_HASHNODE PTRS(sizeof(struct hashnode)) static unsigned Hashnode_gets, Hashnode_frees; /************* * * Hashtab get_hashtab() * *************/ static Hashtab get_hashtab(void) { Hashtab p = get_cmem(PTRS_HASHTAB); Hashtab_gets++; return(p); } /* get_hashtab */ /************* * * free_hashtab() * *************/ static void free_hashtab(Hashtab p) { free_mem(p, PTRS_HASHTAB); Hashtab_frees++; } /* free_hashtab */ /************* * * Hashnode get_hashnode() * *************/ static Hashnode get_hashnode(void) { Hashnode p = get_cmem(PTRS_HASHNODE); Hashnode_gets++; return(p); } /* get_hashnode */ /************* * * free_hashnode() * *************/ static void free_hashnode(Hashnode p) { free_mem(p, PTRS_HASHNODE); Hashnode_frees++; } /* free_hashnode */ /************* * * fprint_hash_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the hash package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_hash_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct hashtab); fprintf(fp, "hashtab (%4d) %11u%11u%11u%9.1f K\n", n, Hashtab_gets, Hashtab_frees, Hashtab_gets - Hashtab_frees, ((Hashtab_gets - Hashtab_frees) * n) / 1024.); n = sizeof(struct hashnode); fprintf(fp, "hashnode (%4d) %11u%11u%11u%9.1f K\n", n, Hashnode_gets, Hashnode_frees, Hashnode_gets - Hashnode_frees, ((Hashnode_gets - Hashnode_frees) * n) / 1024.); } /* fprint_hash_mem */ /************* * * p_hash_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the hash package. */ /* PUBLIC */ void p_hash_mem() { fprint_hash_mem(stdout, TRUE); } /* p_hash_mem */ /* * end of memory management */ /************* * * hash_init() * *************/ /* DOCUMENTATION Allocate and initialize a hash table of the given size. */ /* PUBLIC */ Hashtab hash_init(int size) { Hashtab p = get_hashtab(); p->size = size; p->table = calloc(size, sizeof(Hashnode)); return p; } /* hash_init */ /************* * * hash_insert() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void hash_insert(void *v, unsigned hashval, Hashtab h) { int i = hashval % h->size; Hashnode new = get_hashnode(); new->v = v; new->next = h->table[i]; h->table[i] = new; } /* hash_insert */ /************* * * hash_lookup() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void *hash_lookup(void *v, unsigned hashval, Hashtab h, BOOL (*id_func) (void *, void *)) { Hashnode p = h->table[hashval % h->size]; while (p && !(*id_func)(v, p->v)) p = p->next; return (p ? p->v : NULL); } /* hash_lookup */ /************* * * hash_delete() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void hash_delete(void *v, unsigned hashval, Hashtab h, BOOL (*id_func) (void *, void *)) { int i = hashval % h->size; Hashnode p = h->table[i]; Hashnode prev = NULL; while (p && !(*id_func)(v, p->v)) { prev = p; p = p->next; } if (!p) fatal_error("hash_delete, object not found"); if (prev) prev->next = p->next; else h->table[i] = p->next; free_hashnode(p); } /* hash_delete */ /************* * * hash_destroy() * *************/ /* DOCUMENTATION Free all of the memory used by the given hash table. Do not refer to the table after calling this routine. The hash table need not be empty; */ /* PUBLIC */ void hash_destroy(Hashtab h) { int i; for (i = 0; i < h->size; i++) { Hashnode p = h->table[i]; while (p != NULL) { Hashnode p2 = p; p = p->next; free_hashnode(p2); } } free(h->table); free_hashtab(h); } /* hash_destroy */ /************* * * hash_info() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void hash_info(Hashtab h) { int i; printf("\nHash info, size=%d\n", h->size); for (i = 0; i < h->size; i++) { Hashnode p; int n = 0; for (p = h->table[i]; p; p = p->next) n++; if (n > 0) printf(" bucket %d has %d objects\n", i, n); } fflush(stdout); } /* hash_info */ LADR-2009-11A/ladr/README.termorder0000644000175000017500000000234510225146636015633 0ustar mccunemccune ORIENTING EQUALITIES orient_equalities() (parautil.c) possibly flips equalities and maybe sets a flag in each equality atom: mark_oriented_eq(atom); /* if the "METHOD" says left side is greater */ mark_renamable_flip(atom); /* e.g., commutativity, x(yz)=y(xz) */ The methods are (see symbols.h, assign_order_method in termorder.c): typedef enum { LPO_METHOD, RPO_METHOD, KBO_METHOD } Order_method; ---------------------------------------------------------------------- DECIDING DEDMOULATORS demod.h: enum { NOT_DEMODULATOR, ORIENTED, LEX_DEP_LR, LEX_DEP_RL, LEX_DEP_BOTH }; demod.c: int demodulator_type(Clause c, int lex_dep_demod_lim) returns one of preceding If marked as "oriented", it becomes an ORIENTED demodulator; otherwise, various checks are done. DEMODULATION When a potential demodulator is found, if it is marked as "oriented", it is used (always left-to-right). Otherwise the instance is checked by the "METHOD". PARAMODULATION Oriented equalities: are used left-to-right only (from). Non-oriented equalities: if flag(ordered_instance), then don't use if instance is backward else used both ways (except for renamable flips) LADR-2009-11A/ladr/termflag.c0000644000175000017500000001257210637466323014726 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "termflag.h" /* Private definitions and types */ /* Bits field of term. */ #define TERM_BITS (sizeof(FLAGS_TYPE) * CHAR_BIT) #define SET_BIT(bits, flag) (bits = (bits) | (flag)) #define CLEAR_BIT(bits, flag) (bits = (bits) & ~(flag)) /* #define TP_BIT(bits, flag) (bits & flag) */ static int bits_in_use[TERM_BITS]; /************* * * claim_term_flag() * *************/ /* DOCUMENTATION This routine returns an available flag number for marking terms. If the use will be temporary, make sure to call release_term_flag() when you are finished using the marks. A fatal error occurs if no more flags are available. */ /* PUBLIC */ int claim_term_flag() { int i = 0; while (i < TERM_BITS && bits_in_use[i]) i++; if (i < TERM_BITS) { bits_in_use[i] = 1; return i; } else { fatal_error("claim_term_flag, no more flags are available"); return -1; /* to please the compiler */ } } /* claim_term_flag */ /************* * * release_term_flag() * *************/ /* DOCUMENTATION This routine frees a flag number for future use. */ /* PUBLIC */ void release_term_flag(int bit) { bits_in_use[bit] = 0; } /* release_term_flag */ /************* * * term_flag_set() * *************/ /* DOCUMENTATION This routine sets a flag on a term. The flag argument is a small integer in the range [0 .. n-1], where n is the number of bits available for flags. If n is out of range, none of the flags will change.

    Term flags are stored as bits in the field private_flags. (Look at the definition of Term to find out big private_flags is.) If you need more flags, you can simply change the type of private_flags to unsigned short (usually 16 bits) or unsigned int (usually 32 bits). It is your responsibility to make sure that all of the flags you use are in range. */ /* PUBLIC */ void term_flag_set(Term t, int flag) { if (flag >= 0 && flag < TERM_BITS) SET_BIT(t->private_flags, 1 << flag); } /* term_flag_set */ /************* * * term_flag_clear() * *************/ /* DOCUMENTATION This routine clears a flag on a term. The flag argument is a small integer in the range [0 .. n-1], where n is the number of bits available for flags. If n is out of range, none of the flags will change. */ /* PUBLIC */ void term_flag_clear(Term t, int flag) { if (flag >= 0 && flag < TERM_BITS) CLEAR_BIT(t->private_flags, 1 << flag); } /* term_flag_clear */ /************* * * term_flag() * *************/ /* DOCUMENTATION This function gets the value of a flag on a term. The flag argument is a small integer in the range [0 ... n-1], where n is the number of bits available for flags. If n is out of range, FALSE is returned. */ /* PUBLIC */ BOOL term_flag(Term t, int flag) { if (flag < 0 || flag >= TERM_BITS) return FALSE; else if (TP_BIT(t->private_flags, 1 << flag)) return TRUE; else return FALSE; } /* term_flag */ /************* * * term_flags() * *************/ /* DOCUMENTATION This routine returns the number of bits available for term flags. The value should always be at least 8. If the value is n, you can use flags numbered [0 ... n-1]. */ /* PUBLIC */ int term_flags() { return TERM_BITS; } /* term_flags */ /************* * * Term copy_term_with_flags() * *************/ /* DOCUMENTATION This routine copies a term, including all of the flags of the term and its subterms. Any other extra fields are not copied. */ /* PUBLIC */ Term copy_term_with_flags(Term t) { Term t2; if (VARIABLE(t)) t2 = get_variable_term(VARNUM(t)); else { int i; t2 = get_rigid_term_like(t); for (i = 0; i < ARITY(t); i++) ARG(t2,i) = copy_term_with_flags(ARG(t,i)); } t2->private_flags = t->private_flags; return t2; } /* copy_term_with_flags */ /************* * * Term copy_term_with_flag() * *************/ /* DOCUMENTATION This routine copies a term, including one specified flag of the term and its subterms. Any other flags or extra fields are not copied. */ /* PUBLIC */ Term copy_term_with_flag(Term t, int flag) { Term t2; if (VARIABLE(t)) t2 = get_variable_term(VARNUM(t)); else { int i; t2 = get_rigid_term_like(t); for (i = 0; i < ARITY(t); i++) ARG(t2,i) = copy_term_with_flag(ARG(t,i), flag); } if (term_flag(t, flag)) term_flag_set(t2, flag); return t2; } /* copy_term_with_flag */ /************* * * term_flag_clear_recursively() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void term_flag_clear_recursively(Term t, int flag) { int i; term_flag_clear(t, flag); for (i = 0; i < ARITY(t); i++) term_flag_clear_recursively(ARG(t,i), flag); } /* clear_term_flag_recursively */ LADR-2009-11A/ladr/clash.c0000644000175000017500000002007410637466321014211 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "clash.h" /* Private definitions and types */ /* * memory management */ #define PTRS_CLASH PTRS(sizeof(struct clash)) static unsigned Clash_gets, Clash_frees; /************* * * Clash get_clash() * *************/ static Clash get_clash(void) { Clash p = get_cmem(PTRS_CLASH); Clash_gets++; return(p); } /* get_clash */ /************* * * free_clash() * *************/ static void free_clash(Clash p) { free_mem(p, PTRS_CLASH); Clash_frees++; } /* free_clash */ /************* * * fprint_clash_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the clash package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_clash_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct clash); fprintf(fp, "clash (%4d) %11u%11u%11u%9.1f K\n", n, Clash_gets, Clash_frees, Clash_gets - Clash_frees, ((Clash_gets - Clash_frees) * n) / 1024.); } /* fprint_clash_mem */ /************* * * p_clash_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the clash package. */ /* PUBLIC */ void p_clash_mem() { fprint_clash_mem(stdout, TRUE); } /* p_clash_mem */ /* * end of memory management */ /************* * * append_clash() * *************/ /* DOCUMENTATION This routine simply allocates a new clash node, links it in after the given node, and returns the new node. */ /* PUBLIC */ Clash append_clash(Clash p) { Clash q = get_clash(); if (p != NULL) p->next = q; return q; } /* append_clash */ /************* * * zap_clash() * *************/ /* DOCUMENTATION Free a clash list. Contexts in clashable nodes (which are assumed to exist and be empty) are freed as well. */ /* PUBLIC */ void zap_clash(Clash p) { while (p != NULL) { Clash q = p; p = p->next; if (q->clashable && !q->clashed) free_context(q->sat_subst); free_clash(q); } } /* zap_clash */ /************* * * atom_to_literal() * *************/ /* DOCUMENTATION This routine takes an atom and returns its parent literal. */ /* PUBLIC */ Literals atom_to_literal(Term atom) { Topform c = atom->container; Literals lit = (c == NULL ? NULL : c->literals); while (lit != NULL && lit->atom != atom) lit = lit->next; return lit; } /* atom_to_literal */ /************* * * apply_lit() * *************/ /* DOCUMENTATION This routine applies a substitution to a literal and returns the instance. The given literal is not changed. */ /* PUBLIC */ Literals apply_lit(Literals lit, Context c) { return new_literal(lit->sign, apply(lit->atom, c)); } /* apply_lit */ /************* * * lit_position() * *************/ static int lit_position(Topform c, Literals lit) { int i = 1; Literals l = c->literals; while (l != NULL && l != lit) { i++; l = l->next; } if (l == lit) return i; else return -1; } /* lit_position */ /************* * * resolve() - construct a clash-resolvent (for hyper or UR) * *************/ static Topform resolve(Clash first, Just_type rule) { Topform r = get_topform(); Topform nuc = first->nuc_lit->atom->container; Ilist j = ilist_append(NULL, nuc->id); Clash p; int n; /* First, include literals in the nucleus. */ for (p = first; p != NULL; p = p->next, n++) { if (!p->clashed) r->literals = append_literal(r->literals, apply_lit(p->nuc_lit, p->nuc_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(nuc->attributes, first->nuc_subst)); /* Next, include literals in the satellites. */ n = 1; /* n-th nucleus literal, starting with 1 */ for (p = first; p != NULL; p = p->next, n++) { if (p->clashed) { if (p->sat_lit == NULL) { /* special code for resolution with x=x */ j = ilist_append(j, n); j = ilist_append(j, 0); j = ilist_append(j, 0); } else { Literals lit; Topform sat = p->sat_lit->atom->container; int sat_pos = lit_position(sat, p->sat_lit); j = ilist_append(j, n); j = ilist_append(j, sat->id); j = ilist_append(j, p->flipped ? -sat_pos : sat_pos); for (lit = sat->literals; lit != NULL; lit = lit->next) { if (lit != p->sat_lit) r->literals = append_literal(r->literals, apply_lit(lit, p->sat_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(sat->attributes, p->sat_subst)); } } } r->justification = resolve_just(j, rule); upward_clause_links(r); return r; } /* resolve */ /************* * * clash_recurse() * *************/ static void clash_recurse(Clash first, Clash p, BOOL (*sat_test) (Literals), Just_type rule, void (*proc_proc) (Topform)) { if (p == NULL) { /* All clashable literals have been mated, so construct the resolvent. */ Topform resolvent = resolve(first, rule); (*proc_proc)(resolvent); } else if (!p->clashable | p->clashed) clash_recurse(first, p->next, sat_test, rule, proc_proc); else { Term fnd_atom; fnd_atom = mindex_retrieve_first(p->nuc_lit->atom, p->mate_index, UNIFY, p->nuc_subst, p->sat_subst, FALSE, &(p->mate_pos)); while (fnd_atom != NULL) { Literals slit = atom_to_literal(fnd_atom); if ((*sat_test)(slit)) { p->clashed = TRUE; p->flipped = FALSE; p->sat_lit = slit; clash_recurse(first, p->next, sat_test, rule, proc_proc); p->clashed = FALSE; } fnd_atom = mindex_retrieve_next(p->mate_pos); } /* If the literal is an equality, try flipping it. */ if (eq_term(p->nuc_lit->atom)) { Term flip = top_flip(p->nuc_lit->atom); fnd_atom = mindex_retrieve_first(flip, p->mate_index, UNIFY, p->nuc_subst, p->sat_subst, FALSE, &(p->mate_pos)); while (fnd_atom != NULL) { Literals slit = atom_to_literal(fnd_atom); if ((*sat_test)(slit)) { p->clashed = TRUE; p->flipped = TRUE; p->sat_lit = slit; clash_recurse(first, p->next, sat_test, rule, proc_proc); p->clashed = FALSE; } fnd_atom = mindex_retrieve_next(p->mate_pos); } zap_top_flip(flip); } /* Built-in resolution with x=x. */ if (neg_eq(p->nuc_lit)) { Term alpha = ARG(p->nuc_lit->atom,0); Term beta = ARG(p->nuc_lit->atom,1); Trail tr = NULL; if (unify(alpha, p->nuc_subst, beta, p->nuc_subst, &tr)) { p->clashed = TRUE; p->sat_lit = NULL; clash_recurse(first, p->next, sat_test, rule, proc_proc); p->clashed = FALSE; undo_subst(tr); } } } } /* clash_recurse */ /************* * * clash() * *************/ /* DOCUMENTATION This routine takes a complete clash list and computes the resolvents.

    • clash -- a complete clash list corresponding to the nucleus.
    • sat_test -- a Boolean function on clauses which identifies potential satellites (e.g., positive clauses for hyperresolution).
    • rule -- the name of the inference rule for the justification list (see just.h).
    • proc_proc -- procedure for processing resolvents.
    */ /* PUBLIC */ void clash(Clash c, BOOL (*sat_test) (Literals), Just_type rule, void (*proc_proc) (Topform)) { clash_recurse(c, c, sat_test, rule, proc_proc); } /* clash */ LADR-2009-11A/ladr/pindex.c0000644000175000017500000003742710637466322014421 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "pindex.h" /* Private definitions and types */ struct pair_index { int finished; /* set if nothing to retrieve */ int n; /* number of lists */ int i, j; /* working pair */ int min; /* smallest wt of inserted clause */ int new_min; /* smallest inserted wt since previous retrieval */ Clist *lists; /* lists */ Clist_pos *top; Clist_pos *curr; struct pair_index *next; /* for avail list */ }; #define INT_LARGE INT_MAX / 2 /* It can be doubled without overflow. */ #define IN_RANGE(i, min, max) (i < min ? min : (i > max ? max : i)) /* * memory management */ #define PTRS_PAIR_INDEX PTRS(sizeof(struct pair_index)) static unsigned Pair_index_gets, Pair_index_frees; /************* * * Pair_index get_pair_index() * *************/ static Pair_index get_pair_index(void) { Pair_index p = get_cmem(PTRS_PAIR_INDEX); p->min = INT_LARGE; p->new_min = INT_LARGE; Pair_index_gets++; return(p); } /* get_pair_index */ /************* * * free_pair_index() * *************/ static void free_pair_index(Pair_index p) { free_mem(p, PTRS_PAIR_INDEX); Pair_index_frees++; } /* free_pair_index */ /************* * * fprint_pindex_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the pindex package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_pindex_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct pair_index); fprintf(fp, "pair_index (%4d) %11u%11u%11u%9.1f K\n", n, Pair_index_gets, Pair_index_frees, Pair_index_gets - Pair_index_frees, ((Pair_index_gets - Pair_index_frees) * n) / 1024.); } /* fprint_pindex_mem */ /************* * * p_pindex_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the pindex package. */ /* PUBLIC */ void p_pindex_mem() { fprint_pindex_mem(stdout, TRUE); } /* p_pindex_mem */ /* * end of memory management */ /************* * * init_pair_index() * * *************/ /* DOCUMENTATION This routine allocates and initializes a Pair_index. Parameter n specifies the range 0 .. n-1 of weights that will be used. If a clause is inserted with weight outside of that range, the effective weight for pair indexing will be set to 0 or n-1. */ /* PUBLIC */ Pair_index init_pair_index(int n) { Pair_index p; int i, j; p = get_pair_index(); p->finished = 1; p->n = n; p->i = 0; p->j = 0; p->min = INT_LARGE; p->new_min = INT_LARGE; p->lists = malloc(n * sizeof(Clist)); p->top = malloc(n * n * sizeof(Clist_pos)); p->curr = malloc(n * n * sizeof(Clist_pos)); /* top and curr will be indexed as top[i*n+j]. */ for (i = 0; i < n; i++) p->lists[i] = clist_init(""); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { p->top[i*p->n+j] = NULL; p->curr[i*p->n+j] = NULL; } return p; } /* init_pair_index */ /************* * * zap_pair_index() * * *************/ /* DOCUMENTATION This routine frees a pair index. It need not be empty. */ /* PUBLIC */ void zap_pair_index(Pair_index p) { int i; for (i = 0; i < p->n; i++) { clist_zap(p->lists[i]); } free(p->lists); free(p->top); free(p->curr); free_pair_index(p); } /* zap_pair_index */ /************* * * pairs_exhausted() * *************/ /* DOCUMENTATION This routine is TRUE if the previous call to retrieve_pair() returned nothing and no more pairs have been inserted since then. (Also, TRUE is returned if no pairs were ever inserted.)

    Note that FALSE may be returned when there really no pairs available. */ /* PUBLIC */ int pairs_exhausted(Pair_index p) { return p->finished; } /* pairs_exhausted */ /************* * * init_pair() * * Initialize top and curr for lists i and j. * *************/ static void init_pair(int i, int j, Pair_index p) { int n = p->n; Clist_pos lp_i = p->lists[i]->first; Clist_pos lp_j = p->lists[j]->first; if (lp_i && lp_j) { if (i == j) { p->top[i*n+i] = lp_i; p->curr[i*n+i] = NULL; } else { p->top[i*n+j] = lp_i; p->top[j*n+i] = lp_j; /* It doesn't matter which curr gets set to NULL. */ p->curr[i*n+j] = lp_i; p->curr[j*n+i] = NULL; } } else { p->top[i*n+j] = NULL; p->top[j*n+i] = NULL; p->curr[i*n+j] = NULL; p->curr[j*n+i] = NULL; } } /* init_pair */ /************* * * insert_pair_index() * *************/ /* DOCUMENTATION This routine inserts a clause into a Pair_index. If the given weight is out of range [0 ... n-1] (where n is the parameter given to init_pair_index()), weight 0 or n-1 will be used instead. */ /* PUBLIC */ void insert_pair_index(Topform c, int wt, Pair_index p) { /* If the new clause will be the only one in its list, then * for each nonempty list, set the top and curr. */ int i, j, n; n = p->n; j = IN_RANGE(wt, 0, n-1); if (p->lists[j]->first == NULL) { clist_append(c, p->lists[j]); for (i = 0; i < p->n; i++) init_pair(i, j, p); } else clist_append(c, p->lists[j]); p->finished = 0; if (wt < p->new_min) p->new_min = wt; if (wt < p->min) p->min = wt; } /* insert_pair_index */ /************* * * delete_pair_index() * *************/ /* DOCUMENTATION This routine removes a clause from a Pair_index. The parameter wt must be the same as when the clause was inserted. A fatal error may occur if the clause was not previously inserted or if it was inserted with a different weight. */ /* PUBLIC */ void delete_pair_index(Topform c, int wt, Pair_index p) { int i, j; int n = p->n; Clist_pos lp; j = IN_RANGE(wt, 0, n-1); for (lp = p->lists[j]->first; lp && lp->c != c; lp = lp->next); if (!lp) { fatal_error("delete_pair_index, clause not found."); } /* We are deleting a clause from list j. For each list i, consider the * pair [i,j]. Top[i,j] and curr[i,j] (say t1 and c1) point into list i, * and top[j,i] and curr[j,i] (say t2 anc c2) point into list j. */ for (i = 0; i < n; i++) { Clist_pos t1 = p->top[i*n+j]; Clist_pos c1 = p->curr[i*n+j]; Clist_pos t2 = p->top[j*n+i]; Clist_pos c2 = p->curr[j*n+i]; if (i == j) { if (t2 == lp) { /* printf("HERE: i == j\n"); */ /* This handles t2=c2, c2==NULL, c2 != NULL, singleton list. */ if (t2->next) { p->top[i*n+i] = t2->next; p->curr[i*n+i] = NULL; } else { p->top[i*n+i] = t2->prev; p->curr[i*n+i] = t2->prev; } } else if (c2 == lp) { p->curr[i*n+i] = c2->prev; } } else { /* i != j */ if (lp == t2) { /* printf("HERE: i != j (B)\n"); */ if (t2 == c2) { if (t2->next) { t2 = t2->next; c2 = c2->next; c1 = NULL; } else if (t2->prev) { t2 = t2->prev; c2 = c2->prev; c1 = t1; } else t1 = c1 = t2 = c2 = NULL; } else if (t2->prev) t2 = t2->prev; else if (t2->next) { t2 = t2->next; c2 = NULL; t1 = c1 = p->lists[i]->first; } else t1 = c1 = t2 = c2 = NULL; } else if (lp == c2) { /* printf("HERE: i != j (D)\n"); */ c2 = c2->prev; } p->top[i*n+j] = t1; p->curr[i*n+j] = c1; p->top[j*n+i] = t2; p->curr[j*n+i] = c2; } } clist_remove(c, p->lists[j]); } /* delete_pair_index */ /************* * * retrieve_pair() * *************/ /* DOCUMENTATION This routine retrieves the next pair from a Pair_index. The caller gives addresses of clauses which are filled in with the answer. If no pair is available, NULLs are filled in. */ /* PUBLIC */ void retrieve_pair(Pair_index p, Topform *cp1, Topform *cp2) { int i, j, k, max_k, found, n; /* First, find i and j, the smallest pair of weights that * have clauses available. p->i and p->j are from the * previous retrieval, and if no clauses have been inserted * since then, start with them. Otherwise, use new_min * (the smallest weight inserted since the previous retrieval) * and min (the smallest weight in the index) to decide * where to start looking. */ if (p->min + p->new_min < p->i + p->j) { i = p->min; j = p->new_min; } else { i = p->i; j = p->j; } n = p->n; k = i+j; max_k = (n + n) - 2; found = 0; while (k <= max_k && !found) { i = k / 2; j = k - i; while (i >= 0 && j < n && !found) { /* This test works if (i==j). */ found = (p->top[i*n+j] != p->curr[i*n+j] || p->top[j*n+i] != p->curr[j*n+i] || (p->top[i*n+j] && p->top[i*n+j]->next) || (p->top[j*n+i] && p->top[j*n+i]->next)); if (!found) { i--; j++; } } if (!found) k++; } if (!found) { *cp1 = NULL; *cp2 = NULL; p->finished = 1; } else { /* OK, there should be a pair in (i,j). */ /* Recall that if top[i,j]=curr[i,j] and top[j,i]=top[j,i], * then all pairs up to those positions have been returned. */ Clist_pos t1 = p->top[i*n+j]; Clist_pos c1 = p->curr[i*n+j]; Clist_pos t2 = p->top[j*n+i]; Clist_pos c2 = p->curr[j*n+i]; if (i == j) { if (t1 == c1) { p->top[i*n+i] = t1 = t1->next; p->curr[i*n+i] = c1 = NULL; } *cp1 = t1->c; p->curr[i*n+i] = c1 = (c1 ? c1->next : p->lists[i]->first); *cp2 = c1->c; } else { /* i != j */ if (t1 == c1 && t2 == c2) { /* Both tops equal their currs, so pick a top to increment. */ if (t1->next && (t1->c->id < t2->c->id || !t2->next)) { p->top[i*n+j] = t1 = t1->next; p->curr[i*n+j] = c1 = c1->next; p->curr[j*n+i] = c2 = NULL; } else { p->top[j*n+i] = t2 = t2->next; p->curr[j*n+i] = c2 = c2->next; p->curr[i*n+j] = c1 = NULL; } } if (t1 == c1) { *cp1 = t1->c; p->curr[j*n+i] = c2 = (c2 ? c2->next : p->lists[j]->first); *cp2 = c2->c; } else if (t2 == c2) { *cp1 = t2->c; p->curr[i*n+j] = c1 = (c1 ? c1->next : p->lists[i]->first); *cp2 = c1->c; } else { fatal_error("retrieve_pair, bad state."); } } /* Save the "working pair" for next time. */ p->i = i; p->j = j; p->new_min = INT_LARGE; } } /* retrieve_pair */ /************* * * p_pair_index() * * Print a pair index. It is printed in detail, so it should be * called only for small test indexes. * *************/ void p_pair_index(Pair_index p) { int i, j, n; Clist_pos x; n = p->n; for (i = 0; i < n; i++) { printf("Clist %d: ", i); for (x = p->lists[i]->first; x; x = x->next) printf(" %3d", x->c->id); printf(".\n"); } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { printf(" ["); if (p->top[i*n+j]) printf("%2d",p->top[i*n+j]->c->id); else printf("--"); printf(","); if (p->curr[i*n+j]) printf("%2d",p->curr[i*n+j]->c->id); else printf("--"); printf("] "); fflush(stdout); } printf("\n"); } } /* p_pair_index */ /************* * * pair_already_used() * *************/ /* DOCUMENTATION This Boolean routine checks if a pair of clauses (with corresponding weights) has already been retrieved. */ /* PUBLIC */ int pair_already_used(Topform c1, int weight1, Topform c2, int weight2, Pair_index p) { int i, j, id1, id2; int rc = 0; int n = p->n; Clist_pos top1, curr1, top2, curr2; id1 = c1->id; id2 = c2->id; i = IN_RANGE(weight1, 0, n-1); j = IN_RANGE(weight2, 0, n-1); top1 = p->top[i*n+j]; curr1 = p->curr[i*n+j]; top2 = p->top[j*n+i]; curr2 = p->curr[j*n+i]; if (!top1 || !top2) { /* One of the lists is empty. If this happens, something is probably wrong: why would we be trying to use c1 and c2? */ fatal_error("pair_already_used, bad state (1)."); } else if (i == j) { /* Let id2 be the greater one. */ if (id1 > id2) { int tmp = id1; id1 = id2; id2 = tmp; } rc = ((id2 < top1->c->id) || (id2 == top1->c->id && curr1 && id1 <= curr1->c->id)); } else { /* i != j */ if (top1 == curr1) { rc = ((id1 < top1->c->id && id2 <= top2->c->id) || (id1 == top1->c->id && curr2 && id2 <= curr2->c->id)); } else if (top2 == curr2) { rc = ((id2 < top2->c->id && id1 <= top1->c->id) || (id2 == top2->c->id && curr1 && id1 <= curr1->c->id)); } else { fatal_error("pair_already_used, bad state (2)."); } } return rc; } /* pair_already_used */ /* * This file has code for indexing clauses that are to be retrieved in * pairs. When a clause is inserted, its weight is given. Retrieval * is by sum of the weights of the pair -- lowest first. Say we have * clauses with weights 0--4. Then pairs will be returned in this order: * * (0,0) * (0,1) * (1,1) (0,2) * (1,2) (0,3) * (2,2) (1,3) (0,4) * (2,3) (1,4) * (3,3) (2,4) * (3,4) * (4,4) * * Objects can be inserted after retrieval has begun; the smallest * available pair will always be returned. When the index is * initialized, the caller supplies a parameter N, and the actual * weight range for indexing will be 0..N-1. If an inserted clause has * weight outside of this range, the weight will be changed to 0 or N-1. * * This is intended to be used for binary inference rules such as * paramodulation and resolution. * * We keep a list of clauses with each weight 0..N-1. When the index * is initialized, we allocate two N x N arrays (top and curr) * to keep track of the positions in the pairs of lists. * (Since the size of the array is not known at compile time, * we access elements as a[i*N+j] instead of a[i][j].) * * For a pair of weights i and j, we use top[i,j] and curr[i,j] to * point to positions in list i w.r.t. list j. And vice versa. * Roughly, it goes like this: Lists grow upward, and clauses above * "top" have not yet been considered. Increment top[i,j], then return * top[i,j] with each member of list j up to top[j,i]. (Curr[j,i] * marks the position between retrievals.) Now all pairs up to the two * tops have been returned. Now pick the top with the smallest clause * ID, increment it, and continue. If at any point a new clause C is * inserted into the index, and C goes with other clasues to make * smaller pairs, those smaller pairs are returned before continuing * with i and j. * * Valid states of an index. * Case 1: i == j. * (a) top and curr are both NULL; this occurs if the list is empty. * (b) top and top=curr; done up through top. * (c) top and !curr; done up through top-1. * (d) top and curr and top > curr; done up through . * Case 2: i != j. * (a) !t1 and !t2; one or both lists empty. * (b) t1 and t2 and t1=c1 and t2=c2; done up through tops. * (c) t1 and t2 and t1=c1 and c2=NULL; done up through . * (d) t1 and t2 and t1=c1 and c2; * also through . * (e) same as c,d, but vice versa. * * This is similar to the method in "A Theorem-Proving Language * for Experimentation" by Henschen, Overbeek, Wos, CACM 17(6), 1974. * */ LADR-2009-11A/ladr/btu.h0000644000175000017500000000340711151265364013713 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_BTU_H #define TP_BTU_H #include "dioph.h" #include "unify.h" /* INTRODUCTION This package handles "backtrack unification", that is, unification that allows more than one unifier for a pair of terms, and computes the unifiers incrementally by backtracking. As I write this, we support associative commutative (AC) operations and commutative/symmetric (C) operations. Symbols are declared to be AC with set_assoc_comm() and C with set_commutative(). The use of Terms and Contexts is similar to ordinary unification, except that the means for undoing substitutions is different. */ /* Public definitions */ typedef struct btu_state * Btu_state; /* End of public definitions */ /* Public function prototypes from btu.c */ void fprint_btu_mem(FILE *fp, BOOL heading); void p_btu_mem(); Btu_state unify_bt_first(Term t1, Context c1, Term t2, Context c2); Btu_state unify_bt_next(Btu_state bt1); void unify_bt_cancel(Btu_state bt); void p_bt_tree(Btu_state bt, int n); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/memory.c~0000644000175000017500000001616310637466322014632 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "memory.h" #define MALLOC_MEGS 20 /* size of blocks malloced by palloc */ #define DEFAULT_MAX_MEGS 200 /* change with set_max_megs(n) */ #define MAX_MEM_LISTS 500 /* number of lists of available nodes */ static void ** M[MAX_MEM_LISTS]; static BOOL Max_megs_check = TRUE; static int Max_megs = DEFAULT_MAX_MEGS; /* change with set_max_megs(n) */ static void (*Exit_proc) (void); /* set with set_max_megs_proc() */ static int Malloc_calls = 0; /* number of calls to malloc by palloc */ static unsigned Bytes_palloced = 0; static void *Block = NULL; /* location returned by most recent malloc */ static void *Block_pos = NULL; /* current position in block */ static unsigned Mem_calls = 0; static unsigned Mem_calls_overflows = 0; #define BUMP_MEM_CALLS {Mem_calls++; if (Mem_calls==0) Mem_calls_overflows++;} /************* * * void *palloc(n) -- assume n is a multiple of BYTES_POINTER. * *************/ static void *palloc(size_t n) { if (n == 0) return NULL; else { void *chunk; size_t malloc_bytes = MALLOC_MEGS*1024*1024; if (Block==NULL || Block + malloc_bytes - Block_pos < n) { /* First call or not enough in the current block, so get a new block. */ if (n > malloc_bytes) { printf("palloc, n=%d\n", (int) n); fatal_error("palloc, request too big; reset MALLOC_MEGS"); } else if (Max_megs_check && (Malloc_calls+1)*MALLOC_MEGS > Max_megs) { if (Exit_proc) (*Exit_proc)(); else fatal_error("palloc, Max_megs parameter exceeded"); } else { Block_pos = Block = malloc(malloc_bytes); Malloc_calls++; if (Block_pos == NULL) fatal_error("palloc, operating system is out of memory"); } } chunk = Block_pos; Block_pos += n; Bytes_palloced += n; return(chunk); } } /* palloc */ /************* * * get_cmem() * *************/ /* DOCUMENTATION Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is initialized to all 0. */ /* PUBLIC */ void *get_cmem(unsigned n) { if (n == 0) return NULL; else { void **p = NULL; BUMP_MEM_CALLS; if (n >= MAX_MEM_LISTS) return calloc(n, BYTES_POINTER); else if (M[n] == NULL) p = palloc(n * BYTES_POINTER); else { /* the first pointer is used for the avail list */ p = M[n]; M[n] = *p; } { int i; for (i = 0; i < n; i++) p[i] = 0; } return p; } } /* get_cmem */ /************* * * get_mem() * *************/ /* DOCUMENTATION Get a chunk of memory that will hold n pointers (NOT n BYTES). The memory is NOT initialized. */ /* PUBLIC */ void *get_mem(unsigned n) { if (n == 0) return NULL; else { void **p = NULL; BUMP_MEM_CALLS; if (n >= MAX_MEM_LISTS) p = malloc(n * BYTES_POINTER); else if (M[n] == NULL) p = palloc(n * BYTES_POINTER); else { /* the first pointer is used for the avail list */ p = M[n]; M[n] = *p; } return p; } } /* get_mem */ /************* * * free_mem() * *************/ /* DOCUMENTATION Free a chunk of memory that holds n pointers (not n bytes) that was returned from a previous get_mem() or get_cmem() call. */ /* PUBLIC */ void free_mem(void *q, unsigned n) { if (n == 0) ; /* do nothing */ else { /* put it on the appropriate avail list */ void **p = q; if (n >= MAX_MEM_LISTS) free(p); else { /* the first pointer is used for the avail list */ *p = M[n]; M[n] = p; } } } /* free_mem */ /************* * * mlist_length() * *************/ static int mlist_length(void **p) { int n; for (n = 0; p; p = *p, n++); return n; } /* mlist_length */ /************* * * memory_report() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void memory_report(FILE *fp) { int i; fprintf(fp, "\nMemory report, %d @ %d = %d megs (%.2f megs used).\n", Malloc_calls, MALLOC_MEGS, Malloc_calls * MALLOC_MEGS, Bytes_palloced / (1024 * 1024.0)); for (i = 0; i < MAX_MEM_LISTS; i++) { int n = mlist_length(M[i]); if (n != 0) fprintf(fp, "List %3d, length %7d, %8.1f K\n", i, n, i * n * BYTES_POINTER / 1024.); } } /* memory_report */ /************* * * int megs_malloced() -- How many MB have been dynamically allocated? * *************/ /* DOCUMENTATION This routine returns the number of megabytes that palloc() has obtained from the operating system by malloc(); */ /* PUBLIC */ int megs_malloced(void) { return Malloc_calls * MALLOC_MEGS; } /* megs_malloced */ /************* * * set_max_megs() * *************/ /* DOCUMENTATION This routine changes the limit on the amount of memory obtained from malloc() by palloc(). The argument is in megabytes. The default value is DEFAULT_MAX_MEGS. */ /* PUBLIC */ void set_max_megs(int megs) { Max_megs = (megs == -1 ? INT_MAX : megs); } /* set_max_megs */ /************* * * set_max_megs_proc() * *************/ /* DOCUMENTATION This routine is used to specify the routine that will be called if max_megs is exceeded. */ /* PUBLIC */ void set_max_megs_proc(void (*proc)(void)) { Exit_proc = proc; } /* set_max_megs_proc */ /************* * * bytes_palloced() * *************/ /* DOCUMENTATION How many bytes have been allocated by the palloc() routine? This includes all of the get_mem() calls. */ /* PUBLIC */ int bytes_palloced(void) { return Bytes_palloced; } /* bytes_palloced */ /************* * * tp_alloc() * *************/ /* DOCUMENTATION Allocate n bytes of memory, aligned on a pointer boundary. The memory is not initialized, and it cannot be freed. */ /* PUBLIC */ void *tp_alloc(size_t n) { /* If n is not a multiple of BYTES_POINTER, round up so that it is. */ if (n % BYTES_POINTER != 0) { n += (BYTES_POINTER - (n % BYTES_POINTER)); } return palloc(n); } /* tp_alloc */ /************* * * mega_mem_calls() * *************/ /* DOCUMENTATION */ /* PUBLIC */ unsigned mega_mem_calls(void) { return (Mem_calls / 1000000) + ((UINT_MAX / 1000000) * Mem_calls_overflows); } /* mega_mem_calls */ /************* * * disable_max_megs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void disable_max_megs(void) { Max_megs_check = FALSE; } /* disable_max_megs */ /************* * * enable_max_megs() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void enable_max_megs(void) { Max_megs_check = TRUE; } /* enable_max_megs */ LADR-2009-11A/ladr/glist.h0000644000175000017500000001107611151265363014243 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_GLIST_H #define TP_GLIST_H #include "order.h" #include "string.h" /* INTRODUCTION This package handles Plist (singly-linked list of void pointers), Ilist (singly-linked list of integers), I2list (singly-linked list of pairs), I3list (singly-linked list of triples). */ /* Public definitions */ typedef struct plist * Plist; struct plist { void *v; Plist next; }; typedef struct ilist * Ilist; struct ilist { int i; Ilist next; }; typedef struct i2list * I2list; struct i2list { int i; int j; I2list next; }; typedef struct i3list * I3list; struct i3list { int i; int j; int k; I3list next; }; /* End of public definitions */ /* Public function prototypes from glist.c */ Ilist get_ilist(void); void free_ilist(Ilist p); Plist get_plist(void); void free_plist(Plist p); I2list get_i2list(void); void free_i2list(I2list p); I3list get_i3list(void); void free_i3list(I3list p); void fprint_glist_mem(FILE *fp, BOOL heading); void p_glist_mem(); Plist plist_cat(Plist p1, Plist p2); Plist plist_cat2(Plist p1, Plist p2); Plist plist_pop(Plist p); int plist_count(Plist p); Plist reverse_plist(Plist p); Plist copy_plist(Plist p); void zap_plist(Plist p); Plist plist_append(Plist lst, void *v); Plist plist_prepend(Plist lst, void *v); BOOL plist_member(Plist lst, void *v); Plist plist_subtract(Plist p1, Plist p2); BOOL plist_subset(Plist a, Plist b); Plist plist_remove(Plist p, void *v); Plist plist_remove_string(Plist p, char *s); Plist sort_plist(Plist objects, Ordertype (*comp_proc) (void *, void *)); Plist plist_remove_last(Plist p); int position_of_string_in_plist(char *s, Plist p); BOOL string_member_plist(char *s, Plist p); int longest_string_in_plist(Plist p); void *ith_in_plist(Plist p, int i); void *plist_last(Plist p); Ilist ilist_cat(Ilist p1, Ilist p2); Ilist ilist_cat2(Ilist p1, Ilist p2); Ilist ilist_pop(Ilist p); int ilist_count(Ilist p); Ilist reverse_ilist(Ilist p); Ilist copy_ilist(Ilist p); void zap_ilist(Ilist p); Ilist ilist_append(Ilist lst, int i); Ilist ilist_prepend(Ilist lst, int i); Ilist ilist_last(Ilist lst); BOOL ilist_member(Ilist lst, int i); Ilist ilist_subtract(Ilist p1, Ilist p2); Ilist ilist_removeall(Ilist p, int i); Ilist ilist_intersect(Ilist a, Ilist b); Ilist ilist_union(Ilist a, Ilist b); Ilist ilist_set(Ilist m); Ilist ilist_rem_dups(Ilist m); BOOL ilist_is_set(Ilist a); BOOL ilist_subset(Ilist a, Ilist b); void fprint_ilist(FILE *fp, Ilist p); void p_ilist(Ilist p); Ilist ilist_copy(Ilist p); Ilist ilist_remove_last(Ilist p); int ilist_occurrences(Ilist p, int i); Ilist ilist_insert_up(Ilist p, int i); int position_in_ilist(int i, Ilist p); void zap_i2list(I2list p); I2list i2list_append(I2list lst, int i, int j); I2list i2list_prepend(I2list lst, int i, int j); I2list i2list_removeall(I2list p, int i); I2list i2list_member(I2list lst, int i); void p_i2list(I2list p); int i2list_count(I2list p); BOOL i3list_member(I3list lst, int i, int j, int k); I3list i3list_append(I3list lst, int i, int j, int k); I3list i3list_prepend(I3list lst, int i, int j, int k); void zap_i3list(I3list p); I3list reverse_i3list(I3list p); I3list copy_i3list(I3list p); int i3list_count(I3list p); I2list alist_insert(I2list p, int key, int val); int assoc(I2list p, int key); I3list alist2_insert(I3list p, int key, int a, int b); int assoc2a(I3list p, int key); int assoc2b(I3list p, int key); I3list alist2_remove(I3list p, int key); BOOL i2list_multimember(I2list b, int i, int n); BOOL i2list_multisubset(I2list a, I2list b); I2list multiset_add_n(I2list a, int i, int n); I2list multiset_add(I2list a, int i); I2list multiset_union(I2list a, I2list b); Ilist multiset_to_set(I2list m); int multiset_occurrences(I2list m, int i); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/avltree.h0000644000175000017500000000520311151265363014556 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_AVLTREE_H #define TP_AVLTREE_H #include "memory.h" #include "order.h" /* INTRODUCTION This is a simple implementation of AVL trees. These are binary search trees with the property that for each node, the difference in height of the two subtrees is at most one.

    The items that are stored in the tree are simply pointers, which are assumed to contain the keys and data.

    The caller supplies a comparison function, for example

        Ordertype compare(void *v1, void *v2)
    or
        Ordertype compare(struct my_data *p1, struct my_data *p2)
    
    that is assumed to return LESS_THAN, GREATER_THAN, or SAME_AS.

    Aside from the ordinary "insert", "find", and "delete" operations, there is a "position" operation that tells where an item is in w.r.t. the inorder traversal of the tree, and an operation that finds the item at a given position. */ /* Public definitions */ typedef struct avl_node * Avl_node; /* End of public definitions */ /* Public function prototypes from avltree.c */ void fprint_avltree_mem(FILE *fp, BOOL heading); void p_avltree_mem(); int avl_height(Avl_node p); int avl_size(Avl_node p); Avl_node avl_insert(Avl_node p, void *item, Ordertype (*compare) (void *, void *)); Avl_node avl_delete(Avl_node p, void *item, Ordertype (*compare) (void *, void *)); void *avl_find(Avl_node p, void *item, Ordertype (*compare) (void *, void *)); void *avl_smallest(Avl_node p); void *avl_largest(Avl_node p); int avl_place(Avl_node p, void *item, Ordertype (*compare) (void *, void *)); double avl_position(Avl_node p, void *item, Ordertype (*compare) (void *, void *)); void *avl_nth_item(Avl_node p, int n); void *avl_item_at_position(Avl_node p, double pos); void avl_zap(Avl_node p); void avl_check(Avl_node p, Ordertype (*compare) (void *, void *)); void p_avl(Avl_node p, int level); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/string.h0000644000175000017500000000326611151265363014431 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_STRING_H #define TP_STRING_H #include "memory.h" /* INTRODUCTION This package contains a few utilities for character strings. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from string.c */ BOOL str_ident(char *s, char *t); char *new_str_copy(char *str); BOOL string_member(char *string, char **strings, int n); int which_string_member(char *string, char **strings, int n); BOOL initial_substring(char *x, char *y); BOOL substring(char *x, char *y); void reverse_chars(char *s, int start, int end); int natural_string(char *str); int char_occurrences(char *s, char c); char *escape_char(char *s, char c); BOOL str_to_int(char *str, int *ip); char *int_to_str(int n, char *s, int size); BOOL str_to_double(char *s, double *dp); char *double_to_str(double d, char *s, int size); BOOL string_of_repeated(char c, char *s); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/compress.c0000644000175000017500000000726210637466321014756 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "compress.h" /* Private definitions and types */ /************* * * uncompress_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Term uncompress_term(char *s, int *ip) { char c = s[(*ip)++]; if (c <= 0) return get_variable_term(-c); else { int arity = sn_to_arity(c); Term t = get_rigid_term_dangerously(c, arity); int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = uncompress_term(s, ip); return t; } } /* uncompress_term */ /************* * * compress_term_recurse() * *************/ static void compress_term_recurse(String_buf sb, Term t) { if (VARIABLE(t)) sb_append_char(sb, -VARNUM(t)); else { int i; sb_append_char(sb, SYMNUM(t)); for (i = 0; i < ARITY(t); i++) { compress_term_recurse(sb, ARG(t,i)); } } } /* compress_term_recurse */ /************* * * compress_term() * *************/ /* DOCUMENTATION */ /* PUBLIC */ char *compress_term(Term t) { String_buf sb = get_string_buf(); compress_term_recurse(sb, t); { char *s; s = sb_to_malloc_char_array(sb); zap_string_buf(sb); return s; } } /* compress_term */ /************* * * compress_clause() * *************/ /* DOCUMENTATION When clasues are compressed, they lose any orientation marks on atoms. Marks are restored by a call to orient_equalities during uncompression. */ /* PUBLIC */ void compress_clause(Topform c) { if (c->compressed != NULL) fatal_error("compress_clause, clause already compressed"); else if (-MAX_VARS < CHAR_MIN || greatest_symnum() > CHAR_MAX) return; /* unable to compress, because symbols don't fit in char */ else if (c->literals == NULL) return; else { Term t = lits_to_term(c->literals); /* printf("compressing clause %d\n", c->id); */ c->compressed = compress_term(t); free_lits_to_term(t); c->neg_compressed = negative_clause(c->literals); zap_literals(c->literals); c->literals = NULL; } } /* compress_clause */ /************* * * uncompress_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void uncompress_clause(Topform c) { if (c->compressed) { int i = 0; Term t = uncompress_term(c->compressed, &i); c->literals = term_to_literals(t, NULL); upward_clause_links(c); zap_term(t); /* printf("UNcompressed clause %d\n", c->id); */ free(c->compressed); c->compressed = NULL; c->neg_compressed = FALSE; if (!c->used) { printf("\n%% Uncompressing unused clause: "); fprint_clause(stdout, c); } } } /* uncompress_clause */ /************* * * uncompress_clauses() * *************/ /* DOCUMENTATION Given a Plist of clauses, uncompress the compressed ones. */ /* PUBLIC */ void uncompress_clauses(Plist p) { Plist a; for (a = p; a; a = a->next) { Topform c = a->v; if (c->compressed) { uncompress_clause(c); orient_equalities(c, FALSE); /* mark, but don't flip */ } } } /* uncompress_clauses */ LADR-2009-11A/ladr/flatdemod.h0000644000175000017500000000317711151265364015064 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_FLATDEMOD_H #define TP_FLATDEMOD_H #include "parautil.h" #include "mindex.h" /* INTRODUCTION */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from flatdemod.c */ Flatterm fapply_demod(Term t, Context c); Plist discrim_flat_retrieve_leaf(Flatterm fin, Discrim root, Context subst, Flatterm *ppos); void *discrim_flat_retrieve_first(Flatterm f, Discrim root, Context subst, Discrim_pos *ppos); void *discrim_flat_retrieve_next(Discrim_pos pos); void discrim_flat_cancel(Discrim_pos pos); Term fdemodulate(Term t, Discrim root, int *step_limit, int *increase_limit, int *sequence, I3list *just_head, BOOL lex_order_vars); int fdemod_attempts(); int fdemod_rewrites(); void fdemod_clause(Topform c, Mindex idx, int *step_limit, int *increase_limit, BOOL lex_order_vars); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/definitions.c0000644000175000017500000002065311140513750015422 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "definitions.h" /* Private definitions and types */ /* * memory management */ /************* * * is_definition() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL is_definition(Formula f) { if (!closed_formula(f)) return FALSE; else { Plist vars = NULL; /* leading universal quantifiers */ BOOL ok = TRUE; Formula g; for (g = f; g->type == ALL_FORM; g = g->kids[0]) { Term t = get_rigid_term(g->qvar, 0); vars = plist_append(vars, t); } if (g->type != IFF_FORM || g->kids[0]->type != ATOM_FORM) ok = FALSE; else { Term atom = g->kids[0]->atom; Plist args = plist_of_subterms(atom); ok = (ARITY(atom) == plist_count(vars) && tlist_set(vars) && tlist_subset(vars, args) && tlist_subset(args, vars)); zap_plist(args); /* shallow */ } zap_plist_of_terms(vars); /* deep */ if (ok) { /* check that the defined symbol does not occur in the right side */ ok = !relation_symbol_in_formula(SYMNUM(g->kids[0]->atom), g->kids[1]); } return ok; } } /* is_definition */ /************* * * subst_terms() * *************/ static Term subst_terms(Term t, Plist vars, Plist terms, Plist qvars) { /* In Term t, replace members of vars (really constants) with (copies of) the corresponding members of terms. EXCEPT if the var (constant) is a member of qvars. Note that "vars" and "terms" are lists of terms, and "qvars" is a list of strings. */ if (CONSTANT(t)) { if (!string_member_plist(sn_to_str(SYMNUM(t)), qvars)) { int i = position_of_term_in_tlist(t, vars); if (i != -1) { Term corresponding_term = ith_in_plist(terms, i); zap_term(t); t = copy_term(corresponding_term); } } return t; } else { int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = subst_terms(ARG(t,i), vars, terms, qvars); return t; } } /* subst_terms */ /************* * * subst_free_vars() * *************/ static void subst_free_vars(Formula f, Plist vars, Plist terms, Plist qvars) { if (f->type == ATOM_FORM) f->atom = subst_terms(f->atom, vars, terms, qvars); else if (quant_form(f)) { Plist qvars2 = plist_prepend(qvars, f->qvar); subst_free_vars(f->kids[0], vars, terms, qvars2); free_plist(qvars2); /* first_node only, leaves qvars as it was */ } else { int i; for (i = 0; i < f->arity; i++) subst_free_vars(f->kids[i], vars, terms, qvars); } } /* subst_free_vars */ /************* * * subst_atomic_formula() * *************/ static Formula subst_atomic_formula(Formula f, Formula target, Formula replacement) { /* We have to do *simultaneous* replacement, instead of making a sequence of calls to subst_free_var. For example, consider f=p(y,z), target=p(x,y), replacement=r(x,y). Sequential replacement gives r(z,z) instead of r(y,z). */ if (f->type == ATOM_FORM) { if (SYMNUM(f->atom) == SYMNUM(target->atom)) { Formula new = formula_copy(replacement); Plist vars = plist_of_subterms(target->atom); Plist terms = plist_of_subterms(f->atom); /* We have to prevent capture of constants in f by quantifiers in the repalcement. */ Ilist constants_in_f = constants_in_formula(f); rename_these_bound_vars(new, constants_in_f); subst_free_vars(new, vars, terms, NULL); zap_plist(vars); zap_plist(terms); zap_ilist(constants_in_f); zap_term(f->atom); return new; } } else { int i; for (i = 0; i < f->arity; i++) f->kids[i] = subst_atomic_formula(f->kids[i], target, replacement); } return f; } /* subst_atomic_formula */ /************* * * strip_quantifiers() * *************/ static Formula strip_quantifiers(Formula f) { while (quant_form(f)) f = f->kids[0]; return f; } /* strip_quantifiers */ /************* * * definition_applies() * *************/ static BOOL definition_applies(Formula f, Formula def) { int symnum; if (!is_definition(def)) { p_formula(def); fatal_error("definition_applies received non-definition"); } def = strip_quantifiers(def); symnum = SYMNUM(def->kids[0]->atom); return relation_in_formula(f, symnum); } /* definition_applies */ /************* * * expand_with_definition() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Formula expand_with_definition(Formula f, Formula def) { Formula g = formula_copy(f); Formula result; Ilist constants_in_def; if (!is_definition(def)) { p_formula(def); fatal_error("expand_with_definition received non-definition"); } /* We have to prevent capture of constants in the definition by quantifiers in the formula being expanded. */ constants_in_def = constants_in_formula(def); rename_these_bound_vars(g, constants_in_def); zap_ilist(constants_in_def); def = strip_quantifiers(def); result = subst_atomic_formula(g, def->kids[0], def->kids[1]); return result; } /* expand_with_definition */ /************* * * first_definition() * *************/ static Topform first_definition(Plist p) { if (p == NULL) return NULL; else { Topform tf = p->v; if (is_definition(tf->formula)) return tf; else return first_definition(p->next); } } /* first_definition */ /************* * * process_definitions() * *************/ /* DOCUMENTATION All arguments are plists of Topforms containing formulas. */ /* PUBLIC */ void process_definitions(Plist formulas, Plist *results, Plist *defs, Plist *rewritten) { Plist work = formulas; Topform def; *defs = NULL; *rewritten = NULL; def = first_definition(work); while (def) { Plist p; work = plist_remove(work, def); *defs = plist_append(*defs, def); for (p = work; p; p = p->next) { Topform old = p->v; if (definition_applies(old->formula, def->formula)) { Topform new = get_topform(); new->is_formula = TRUE; new->formula = expand_with_definition(old->formula, def->formula); assign_clause_id(new); new->justification = expand_def_just(old, def); *rewritten = plist_append(*rewritten, old); p->v = new; } } def = first_definition(work); } *results = work; } /* process_definitions */ /************* * * expand_with_definitions() * *************/ /* DOCUMENTATION All arguments are plists of Topforms containing formulas. */ /* PUBLIC */ void expand_with_definitions(Plist formulas, Plist defs, Plist *results, Plist *rewritten) { Plist p1; for (p1 = formulas; p1; p1 = p1->next) { Topform work = p1->v; Plist p2; for (p2 = defs; p2; p2 = p2->next) { Topform def = p2->v; if (definition_applies(work->formula, def->formula)) { Topform new = get_topform(); new->is_formula = TRUE; new->formula = expand_with_definition(work->formula, def->formula); assign_clause_id(work); new->justification = expand_def_just(work, def); *rewritten = plist_prepend(*rewritten, work); work = new; } } *results = plist_prepend(*results, work); } zap_plist(formulas); /* shallow */ *results = reverse_plist(*results); } /* expand_with_definitions */ /************* * * separate_definitions() * *************/ /* DOCUMENTATION All arguments are plists of Topforms containing formulas. */ /* PUBLIC */ void separate_definitions(Plist formulas, Plist *defs, Plist *nondefs) { Plist p; *defs = NULL; *nondefs = NULL; for (p = formulas; p; p = p->next) { Topform tf = p->v; if (is_definition(tf->formula)) *defs = plist_prepend(*defs, tf); else *nondefs = plist_prepend(*nondefs, tf); } zap_plist(formulas); /* shallow */ *defs = reverse_plist(*defs); *nondefs = reverse_plist(*nondefs); } /* separate_definitions */ LADR-2009-11A/ladr/maximal.h0000644000175000017500000000326611151265364014554 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_MAXIMAL_H #define TP_MAXIMAL_H #include "literals.h" #include "termorder.h" /* INTRODUCTION */ /* Public definitions */ enum { /* how to check for maximal literals */ FLAG_CHECK, FULL_CHECK }; /* End of public definitions */ /* Public function prototypes from maximal.c */ void init_maximal(void); BOOL max_lit_test(Literals lits, Literals lit); BOOL max_signed_lit_test(Literals lits, Literals lit); void mark_maximal_literals(Literals lits); BOOL maximal_literal(Literals lits, Literals lit, int check); BOOL maximal_signed_literal(Literals lits, Literals lit, int check); int number_of_maximal_literals(Literals lits, int check); void mark_selected_literal(Literals lit); void mark_selected_literals(Literals lits, char *selection); BOOL selected_literal(Literals lit); BOOL exists_selected_literal(Literals lits); void copy_selected_literal_marks(Literals a, Literals b); #endif /* conditional compilation of whole file */ LADR-2009-11A/ladr/ac_redun.c0000644000175000017500000002711610637466321014703 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "ac_redun.h" static Ilist C_symbols = NULL; /* C: commutative */ static Ilist A1_symbols = NULL; /* A1: associative (xy)z = x(yz) */ static Ilist A2_symbols = NULL; /* A2: c-associative x(yz) = y(xz) */ static Ilist AC_symbols = NULL; /* AC: All three */ /* Private definitions and types */ /************* * * same_top() * *************/ /* DOCUMENTATION Do the two terms have the same top symbol? */ /* PUBLIC */ BOOL same_top(Term t1, Term t2) { if (VARIABLE(t1) || VARIABLE(t2)) return term_ident(t1, t2); else return SYMNUM(t1) == SYMNUM(t2); } /* same_top */ /************* * * commutativity() * *************/ /* DOCUMENTATION If the atom is commutativity, return the symnum of the operation; otherwise return 0 (which is never a symnum). */ /* PUBLIC */ int commutativity(Term atom) { if (eq_term(atom)) { Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (ARITY(alpha) == 2 && same_top(alpha, beta)) { Term a = ARG(alpha,0); Term b = ARG(alpha,1); Term c = ARG(beta,0); Term d = ARG(beta,1); if (VARIABLE(a) && VARIABLE(b) && VARNUM(a) != VARNUM(b) && term_ident(a,d) && term_ident(b,c)) return SYMNUM(alpha); } } return 0; } /* commutativity */ /************* * * associativity() * *************/ /* DOCUMENTATION If the atom is associativity, f(f(x,y),z) = f(x,f(y,z)), return the symnum of the operation; otherwise return 0 (which is never a symnum). */ /* PUBLIC */ int associativity(Term atom) { if (eq_term(atom)) { Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (ARITY(alpha) == 2 && same_top(alpha, beta) && same_top(alpha, ARG(alpha,0)) && same_top(alpha, ARG(beta,1))) { Term a = ARG(ARG(alpha,0),0); Term b = ARG(ARG(alpha,0),1); Term c = ARG(alpha,1); Term d = ARG(beta,0); Term e = ARG(ARG(beta,1),0); Term f = ARG(ARG(beta,1),1); if (VARIABLE(a) && VARIABLE(b) && VARIABLE(c) && VARNUM(a) != VARNUM(b) && VARNUM(b) != VARNUM(c) && VARNUM(a) != VARNUM(c) && term_ident(a,d) && term_ident(b,e) && term_ident(c,f)) return SYMNUM(alpha); } } return 0; } /* associativity */ /************* * * c_associativity() * *************/ /* DOCUMENTATION If the atom is c_associativity, f(x,f(y,z)) = f(y,f(x,z)), return the symnum of the operation; otherwise return 0 (which is never a symnum). */ /* PUBLIC */ int c_associativity(Term atom) { if (eq_term(atom)) { Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (ARITY(alpha) == 2 && same_top(alpha, beta) && same_top(alpha, ARG(alpha,1)) && same_top(alpha, ARG(beta,1))) { Term a = ARG(alpha,0); Term b = ARG(ARG(alpha,1),0); Term c = ARG(ARG(alpha,1),1); Term d = ARG(beta,0); Term e = ARG(ARG(beta,1),0); Term f = ARG(ARG(beta,1),1); if (VARIABLE(a) && VARIABLE(b) && VARIABLE(c) && VARNUM(a) != VARNUM(b) && VARNUM(b) != VARNUM(c) && VARNUM(a) != VARNUM(c) && term_ident(a,e) && term_ident(b,d) && term_ident(c,f)) return SYMNUM(alpha); } } return 0; } /* c_associativity */ /************* * * associativity3() * *************/ /* DOCUMENTATION If the atom is any of the following (ab)c = a(bc) (ab)c = a(cb) (ab)c = b(ac) (ab)c = b(ca) return the symnum of the operation; otherwise return 0 (which is never a symnum). */ /* PUBLIC */ int associativity3(Term atom) { if (eq_term(atom)) { Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (ARITY(alpha) == 2 && same_top(alpha, beta) && same_top(alpha, ARG(alpha,0)) && same_top(alpha, ARG(beta,1))) { Term a = ARG(ARG(alpha,0),0); Term b = ARG(ARG(alpha,0),1); Term c = ARG(alpha,1); Term d = ARG(beta,0); Term e = ARG(ARG(beta,1),0); Term f = ARG(ARG(beta,1),1); if (VARIABLE(a) && VARIABLE(b) && VARIABLE(c) && VARNUM(a) != VARNUM(b) && VARNUM(b) != VARNUM(c) && VARNUM(a) != VARNUM(c) && ((term_ident(a,d) && term_ident(b,e) && term_ident(c,f)) | (term_ident(a,d) && term_ident(b,f) && term_ident(c,e)) | (term_ident(a,e) && term_ident(b,d) && term_ident(c,f)) | (term_ident(a,f) && term_ident(b,d) && term_ident(c,e)) ) ) return SYMNUM(alpha); } } return 0; } /* associativity3 */ /************* * * associativity4() * *************/ /* DOCUMENTATION If the atom is any of the following a(bc) = b(ac) a(bc) = b(ca) a(bc) = c(ab) a(bc) = c(ba) return the symnum of the operation; otherwise return 0 (which is never a symnum). */ /* PUBLIC */ int associativity4(Term atom) { if (eq_term(atom)) { Term alpha = ARG(atom, 0); Term beta = ARG(atom, 1); if (ARITY(alpha) == 2 && same_top(alpha, beta) && same_top(alpha, ARG(alpha,1)) && same_top(alpha, ARG(beta,1))) { Term a = ARG(alpha,0); Term b = ARG(ARG(alpha,1),0); Term c = ARG(ARG(alpha,1),1); Term d = ARG(beta,0); Term e = ARG(ARG(beta,1),0); Term f = ARG(ARG(beta,1),1); if (VARIABLE(a) && VARIABLE(b) && VARIABLE(c) && VARNUM(a) != VARNUM(b) && VARNUM(b) != VARNUM(c) && VARNUM(a) != VARNUM(c) && ((term_ident(d,b) && term_ident(e,a) && term_ident(f,c)) | (term_ident(d,b) && term_ident(e,c) && term_ident(f,a)) | (term_ident(d,c) && term_ident(e,a) && term_ident(f,b)) | (term_ident(d,c) && term_ident(e,b) && term_ident(f,a)))) return SYMNUM(alpha); } } return 0; } /* associativity4 */ /************* * * can_compare() * * Total lexicographic order on terms: var < constant < complex. * Argument sn is the greatest symbol at the root. * *************/ static Ordertype can_compare(Term a, Term b, int sn) { if (VARIABLE(a) || VARIABLE(b)) return term_compare_vcp(a, b); else if (SYMNUM(a) == sn && SYMNUM(b) == sn) return term_compare_vcp(a, b); else if (SYMNUM(a) == sn) return GREATER_THAN; else if (SYMNUM(b) == sn) return LESS_THAN; else return term_compare_vcp(a, b); } /* can_compare */ /************* * * canon() -- yet another canonicalizer. * *************/ static Term canon(Term t, int flag) { if (term_flag(t, flag)) return t; /* already canonicalized */ else if (VARIABLE(t)) return t; else { int sn = SYMNUM(t); int i; for (i = 0; i < ARITY(t); i++) ARG(t,i) = canon(ARG(t,i), flag); if (ilist_member(AC_symbols, sn)) { Term a = ARG(t,0); Term b = ARG(t,1); if (same_top(t, b) && can_compare(a, ARG(b,0), sn) == GREATER_THAN) { Term b0 = ARG(b,0); ARG(t,0) = b0; ARG(b,0) = a; term_flag_clear(b, flag); ARG(t,1) = canon(b, flag); t = canon(t, flag); } else if (can_compare(a, b, sn) == GREATER_THAN) { ARG(t,0) = b; ARG(t,1) = a; t = canon(t, flag); } } else if (ilist_member(C_symbols, sn)) { Term a = ARG(t,0); Term b = ARG(t,1); if (can_compare(a, b, sn) == GREATER_THAN) { ARG(t,0) = b; ARG(t,1) = a; } } term_flag_set(t, flag); /* mark as canonicalized */ return t; } } /* canon */ /************* * * cac_redundant_atom() * *************/ static BOOL cac_redundant_atom(Term atom) { if (!eq_term(atom)) return FALSE; /* must be equality atom */ else if (VARIABLE(ARG(atom,0)) || VARIABLE(ARG(atom,1))) return FALSE; /* neither side can be a variable */ else if (SYMNUM(ARG(atom,0)) != SYMNUM(ARG(atom,1))) return FALSE; /* function symbols must be the same */ else if (symbol_count(ARG(atom,0)) != symbol_count(ARG(atom,1))) return FALSE; /* symbol counts must be the same */ else if (commutativity(atom)) return FALSE; else if (associativity(atom)) return FALSE; else if (c_associativity(atom)) return FALSE; else { /* Copy terms, AC-canonicalize, check for identity. */ int flag = claim_term_flag(); /* for marking canonicalized subterms */ BOOL cac_redund; Term a = copy_term(ARG(atom, 0)); Term b = copy_term(ARG(atom, 1)); a = canon(a, flag); b = canon(b, flag); cac_redund = term_ident(a,b); zap_term(a); zap_term(b); release_term_flag(flag); return cac_redund; } } /* cac_redundant_atom */ /************* * * cac_tautology() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL cac_tautology(Literals lits) { if (C_symbols == NULL) return FALSE; else if (lits == NULL) return FALSE; else if (lits->sign && cac_redundant_atom(lits->atom)) return TRUE; else return cac_tautology(lits->next); } /* cac_tautology */ /************* * * cac_redundancy() * *************/ /* DOCUMENTATION This routine checks if the clause is commutativity or "c-associativity" x(yz)=y(xz); if so, it stores that information for later calls to cac_redundancy(). If an operation is found to C or AC, return TRUE; if found to be just A, return FALSE;

    Otherwise, if any positive literal is an instance of x=x (mod C and AC as previously noted), it is rewritten to $T. Then return FALSE.

    Motivation: If we know that * is commutative, and we derive an equation f(a,b*c)=f(a,c*b), we can delete that equation, because commutativity can do anything that equation can do. The same goes for AC operations. */ /* PUBLIC */ BOOL cac_redundancy(Topform c, BOOL print) { if (pos_eq_unit(c->literals)) { Term atom = c->literals->atom; int sn = SYMNUM(ARG(atom, 0)); BOOL new_assoc; if (!ilist_member(C_symbols, sn) && commutativity(atom)) { C_symbols = ilist_append(C_symbols, sn); if (ilist_member(A1_symbols, sn) && ilist_member(A2_symbols, sn)) { if (print) printf("\n%% Operation %s associative-commutative; " "CAC redundancy checks enabled.\n", sn_to_str(sn)); AC_symbols = ilist_append(AC_symbols, sn); } else { if (print) printf("\n%% Operation %s is commutative; " "C redundancy checks enabled.\n", sn_to_str(sn)); } return TRUE; /* New C symbol, may also be A1 and/or A2. */ } if (!ilist_member(A1_symbols, sn) && associativity(atom)) { A1_symbols = ilist_append(A1_symbols, sn); new_assoc = TRUE; } else if (!ilist_member(A2_symbols, sn) && c_associativity(atom)) { A2_symbols = ilist_append(A2_symbols, sn); new_assoc = TRUE; } else new_assoc = FALSE; if (new_assoc) { if (ilist_member(C_symbols, sn) && ilist_member(A1_symbols, sn) && ilist_member(A2_symbols, sn)) { if (print) printf("\n%% Operation %s is associative-commutative; " "CAC redundancy checks enabled.\n", sn_to_str(sn)); AC_symbols = ilist_append(AC_symbols, sn); return TRUE; /* C, A1, A2 (A1 or A2 is newly found) */ } else return FALSE; /* A1 or A2 newly found */ } } /* pos_eq_unit */ if (cac_tautology(c->literals)) { zap_literals(c->literals); c->literals = get_literals(); c->literals->sign = TRUE; c->literals->atom = get_rigid_term(true_sym(), 0); c->literals->atom->container = c; } return FALSE; } /* cac_redundancy */ LADR-2009-11A/ladr/parse.h0000644000175000017500000000561711157754017014244 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef TP_PARSE_H #define TP_PARSE_H #include "listterm.h" /* INTRODUCTION This package has routines for reading and writing terms in human-readable form. Binary function symbols can be declared to be infix with a precedence and left or right association, so that many parentheses can be omitted. Unary symbols can be declared to be prefix or postfix. In addition, prolog-style list-notation and quantified formulas are supported.

    The symbol declarations and parse rules are similar to the method used by many Prolog systems (although we use mnemonic names instead of xfy, yfx, yf, etc.). The symbol declarations are made with set_parse_type().

    This package is based on code taked form Otter and EQP, but there are some important differences. Detailed documentation should be available elsewhere.

    The intension is to use this package for reading and writing all types of data (terms, clauses, formulas, control information, etc.), with outside routines to translate to/from the appropriate internal data structure when necessary. */ /* Public definitions */ /* End of public definitions */ /* Public function prototypes from parse.c */ void fprint_parse_mem(FILE *fp, BOOL heading); void p_parse_mem(void); void translate_neg_equalities(BOOL flag); BOOL ordinary_constant_string(char *s); Term sread_term(String_buf sb, FILE *fout); Term read_term(FILE *fin, FILE *fout); Term parse_term_from_string(char *s); void sb_write_term(String_buf sb, Term t); void fwrite_term(FILE *fp, Term t); void fwrite_term_nl(FILE *fp, Term t); char *process_quoted_symbol(char *str); void declare_parse_type(char *str, int precedence, Parsetype type); void declare_quantifier_precedence(int prec); void declare_standard_parse_types(void); BOOL redeclare_symbol_and_copy_parsetype(char *operation, char *str, BOOL echo, FILE *fout); void skip_to_nl(FILE *fp); Plist split_string(char *onlys); void set_cons_char(char c); char get_cons_char(void); void set_quote_char(char c); char get_quote_char(void); void parenthesize(BOOL setting); void check_for_illegal_symbols(BOOL setting); void simple_parse(BOOL setting); #endif /* conditional compilation of whole file */ LADR-2009-11A/apps.examples/0000755000175000017500000000000010656104201014571 5ustar mccunemccuneLADR-2009-11A/apps.examples/Makefile0000644000175000017500000000046107714766447016265 0ustar mccunemccuneOUTPUTS = qg.out3 qg.iso3 MOL-cand.238 OL.8 OL.8.out OL.6 BA-sheffer.out \ lattice-sax.rewritten meet-join-equations.out mjc01s-equations.out \ OL.8.upper-covers test: $(MAKE) backup ./run-all clean: /bin/rm -rf $(OUTPUTS) backup backup: /bin/rm -rf backup mkdir backup && mv $(OUTPUTS) backup LADR-2009-11A/apps.examples/distributivity0000644000175000017500000000004110131333576017614 0ustar mccunemccunex ^ (y v z) = (x ^ y) v (x ^ z). LADR-2009-11A/apps.examples/interp.OL60000644000175000017500000000217307667723323016443 0ustar mccunemccuneinterpretation(6, [ function(c(_), [1,0,3,2,5,4]), function(^(_,_), [0,0,0,0,0,0,0,1,2,3,4,5,0,2,2,0,0,0,0,3,0,3,0,0,0,4,0,0,4,0,0,5,0,0,0,5]), function(v(_,_), [0,1,2,3,4,5,1,1,1,1,1,1,2,1,2,1,1,1,3,1,1,3,1,1,4,1,1,1,4,1,5,1,1,1,1,5]), function(f(_,_), [1,1,1,1,1,1,1,0,3,2,5,4,1,3,3,1,1,1,1,2,1,2,1,1,1,5,1,1,5,1,1,4,1,1,1,4]), function(m(_,_), [0,0,0,0,0,0,0,1,2,3,4,5,0,2,2,0,0,0,0,3,0,3,0,0,0,4,0,0,4,0,0,5,0,0,0,5]), function(j(_,_), [0,1,2,3,4,5,1,1,1,1,1,1,2,1,2,1,1,1,3,1,1,3,1,1,4,1,1,1,4,1,5,1,1,1,1,5])]). interpretation(6, [ function(c(_), [1,0,3,2,5,4]), function(^(_,_), [0,0,0,0,0,0,0,1,2,3,4,5,0,2,2,0,0,5,0,3,0,3,3,0,0,4,0,3,4,0,0,5,5,0,0,5]), function(v(_,_), [0,1,2,3,4,5,1,1,1,1,1,1,2,1,2,1,1,2,3,1,1,3,4,1,4,1,1,4,4,1,5,1,2,1,1,5]), function(f(_,_), [1,1,1,1,1,1,1,0,3,2,5,4,1,3,3,1,1,4,1,2,1,2,2,1,1,5,1,2,5,1,1,4,4,1,1,4]), function(m(_,_), [0,0,0,0,0,0,0,1,2,3,4,5,0,2,2,0,0,5,0,3,0,3,3,0,0,4,0,3,4,0,0,5,5,0,0,5]), function(j(_,_), [0,1,2,3,4,5,1,1,1,1,1,1,2,1,2,1,1,2,3,1,1,3,4,1,4,1,1,4,4,1,5,1,2,1,1,5])]). % isofilter: input=5, kept=2, checks=3, perms=3, 0.01 seconds. LADR-2009-11A/apps.examples/qg.in0000644000175000017500000000036310654704052015542 0ustar mccunemccuneassign(max_models, -1). % This means there is no limit. op(400, infix, *). op(400, infix, \). op(400, infix, /). formulas(theory). % Quasigroup axioms x * (x \ y) = y. x \ (x * y) = y. (x / y) * y = x. (x * y) / y = x. end_of_list. LADR-2009-11A/apps.examples/lattice-sax0000644000175000017500000000146207671674312016757 0ustar mccunemccune% Each these four equations is single axiom for lattice theory (((x ^ y) v (y ^ (x v y))) ^ z) v (((x ^ (((x1 ^ y) v (y ^ x2)) v y)) v (((y ^ (((x1 v (y v x2)) ^ (x3 v y)) ^ y)) v (u ^ (y v (((x1 v (y v x2)) ^ (x3 v y)) ^ y)))) ^ (x v (((x1 ^ y) v (y ^ x2)) v y)))) ^ (((x ^ y) v (y ^ (x v y))) v z)) = y. % length 79, 7 variables (((x ^ y) v (y ^ (x v y))) ^ z) v (((x ^ (((x1 ^ y) v (y ^ x2)) v y)) v (((y ^ (((x1 v (y v x2)) ^ (x3 v y)) ^ y)) v (u ^ (y v (((y v xnew) ^ (x3 v y)) ^ y)))) ^ (x v (((x1 ^ y) v (y ^ x2)) v y)))) ^ (((x ^ y) v (y ^ (x v y))) v z)) = y. % length 77, 8 variables (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. % A1 (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (((w v x) ^ (v6 v x)) v v7) = x. % A2 LADR-2009-11A/apps.examples/run-all0000755000175000017500000000240110131333612016064 0ustar mccunemccune#!/bin/csh # This script should run the examples described in index.html. set path = (../bin $path) # Remove isomorphic interpretations. mace4 -n3 < qg.in | get_interps > qg.out3 isofilter < qg.out3 > qg.iso3 # Use a set of interpretations to filter a stream of clauses. clausefilter non-MOL-OML false_in_all < MOL-cand.296 > MOL-cand.238 # Use a set of clauses to filter a stream of interpretations: # Get the nondistributive OLs (BAs) of order 8. mace4 -n8 < OL.in | get_interps | isofilter > OL.8 interpfilter distributivity some_false < OL.8 > OL.8.out # Given a set of interpretations and a stream of clauses, # print the interpretations that model each clause. mace4 -n6 < OL.in | get_interps | isofilter > OL.6 clausetester OL.6 < BA-sheffer > BA-sheffer.out # Given a set of rewrite rules, rewrite a stream of terms or clauses. rewriter lattice.rules < lattice-sax > lattice-sax.rewritten # Decision procedure for lattice identities in meet and join. latfilter < meet-join-equations > meet-join-equations.out # Decision procedure for ortholattice identities in # meet/join/complement/0/1/shefferstroke. olfilter < mjc01s-equations > mjc01s-equations.out # Print the upper covers of the 5 ortholattices of order 8. upper-covers < OL.8 > OL.8.upper-covers LADR-2009-11A/apps.examples/BA-sheffer0000644000175000017500000003133507667724551016453 0ustar mccunemccune% These are Boolean Algebra identities in terms of the Sheffer stroke. % Every such identity (or its mirror image), up through length 15, % is captured by a member of this list. f(f(x,x),f(x,y)) = x. f(f(x,x),f(y,x)) = x. f(f(y,f(y,y)),f(x,x)) = x. f(f(f(y,y),y),f(x,x)) = x. f(f(x,f(y,z)),f(x,z)) = x. f(f(x,f(y,z)),f(z,x)) = x. f(f(x,f(y,z)),f(x,y)) = x. f(f(x,f(y,z)),f(y,x)) = x. f(f(f(y,z),x),f(x,z)) = x. f(f(f(y,z),x),f(z,x)) = x. f(f(f(y,z),x),f(x,y)) = x. f(f(f(y,z),x),f(y,x)) = x. f(f(x,f(y,f(y,y))),f(x,z)) = x. f(f(x,f(f(y,y),y)),f(x,z)) = x. f(f(x,f(y,f(y,y))),f(z,x)) = x. f(f(x,f(f(y,y),y)),f(z,x)) = x. f(f(f(y,f(y,y)),x),f(x,z)) = x. f(f(f(f(y,y),y),x),f(x,z)) = x. f(f(f(y,f(y,y)),x),f(z,x)) = x. f(f(f(f(y,y),y),x),f(z,x)) = x. f(f(x,f(f(x,y),y)),f(x,z)) = x. f(f(x,f(f(x,y),y)),f(z,x)) = x. f(f(f(f(x,y),z),z),f(x,x)) = x. f(f(x,f(y,f(x,y))),f(x,z)) = x. f(f(x,f(f(y,x),y)),f(x,z)) = x. f(f(x,f(y,f(x,y))),f(z,x)) = x. f(f(x,f(f(y,x),y)),f(z,x)) = x. f(f(x,f(y,f(y,x))),f(x,z)) = x. f(f(f(f(x,y),y),x),f(x,z)) = x. f(f(x,f(y,f(y,x))),f(z,x)) = x. f(f(f(f(x,y),y),x),f(z,x)) = x. f(f(f(f(y,x),z),z),f(x,x)) = x. f(f(y,f(f(x,z),y)),f(x,x)) = x. f(f(f(y,f(x,z)),y),f(x,x)) = x. f(f(f(y,f(x,y)),x),f(x,z)) = x. f(f(f(f(y,x),y),x),f(x,z)) = x. f(f(f(y,f(x,y)),x),f(z,x)) = x. f(f(f(f(y,x),y),x),f(z,x)) = x. f(f(y,f(f(z,x),y)),f(x,x)) = x. f(f(f(y,f(z,x)),y),f(x,x)) = x. f(f(f(y,f(y,x)),x),f(x,z)) = x. f(f(f(y,f(y,x)),x),f(z,x)) = x. f(f(y,f(y,f(x,z))),f(x,x)) = x. f(f(y,f(y,f(z,x))),f(x,x)) = x. f(f(x,f(f(x,x),y)),f(x,z)) = x. f(f(x,f(f(x,x),y)),f(z,x)) = x. f(f(f(f(x,x),y),x),f(x,z)) = x. f(f(f(f(x,x),y),x),f(z,x)) = x. f(f(x,f(y,f(x,x))),f(x,z)) = x. f(f(x,f(y,f(x,x))),f(z,x)) = x. f(f(f(y,f(x,x)),x),f(x,z)) = x. f(f(f(y,f(x,x)),x),f(z,x)) = x. f(f(x,f(y,f(y,y))),f(z,f(z,z))) = x. f(f(x,f(f(y,y),y)),f(z,f(z,z))) = x. f(f(x,f(y,f(y,y))),f(f(z,z),z)) = x. f(f(x,f(f(y,y),y)),f(f(z,z),z)) = x. f(f(f(y,f(y,y)),x),f(z,f(z,z))) = x. f(f(f(f(y,y),y),x),f(z,f(z,z))) = x. f(f(f(y,f(y,y)),x),f(f(z,z),z)) = x. f(f(f(f(y,y),y),x),f(f(z,z),z)) = x. f(f(f(f(x,y),y),y),f(x,f(z,y))) = x. f(f(f(f(x,y),y),y),f(x,f(y,z))) = x. f(f(f(f(x,y),y),y),f(f(z,y),x)) = x. f(f(f(f(x,y),y),y),f(f(y,z),x)) = x. f(f(y,f(f(x,y),y)),f(x,f(z,y))) = x. f(f(f(y,f(x,y)),y),f(x,f(z,y))) = x. f(f(f(f(y,x),y),y),f(x,f(z,y))) = x. f(f(y,f(f(x,y),y)),f(x,f(y,z))) = x. f(f(f(y,f(x,y)),y),f(x,f(y,z))) = x. f(f(f(f(y,x),y),y),f(x,f(y,z))) = x. f(f(y,f(f(x,y),y)),f(f(z,y),x)) = x. f(f(f(y,f(x,y)),y),f(f(z,y),x)) = x. f(f(f(f(y,x),y),y),f(f(z,y),x)) = x. f(f(y,f(f(x,y),y)),f(f(y,z),x)) = x. f(f(f(y,f(x,y)),y),f(f(y,z),x)) = x. f(f(f(f(y,x),y),y),f(f(y,z),x)) = x. f(f(y,f(y,f(x,y))),f(x,f(z,y))) = x. f(f(y,f(f(y,x),y)),f(x,f(z,y))) = x. f(f(f(y,f(y,x)),y),f(x,f(z,y))) = x. f(f(y,f(y,f(x,y))),f(x,f(y,z))) = x. f(f(y,f(f(y,x),y)),f(x,f(y,z))) = x. f(f(f(y,f(y,x)),y),f(x,f(y,z))) = x. f(f(y,f(y,f(x,y))),f(f(z,y),x)) = x. f(f(y,f(f(y,x),y)),f(f(z,y),x)) = x. f(f(f(y,f(y,x)),y),f(f(z,y),x)) = x. f(f(y,f(y,f(x,y))),f(f(y,z),x)) = x. f(f(y,f(f(y,x),y)),f(f(y,z),x)) = x. f(f(f(y,f(y,x)),y),f(f(y,z),x)) = x. f(f(y,f(y,f(y,x))),f(x,f(z,y))) = x. f(f(y,f(y,f(y,x))),f(x,f(y,z))) = x. f(f(y,f(y,f(y,x))),f(f(z,y),x)) = x. f(f(y,f(y,f(y,x))),f(f(y,z),x)) = x. f(f(x,f(f(x,y),y)),f(z,f(z,z))) = x. f(f(x,f(f(x,y),y)),f(f(z,z),z)) = x. f(f(x,f(y,f(x,y))),f(z,f(z,z))) = x. f(f(x,f(f(y,x),y)),f(z,f(z,z))) = x. f(f(x,f(y,f(x,y))),f(f(z,z),z)) = x. f(f(x,f(f(y,x),y)),f(f(z,z),z)) = x. f(f(x,f(y,f(y,x))),f(z,f(z,z))) = x. f(f(f(f(x,y),y),x),f(z,f(z,z))) = x. f(f(x,f(y,f(y,x))),f(f(z,z),z)) = x. f(f(f(f(x,y),y),x),f(f(z,z),z)) = x. f(f(f(f(x,y),z),z),f(x,f(y,z))) = x. f(f(f(f(x,y),z),z),f(x,f(z,y))) = x. f(f(f(f(x,y),z),z),f(f(y,z),x)) = x. f(f(f(f(x,y),z),z),f(f(z,y),x)) = x. f(f(f(y,f(x,y)),x),f(z,f(z,z))) = x. f(f(f(f(y,x),y),x),f(z,f(z,z))) = x. f(f(f(y,f(x,y)),x),f(f(z,z),z)) = x. f(f(f(f(y,x),y),x),f(f(z,z),z)) = x. f(f(f(f(y,x),z),z),f(x,f(y,z))) = x. f(f(f(f(y,x),z),z),f(x,f(z,y))) = x. f(f(f(f(y,x),z),z),f(f(y,z),x)) = x. f(f(f(f(y,x),z),z),f(f(z,y),x)) = x. f(f(f(y,f(y,x)),x),f(z,f(z,z))) = x. f(f(f(y,f(y,x)),x),f(f(z,z),z)) = x. f(f(y,f(f(x,z),y)),f(x,f(z,y))) = x. f(f(f(y,f(x,z)),y),f(x,f(z,y))) = x. f(f(y,f(f(x,z),y)),f(x,f(y,z))) = x. f(f(f(y,f(x,z)),y),f(x,f(y,z))) = x. f(f(y,f(f(x,z),y)),f(f(z,y),x)) = x. f(f(f(y,f(x,z)),y),f(f(z,y),x)) = x. f(f(y,f(f(x,z),y)),f(f(y,z),x)) = x. f(f(f(y,f(x,z)),y),f(f(y,z),x)) = x. f(f(y,f(f(z,x),y)),f(x,f(z,y))) = x. f(f(f(y,f(z,x)),y),f(x,f(z,y))) = x. f(f(y,f(f(z,x),y)),f(x,f(y,z))) = x. f(f(f(y,f(z,x)),y),f(x,f(y,z))) = x. f(f(y,f(f(z,x),y)),f(f(z,y),x)) = x. f(f(f(y,f(z,x)),y),f(f(z,y),x)) = x. f(f(y,f(f(z,x),y)),f(f(y,z),x)) = x. f(f(f(y,f(z,x)),y),f(f(y,z),x)) = x. f(f(y,f(y,f(x,z))),f(x,f(z,y))) = x. f(f(y,f(y,f(x,z))),f(x,f(y,z))) = x. f(f(y,f(y,f(x,z))),f(f(z,y),x)) = x. f(f(y,f(y,f(x,z))),f(f(y,z),x)) = x. f(f(y,f(y,f(z,x))),f(x,f(z,y))) = x. f(f(y,f(y,f(z,x))),f(x,f(y,z))) = x. f(f(y,f(y,f(z,x))),f(f(z,y),x)) = x. f(f(y,f(y,f(z,x))),f(f(y,z),x)) = x. f(f(x,f(f(x,x),y)),f(z,f(z,z))) = x. f(f(x,f(f(x,x),y)),f(f(z,z),z)) = x. f(f(f(f(x,x),y),x),f(z,f(z,z))) = x. f(f(f(f(x,x),y),x),f(f(z,z),z)) = x. f(f(f(f(x,x),y),y),f(x,f(z,y))) = x. f(f(f(f(x,x),y),y),f(x,f(y,z))) = x. f(f(f(f(x,x),y),y),f(f(z,y),x)) = x. f(f(f(f(x,x),y),y),f(f(y,z),x)) = x. f(f(x,f(y,f(x,x))),f(z,f(z,z))) = x. f(f(x,f(y,f(x,x))),f(f(z,z),z)) = x. f(f(f(y,f(x,x)),x),f(z,f(z,z))) = x. f(f(f(y,f(x,x)),x),f(f(z,z),z)) = x. f(f(y,f(f(x,x),y)),f(x,f(z,y))) = x. f(f(f(y,f(x,x)),y),f(x,f(z,y))) = x. f(f(y,f(f(x,x),y)),f(x,f(y,z))) = x. f(f(f(y,f(x,x)),y),f(x,f(y,z))) = x. f(f(y,f(f(x,x),y)),f(f(z,y),x)) = x. f(f(f(y,f(x,x)),y),f(f(z,y),x)) = x. f(f(y,f(f(x,x),y)),f(f(y,z),x)) = x. f(f(f(y,f(x,x)),y),f(f(y,z),x)) = x. f(f(y,f(y,f(x,x))),f(x,f(z,y))) = x. f(f(y,f(y,f(x,x))),f(x,f(y,z))) = x. f(f(y,f(y,f(x,x))),f(f(z,y),x)) = x. f(f(y,f(y,f(x,x))),f(f(y,z),x)) = x. f(f(x,f(y,f(z,z))),f(x,f(u,z))) = x. f(f(x,f(y,f(z,z))),f(x,f(z,u))) = x. f(f(x,f(y,f(z,z))),f(f(u,z),x)) = x. f(f(x,f(y,f(z,z))),f(f(z,u),x)) = x. f(f(x,f(f(y,y),z)),f(x,f(u,y))) = x. f(f(x,f(f(y,y),z)),f(x,f(y,u))) = x. f(f(x,f(f(y,y),z)),f(f(u,y),x)) = x. f(f(x,f(f(y,y),z)),f(f(y,u),x)) = x. f(f(f(y,f(z,z)),x),f(x,f(u,z))) = x. f(f(f(y,f(z,z)),x),f(x,f(z,u))) = x. f(f(f(y,f(z,z)),x),f(f(u,z),x)) = x. f(f(f(y,f(z,z)),x),f(f(z,u),x)) = x. f(f(f(f(y,y),z),x),f(x,f(u,y))) = x. f(f(f(f(y,y),z),x),f(x,f(y,u))) = x. f(f(f(f(y,y),z),x),f(f(u,y),x)) = x. f(f(f(f(y,y),z),x),f(f(y,u),x)) = x. f(f(x,f(y,f(z,u))),f(x,f(u,z))) = x. f(f(x,f(y,f(z,u))),f(f(u,z),x)) = x. f(f(x,f(y,f(y,z))),f(x,f(u,z))) = x. f(f(x,f(y,f(y,z))),f(x,f(z,u))) = x. f(f(x,f(y,f(y,z))),f(f(u,z),x)) = x. f(f(x,f(y,f(y,z))),f(f(z,u),x)) = x. f(f(x,f(f(y,z),u)),f(x,f(z,y))) = x. f(f(x,f(f(y,z),u)),f(f(z,y),x)) = x. f(f(x,f(y,f(z,y))),f(x,f(u,z))) = x. f(f(x,f(f(y,z),y)),f(x,f(u,z))) = x. f(f(x,f(y,f(z,y))),f(x,f(z,u))) = x. f(f(x,f(f(y,z),y)),f(x,f(z,u))) = x. f(f(x,f(y,f(z,y))),f(f(u,z),x)) = x. f(f(x,f(f(y,z),y)),f(f(u,z),x)) = x. f(f(x,f(y,f(z,y))),f(f(z,u),x)) = x. f(f(x,f(f(y,z),y)),f(f(z,u),x)) = x. f(f(x,f(f(y,z),z)),f(x,f(u,y))) = x. f(f(x,f(f(y,z),z)),f(x,f(y,u))) = x. f(f(x,f(f(y,z),z)),f(f(u,y),x)) = x. f(f(x,f(f(y,z),z)),f(f(y,u),x)) = x. f(f(f(y,f(z,u)),x),f(x,f(u,z))) = x. f(f(f(y,f(z,u)),x),f(f(u,z),x)) = x. f(f(f(y,f(y,z)),x),f(x,f(u,z))) = x. f(f(f(y,f(y,z)),x),f(x,f(z,u))) = x. f(f(f(y,f(y,z)),x),f(f(u,z),x)) = x. f(f(f(y,f(y,z)),x),f(f(z,u),x)) = x. f(f(f(f(y,z),u),x),f(x,f(z,y))) = x. f(f(f(f(y,z),u),x),f(f(z,y),x)) = x. f(f(f(y,f(z,y)),x),f(x,f(u,z))) = x. f(f(f(f(y,z),y),x),f(x,f(u,z))) = x. f(f(f(y,f(z,y)),x),f(x,f(z,u))) = x. f(f(f(f(y,z),y),x),f(x,f(z,u))) = x. f(f(f(y,f(z,y)),x),f(f(u,z),x)) = x. f(f(f(f(y,z),y),x),f(f(u,z),x)) = x. f(f(f(y,f(z,y)),x),f(f(z,u),x)) = x. f(f(f(f(y,z),y),x),f(f(z,u),x)) = x. f(f(f(f(y,z),z),x),f(x,f(u,y))) = x. f(f(f(f(y,z),z),x),f(x,f(y,u))) = x. f(f(f(f(y,z),z),x),f(f(u,y),x)) = x. f(f(f(f(y,z),z),x),f(f(y,u),x)) = x. f(f(x,f(f(x,y),z)),f(x,f(u,y))) = x. f(f(x,f(f(x,y),z)),f(x,f(y,u))) = x. f(f(x,f(f(x,y),z)),f(f(u,y),x)) = x. f(f(x,f(f(x,y),z)),f(f(y,u),x)) = x. f(f(x,f(y,f(x,z))),f(x,f(u,z))) = x. f(f(x,f(y,f(x,z))),f(x,f(z,u))) = x. f(f(x,f(y,f(x,z))),f(f(u,z),x)) = x. f(f(x,f(y,f(x,z))),f(f(z,u),x)) = x. f(f(x,f(y,f(z,x))),f(x,f(u,z))) = x. f(f(x,f(y,f(z,x))),f(x,f(z,u))) = x. f(f(x,f(y,f(z,x))),f(f(u,z),x)) = x. f(f(x,f(y,f(z,x))),f(f(z,u),x)) = x. f(f(x,f(f(y,x),z)),f(x,f(u,y))) = x. f(f(x,f(f(y,x),z)),f(x,f(y,u))) = x. f(f(x,f(f(y,x),z)),f(f(u,y),x)) = x. f(f(x,f(f(y,x),z)),f(f(y,u),x)) = x. f(f(f(f(x,y),z),x),f(x,f(u,y))) = x. f(f(f(f(x,y),z),x),f(x,f(y,u))) = x. f(f(f(f(x,y),z),x),f(f(u,y),x)) = x. f(f(f(f(x,y),z),x),f(f(y,u),x)) = x. f(f(f(y,f(x,z)),x),f(x,f(u,z))) = x. f(f(f(y,f(x,z)),x),f(x,f(z,u))) = x. f(f(f(y,f(x,z)),x),f(f(u,z),x)) = x. f(f(f(y,f(x,z)),x),f(f(z,u),x)) = x. f(f(f(y,f(z,x)),x),f(x,f(u,z))) = x. f(f(f(y,f(z,x)),x),f(x,f(z,u))) = x. f(f(f(y,f(z,x)),x),f(f(u,z),x)) = x. f(f(f(y,f(z,x)),x),f(f(z,u),x)) = x. f(f(f(f(y,x),z),x),f(x,f(u,y))) = x. f(f(f(f(y,x),z),x),f(x,f(y,u))) = x. f(f(f(f(y,x),z),x),f(f(u,y),x)) = x. f(f(f(f(y,x),z),x),f(f(y,u),x)) = x. f(f(f(f(y,f(z,z)),z),z),f(x,x)) = x. f(f(y,f(f(z,f(y,y)),y)),f(x,x)) = x. f(f(f(y,f(z,f(y,y))),y),f(x,x)) = x. f(f(y,f(y,f(z,f(y,y)))),f(x,x)) = x. f(f(f(f(f(y,y),z),y),y),f(x,x)) = x. f(f(y,f(f(f(y,y),z),y)),f(x,x)) = x. f(f(f(y,f(f(y,y),z)),y),f(x,x)) = x. f(f(y,f(y,f(f(y,y),z))),f(x,x)) = x. f(f(y,f(y,f(z,f(z,z)))),f(x,x)) = x. f(f(y,f(y,f(f(z,z),z))),f(x,x)) = x. f(f(f(f(y,f(y,z)),z),z),f(x,x)) = x. f(f(f(f(y,f(z,y)),z),z),f(x,x)) = x. f(f(f(f(f(y,z),y),z),z),f(x,x)) = x. f(f(y,f(f(z,f(z,z)),y)),f(x,x)) = x. f(f(y,f(f(f(z,z),z),y)),f(x,x)) = x. f(f(f(y,f(z,f(z,z))),y),f(x,x)) = x. f(f(f(y,f(f(z,z),z)),y),f(x,x)) = x. f(f(y,f(f(z,f(z,y)),y)),f(x,x)) = x. f(f(f(y,f(z,f(z,y))),y),f(x,x)) = x. f(f(f(f(f(y,z),z),y),y),f(x,x)) = x. f(f(y,f(f(z,f(y,z)),y)),f(x,x)) = x. f(f(y,f(f(f(z,y),z),y)),f(x,x)) = x. f(f(f(y,f(z,f(y,z))),y),f(x,x)) = x. f(f(f(y,f(f(z,y),z)),y),f(x,x)) = x. f(f(y,f(y,f(z,f(z,y)))),f(x,x)) = x. f(f(y,f(f(f(y,z),z),y)),f(x,x)) = x. f(f(f(y,f(f(y,z),z)),y),f(x,x)) = x. f(f(y,f(y,f(z,f(y,z)))),f(x,x)) = x. f(f(y,f(y,f(f(z,y),z))),f(x,x)) = x. f(f(y,f(y,f(f(y,z),z))),f(x,x)) = x. f(f(f(f(y,f(y,y)),z),z),f(x,x)) = x. f(f(f(f(f(y,y),y),z),z),f(x,x)) = x. f(f(x,f(f(f(y,z),u),u)),f(x,z)) = x. f(f(x,f(f(f(y,z),u),u)),f(z,x)) = x. f(f(x,f(y,f(f(z,u),y))),f(x,u)) = x. f(f(x,f(f(y,f(z,u)),y)),f(x,u)) = x. f(f(x,f(y,f(f(z,u),y))),f(u,x)) = x. f(f(x,f(f(y,f(z,u)),y)),f(u,x)) = x. f(f(x,f(f(f(y,z),u),u)),f(x,y)) = x. f(f(x,f(f(f(y,z),u),u)),f(y,x)) = x. f(f(x,f(y,f(y,f(z,u)))),f(x,u)) = x. f(f(x,f(y,f(y,f(z,u)))),f(u,x)) = x. f(f(x,f(y,f(y,f(z,u)))),f(x,z)) = x. f(f(x,f(y,f(y,f(z,u)))),f(z,x)) = x. f(f(x,f(y,f(f(z,u),y))),f(x,z)) = x. f(f(x,f(f(y,f(z,u)),y)),f(x,z)) = x. f(f(x,f(y,f(f(z,u),y))),f(z,x)) = x. f(f(x,f(f(y,f(z,u)),y)),f(z,x)) = x. f(f(f(f(f(y,z),u),u),x),f(x,z)) = x. f(f(f(f(f(y,z),u),u),x),f(z,x)) = x. f(f(f(y,f(f(z,u),y)),x),f(x,u)) = x. f(f(f(f(y,f(z,u)),y),x),f(x,u)) = x. f(f(f(y,f(f(z,u),y)),x),f(u,x)) = x. f(f(f(f(y,f(z,u)),y),x),f(u,x)) = x. f(f(f(f(f(y,z),u),u),x),f(x,y)) = x. f(f(f(f(f(y,z),u),u),x),f(y,x)) = x. f(f(f(y,f(y,f(z,u))),x),f(x,u)) = x. f(f(f(y,f(y,f(z,u))),x),f(u,x)) = x. f(f(f(y,f(y,f(z,u))),x),f(x,z)) = x. f(f(f(y,f(y,f(z,u))),x),f(z,x)) = x. f(f(f(y,f(f(z,u),y)),x),f(x,z)) = x. f(f(f(f(y,f(z,u)),y),x),f(x,z)) = x. f(f(f(y,f(f(z,u),y)),x),f(z,x)) = x. f(f(f(f(y,f(z,u)),y),x),f(z,x)) = x. f(f(x,f(f(x,f(y,z)),u)),f(x,z)) = x. f(f(x,f(f(x,f(y,z)),u)),f(z,x)) = x. f(f(x,f(f(x,f(y,z)),u)),f(x,y)) = x. f(f(x,f(f(x,f(y,z)),u)),f(y,x)) = x. f(f(x,f(y,f(x,f(z,u)))),f(x,u)) = x. f(f(x,f(y,f(x,f(z,u)))),f(u,x)) = x. f(f(x,f(y,f(x,f(z,u)))),f(x,z)) = x. f(f(x,f(y,f(x,f(z,u)))),f(z,x)) = x. f(f(x,f(y,f(f(z,u),x))),f(x,u)) = x. f(f(x,f(y,f(f(z,u),x))),f(u,x)) = x. f(f(x,f(f(f(y,z),x),u)),f(x,z)) = x. f(f(x,f(f(f(y,z),x),u)),f(z,x)) = x. f(f(x,f(y,f(f(z,u),x))),f(x,z)) = x. f(f(f(f(x,f(y,z)),u),x),f(x,z)) = x. f(f(x,f(y,f(f(z,u),x))),f(z,x)) = x. f(f(f(f(x,f(y,z)),u),x),f(z,x)) = x. f(f(x,f(f(f(y,z),x),u)),f(x,y)) = x. f(f(x,f(f(f(y,z),x),u)),f(y,x)) = x. f(f(f(f(x,f(y,z)),u),x),f(x,y)) = x. f(f(f(f(x,f(y,z)),u),x),f(y,x)) = x. f(f(f(y,f(x,f(z,u))),x),f(x,u)) = x. f(f(f(y,f(x,f(z,u))),x),f(u,x)) = x. f(f(f(y,f(x,f(z,u))),x),f(x,z)) = x. f(f(f(y,f(x,f(z,u))),x),f(z,x)) = x. f(f(f(y,f(f(z,u),x)),x),f(x,u)) = x. f(f(f(y,f(f(z,u),x)),x),f(u,x)) = x. f(f(f(f(f(y,z),x),u),x),f(x,z)) = x. f(f(f(f(f(y,z),x),u),x),f(z,x)) = x. f(f(f(y,f(f(z,u),x)),x),f(x,z)) = x. f(f(f(y,f(f(z,u),x)),x),f(z,x)) = x. f(f(f(f(f(y,z),x),u),x),f(x,y)) = x. f(f(f(f(f(y,z),x),u),x),f(y,x)) = x. f(f(f(f(x,y),f(x,z)),u),f(x,x)) = x. f(f(f(f(x,y),f(z,x)),u),f(x,x)) = x. f(f(f(f(y,x),f(x,z)),u),f(x,x)) = x. f(f(y,f(f(x,z),f(x,u))),f(x,x)) = x. f(f(f(f(y,x),f(z,x)),u),f(x,x)) = x. f(f(y,f(f(x,z),f(u,x))),f(x,x)) = x. f(f(y,f(f(z,x),f(x,u))),f(x,x)) = x. f(f(y,f(f(z,x),f(u,x))),f(x,x)) = x. LADR-2009-11A/apps.examples/OL.in0000644000175000017500000000100207710323011015423 0ustar mccunemccuneop(400, infix, ^). op(400, infix, v). set(print_models_portable). assign(max_models, -1). % This means there is no limit. clauses(theory). x v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. x ^ y = y ^ x. (x ^ y) ^ z = x ^ (y ^ z). x ^ (x v y) = x. % Add the following pair for complemented lattice x v c(x) = 1. x ^ c(x) = 0. % Add the following for ortholattice c(x ^ y) = c(x) v c(y). c(x v y) = c(x) ^ c(y). c(c(x)) = x. % definition of Sheffer Stroke f(x,y) = c(x) v c(y). end_of_list. LADR-2009-11A/apps.examples/lattice-sax.id-check0000644000175000017500000000130407671653640020421 0ustar mccunemccune(((x ^ y) v (y ^ (x v y))) ^ z) v (((x ^ (((x1 ^ y) v (y ^ x2)) v y)) v (((y ^ (((x1 v (y v x2)) ^ (x3 v y)) ^ y)) v (u ^ (y v (((x1 v (y v x2)) ^ (x3 v y)) ^ y)))) ^ (x v (((x1 ^ y) v (y ^ x2)) v y)))) ^ (((x ^ y) v (y ^ (x v y))) v z)) = y. (((x ^ y) v (y ^ (x v y))) ^ z) v (((x ^ (((x1 ^ y) v (y ^ x2)) v y)) v (((y ^ (((x1 v (y v x2)) ^ (x3 v y)) ^ y)) v (u ^ (y v (((y v xnew) ^ (x3 v y)) ^ y)))) ^ (x v (((x1 ^ y) v (y ^ x2)) v y)))) ^ (((x ^ y) v (y ^ (x v y))) v z)) = y. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (((w v x) ^ (v6 v x)) v v7) = x. % olfilter: checked 4, passed 4, user 0.00, system 0.01. LADR-2009-11A/apps.examples/non-MOL-OML0000644000175000017500000003220610131325257016367 0ustar mccunemccune% These are all of the nonmodular OMLs up through size 16. interpretation(10, [ function(c(_), [1,0,5,6,7,2,3,4,9,8]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,3,1,1,3,1,1,1,1,1,1,4,1,1,1,4,4,1,1,1,4,5,1,1,1,4,5,1,8,8,4,6,1,1,1,1,1,6,1,1,1,7,1,2,1,1,8,1,7,8,2,8,1,1,1,1,8,1,8,8,1,9,1,2,1,4,4,1,2,1,9]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,0,2,2,0,9,0,0,7,7,9,0,3,0,3,0,0,0,0,0,0,0,4,9,0,4,5,0,0,5,9,0,5,0,0,5,5,0,0,5,0,0,6,0,0,0,0,6,0,0,0,0,7,7,0,0,0,0,7,7,0,0,8,7,0,5,5,0,7,8,0,0,9,9,0,9,0,0,0,0,9]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,1,5,5,1,8,1,1,4,4,8,1,6,1,6,1,1,1,1,1,1,1,7,8,1,7,2,1,1,2,8,1,2,1,1,2,2,1,1,2,1,1,3,1,1,1,1,3,1,1,1,1,4,4,1,1,1,1,4,4,1,1,9,4,1,2,2,1,4,9,1,1,8,8,1,8,1,1,1,1,8])]). % isofilter: input=2, kept=1, checks=1, perms=5, 0.02 seconds. interpretation(12, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,1,3,1,1,3,1,1,1,1,1,1,1,1,4,1,1,1,4,4,1,1,1,4,1,1,5,1,1,1,4,5,1,8,8,4,1,1,6,1,1,1,1,1,6,1,1,1,1,1,7,1,2,1,1,8,1,7,8,2,1,1,8,1,1,1,1,8,1,8,8,1,1,1,9,1,2,1,4,4,1,2,1,9,1,1,10,1,1,1,1,1,1,1,1,1,10,1,11,1,1,1,1,1,1,1,1,1,1,11]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,0,2,2,0,9,0,0,7,7,9,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0,4,9,0,4,5,0,0,5,9,0,0,0,5,0,0,5,5,0,0,5,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,7,7,0,0,0,0,7,7,0,0,0,0,8,7,0,5,5,0,7,8,0,0,0,0,9,9,0,9,0,0,0,0,9,0,0,0,10,0,0,0,0,0,0,0,0,10,0,0,11,0,0,0,0,0,0,0,0,0,11]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,1,5,5,1,8,1,1,4,4,8,1,1,1,6,1,6,1,1,1,1,1,1,1,1,1,7,8,1,7,2,1,1,2,8,1,1,1,2,1,1,2,2,1,1,2,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,4,4,1,1,1,1,4,4,1,1,1,1,9,4,1,2,2,1,4,9,1,1,1,1,8,8,1,8,1,1,1,1,8,1,1,1,11,1,1,1,1,1,1,1,1,11,1,1,10,1,1,1,1,1,1,1,1,1,10])]). % isofilter: input=2, kept=1, checks=1, perms=49, 0.03 seconds. interpretation(14, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,2,1,2,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,1,1,1,1,4,1,1,1,4,5,1,1,1,1,5,1,8,8,10,10,8,1,8,6,1,1,1,1,1,6,1,1,1,1,1,1,1,7,1,1,1,1,8,1,7,8,12,1,8,12,8,8,1,1,1,1,8,1,8,8,1,1,8,1,8,9,1,2,1,4,10,1,12,1,9,10,2,12,4,10,1,1,1,1,10,1,1,1,10,10,1,1,1,11,1,2,1,1,8,1,8,8,2,1,11,1,8,12,1,1,1,1,1,1,12,1,12,1,1,12,1,13,1,1,1,4,8,1,8,8,4,1,8,1,13]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,0,2,2,0,9,0,0,0,11,9,9,11,9,0,0,3,0,3,0,0,0,0,0,0,0,0,0,0,0,4,9,0,4,0,0,0,13,9,9,0,9,13,0,5,0,0,0,5,0,0,5,0,5,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,7,0,0,0,0,0,7,7,0,0,0,7,0,0,8,11,0,13,5,0,7,8,0,5,11,7,13,0,9,9,0,9,0,0,0,0,9,9,0,9,0,0,10,9,0,9,5,0,0,5,9,10,0,9,0,0,11,11,0,0,0,0,0,11,0,0,11,0,0,0,12,9,0,9,0,0,7,7,9,9,0,12,0,0,13,0,0,13,0,0,0,13,0,0,0,0,13]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,1,5,5,1,8,1,1,1,10,8,8,10,8,1,1,6,1,6,1,1,1,1,1,1,1,1,1,1,1,7,8,1,7,1,1,1,12,8,8,1,8,12,1,2,1,1,1,2,1,1,2,1,2,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,1,4,1,1,1,1,1,4,4,1,1,1,4,1,1,9,10,1,12,2,1,4,9,1,2,10,4,12,1,8,8,1,8,1,1,1,1,8,8,1,8,1,1,11,8,1,8,2,1,1,2,8,11,1,8,1,1,10,10,1,1,1,1,1,10,1,1,10,1,1,1,13,8,1,8,1,1,4,4,8,8,1,13,1,1,12,1,1,12,1,1,1,12,1,1,1,1,12])]). interpretation(14, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,4,1,1,1,4,1,1,1,1,5,1,1,1,4,5,1,8,8,4,1,1,1,1,6,1,1,1,1,1,6,1,1,1,1,1,1,1,7,1,2,1,1,8,1,7,8,2,1,1,1,1,8,1,1,1,1,8,1,8,8,1,1,1,1,1,9,1,2,1,4,4,1,2,1,9,1,1,1,1,10,1,1,1,1,1,1,1,1,1,10,1,1,1,11,1,1,1,1,1,1,1,1,1,1,11,1,1,12,1,1,1,1,1,1,1,1,1,1,1,12,1,13,1,1,1,1,1,1,1,1,1,1,1,1,13]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,0,2,2,0,9,0,0,7,7,9,0,0,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0,0,0,4,9,0,4,5,0,0,5,9,0,0,0,0,0,5,0,0,5,5,0,0,5,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,7,7,0,0,0,0,7,7,0,0,0,0,0,0,8,7,0,5,5,0,7,8,0,0,0,0,0,0,9,9,0,9,0,0,0,0,9,0,0,0,0,0,10,0,0,0,0,0,0,0,0,10,0,0,0,0,11,0,0,0,0,0,0,0,0,0,11,0,0,0,12,0,0,0,0,0,0,0,0,0,0,12,0,0,13,0,0,0,0,0,0,0,0,0,0,0,13]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,1,5,5,1,8,1,1,4,4,8,1,1,1,1,1,6,1,6,1,1,1,1,1,1,1,1,1,1,1,7,8,1,7,2,1,1,2,8,1,1,1,1,1,2,1,1,2,2,1,1,2,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,1,4,4,1,1,1,1,4,4,1,1,1,1,1,1,9,4,1,2,2,1,4,9,1,1,1,1,1,1,8,8,1,8,1,1,1,1,8,1,1,1,1,1,11,1,1,1,1,1,1,1,1,11,1,1,1,1,10,1,1,1,1,1,1,1,1,1,10,1,1,1,13,1,1,1,1,1,1,1,1,1,1,13,1,1,12,1,1,1,1,1,1,1,1,1,1,1,12])]). interpretation(14, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,3,1,3,4,1,1,1,4,4,1,1,1,4,1,1,1,1,5,1,1,1,4,5,1,8,8,4,1,1,1,1,6,1,1,1,1,1,6,1,1,1,10,12,12,10,7,1,2,1,1,8,1,7,8,2,1,1,1,1,8,1,1,1,1,8,1,8,8,1,1,1,1,1,9,1,2,1,4,4,1,2,1,9,1,1,1,1,10,1,1,1,1,1,10,1,1,1,10,1,1,10,11,1,1,3,1,1,12,1,1,1,1,11,12,3,12,1,1,1,1,1,12,1,1,1,1,12,12,1,13,1,1,3,1,1,10,1,1,1,10,3,1,13]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,0,2,2,0,9,0,0,7,7,9,0,0,0,0,0,3,0,3,0,0,0,0,0,0,13,11,11,13,0,4,9,0,4,5,0,0,5,9,0,0,0,0,0,5,0,0,5,5,0,0,5,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,6,0,6,0,0,7,7,0,0,0,0,7,7,0,0,0,0,0,0,8,7,0,5,5,0,7,8,0,0,0,0,0,0,9,9,0,9,0,0,0,0,9,0,0,0,0,0,10,0,13,0,0,6,0,0,0,10,0,6,13,0,11,0,11,0,0,0,0,0,0,0,11,11,0,0,12,0,11,0,0,6,0,0,0,6,11,12,0,0,13,0,13,0,0,0,0,0,0,13,0,0,13]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,1,5,5,1,8,1,1,4,4,8,1,1,1,1,1,6,1,6,1,1,1,1,1,1,12,10,10,12,1,7,8,1,7,2,1,1,2,8,1,1,1,1,1,2,1,1,2,2,1,1,2,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,3,1,3,1,1,4,4,1,1,1,1,4,4,1,1,1,1,1,1,9,4,1,2,2,1,4,9,1,1,1,1,1,1,8,8,1,8,1,1,1,1,8,1,1,1,1,1,11,1,12,1,1,3,1,1,1,11,1,3,12,1,10,1,10,1,1,1,1,1,1,1,10,10,1,1,13,1,10,1,1,3,1,1,1,3,10,13,1,1,12,1,12,1,1,1,1,1,1,12,1,1,12])]). % isofilter: input=23, kept=3, checks=20, perms=38324, 0.52 seconds. interpretation(16, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,2,1,2,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,1,1,1,1,4,1,1,1,4,1,1,5,1,1,1,1,5,1,8,8,10,10,8,1,8,1,1,6,1,1,1,1,1,6,1,1,1,1,1,1,1,1,1,7,1,1,1,1,8,1,7,8,12,1,8,12,8,1,1,8,1,1,1,1,8,1,8,8,1,1,8,1,8,1,1,9,1,2,1,4,10,1,12,1,9,10,2,12,4,1,1,10,1,1,1,1,10,1,1,1,10,10,1,1,1,1,1,11,1,2,1,1,8,1,8,8,2,1,11,1,8,1,1,12,1,1,1,1,1,1,12,1,12,1,1,12,1,1,1,13,1,1,1,4,8,1,8,8,4,1,8,1,13,1,1,14,1,1,1,1,1,1,1,1,1,1,1,1,1,14,1,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,15]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,2,2,0,9,0,0,0,11,9,9,11,9,0,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,4,9,0,4,0,0,0,13,9,9,0,9,13,0,0,0,5,0,0,0,5,0,0,5,0,5,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,7,7,0,0,0,7,0,0,0,0,8,11,0,13,5,0,7,8,0,5,11,7,13,0,0,0,9,9,0,9,0,0,0,0,9,9,0,9,0,0,0,0,10,9,0,9,5,0,0,5,9,10,0,9,0,0,0,0,11,11,0,0,0,0,0,11,0,0,11,0,0,0,0,0,12,9,0,9,0,0,7,7,9,9,0,12,0,0,0,0,13,0,0,13,0,0,0,13,0,0,0,0,13,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,15]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14,1,5,5,1,8,1,1,1,10,8,8,10,8,1,1,1,1,6,1,6,1,1,1,1,1,1,1,1,1,1,1,1,1,7,8,1,7,1,1,1,12,8,8,1,8,12,1,1,1,2,1,1,1,2,1,1,2,1,2,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,4,4,1,1,1,4,1,1,1,1,9,10,1,12,2,1,4,9,1,2,10,4,12,1,1,1,8,8,1,8,1,1,1,1,8,8,1,8,1,1,1,1,11,8,1,8,2,1,1,2,8,11,1,8,1,1,1,1,10,10,1,1,1,1,1,10,1,1,10,1,1,1,1,1,13,8,1,8,1,1,4,4,8,8,1,13,1,1,1,1,12,1,1,12,1,1,1,12,1,1,1,1,12,1,1,1,15,1,1,1,1,1,1,1,1,1,1,1,1,15,1,1,14,1,1,1,1,1,1,1,1,1,1,1,1,1,14])]). interpretation(16, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,2,1,2,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,3,1,3,4,1,1,1,4,1,1,1,1,4,1,1,1,4,1,1,5,1,1,1,1,5,1,8,8,10,10,8,1,8,1,1,6,1,1,1,1,1,6,12,1,12,1,1,12,14,14,12,7,1,1,1,1,8,12,7,8,12,1,8,12,8,1,12,8,1,1,1,1,8,1,8,8,1,1,8,1,8,1,1,9,1,2,1,4,10,12,12,1,9,10,2,12,4,1,12,10,1,1,1,1,10,1,1,1,10,10,1,1,1,1,1,11,1,2,1,1,8,1,8,8,2,1,11,1,8,1,1,12,1,1,1,1,1,12,12,1,12,1,1,12,1,1,12,13,1,1,3,4,8,14,8,8,4,1,8,1,13,14,3,14,1,1,1,1,1,14,1,1,1,1,1,1,14,14,1,15,1,1,3,1,1,12,12,1,12,1,1,12,3,1,15]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,2,2,0,9,0,0,0,11,9,9,11,9,0,0,0,0,3,0,3,13,0,0,0,13,0,0,0,15,13,13,15,0,4,9,13,4,0,0,0,13,9,9,0,9,13,13,0,0,5,0,0,0,5,0,0,5,0,5,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,6,0,6,0,0,7,0,0,0,0,0,7,7,0,0,0,7,0,0,0,0,8,11,13,13,5,0,7,8,0,5,11,7,13,13,0,0,9,9,0,9,0,0,0,0,9,9,0,9,0,0,0,0,10,9,0,9,5,0,0,5,9,10,0,9,0,0,0,0,11,11,0,0,0,0,0,11,0,0,11,0,0,0,0,0,12,9,15,9,0,6,7,7,9,9,0,12,0,6,15,0,13,0,13,13,0,0,0,13,0,0,0,0,13,13,0,0,14,0,13,13,0,6,0,13,0,0,0,6,13,14,0,0,15,0,15,0,0,0,0,0,0,0,0,15,0,0,15]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14,1,5,5,1,8,1,1,1,10,8,8,10,8,1,1,1,1,6,1,6,12,1,1,1,12,1,1,1,14,12,12,14,1,7,8,12,7,1,1,1,12,8,8,1,8,12,12,1,1,2,1,1,1,2,1,1,2,1,2,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,3,1,3,1,1,4,1,1,1,1,1,4,4,1,1,1,4,1,1,1,1,9,10,12,12,2,1,4,9,1,2,10,4,12,12,1,1,8,8,1,8,1,1,1,1,8,8,1,8,1,1,1,1,11,8,1,8,2,1,1,2,8,11,1,8,1,1,1,1,10,10,1,1,1,1,1,10,1,1,10,1,1,1,1,1,13,8,14,8,1,3,4,4,8,8,1,13,1,3,14,1,12,1,12,12,1,1,1,12,1,1,1,1,12,12,1,1,15,1,12,12,1,3,1,12,1,1,1,3,12,15,1,1,14,1,14,1,1,1,1,1,1,1,1,14,1,1,14])]). interpretation(16, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,1,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,4,1,1,1,4,1,1,1,1,1,1,5,1,1,1,4,5,1,8,8,4,1,1,1,1,1,1,6,1,1,1,1,1,6,1,1,1,1,1,1,1,1,1,7,1,2,1,1,8,1,7,8,2,1,1,1,1,1,1,8,1,1,1,1,8,1,8,8,1,1,1,1,1,1,1,9,1,2,1,4,4,1,2,1,9,1,1,1,1,1,1,10,1,1,1,1,1,1,1,1,1,10,1,1,1,1,1,11,1,1,1,1,1,1,1,1,1,1,11,1,1,1,1,12,1,1,1,1,1,1,1,1,1,1,1,12,1,1,1,13,1,1,1,1,1,1,1,1,1,1,1,1,13,1,1,14,1,1,1,1,1,1,1,1,1,1,1,1,1,14,1,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,15]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,2,2,0,9,0,0,7,7,9,0,0,0,0,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,4,9,0,4,5,0,0,5,9,0,0,0,0,0,0,0,5,0,0,5,5,0,0,5,0,0,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,7,7,0,0,0,0,7,7,0,0,0,0,0,0,0,0,8,7,0,5,5,0,7,8,0,0,0,0,0,0,0,0,9,9,0,9,0,0,0,0,9,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,13,0,0,0,0,0,0,0,0,0,0,0,13,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,15]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14,1,5,5,1,8,1,1,4,4,8,1,1,1,1,1,1,1,6,1,6,1,1,1,1,1,1,1,1,1,1,1,1,1,7,8,1,7,2,1,1,2,8,1,1,1,1,1,1,1,2,1,1,2,2,1,1,2,1,1,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,4,1,1,1,1,4,4,1,1,1,1,1,1,1,1,9,4,1,2,2,1,4,9,1,1,1,1,1,1,1,1,8,8,1,8,1,1,1,1,8,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,10,1,1,1,1,1,1,1,1,1,10,1,1,1,1,1,13,1,1,1,1,1,1,1,1,1,1,13,1,1,1,1,12,1,1,1,1,1,1,1,1,1,1,1,12,1,1,1,15,1,1,1,1,1,1,1,1,1,1,1,1,15,1,1,14,1,1,1,1,1,1,1,1,1,1,1,1,1,14])]). interpretation(16, [ function(c(_), [1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14]), function(v(_,_), [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,1,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,4,1,1,1,4,1,1,1,1,1,1,5,1,1,1,4,5,1,8,8,4,1,1,1,1,1,1,6,1,1,1,1,1,6,1,1,1,1,1,1,1,1,1,7,1,2,1,1,8,1,7,8,2,1,1,1,1,1,1,8,1,1,1,1,8,1,8,8,1,1,1,1,1,1,1,9,1,2,1,4,4,1,2,1,9,1,1,1,1,1,1,10,1,1,1,1,1,1,1,1,1,10,1,1,10,1,10,11,1,1,1,1,1,1,1,1,1,1,11,12,14,14,12,12,1,1,1,1,1,1,1,1,1,1,12,12,1,1,12,13,1,1,1,1,1,1,1,1,1,10,14,1,13,14,10,14,1,1,1,1,1,1,1,1,1,1,14,1,14,14,1,15,1,1,1,1,1,1,1,1,1,10,12,12,10,1,15]), function(^(_,_), [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,2,2,0,9,0,0,7,7,9,0,0,0,0,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,4,9,0,4,5,0,0,5,9,0,0,0,0,0,0,0,5,0,0,5,5,0,0,5,0,0,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,7,7,0,0,0,0,7,7,0,0,0,0,0,0,0,0,8,7,0,5,5,0,7,8,0,0,0,0,0,0,0,0,9,9,0,9,0,0,0,0,9,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,10,0,15,13,13,15,0,11,0,0,0,0,0,0,0,0,0,11,11,0,11,0,0,12,0,0,0,0,0,0,0,0,15,11,12,0,11,15,0,13,0,0,0,0,0,0,0,0,13,0,0,13,13,0,0,14,0,0,0,0,0,0,0,0,13,11,11,13,14,0,0,15,0,0,0,0,0,0,0,0,15,0,15,0,0,15]), function(f(_,_), [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,5,6,7,2,3,4,9,8,11,10,13,12,15,14,1,5,5,1,8,1,1,4,4,8,1,1,1,1,1,1,1,6,1,6,1,1,1,1,1,1,1,1,1,1,1,1,1,7,8,1,7,2,1,1,2,8,1,1,1,1,1,1,1,2,1,1,2,2,1,1,2,1,1,1,1,1,1,1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,4,1,1,1,1,4,4,1,1,1,1,1,1,1,1,9,4,1,2,2,1,4,9,1,1,1,1,1,1,1,1,8,8,1,8,1,1,1,1,8,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,11,1,14,12,12,14,1,10,1,1,1,1,1,1,1,1,1,10,10,1,10,1,1,13,1,1,1,1,1,1,1,1,14,10,13,1,10,14,1,12,1,1,1,1,1,1,1,1,12,1,1,12,12,1,1,15,1,1,1,1,1,1,1,1,12,10,10,12,15,1,1,14,1,1,1,1,1,1,1,1,14,1,14,1,1,14])]). % isofilter: input=61, kept=4, checks=57, perms=993828, 3.45 seconds. LADR-2009-11A/apps.examples/backup.Mar10/0000755000175000017500000000000010214152012016706 5ustar mccunemccuneLADR-2009-11A/apps.examples/backup.Mar10/meet-join-equations.out0000644000175000017500000000031210214151516023340 0ustar mccunemccunex v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. % latfilter: checked 6, passed 4, user 0.00, system 0.00. LADR-2009-11A/apps.examples/backup.Mar10/qg.out30000644000175000017500000000315010214151511020133 0ustar mccunemccuneinterpretation( 3, [ function(*(_,_), [0,1,2, 1,2,0, 2,0,1]), function(/(_,_), [0,2,1, 1,0,2, 2,1,0]), function(\(_,_), [0,1,2, 2,0,1, 1,2,0]) ]). interpretation( 3, [ function(*(_,_), [0,1,2, 2,0,1, 1,2,0]), function(/(_,_), [0,1,2, 2,0,1, 1,2,0]), function(\(_,_), [0,1,2, 1,2,0, 2,0,1]) ]). interpretation( 3, [ function(*(_,_), [0,2,1, 1,0,2, 2,1,0]), function(/(_,_), [0,1,2, 1,2,0, 2,0,1]), function(\(_,_), [0,2,1, 1,0,2, 2,1,0]) ]). interpretation( 3, [ function(*(_,_), [0,2,1, 2,1,0, 1,0,2]), function(/(_,_), [0,2,1, 2,1,0, 1,0,2]), function(\(_,_), [0,2,1, 2,1,0, 1,0,2]) ]). interpretation( 3, [ function(*(_,_), [1,0,2, 0,2,1, 2,1,0]), function(/(_,_), [1,0,2, 0,2,1, 2,1,0]), function(\(_,_), [1,0,2, 0,2,1, 2,1,0]) ]). interpretation( 3, [ function(*(_,_), [1,2,0, 0,1,2, 2,0,1]), function(/(_,_), [1,2,0, 0,1,2, 2,0,1]), function(\(_,_), [2,0,1, 0,1,2, 1,2,0]) ]). interpretation( 3, [ function(*(_,_), [1,0,2, 2,1,0, 0,2,1]), function(/(_,_), [2,0,1, 0,1,2, 1,2,0]), function(\(_,_), [1,0,2, 2,1,0, 0,2,1]) ]). interpretation( 3, [ function(*(_,_), [1,2,0, 2,0,1, 0,1,2]), function(/(_,_), [2,1,0, 0,2,1, 1,0,2]), function(\(_,_), [2,0,1, 1,2,0, 0,1,2]) ]). LADR-2009-11A/apps.examples/backup.Mar10/OL.8.upper-covers0000644000175000017500000000121010214151516021744 0ustar mccunemccune% UPPER-COVERS of Lattice 1 ( (0 (2 3 4 5 6 7)) (1 ()) (2 (1)) (3 (1)) (4 (1)) (5 (1)) (6 (1)) (7 (1)) ) % end of upper-covers % UPPER-COVERS of Lattice 2 ( (0 (2 3 5 7)) (1 ()) (2 (1)) (3 (1)) (4 (1)) (5 (6)) (6 (1)) (7 (4)) ) % end of upper-covers % UPPER-COVERS of Lattice 3 ( (0 (3 4 7)) (1 ()) (2 (1)) (3 (6)) (4 (6)) (5 (1)) (6 (1)) (7 (2 5)) ) % end of upper-covers % UPPER-COVERS of Lattice 4 ( (0 (5 7)) (1 ()) (2 (6)) (3 (4)) (4 (1)) (5 (2)) (6 (1)) (7 (3)) ) % end of upper-covers % UPPER-COVERS of Lattice 5 ( (0 (2 4 7)) (1 ()) (2 (5 6)) (3 (1)) (4 (3 6)) (5 (1)) (6 (1)) (7 (3 5)) ) % end of upper-covers % upper-covers: translated=5 LADR-2009-11A/apps.examples/backup.Mar10/qg.iso30000644000175000017500000000231610214151511020121 0ustar mccunemccune interpretation(3, [ function(*(_,_), [ 0,1,2, 1,2,0, 2,0,1]), function(/(_,_), [ 0,2,1, 1,0,2, 2,1,0]), function(\(_,_), [ 0,1,2, 2,0,1, 1,2,0])]). interpretation(3, [ function(*(_,_), [ 0,1,2, 2,0,1, 1,2,0]), function(/(_,_), [ 0,1,2, 2,0,1, 1,2,0]), function(\(_,_), [ 0,1,2, 1,2,0, 2,0,1])]). interpretation(3, [ function(*(_,_), [ 0,2,1, 1,0,2, 2,1,0]), function(/(_,_), [ 0,1,2, 1,2,0, 2,0,1]), function(\(_,_), [ 0,2,1, 1,0,2, 2,1,0])]). interpretation(3, [ function(*(_,_), [ 0,2,1, 2,1,0, 1,0,2]), function(/(_,_), [ 0,2,1, 2,1,0, 1,0,2]), function(\(_,_), [ 0,2,1, 2,1,0, 1,0,2])]). interpretation(3, [ function(*(_,_), [ 1,0,2, 0,2,1, 2,1,0]), function(/(_,_), [ 1,0,2, 0,2,1, 2,1,0]), function(\(_,_), [ 1,0,2, 0,2,1, 2,1,0])]). % isofilter: input=8, kept=5, checks=16, perms=88, 0.01 seconds. LADR-2009-11A/apps.examples/backup.Mar10/lattice-sax.rewritten0000644000175000017500000000034510214151516023103 0ustar mccunemccuney = y. y = y. (x v (v ^ ((x ^ z) v (x ^ u)))) ^ (w v ((x v v6) ^ (x v v7))) = x. (x v (v ^ ((x ^ z) v (x ^ u)))) ^ (v7 v ((x v w) ^ (x v v6))) = x. % rewriter lattice.rules: rewrote 4 terms with 42 rewrite steps in 0.00 seconds. LADR-2009-11A/apps.examples/backup.Mar10/MOL-cand.2380000644000175000017500000003025010214151515020505 0ustar mccunemccunef(f(f(f(f(x,y),z),z),y),f(f(f(x,y),f(z,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,x),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(z,y),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(x,y),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(x,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(x,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(z,y),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(f(x,y),f(y,x)),x),f(y,f(f(f(y,x),z),z))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(y,x),z),z))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(x,y),z),z))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(x,y),z),z))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(y,x)),x),f(y,f(f(z,f(y,x)),z))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(z,f(x,y)),z))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(x,f(y,z)),x))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(z,f(y,x)),z))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(x,f(y,z)),x))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(f(y,z),x)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(f(z,y),x)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(f(y,z),x)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(f(z,y),x)))) = y. f(f(f(f(x,y),f(y,y)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(x,f(y,z))))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(x,f(y,z))))) = y. f(f(f(f(x,y),f(y,y)),x),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(z,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),y),f(f(f(x,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(z,y),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(x,y),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),y),f(f(f(z,y),f(x,y)),z)) = y. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,x),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(z,y),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(x,y),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(f(x,y),z),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(y,x),z),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(x,y),z),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(y,x),z),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(z,f(x,y)),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(z,f(x,y)),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,x),x),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(f(x,z),x),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(x,f(z,x)),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(z,x),x)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(x,z),x)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(x,f(z,x))),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(x,f(x,z))),z)) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(x,z),x),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(x,f(z,x)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(x,f(x,z)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(z,x),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(x,z),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(z,x),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(x,z),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(x,f(z,x))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(x,f(x,z))))) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(u,y),f(x,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(y,u),f(x,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(x,y),f(u,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(u,y),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,u),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,x),f(y,u)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(x,y),f(y,u)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(y,x),u),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(x,y),u),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(y,x),u),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(x,y),u),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(u,f(y,x)),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(u,f(x,y)),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(u,f(y,x)),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(u,f(x,y)),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(f(y,x),u)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(f(x,y),u)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(f(y,x),u)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(f(x,y),u)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(x,f(x,f(y,z))),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(x,f(x,f(y,z))),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(x,f(x,f(y,z))),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(u,f(y,x))))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(u,f(y,x))))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,u),u),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,u),z),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,f(u,z)),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,f(z,u)),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(u,z),u)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(z,u),u)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(u,f(u,z))),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(u,f(z,u))),z)) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(u,z),u),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(z,u),u),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(u,f(u,z)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(u,f(z,u)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(u,z),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(z,u),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(u,z),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(z,u),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(u,f(u,z))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(u,f(z,u))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(u,f(u,z))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(u,f(z,u))))) = y. % clausefilter non-MOL-OML false_in_all: checked 296, passed 238, 4.42 seconds. LADR-2009-11A/apps.examples/backup.Mar10/OL.60000644000175000017500000000207510214151516017323 0ustar mccunemccune interpretation(6, [ function(^(_,_), [ 0,0,0,0,0,0, 0,1,2,3,4,5, 0,2,2,0,0,0, 0,3,0,3,0,0, 0,4,0,0,4,0, 0,5,0,0,0,5]), function(v(_,_), [ 0,1,2,3,4,5, 1,1,1,1,1,1, 2,1,2,1,1,1, 3,1,1,3,1,1, 4,1,1,1,4,1, 5,1,1,1,1,5]), function(c(_), [1,0,3,2,5,4]), function(f(_,_), [ 1,1,1,1,1,1, 1,0,3,2,5,4, 1,3,3,1,1,1, 1,2,1,2,1,1, 1,5,1,1,5,1, 1,4,1,1,1,4])]). interpretation(6, [ function(^(_,_), [ 0,0,0,0,0,0, 0,1,2,3,4,5, 0,2,2,0,0,5, 0,3,0,3,3,0, 0,4,0,3,4,0, 0,5,5,0,0,5]), function(v(_,_), [ 0,1,2,3,4,5, 1,1,1,1,1,1, 2,1,2,1,1,2, 3,1,1,3,4,1, 4,1,1,4,4,1, 5,1,2,1,1,5]), function(c(_), [1,0,3,2,5,4]), function(f(_,_), [ 1,1,1,1,1,1, 1,0,3,2,5,4, 1,3,3,1,1,4, 1,2,1,2,2,1, 1,5,1,2,5,1, 1,4,4,1,1,4])]). % isofilter: input=5, kept=2, checks=3, perms=3, 0.01 seconds. LADR-2009-11A/apps.examples/backup.Mar10/BA-sheffer.out0000644000175000017500000003405210214151516021355 0ustar mccunemccunef(f(x,x),f(x,y)) = x. % 1 2 f(f(x,x),f(y,x)) = x. % 1 2 f(f(x,f(x,x)),f(y,y)) = y. % 1 2 f(f(f(x,x),x),f(y,y)) = y. % 1 2 f(f(x,f(y,z)),f(x,z)) = x. % f(f(x,f(y,z)),f(z,x)) = x. % f(f(x,f(y,z)),f(x,y)) = x. % f(f(x,f(y,z)),f(y,x)) = x. % f(f(f(x,y),z),f(z,y)) = z. % f(f(f(x,y),z),f(y,z)) = z. % f(f(f(x,y),z),f(z,x)) = z. % f(f(f(x,y),z),f(x,z)) = z. % f(f(x,f(y,f(y,y))),f(x,z)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(x,z)) = x. % 1 2 f(f(x,f(y,f(y,y))),f(z,x)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(z,x)) = x. % 1 2 f(f(f(x,f(x,x)),y),f(y,z)) = y. % 1 2 f(f(f(f(x,x),x),y),f(y,z)) = y. % 1 2 f(f(f(x,f(x,x)),y),f(z,y)) = y. % 1 2 f(f(f(f(x,x),x),y),f(z,y)) = y. % 1 2 f(f(x,f(f(x,y),y)),f(x,z)) = x. % f(f(x,f(f(x,y),y)),f(z,x)) = x. % f(f(f(f(x,y),z),z),f(x,x)) = x. % f(f(x,f(y,f(x,y))),f(x,z)) = x. % f(f(x,f(f(y,x),y)),f(x,z)) = x. % f(f(x,f(y,f(x,y))),f(z,x)) = x. % f(f(x,f(f(y,x),y)),f(z,x)) = x. % f(f(x,f(y,f(y,x))),f(x,z)) = x. % f(f(f(f(x,y),y),x),f(x,z)) = x. % f(f(x,f(y,f(y,x))),f(z,x)) = x. % f(f(f(f(x,y),y),x),f(z,x)) = x. % f(f(f(f(x,y),z),z),f(y,y)) = y. % f(f(x,f(f(y,z),x)),f(y,y)) = y. % f(f(f(x,f(y,z)),x),f(y,y)) = y. % f(f(f(x,f(y,x)),y),f(y,z)) = y. % f(f(f(f(x,y),x),y),f(y,z)) = y. % f(f(f(x,f(y,x)),y),f(z,y)) = y. % f(f(f(f(x,y),x),y),f(z,y)) = y. % f(f(x,f(f(y,z),x)),f(z,z)) = z. % f(f(f(x,f(y,z)),x),f(z,z)) = z. % f(f(f(x,f(x,y)),y),f(y,z)) = y. % f(f(f(x,f(x,y)),y),f(z,y)) = y. % f(f(x,f(x,f(y,z))),f(y,y)) = y. % f(f(x,f(x,f(y,z))),f(z,z)) = z. % f(f(x,f(f(x,x),y)),f(x,z)) = x. % 1 2 f(f(x,f(f(x,x),y)),f(z,x)) = x. % 1 2 f(f(f(f(x,x),y),x),f(x,z)) = x. % 1 2 f(f(f(f(x,x),y),x),f(z,x)) = x. % 1 2 f(f(x,f(y,f(x,x))),f(x,z)) = x. % 1 2 f(f(x,f(y,f(x,x))),f(z,x)) = x. % 1 2 f(f(f(x,f(y,y)),y),f(y,z)) = y. % 1 2 f(f(f(x,f(y,y)),y),f(z,y)) = y. % 1 2 f(f(x,f(y,f(y,y))),f(z,f(z,z))) = x. % 1 2 f(f(x,f(f(y,y),y)),f(z,f(z,z))) = x. % 1 2 f(f(x,f(y,f(y,y))),f(f(z,z),z)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(f(z,z),z)) = x. % 1 2 f(f(f(x,f(x,x)),y),f(z,f(z,z))) = y. % 1 2 f(f(f(f(x,x),x),y),f(z,f(z,z))) = y. % 1 2 f(f(f(x,f(x,x)),y),f(f(z,z),z)) = y. % 1 2 f(f(f(f(x,x),x),y),f(f(z,z),z)) = y. % 1 2 f(f(f(f(x,y),y),y),f(x,f(z,y))) = x. % f(f(f(f(x,y),y),y),f(x,f(y,z))) = x. % f(f(f(f(x,y),y),y),f(f(z,y),x)) = x. % f(f(f(f(x,y),y),y),f(f(y,z),x)) = x. % f(f(x,f(f(y,x),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,x)),x),f(y,f(z,x))) = y. % f(f(f(f(x,y),x),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,x),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,x)),x),f(y,f(x,z))) = y. % f(f(f(f(x,y),x),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,x),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,x)),x),f(f(z,x),y)) = y. % f(f(f(f(x,y),x),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,x),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,x)),x),f(f(x,z),y)) = y. % f(f(f(f(x,y),x),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,x))),f(y,f(z,x))) = y. % f(f(x,f(f(x,y),x)),f(y,f(z,x))) = y. % f(f(f(x,f(x,y)),x),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,x))),f(y,f(x,z))) = y. % f(f(x,f(f(x,y),x)),f(y,f(x,z))) = y. % f(f(f(x,f(x,y)),x),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,x))),f(f(z,x),y)) = y. % f(f(x,f(f(x,y),x)),f(f(z,x),y)) = y. % f(f(f(x,f(x,y)),x),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,x))),f(f(x,z),y)) = y. % f(f(x,f(f(x,y),x)),f(f(x,z),y)) = y. % f(f(f(x,f(x,y)),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(x,y))),f(y,f(z,x))) = y. % f(f(x,f(x,f(x,y))),f(y,f(x,z))) = y. % f(f(x,f(x,f(x,y))),f(f(z,x),y)) = y. % f(f(x,f(x,f(x,y))),f(f(x,z),y)) = y. % f(f(x,f(f(x,y),y)),f(z,f(z,z))) = x. % f(f(x,f(f(x,y),y)),f(f(z,z),z)) = x. % f(f(x,f(y,f(x,y))),f(z,f(z,z))) = x. % f(f(x,f(f(y,x),y)),f(z,f(z,z))) = x. % f(f(x,f(y,f(x,y))),f(f(z,z),z)) = x. % f(f(x,f(f(y,x),y)),f(f(z,z),z)) = x. % f(f(x,f(y,f(y,x))),f(z,f(z,z))) = x. % f(f(f(f(x,y),y),x),f(z,f(z,z))) = x. % f(f(x,f(y,f(y,x))),f(f(z,z),z)) = x. % f(f(f(f(x,y),y),x),f(f(z,z),z)) = x. % f(f(f(f(x,y),z),z),f(x,f(y,z))) = x. % f(f(f(f(x,y),z),z),f(x,f(z,y))) = x. % f(f(f(f(x,y),z),z),f(f(y,z),x)) = x. % f(f(f(f(x,y),z),z),f(f(z,y),x)) = x. % f(f(f(x,f(y,x)),y),f(z,f(z,z))) = y. % f(f(f(f(x,y),x),y),f(z,f(z,z))) = y. % f(f(f(x,f(y,x)),y),f(f(z,z),z)) = y. % f(f(f(f(x,y),x),y),f(f(z,z),z)) = y. % f(f(f(f(x,y),z),z),f(y,f(x,z))) = y. % f(f(f(f(x,y),z),z),f(y,f(z,x))) = y. % f(f(f(f(x,y),z),z),f(f(x,z),y)) = y. % f(f(f(f(x,y),z),z),f(f(z,x),y)) = y. % f(f(f(x,f(x,y)),y),f(z,f(z,z))) = y. % f(f(f(x,f(x,y)),y),f(f(z,z),z)) = y. % f(f(x,f(f(y,z),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,z)),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,z),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,z)),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,z),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,z)),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,z),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,z)),x),f(f(x,z),y)) = y. % f(f(x,f(f(y,z),x)),f(z,f(y,x))) = z. % f(f(f(x,f(y,z)),x),f(z,f(y,x))) = z. % f(f(x,f(f(y,z),x)),f(z,f(x,y))) = z. % f(f(f(x,f(y,z)),x),f(z,f(x,y))) = z. % f(f(x,f(f(y,z),x)),f(f(y,x),z)) = z. % f(f(f(x,f(y,z)),x),f(f(y,x),z)) = z. % f(f(x,f(f(y,z),x)),f(f(x,y),z)) = z. % f(f(f(x,f(y,z)),x),f(f(x,y),z)) = z. % f(f(x,f(x,f(y,z))),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,z))),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,z))),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,z))),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,z))),f(z,f(y,x))) = z. % f(f(x,f(x,f(y,z))),f(z,f(x,y))) = z. % f(f(x,f(x,f(y,z))),f(f(y,x),z)) = z. % f(f(x,f(x,f(y,z))),f(f(x,y),z)) = z. % f(f(x,f(f(x,x),y)),f(z,f(z,z))) = x. % 1 2 f(f(x,f(f(x,x),y)),f(f(z,z),z)) = x. % 1 2 f(f(f(f(x,x),y),x),f(z,f(z,z))) = x. % 1 2 f(f(f(f(x,x),y),x),f(f(z,z),z)) = x. % 1 2 f(f(f(f(x,x),y),y),f(x,f(z,y))) = x. % f(f(f(f(x,x),y),y),f(x,f(y,z))) = x. % f(f(f(f(x,x),y),y),f(f(z,y),x)) = x. % f(f(f(f(x,x),y),y),f(f(y,z),x)) = x. % f(f(x,f(y,f(x,x))),f(z,f(z,z))) = x. % 1 2 f(f(x,f(y,f(x,x))),f(f(z,z),z)) = x. % 1 2 f(f(f(x,f(y,y)),y),f(z,f(z,z))) = y. % 1 2 f(f(f(x,f(y,y)),y),f(f(z,z),z)) = y. % 1 2 f(f(x,f(f(y,y),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,y)),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,y),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,y)),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,y),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,y)),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,y),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,y)),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,y))),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,y))),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,y))),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,y))),f(f(x,z),y)) = y. % f(f(x,f(y,f(z,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,z))),f(f(z,u),x)) = x. % f(f(x,f(f(y,y),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,y),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,y),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,y),z)),f(f(y,u),x)) = x. % f(f(f(x,f(y,y)),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,y)),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,y)),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,y)),z),f(f(y,u),z)) = z. % f(f(f(f(x,x),y),z),f(z,f(u,x))) = z. % f(f(f(f(x,x),y),z),f(z,f(x,u))) = z. % f(f(f(f(x,x),y),z),f(f(u,x),z)) = z. % f(f(f(f(x,x),y),z),f(f(x,u),z)) = z. % f(f(x,f(y,f(z,u))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,u))),f(f(u,z),x)) = x. % f(f(x,f(y,f(y,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(y,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(y,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(y,z))),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),u)),f(x,f(z,y))) = x. % f(f(x,f(f(y,z),u)),f(f(z,y),x)) = x. % f(f(x,f(y,f(z,y))),f(x,f(u,z))) = x. % f(f(x,f(f(y,z),y)),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,y))),f(x,f(z,u))) = x. % f(f(x,f(f(y,z),y)),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,y))),f(f(u,z),x)) = x. % f(f(x,f(f(y,z),y)),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,y))),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),y)),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,z),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,z),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,z),z)),f(f(y,u),x)) = x. % f(f(f(x,f(y,z)),u),f(u,f(z,y))) = u. % f(f(f(x,f(y,z)),u),f(f(z,y),u)) = u. % f(f(f(x,f(x,y)),z),f(z,f(u,y))) = z. % f(f(f(x,f(x,y)),z),f(z,f(y,u))) = z. % f(f(f(x,f(x,y)),z),f(f(u,y),z)) = z. % f(f(f(x,f(x,y)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),z),u),f(u,f(y,x))) = u. % f(f(f(f(x,y),z),u),f(f(y,x),u)) = u. % f(f(f(x,f(y,x)),z),f(z,f(u,y))) = z. % f(f(f(f(x,y),x),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,x)),z),f(z,f(y,u))) = z. % f(f(f(f(x,y),x),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,x)),z),f(f(u,y),z)) = z. % f(f(f(f(x,y),x),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,x)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),x),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),y),z),f(z,f(u,x))) = z. % f(f(f(f(x,y),y),z),f(z,f(x,u))) = z. % f(f(f(f(x,y),y),z),f(f(u,x),z)) = z. % f(f(f(f(x,y),y),z),f(f(x,u),z)) = z. % f(f(x,f(f(x,y),z)),f(x,f(u,y))) = x. % f(f(x,f(f(x,y),z)),f(x,f(y,u))) = x. % f(f(x,f(f(x,y),z)),f(f(u,y),x)) = x. % f(f(x,f(f(x,y),z)),f(f(y,u),x)) = x. % f(f(x,f(y,f(x,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(x,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(x,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(x,z))),f(f(z,u),x)) = x. % f(f(x,f(y,f(z,x))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,x))),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,x))),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,x))),f(f(z,u),x)) = x. % f(f(x,f(f(y,x),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,x),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,x),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,x),z)),f(f(y,u),x)) = x. % f(f(f(f(x,y),z),x),f(x,f(u,y))) = x. % f(f(f(f(x,y),z),x),f(x,f(y,u))) = x. % f(f(f(f(x,y),z),x),f(f(u,y),x)) = x. % f(f(f(f(x,y),z),x),f(f(y,u),x)) = x. % f(f(f(x,f(y,z)),y),f(y,f(u,z))) = y. % f(f(f(x,f(y,z)),y),f(y,f(z,u))) = y. % f(f(f(x,f(y,z)),y),f(f(u,z),y)) = y. % f(f(f(x,f(y,z)),y),f(f(z,u),y)) = y. % f(f(f(x,f(y,z)),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,z)),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,z)),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,z)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),z),y),f(y,f(u,x))) = y. % f(f(f(f(x,y),z),y),f(y,f(x,u))) = y. % f(f(f(f(x,y),z),y),f(f(u,x),y)) = y. % f(f(f(f(x,y),z),y),f(f(x,u),y)) = y. % f(f(f(f(x,f(y,y)),y),y),f(z,z)) = z. % 1 2 f(f(x,f(f(y,f(x,x)),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(y,f(x,x))),x),f(z,z)) = z. % 1 2 f(f(x,f(x,f(y,f(x,x)))),f(z,z)) = z. % 1 2 f(f(f(f(f(x,x),y),x),x),f(z,z)) = z. % 1 2 f(f(x,f(f(f(x,x),y),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(f(x,x),y)),x),f(z,z)) = z. % 1 2 f(f(x,f(x,f(f(x,x),y))),f(z,z)) = z. % 1 2 f(f(x,f(x,f(y,f(y,y)))),f(z,z)) = z. % 1 2 f(f(x,f(x,f(f(y,y),y))),f(z,z)) = z. % 1 2 f(f(f(f(x,f(x,y)),y),y),f(z,z)) = z. % 2 f(f(f(f(x,f(y,x)),y),y),f(z,z)) = z. % 2 f(f(f(f(f(x,y),x),y),y),f(z,z)) = z. % 2 f(f(x,f(f(y,f(y,y)),x)),f(z,z)) = z. % 1 2 f(f(x,f(f(f(y,y),y),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(y,f(y,y))),x),f(z,z)) = z. % 1 2 f(f(f(x,f(f(y,y),y)),x),f(z,z)) = z. % 1 2 f(f(x,f(f(y,f(y,x)),x)),f(z,z)) = z. % 2 f(f(f(x,f(y,f(y,x))),x),f(z,z)) = z. % 2 f(f(f(f(f(x,y),y),x),x),f(z,z)) = z. % 2 f(f(x,f(f(y,f(x,y)),x)),f(z,z)) = z. % 2 f(f(x,f(f(f(y,x),y),x)),f(z,z)) = z. % 2 f(f(f(x,f(y,f(x,y))),x),f(z,z)) = z. % 2 f(f(f(x,f(f(y,x),y)),x),f(z,z)) = z. % 2 f(f(x,f(x,f(y,f(y,x)))),f(z,z)) = z. % 2 f(f(x,f(f(f(x,y),y),x)),f(z,z)) = z. % 2 f(f(f(x,f(f(x,y),y)),x),f(z,z)) = z. % 2 f(f(x,f(x,f(y,f(x,y)))),f(z,z)) = z. % 2 f(f(x,f(x,f(f(y,x),y))),f(z,z)) = z. % 2 f(f(x,f(x,f(f(x,y),y))),f(z,z)) = z. % 2 f(f(f(f(x,f(x,x)),y),y),f(z,z)) = z. % 1 2 f(f(f(f(f(x,x),x),y),y),f(z,z)) = z. % 1 2 f(f(x,f(f(f(y,z),u),u)),f(x,z)) = x. % f(f(x,f(f(f(y,z),u),u)),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),y))),f(x,u)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(x,u)) = x. % f(f(x,f(y,f(f(z,u),y))),f(u,x)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(u,x)) = x. % f(f(x,f(f(f(y,z),u),u)),f(x,y)) = x. % f(f(x,f(f(f(y,z),u),u)),f(y,x)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(x,u)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(u,x)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(x,z)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),y))),f(x,z)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(x,z)) = x. % f(f(x,f(y,f(f(z,u),y))),f(z,x)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(z,x)) = x. % f(f(f(f(f(x,y),z),z),u),f(u,y)) = u. % f(f(f(f(f(x,y),z),z),u),f(y,u)) = u. % f(f(f(x,f(f(y,z),x)),u),f(u,z)) = u. % f(f(f(f(x,f(y,z)),x),u),f(u,z)) = u. % f(f(f(x,f(f(y,z),x)),u),f(z,u)) = u. % f(f(f(f(x,f(y,z)),x),u),f(z,u)) = u. % f(f(f(f(f(x,y),z),z),u),f(u,x)) = u. % f(f(f(f(f(x,y),z),z),u),f(x,u)) = u. % f(f(f(x,f(x,f(y,z))),u),f(u,z)) = u. % f(f(f(x,f(x,f(y,z))),u),f(z,u)) = u. % f(f(f(x,f(x,f(y,z))),u),f(u,y)) = u. % f(f(f(x,f(x,f(y,z))),u),f(y,u)) = u. % f(f(f(x,f(f(y,z),x)),u),f(u,y)) = u. % f(f(f(f(x,f(y,z)),x),u),f(u,y)) = u. % f(f(f(x,f(f(y,z),x)),u),f(y,u)) = u. % f(f(f(f(x,f(y,z)),x),u),f(y,u)) = u. % f(f(x,f(f(x,f(y,z)),u)),f(x,z)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(z,x)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(x,y)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(y,x)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(x,u)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(u,x)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(x,z)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),x))),f(x,u)) = x. % f(f(x,f(y,f(f(z,u),x))),f(u,x)) = x. % f(f(x,f(f(f(y,z),x),u)),f(x,z)) = x. % f(f(x,f(f(f(y,z),x),u)),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),x))),f(x,z)) = x. % f(f(f(f(x,f(y,z)),u),x),f(x,z)) = x. % f(f(x,f(y,f(f(z,u),x))),f(z,x)) = x. % f(f(f(f(x,f(y,z)),u),x),f(z,x)) = x. % f(f(x,f(f(f(y,z),x),u)),f(x,y)) = x. % f(f(x,f(f(f(y,z),x),u)),f(y,x)) = x. % f(f(f(f(x,f(y,z)),u),x),f(x,y)) = x. % f(f(f(f(x,f(y,z)),u),x),f(y,x)) = x. % f(f(f(x,f(y,f(z,u))),y),f(y,u)) = y. % f(f(f(x,f(y,f(z,u))),y),f(u,y)) = y. % f(f(f(x,f(y,f(z,u))),y),f(y,z)) = y. % f(f(f(x,f(y,f(z,u))),y),f(z,y)) = y. % f(f(f(x,f(f(y,z),u)),u),f(u,z)) = u. % f(f(f(x,f(f(y,z),u)),u),f(z,u)) = u. % f(f(f(f(f(x,y),z),u),z),f(z,y)) = z. % f(f(f(f(f(x,y),z),u),z),f(y,z)) = z. % f(f(f(x,f(f(y,z),u)),u),f(u,y)) = u. % f(f(f(x,f(f(y,z),u)),u),f(y,u)) = u. % f(f(f(f(f(x,y),z),u),z),f(z,x)) = z. % f(f(f(f(f(x,y),z),u),z),f(x,z)) = z. % f(f(f(f(x,y),f(x,z)),u),f(x,x)) = x. % 1 2 f(f(f(f(x,y),f(z,x)),u),f(x,x)) = x. % 1 2 f(f(f(f(x,y),f(y,z)),u),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(y,u))),f(y,y)) = y. % 1 2 f(f(f(f(x,y),f(z,y)),u),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(u,y))),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(z,u))),f(z,z)) = z. % 1 2 f(f(x,f(f(y,z),f(u,z))),f(z,z)) = z. % 1 2 % interp 1 models 60 clauses. % interp 2 models 76 clauses. LADR-2009-11A/apps.examples/backup.Mar10/OL.8.out0000644000175000017500000000415510214151516020134 0ustar mccunemccuneinterpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,0,0,0,0,3,0,3,0,0,0,0,0,4,0,0,4,0,0,0,0,5,0,0,0,5,0,0,0,6,0,0,0,0,6,0,0,7,0,0,0,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,3,1,1,3,1,1,1,1,4,1,1,1,4,1,1,1,5,1,1,1,1,5,1,1,6,1,1,1,1,1,6,1,7,1,1,1,1,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,1,1,1,1,2,1,2,1,1,1,1,1,5,1,1,5,1,1,1,1,4,1,1,1,4,1,1,1,7,1,1,1,1,7,1,1,6,1,1,1,1,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,0,0,0,0,3,0,3,0,0,0,0,0,4,0,0,4,0,0,7,0,5,0,0,0,5,5,0,0,6,0,0,0,5,6,0,0,7,0,0,7,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,3,1,1,3,1,1,1,1,4,1,1,1,4,1,1,4,5,1,1,1,1,5,6,1,6,1,1,1,1,6,6,1,7,1,1,1,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,1,1,1,1,2,1,2,1,1,1,1,1,5,1,1,5,1,1,6,1,4,1,1,1,4,4,1,1,7,1,1,1,4,7,1,1,6,1,1,6,1,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,7,0,7,0,3,0,3,0,0,3,0,0,4,0,0,4,0,4,0,0,5,7,0,0,5,0,7,0,6,0,3,4,0,6,0,0,7,7,0,0,7,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,3,1,1,3,6,1,6,1,4,1,1,6,4,1,6,1,5,1,1,1,1,5,1,5,6,1,1,6,6,1,6,1,7,1,2,1,1,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,6,1,6,1,2,1,2,1,1,2,1,1,5,1,1,5,1,5,1,1,4,6,1,1,4,1,6,1,7,1,2,5,1,7,1,1,6,6,1,1,6,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,5,2,0,0,3,0,3,3,0,0,7,0,4,0,3,4,0,0,7,0,5,5,0,0,5,5,0,0,6,2,0,0,5,6,0,0,7,0,7,7,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,2,6,1,3,1,1,3,4,1,1,3,4,1,1,4,4,1,1,4,5,1,2,1,1,5,6,1,6,1,6,1,1,6,6,1,7,1,1,3,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,4,3,1,1,2,1,2,2,1,1,6,1,5,1,2,5,1,1,6,1,4,4,1,1,4,4,1,1,7,3,1,1,4,7,1,1,6,1,6,6,1,1,6])]). % interpfilter distributivity some_false: checked 5, passed 4, 0.01 seconds. LADR-2009-11A/apps.examples/backup.Mar10/OL.80000644000175000017500000000724710214151516017333 0ustar mccunemccune interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,0,0,0, 0,3,0,3,0,0,0,0, 0,4,0,0,4,0,0,0, 0,5,0,0,0,5,0,0, 0,6,0,0,0,0,6,0, 0,7,0,0,0,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,1, 3,1,1,3,1,1,1,1, 4,1,1,1,4,1,1,1, 5,1,1,1,1,5,1,1, 6,1,1,1,1,1,6,1, 7,1,1,1,1,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,1,1,1, 1,2,1,2,1,1,1,1, 1,5,1,1,5,1,1,1, 1,4,1,1,1,4,1,1, 1,7,1,1,1,1,7,1, 1,6,1,1,1,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,0,0,0, 0,3,0,3,0,0,0,0, 0,4,0,0,4,0,0,7, 0,5,0,0,0,5,5,0, 0,6,0,0,0,5,6,0, 0,7,0,0,7,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,1, 3,1,1,3,1,1,1,1, 4,1,1,1,4,1,1,4, 5,1,1,1,1,5,6,1, 6,1,1,1,1,6,6,1, 7,1,1,1,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,1,1,1, 1,2,1,2,1,1,1,1, 1,5,1,1,5,1,1,6, 1,4,1,1,1,4,4,1, 1,7,1,1,1,4,7,1, 1,6,1,1,6,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,7,0,7, 0,3,0,3,0,0,3,0, 0,4,0,0,4,0,4,0, 0,5,7,0,0,5,0,7, 0,6,0,3,4,0,6,0, 0,7,7,0,0,7,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,2, 3,1,1,3,6,1,6,1, 4,1,1,6,4,1,6,1, 5,1,1,1,1,5,1,5, 6,1,1,6,6,1,6,1, 7,1,2,1,1,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,6,1,6, 1,2,1,2,1,1,2,1, 1,5,1,1,5,1,5,1, 1,4,6,1,1,4,1,6, 1,7,1,2,5,1,7,1, 1,6,6,1,1,6,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,5,2,0, 0,3,0,3,3,0,0,7, 0,4,0,3,4,0,0,7, 0,5,5,0,0,5,5,0, 0,6,2,0,0,5,6,0, 0,7,0,7,7,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,2,6,1, 3,1,1,3,4,1,1,3, 4,1,1,4,4,1,1,4, 5,1,2,1,1,5,6,1, 6,1,6,1,1,6,6,1, 7,1,1,3,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,4,3,1, 1,2,1,2,2,1,1,6, 1,5,1,2,5,1,1,6, 1,4,4,1,1,4,4,1, 1,7,3,1,1,4,7,1, 1,6,1,6,6,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,2,2,0, 0,3,0,3,4,7,4,7, 0,4,0,4,4,0,4,0, 0,5,2,7,0,5,2,7, 0,6,2,4,4,2,6,0, 0,7,0,7,0,7,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,6,5,6,5, 3,1,1,3,3,1,1,3, 4,1,6,3,4,1,6,3, 5,1,5,1,1,5,1,5, 6,1,6,1,6,1,6,1, 7,1,5,3,3,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,3,3,1, 1,2,1,2,5,6,5,6, 1,5,1,5,5,1,5,1, 1,4,3,6,1,4,3,6, 1,7,3,5,5,3,7,1, 1,6,1,6,1,6,1,6])]). % isofilter: input=61, kept=5, checks=56, perms=80, 0.18 seconds. LADR-2009-11A/apps.examples/backup.Mar10/mjc01s-equations.out0000644000175000017500000000056610214151516022561 0ustar mccunemccunex v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. x ^ c(x) = 0. c(x ^ y) = c(x) v c(y). c(x v y) = c(x) ^ c(y). c(c(x)) = x. f(f(x,x),f(x,y)) = x. f(x,f(x,x)) = f(y,f(y,y)). f(x,f(f(y,z),f(y,z))) = f(z,f(f(y,x),f(y,x))). % olfilter: checked 16, passed 11, user 0.00, system 0.00. LADR-2009-11A/apps.examples/MOL-cand.2960000644000175000017500000003604007667720647016422 0ustar mccunemccunef(f(f(f(f(x,z),y),y),z),f(f(f(x,z),f(y,z)),x)) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,x),f(z,y)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(y,z),f(z,x)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(x,z),f(z,y)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,z),f(z,y)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,z),f(z,x)))) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(f(x,z),f(z,x)),x),f(z,f(f(f(z,x),y),y))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(f(z,y),x),x))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(f(y,z),x),x))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(f(z,x),y),y))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(f(x,z),y),y))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(f(z,y),x),x))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(f(y,z),x),x))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(f(x,z),y),y))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(f(z,y),x),x))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(f(y,z),x),x))) = z. f(f(f(f(x,z),f(z,x)),x),f(z,f(f(y,f(z,x)),y))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(x,f(y,z)),x))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(y,f(x,z)),y))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(x,f(z,y)),x))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(x,f(y,z)),x))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(y,f(z,x)),y))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(x,f(z,y)),x))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(x,f(y,z)),x))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(y,f(f(z,x),y)))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(x,f(f(z,y),x)))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(x,f(f(y,z),x)))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(y,f(f(z,x),y)))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(x,f(f(z,y),x)))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(x,f(f(y,z),x)))) = z. f(f(f(f(x,z),f(z,z)),x),f(z,f(y,f(f(z,x),y)))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(y,f(y,f(z,x))))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(x,f(x,f(z,y))))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(x,f(x,f(z,y))))) = z. f(f(f(f(x,z),f(z,z)),x),f(z,f(y,f(y,f(z,x))))) = z. f(f(f(x,f(f(z,y),x)),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(x,f(f(z,y),x)),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(y,z),f(z,x)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(x,f(x,f(z,y))),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(y,z),f(z,x)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(x,f(f(z,x),f(z,x))),f(z,f(f(f(x,z),y),y))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(f(z,x),y),y))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(f(x,z),y),y))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(f(z,x),y),y))) = z. f(f(x,f(f(z,x),f(z,x))),f(z,f(f(y,f(z,x)),y))) = z. f(f(x,f(f(z,x),f(z,x))),f(z,f(f(y,f(x,z)),y))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(y,f(z,x)),y))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(y,f(z,x)),y))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(y,f(x,z)),y))) = z. f(f(x,f(f(z,x),f(z,x))),f(z,f(y,f(f(z,x),y)))) = z. f(f(x,f(f(z,x),f(z,x))),f(z,f(y,f(f(x,z),y)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(y,f(f(z,x),y)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(y,f(f(x,z),y)))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(y,f(f(z,x),y)))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(y,f(f(x,z),y)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(y,f(y,f(z,x))))) = z. f(f(f(x,f(z,z)),z),f(f(f(f(y,x),x),f(y,z)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(f(x,y),x),f(y,z)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(x,f(y,x)),f(y,z)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(f(y,x),x)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(f(x,y),x)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(x,f(y,x))),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(x,f(x,y))),y)) = z. f(f(f(x,f(z,z)),z),f(y,f(f(f(x,y),x),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(x,f(y,x)),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(x,f(x,y)),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(f(y,x),x)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(f(x,y),x)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(f(y,x),x)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(f(x,y),x)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(x,f(y,x))))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(x,f(x,y))))) = z. f(f(f(x,z),z),f(f(f(z,y),f(x,z)),f(f(x,x),y))) = z. f(f(f(x,z),z),f(f(f(y,z),f(x,z)),f(y,f(x,x)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(z,y),f(z,x)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(x,z),f(z,y)))) = z. f(f(f(x,f(x,z)),x),f(z,f(z,f(f(y,x),f(u,x))))) = z. f(f(f(x,f(x,z)),x),f(z,f(z,f(f(y,x),f(x,u))))) = z. f(f(f(x,f(x,z)),x),f(z,f(z,f(f(x,y),f(u,x))))) = z. f(f(f(x,f(x,z)),x),f(z,f(z,f(f(x,y),f(x,u))))) = z. f(f(x,f(x,f(z,x))),f(z,f(z,f(f(y,x),f(u,x))))) = z. f(f(x,f(x,f(z,x))),f(z,f(z,f(f(y,x),f(x,u))))) = z. f(f(x,f(x,f(z,x))),f(z,f(z,f(f(x,y),f(u,x))))) = z. f(f(x,f(x,f(z,x))),f(z,f(z,f(f(x,y),f(x,u))))) = z. f(f(x,f(x,f(x,z))),f(z,f(z,f(f(y,x),f(u,x))))) = z. f(f(x,f(x,f(x,z))),f(z,f(z,f(f(y,x),f(x,u))))) = z. f(f(x,f(x,f(x,z))),f(z,f(z,f(f(x,y),f(u,x))))) = z. f(f(x,f(x,f(x,z))),f(z,f(z,f(f(x,y),f(x,u))))) = z. f(f(f(f(f(x,z),y),y),z),f(f(f(u,z),f(x,z)),x)) = z. f(f(f(f(f(x,z),y),y),z),f(f(f(z,u),f(x,z)),x)) = z. f(f(f(f(f(x,z),y),y),z),f(f(f(x,z),f(u,z)),x)) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(u,z),f(z,x)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,u),f(z,x)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,x),f(z,u)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(x,z),f(z,u)))) = z. f(f(f(f(f(x,z),y),y),z),f(x,f(f(z,z),f(z,u)))) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(f(x,f(z,y)),x),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(f(z,y),u),u))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(f(y,z),u),u))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(f(z,x),u),u))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(f(x,z),u),u))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(f(z,y),u),u))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(f(y,z),u),u))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(f(z,x),u),u))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(f(x,z),u),u))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(f(z,y),u),u))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(f(y,z),u),u))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(u,f(z,y)),u))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(f(u,f(y,z)),u))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(u,f(z,x)),u))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(f(u,f(x,z)),u))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(u,f(z,y)),u))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(f(u,f(y,z)),u))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(u,f(z,x)),u))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(f(u,f(x,z)),u))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(u,f(z,y)),u))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(f(u,f(y,z)),u))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(u,f(f(z,y),u)))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(u,f(f(y,z),u)))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(u,f(f(z,x),u)))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(u,f(f(x,z),u)))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(u,f(f(z,y),u)))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(u,f(f(y,z),u)))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(u,f(f(z,x),u)))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(u,f(f(x,z),u)))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(u,f(f(z,y),u)))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(u,f(f(y,z),u)))) = z. f(f(f(f(x,z),f(z,y)),y),f(z,f(u,f(u,f(z,y))))) = z. f(f(f(f(x,z),f(z,y)),x),f(z,f(u,f(u,f(z,x))))) = z. f(f(f(f(x,z),f(y,z)),y),f(z,f(u,f(u,f(z,y))))) = z. f(f(f(f(x,z),f(y,z)),x),f(z,f(u,f(u,f(z,x))))) = z. f(f(f(f(x,z),f(z,z)),y),f(z,f(u,f(u,f(z,y))))) = z. f(f(f(x,f(f(z,y),x)),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(f(z,y),x)),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(f(z,y),x)),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(f(z,y),x)),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(x,f(x,f(z,y))),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(z,y))),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(x,f(z,y))),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(x,f(z,y))),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(f(z,x),u),u))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(f(x,z),u),u))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(f(z,x),u),u))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(f(x,z),u),u))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(f(f(z,x),u),u))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(f(f(x,z),u),u))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(u,f(z,x)),u))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(f(u,f(x,z)),u))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(u,f(z,x)),u))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(f(u,f(x,z)),u))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(f(u,f(z,x)),u))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(f(u,f(x,z)),u))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(u,f(f(z,x),u)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(u,f(f(x,z),u)))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(u,f(f(z,x),u)))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(u,f(f(x,z),u)))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(u,f(f(z,x),u)))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(u,f(f(x,z),u)))) = z. f(f(x,f(f(z,y),f(z,x))),f(z,f(u,f(u,f(z,x))))) = z. f(f(x,f(f(z,x),f(z,y))),f(z,f(u,f(u,f(z,x))))) = z. f(f(x,f(f(z,x),f(y,z))),f(z,f(u,f(u,f(z,x))))) = z. f(f(f(x,f(z,z)),z),f(f(f(f(y,u),u),f(y,z)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(f(y,u),y),f(u,z)),u)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,f(u,y)),f(u,z)),u)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,f(y,u)),f(u,z)),u)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(f(u,y),u)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(f(y,u),u)),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(u,f(u,y))),y)) = z. f(f(f(x,f(z,z)),z),f(f(f(y,z),f(u,f(y,u))),y)) = z. f(f(f(x,f(z,z)),z),f(y,f(f(f(u,y),u),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(f(y,u),u),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(u,f(u,y)),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(u,f(y,u)),f(z,y)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(f(u,y),u)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(f(y,u),u)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(f(u,y),u)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(f(y,u),u)))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(u,f(u,y))))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(z,y),f(u,f(y,u))))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(u,f(u,y))))) = z. f(f(f(x,f(z,z)),z),f(y,f(f(y,z),f(u,f(y,u))))) = z. f(f(f(x,z),z),f(f(f(f(f(x,x),y),z),f(u,z)),x)) = z. f(f(f(x,z),z),f(f(f(f(y,f(x,x)),z),f(u,z)),x)) = z. f(f(f(x,z),z),f(f(f(z,y),f(f(f(x,x),u),z)),x)) = z. f(f(f(x,z),z),f(f(f(y,z),f(f(f(x,x),u),z)),x)) = z. f(f(f(x,z),z),f(f(f(z,y),f(f(u,f(x,x)),z)),x)) = z. f(f(f(x,z),z),f(f(f(y,z),f(f(u,f(x,x)),z)),x)) = z. f(f(f(x,z),z),f(f(f(z,y),f(x,z)),f(f(x,x),u))) = z. f(f(f(x,z),z),f(f(f(y,z),f(x,z)),f(f(x,x),u))) = z. f(f(f(x,z),z),f(f(f(x,z),f(y,z)),f(f(x,x),u))) = z. f(f(f(x,z),z),f(f(f(z,y),f(x,z)),f(f(z,z),u))) = z. f(f(f(x,z),z),f(f(f(y,z),f(x,z)),f(f(z,z),u))) = z. f(f(f(x,z),z),f(f(f(x,z),f(y,z)),f(f(z,z),u))) = z. f(f(f(x,z),z),f(f(f(z,y),f(x,z)),f(u,f(x,x)))) = z. f(f(f(x,z),z),f(f(f(y,z),f(x,z)),f(u,f(x,x)))) = z. f(f(f(x,z),z),f(f(f(x,z),f(y,z)),f(u,f(x,x)))) = z. f(f(f(x,z),z),f(f(f(x,x),y),f(f(u,z),f(z,x)))) = z. f(f(f(x,z),z),f(f(f(x,x),y),f(f(z,u),f(z,x)))) = z. f(f(f(x,z),z),f(f(f(x,x),y),f(f(z,x),f(z,u)))) = z. f(f(f(x,z),z),f(f(f(x,x),y),f(f(x,z),f(z,u)))) = z. f(f(f(x,z),z),f(f(f(z,z),y),f(f(u,z),f(z,x)))) = z. f(f(f(x,z),z),f(f(f(z,z),y),f(f(x,z),f(z,u)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(u,z),f(z,x)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(z,u),f(z,x)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(z,x),f(z,u)))) = z. f(f(f(x,z),z),f(f(y,f(x,x)),f(f(x,z),f(z,u)))) = z. f(f(f(x,z),z),f(x,f(f(f(f(x,x),y),z),f(z,u)))) = z. f(f(f(x,z),z),f(x,f(f(f(y,f(x,x)),z),f(z,u)))) = z. f(f(f(x,z),z),f(x,f(f(z,f(f(x,x),y)),f(z,u)))) = z. f(f(f(x,z),z),f(x,f(f(z,f(y,f(x,x))),f(z,u)))) = z. f(f(f(x,z),z),f(x,f(f(z,y),f(z,f(f(x,x),u))))) = z. f(f(f(x,z),z),f(x,f(f(y,z),f(z,f(f(x,x),u))))) = z. f(f(f(x,z),z),f(x,f(f(z,y),f(z,f(u,f(x,x)))))) = z. f(f(f(x,z),z),f(x,f(f(y,z),f(z,f(u,f(x,x)))))) = z. f(f(x,z),f(f(f(f(z,x),z),f(y,z)),f(f(z,z),u))) = z. f(f(x,z),f(f(f(f(x,z),z),f(y,z)),f(f(z,z),u))) = z. f(f(x,z),f(f(f(z,f(z,x)),f(y,z)),f(f(z,z),u))) = z. f(f(x,z),f(f(f(z,f(x,z)),f(y,z)),f(f(z,z),u))) = z. f(f(x,z),f(f(f(z,z),y),f(f(f(z,x),z),f(z,u)))) = z. f(f(x,z),f(f(f(z,z),y),f(f(f(x,z),z),f(z,u)))) = z. f(f(x,z),f(f(f(z,z),y),f(f(z,f(z,x)),f(z,u)))) = z. f(f(x,z),f(f(f(z,z),y),f(f(z,f(x,z)),f(z,u)))) = z. f(f(x,z),f(f(f(z,z),y),f(f(z,u),f(z,f(z,x))))) = z. LADR-2009-11A/apps.examples/sed10000644000175000017500000000012107672120756015363 0ustar mccunemccunes/list(clauses)/clauses(theory)/ s/list(interpretations)/terms(interpretations)/ LADR-2009-11A/apps.examples/meet-join-equations0000644000175000017500000000051407671674635020443 0ustar mccunemccune% These are lattice identities x v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. % A1 % These are not lattice identities x v (y ^ (x v z)) = (x v y) ^ (x v z). % Modularity x v (y ^ z) = (x v y) ^ (x v z). % Distributivity LADR-2009-11A/apps.examples/err0000644000175000017500000000041710102471105015302 0ustar mccunemccune ====== Starting search for domain size 3. ====== ----- ALL_MODELS EXIT (8 models) ----- ====== Starting search for domain size 8. ====== ----- ALL_MODELS EXIT (61 models) ----- ====== Starting search for domain size 6. ====== ----- ALL_MODELS EXIT (5 models) ----- LADR-2009-11A/apps.examples/backup.Jan14/0000755000175000017500000000000010171772740016725 5ustar mccunemccuneLADR-2009-11A/apps.examples/backup.Jan14/meet-join-equations.out0000644000175000017500000000031210171772406023346 0ustar mccunemccunex v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. % latfilter: checked 6, passed 4, user 0.00, system 0.00. LADR-2009-11A/apps.examples/backup.Jan14/qg.out30000644000175000017500000000315010171772401020141 0ustar mccunemccuneinterpretation( 3, [ function(*(_,_), [0,1,2, 1,2,0, 2,0,1]), function(\(_,_), [0,1,2, 2,0,1, 1,2,0]), function(/(_,_), [0,2,1, 1,0,2, 2,1,0]) ]). interpretation( 3, [ function(*(_,_), [0,1,2, 2,0,1, 1,2,0]), function(\(_,_), [0,1,2, 1,2,0, 2,0,1]), function(/(_,_), [0,1,2, 2,0,1, 1,2,0]) ]). interpretation( 3, [ function(*(_,_), [0,2,1, 1,0,2, 2,1,0]), function(\(_,_), [0,2,1, 1,0,2, 2,1,0]), function(/(_,_), [0,1,2, 1,2,0, 2,0,1]) ]). interpretation( 3, [ function(*(_,_), [0,2,1, 2,1,0, 1,0,2]), function(\(_,_), [0,2,1, 2,1,0, 1,0,2]), function(/(_,_), [0,2,1, 2,1,0, 1,0,2]) ]). interpretation( 3, [ function(*(_,_), [1,0,2, 0,2,1, 2,1,0]), function(\(_,_), [1,0,2, 0,2,1, 2,1,0]), function(/(_,_), [1,0,2, 0,2,1, 2,1,0]) ]). interpretation( 3, [ function(*(_,_), [1,0,2, 2,1,0, 0,2,1]), function(\(_,_), [1,0,2, 2,1,0, 0,2,1]), function(/(_,_), [2,0,1, 0,1,2, 1,2,0]) ]). interpretation( 3, [ function(*(_,_), [1,2,0, 0,1,2, 2,0,1]), function(\(_,_), [2,0,1, 0,1,2, 1,2,0]), function(/(_,_), [1,2,0, 0,1,2, 2,0,1]) ]). interpretation( 3, [ function(*(_,_), [1,2,0, 2,0,1, 0,1,2]), function(\(_,_), [2,0,1, 1,2,0, 0,1,2]), function(/(_,_), [2,1,0, 0,2,1, 1,0,2]) ]). LADR-2009-11A/apps.examples/backup.Jan14/OL.8.upper-covers0000644000175000017500000000121010171772406021752 0ustar mccunemccune% UPPER-COVERS of Lattice 1 ( (0 (2 3 4 5 6 7)) (1 ()) (2 (1)) (3 (1)) (4 (1)) (5 (1)) (6 (1)) (7 (1)) ) % end of upper-covers % UPPER-COVERS of Lattice 2 ( (0 (2 3 5 7)) (1 ()) (2 (1)) (3 (1)) (4 (1)) (5 (6)) (6 (1)) (7 (4)) ) % end of upper-covers % UPPER-COVERS of Lattice 3 ( (0 (3 4 7)) (1 ()) (2 (1)) (3 (6)) (4 (6)) (5 (1)) (6 (1)) (7 (2 5)) ) % end of upper-covers % UPPER-COVERS of Lattice 4 ( (0 (5 7)) (1 ()) (2 (6)) (3 (4)) (4 (1)) (5 (2)) (6 (1)) (7 (3)) ) % end of upper-covers % UPPER-COVERS of Lattice 5 ( (0 (2 4 7)) (1 ()) (2 (5 6)) (3 (1)) (4 (3 6)) (5 (1)) (6 (1)) (7 (3 5)) ) % end of upper-covers % upper-covers: translated=5 LADR-2009-11A/apps.examples/backup.Jan14/qg.iso30000644000175000017500000000231610171772401020127 0ustar mccunemccune interpretation(3, [ function(*(_,_), [ 0,1,2, 1,2,0, 2,0,1]), function(/(_,_), [ 0,2,1, 1,0,2, 2,1,0]), function(\(_,_), [ 0,1,2, 2,0,1, 1,2,0])]). interpretation(3, [ function(*(_,_), [ 0,1,2, 2,0,1, 1,2,0]), function(/(_,_), [ 0,1,2, 2,0,1, 1,2,0]), function(\(_,_), [ 0,1,2, 1,2,0, 2,0,1])]). interpretation(3, [ function(*(_,_), [ 0,2,1, 1,0,2, 2,1,0]), function(/(_,_), [ 0,1,2, 1,2,0, 2,0,1]), function(\(_,_), [ 0,2,1, 1,0,2, 2,1,0])]). interpretation(3, [ function(*(_,_), [ 0,2,1, 2,1,0, 1,0,2]), function(/(_,_), [ 0,2,1, 2,1,0, 1,0,2]), function(\(_,_), [ 0,2,1, 2,1,0, 1,0,2])]). interpretation(3, [ function(*(_,_), [ 1,0,2, 0,2,1, 2,1,0]), function(/(_,_), [ 1,0,2, 0,2,1, 2,1,0]), function(\(_,_), [ 1,0,2, 0,2,1, 2,1,0])]). % isofilter: input=8, kept=5, checks=16, perms=88, 0.00 seconds. LADR-2009-11A/apps.examples/backup.Jan14/lattice-sax.rewritten0000644000175000017500000000034510171772406023111 0ustar mccunemccuney = y. y = y. (x v (v ^ ((x ^ z) v (x ^ u)))) ^ (w v ((x v v6) ^ (x v v7))) = x. (x v (v ^ ((x ^ z) v (x ^ u)))) ^ (v7 v ((x v w) ^ (x v v6))) = x. % rewriter lattice.rules: rewrote 4 terms with 42 rewrite steps in 0.02 seconds. LADR-2009-11A/apps.examples/backup.Jan14/MOL-cand.2380000644000175000017500000003025010171772405020513 0ustar mccunemccunef(f(f(f(f(x,y),z),z),y),f(f(f(x,y),f(z,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,x),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(z,y),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(x,y),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,z)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(x,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(x,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(z,y),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(f(x,y),f(y,x)),x),f(y,f(f(f(y,x),z),z))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(y,x),z),z))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(x,y),z),z))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(x,y),z),z))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(y,z),x),x))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(z,y),x),x))) = y. f(f(f(f(x,y),f(y,x)),x),f(y,f(f(z,f(y,x)),z))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(z,f(x,y)),z))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(x,f(y,z)),x))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(z,f(y,x)),z))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(x,f(y,z)),x))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(x,f(z,y)),x))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(f(y,z),x)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(f(z,y),x)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(f(y,z),x)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(f(z,y),x)))) = y. f(f(f(f(x,y),f(y,y)),x),f(y,f(z,f(f(y,x),z)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(x,f(x,f(y,z))))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(x,f(x,f(y,z))))) = y. f(f(f(f(x,y),f(y,y)),x),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(z,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),y),f(f(f(x,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(z,y),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(x,y),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,x),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),y),f(f(f(z,y),f(x,y)),z)) = y. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(x,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(x,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,z),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,x),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(z,y),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(x,y),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,x)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(x,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,y),f(y,x)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,x)))) = z. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(f(x,y),z),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(y,x),z),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(x,y),z),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(y,x),z),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(f(z,f(x,y)),z))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(z,f(y,x)),z))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(z,f(x,y)),z))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,x),f(y,x))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(z,f(f(y,x),z)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(z,f(f(x,y),z)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(z,f(z,f(y,x))))) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,x),x),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(f(x,z),x),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(x,f(z,x)),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(z,x),x)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(x,z),x)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(x,f(z,x))),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(x,f(x,z))),z)) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(x,z),x),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(x,f(z,x)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(x,f(x,z)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(z,x),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(x,z),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(z,x),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(x,z),x)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(x,f(z,x))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(x,f(x,z))))) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(u,y),f(x,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(y,u),f(x,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(f(f(x,y),f(u,y)),x)) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(u,y),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,u),f(y,x)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,x),f(y,u)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(x,y),f(y,u)))) = y. f(f(f(f(f(x,y),z),z),y),f(x,f(f(y,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(f(x,f(y,z)),x),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(f(x,f(y,z)),x),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(f(x,f(y,z)),x),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(f(x,f(y,z)),x),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(f(x,f(y,z)),x),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(y,x),u),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(f(x,y),u),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(y,x),u),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(f(x,y),u),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(y,z),u),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(f(z,y),u),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(u,f(y,x)),u))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(f(u,f(x,y)),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(u,f(y,x)),u))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(f(u,f(x,y)),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(u,f(y,z)),u))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(f(u,f(z,y)),u))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(f(y,x),u)))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(f(x,y),u)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(f(y,x),u)))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(f(x,y),u)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(f(y,z),u)))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(f(z,y),u)))) = y. f(f(f(f(x,y),f(y,z)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(f(x,y),f(y,z)),x),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(f(x,y),f(z,y)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(f(x,y),f(z,y)),x),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(f(x,y),f(y,y)),z),f(y,f(u,f(u,f(y,z))))) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(x,f(f(y,z),x)),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(x,f(f(y,z),x)),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(f(y,z),x)),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(f(y,z),x)),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(x,f(f(y,z),x)),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),y),f(f(f(u,y),f(z,y)),z)) = y. f(f(f(x,f(x,f(y,z))),y),f(f(f(y,u),f(z,y)),z)) = y. f(f(f(x,f(x,f(y,z))),y),f(f(f(z,y),f(u,y)),z)) = y. f(f(f(x,f(x,f(y,z))),z),f(f(f(u,z),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(z,u),f(y,z)),y)) = z. f(f(f(x,f(x,f(y,z))),z),f(f(f(y,z),f(u,z)),y)) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(u,y),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,u),f(y,z)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,z),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(z,y),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(u,z),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,u),f(z,y)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,y),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(y,z),f(z,u)))) = z. f(f(f(x,f(x,f(y,z))),y),f(z,f(f(y,y),f(y,u)))) = y. f(f(f(x,f(x,f(y,z))),z),f(y,f(f(z,z),f(z,u)))) = z. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(f(y,x),u),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(f(x,y),u),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(u,f(y,x)),u))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(f(u,f(x,y)),u))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(f(y,x),u)))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(f(x,y),u)))) = y. f(f(x,f(f(y,z),f(y,x))),f(y,f(u,f(u,f(y,x))))) = y. f(f(x,f(f(y,x),f(y,z))),f(y,f(u,f(u,f(y,x))))) = y. f(f(x,f(f(y,x),f(z,y))),f(y,f(u,f(u,f(y,x))))) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,u),u),f(z,y)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(f(z,u),z),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,f(u,z)),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,f(z,u)),f(u,y)),u)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(u,z),u)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(f(z,u),u)),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(u,f(u,z))),z)) = y. f(f(f(x,f(y,y)),y),f(f(f(z,y),f(u,f(z,u))),z)) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(u,z),u),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(f(z,u),u),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(u,f(u,z)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(u,f(z,u)),f(y,z)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(u,z),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(f(z,u),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(u,z),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(f(z,u),u)))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(u,f(u,z))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(y,z),f(u,f(z,u))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(u,f(u,z))))) = y. f(f(f(x,f(y,y)),y),f(z,f(f(z,y),f(u,f(z,u))))) = y. % clausefilter non-MOL-OML false_in_all: checked 296, passed 238, 3.90 seconds. LADR-2009-11A/apps.examples/backup.Jan14/OL.60000644000175000017500000000207510171772406017331 0ustar mccunemccune interpretation(6, [ function(^(_,_), [ 0,0,0,0,0,0, 0,1,2,3,4,5, 0,2,2,0,0,0, 0,3,0,3,0,0, 0,4,0,0,4,0, 0,5,0,0,0,5]), function(v(_,_), [ 0,1,2,3,4,5, 1,1,1,1,1,1, 2,1,2,1,1,1, 3,1,1,3,1,1, 4,1,1,1,4,1, 5,1,1,1,1,5]), function(c(_), [1,0,3,2,5,4]), function(f(_,_), [ 1,1,1,1,1,1, 1,0,3,2,5,4, 1,3,3,1,1,1, 1,2,1,2,1,1, 1,5,1,1,5,1, 1,4,1,1,1,4])]). interpretation(6, [ function(^(_,_), [ 0,0,0,0,0,0, 0,1,2,3,4,5, 0,2,2,0,0,5, 0,3,0,3,3,0, 0,4,0,3,4,0, 0,5,5,0,0,5]), function(v(_,_), [ 0,1,2,3,4,5, 1,1,1,1,1,1, 2,1,2,1,1,2, 3,1,1,3,4,1, 4,1,1,4,4,1, 5,1,2,1,1,5]), function(c(_), [1,0,3,2,5,4]), function(f(_,_), [ 1,1,1,1,1,1, 1,0,3,2,5,4, 1,3,3,1,1,4, 1,2,1,2,2,1, 1,5,1,2,5,1, 1,4,4,1,1,4])]). % isofilter: input=5, kept=2, checks=3, perms=3, 0.01 seconds. LADR-2009-11A/apps.examples/backup.Jan14/BA-sheffer.out0000644000175000017500000003405210171772406021363 0ustar mccunemccunef(f(x,x),f(x,y)) = x. % 1 2 f(f(x,x),f(y,x)) = x. % 1 2 f(f(x,f(x,x)),f(y,y)) = y. % 1 2 f(f(f(x,x),x),f(y,y)) = y. % 1 2 f(f(x,f(y,z)),f(x,z)) = x. % f(f(x,f(y,z)),f(z,x)) = x. % f(f(x,f(y,z)),f(x,y)) = x. % f(f(x,f(y,z)),f(y,x)) = x. % f(f(f(x,y),z),f(z,y)) = z. % f(f(f(x,y),z),f(y,z)) = z. % f(f(f(x,y),z),f(z,x)) = z. % f(f(f(x,y),z),f(x,z)) = z. % f(f(x,f(y,f(y,y))),f(x,z)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(x,z)) = x. % 1 2 f(f(x,f(y,f(y,y))),f(z,x)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(z,x)) = x. % 1 2 f(f(f(x,f(x,x)),y),f(y,z)) = y. % 1 2 f(f(f(f(x,x),x),y),f(y,z)) = y. % 1 2 f(f(f(x,f(x,x)),y),f(z,y)) = y. % 1 2 f(f(f(f(x,x),x),y),f(z,y)) = y. % 1 2 f(f(x,f(f(x,y),y)),f(x,z)) = x. % f(f(x,f(f(x,y),y)),f(z,x)) = x. % f(f(f(f(x,y),z),z),f(x,x)) = x. % f(f(x,f(y,f(x,y))),f(x,z)) = x. % f(f(x,f(f(y,x),y)),f(x,z)) = x. % f(f(x,f(y,f(x,y))),f(z,x)) = x. % f(f(x,f(f(y,x),y)),f(z,x)) = x. % f(f(x,f(y,f(y,x))),f(x,z)) = x. % f(f(f(f(x,y),y),x),f(x,z)) = x. % f(f(x,f(y,f(y,x))),f(z,x)) = x. % f(f(f(f(x,y),y),x),f(z,x)) = x. % f(f(f(f(x,y),z),z),f(y,y)) = y. % f(f(x,f(f(y,z),x)),f(y,y)) = y. % f(f(f(x,f(y,z)),x),f(y,y)) = y. % f(f(f(x,f(y,x)),y),f(y,z)) = y. % f(f(f(f(x,y),x),y),f(y,z)) = y. % f(f(f(x,f(y,x)),y),f(z,y)) = y. % f(f(f(f(x,y),x),y),f(z,y)) = y. % f(f(x,f(f(y,z),x)),f(z,z)) = z. % f(f(f(x,f(y,z)),x),f(z,z)) = z. % f(f(f(x,f(x,y)),y),f(y,z)) = y. % f(f(f(x,f(x,y)),y),f(z,y)) = y. % f(f(x,f(x,f(y,z))),f(y,y)) = y. % f(f(x,f(x,f(y,z))),f(z,z)) = z. % f(f(x,f(f(x,x),y)),f(x,z)) = x. % 1 2 f(f(x,f(f(x,x),y)),f(z,x)) = x. % 1 2 f(f(f(f(x,x),y),x),f(x,z)) = x. % 1 2 f(f(f(f(x,x),y),x),f(z,x)) = x. % 1 2 f(f(x,f(y,f(x,x))),f(x,z)) = x. % 1 2 f(f(x,f(y,f(x,x))),f(z,x)) = x. % 1 2 f(f(f(x,f(y,y)),y),f(y,z)) = y. % 1 2 f(f(f(x,f(y,y)),y),f(z,y)) = y. % 1 2 f(f(x,f(y,f(y,y))),f(z,f(z,z))) = x. % 1 2 f(f(x,f(f(y,y),y)),f(z,f(z,z))) = x. % 1 2 f(f(x,f(y,f(y,y))),f(f(z,z),z)) = x. % 1 2 f(f(x,f(f(y,y),y)),f(f(z,z),z)) = x. % 1 2 f(f(f(x,f(x,x)),y),f(z,f(z,z))) = y. % 1 2 f(f(f(f(x,x),x),y),f(z,f(z,z))) = y. % 1 2 f(f(f(x,f(x,x)),y),f(f(z,z),z)) = y. % 1 2 f(f(f(f(x,x),x),y),f(f(z,z),z)) = y. % 1 2 f(f(f(f(x,y),y),y),f(x,f(z,y))) = x. % f(f(f(f(x,y),y),y),f(x,f(y,z))) = x. % f(f(f(f(x,y),y),y),f(f(z,y),x)) = x. % f(f(f(f(x,y),y),y),f(f(y,z),x)) = x. % f(f(x,f(f(y,x),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,x)),x),f(y,f(z,x))) = y. % f(f(f(f(x,y),x),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,x),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,x)),x),f(y,f(x,z))) = y. % f(f(f(f(x,y),x),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,x),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,x)),x),f(f(z,x),y)) = y. % f(f(f(f(x,y),x),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,x),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,x)),x),f(f(x,z),y)) = y. % f(f(f(f(x,y),x),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,x))),f(y,f(z,x))) = y. % f(f(x,f(f(x,y),x)),f(y,f(z,x))) = y. % f(f(f(x,f(x,y)),x),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,x))),f(y,f(x,z))) = y. % f(f(x,f(f(x,y),x)),f(y,f(x,z))) = y. % f(f(f(x,f(x,y)),x),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,x))),f(f(z,x),y)) = y. % f(f(x,f(f(x,y),x)),f(f(z,x),y)) = y. % f(f(f(x,f(x,y)),x),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,x))),f(f(x,z),y)) = y. % f(f(x,f(f(x,y),x)),f(f(x,z),y)) = y. % f(f(f(x,f(x,y)),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(x,y))),f(y,f(z,x))) = y. % f(f(x,f(x,f(x,y))),f(y,f(x,z))) = y. % f(f(x,f(x,f(x,y))),f(f(z,x),y)) = y. % f(f(x,f(x,f(x,y))),f(f(x,z),y)) = y. % f(f(x,f(f(x,y),y)),f(z,f(z,z))) = x. % f(f(x,f(f(x,y),y)),f(f(z,z),z)) = x. % f(f(x,f(y,f(x,y))),f(z,f(z,z))) = x. % f(f(x,f(f(y,x),y)),f(z,f(z,z))) = x. % f(f(x,f(y,f(x,y))),f(f(z,z),z)) = x. % f(f(x,f(f(y,x),y)),f(f(z,z),z)) = x. % f(f(x,f(y,f(y,x))),f(z,f(z,z))) = x. % f(f(f(f(x,y),y),x),f(z,f(z,z))) = x. % f(f(x,f(y,f(y,x))),f(f(z,z),z)) = x. % f(f(f(f(x,y),y),x),f(f(z,z),z)) = x. % f(f(f(f(x,y),z),z),f(x,f(y,z))) = x. % f(f(f(f(x,y),z),z),f(x,f(z,y))) = x. % f(f(f(f(x,y),z),z),f(f(y,z),x)) = x. % f(f(f(f(x,y),z),z),f(f(z,y),x)) = x. % f(f(f(x,f(y,x)),y),f(z,f(z,z))) = y. % f(f(f(f(x,y),x),y),f(z,f(z,z))) = y. % f(f(f(x,f(y,x)),y),f(f(z,z),z)) = y. % f(f(f(f(x,y),x),y),f(f(z,z),z)) = y. % f(f(f(f(x,y),z),z),f(y,f(x,z))) = y. % f(f(f(f(x,y),z),z),f(y,f(z,x))) = y. % f(f(f(f(x,y),z),z),f(f(x,z),y)) = y. % f(f(f(f(x,y),z),z),f(f(z,x),y)) = y. % f(f(f(x,f(x,y)),y),f(z,f(z,z))) = y. % f(f(f(x,f(x,y)),y),f(f(z,z),z)) = y. % f(f(x,f(f(y,z),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,z)),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,z),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,z)),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,z),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,z)),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,z),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,z)),x),f(f(x,z),y)) = y. % f(f(x,f(f(y,z),x)),f(z,f(y,x))) = z. % f(f(f(x,f(y,z)),x),f(z,f(y,x))) = z. % f(f(x,f(f(y,z),x)),f(z,f(x,y))) = z. % f(f(f(x,f(y,z)),x),f(z,f(x,y))) = z. % f(f(x,f(f(y,z),x)),f(f(y,x),z)) = z. % f(f(f(x,f(y,z)),x),f(f(y,x),z)) = z. % f(f(x,f(f(y,z),x)),f(f(x,y),z)) = z. % f(f(f(x,f(y,z)),x),f(f(x,y),z)) = z. % f(f(x,f(x,f(y,z))),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,z))),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,z))),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,z))),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,z))),f(z,f(y,x))) = z. % f(f(x,f(x,f(y,z))),f(z,f(x,y))) = z. % f(f(x,f(x,f(y,z))),f(f(y,x),z)) = z. % f(f(x,f(x,f(y,z))),f(f(x,y),z)) = z. % f(f(x,f(f(x,x),y)),f(z,f(z,z))) = x. % 1 2 f(f(x,f(f(x,x),y)),f(f(z,z),z)) = x. % 1 2 f(f(f(f(x,x),y),x),f(z,f(z,z))) = x. % 1 2 f(f(f(f(x,x),y),x),f(f(z,z),z)) = x. % 1 2 f(f(f(f(x,x),y),y),f(x,f(z,y))) = x. % f(f(f(f(x,x),y),y),f(x,f(y,z))) = x. % f(f(f(f(x,x),y),y),f(f(z,y),x)) = x. % f(f(f(f(x,x),y),y),f(f(y,z),x)) = x. % f(f(x,f(y,f(x,x))),f(z,f(z,z))) = x. % 1 2 f(f(x,f(y,f(x,x))),f(f(z,z),z)) = x. % 1 2 f(f(f(x,f(y,y)),y),f(z,f(z,z))) = y. % 1 2 f(f(f(x,f(y,y)),y),f(f(z,z),z)) = y. % 1 2 f(f(x,f(f(y,y),x)),f(y,f(z,x))) = y. % f(f(f(x,f(y,y)),x),f(y,f(z,x))) = y. % f(f(x,f(f(y,y),x)),f(y,f(x,z))) = y. % f(f(f(x,f(y,y)),x),f(y,f(x,z))) = y. % f(f(x,f(f(y,y),x)),f(f(z,x),y)) = y. % f(f(f(x,f(y,y)),x),f(f(z,x),y)) = y. % f(f(x,f(f(y,y),x)),f(f(x,z),y)) = y. % f(f(f(x,f(y,y)),x),f(f(x,z),y)) = y. % f(f(x,f(x,f(y,y))),f(y,f(z,x))) = y. % f(f(x,f(x,f(y,y))),f(y,f(x,z))) = y. % f(f(x,f(x,f(y,y))),f(f(z,x),y)) = y. % f(f(x,f(x,f(y,y))),f(f(x,z),y)) = y. % f(f(x,f(y,f(z,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,z))),f(f(z,u),x)) = x. % f(f(x,f(f(y,y),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,y),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,y),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,y),z)),f(f(y,u),x)) = x. % f(f(f(x,f(y,y)),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,y)),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,y)),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,y)),z),f(f(y,u),z)) = z. % f(f(f(f(x,x),y),z),f(z,f(u,x))) = z. % f(f(f(f(x,x),y),z),f(z,f(x,u))) = z. % f(f(f(f(x,x),y),z),f(f(u,x),z)) = z. % f(f(f(f(x,x),y),z),f(f(x,u),z)) = z. % f(f(x,f(y,f(z,u))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,u))),f(f(u,z),x)) = x. % f(f(x,f(y,f(y,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(y,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(y,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(y,z))),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),u)),f(x,f(z,y))) = x. % f(f(x,f(f(y,z),u)),f(f(z,y),x)) = x. % f(f(x,f(y,f(z,y))),f(x,f(u,z))) = x. % f(f(x,f(f(y,z),y)),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,y))),f(x,f(z,u))) = x. % f(f(x,f(f(y,z),y)),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,y))),f(f(u,z),x)) = x. % f(f(x,f(f(y,z),y)),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,y))),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),y)),f(f(z,u),x)) = x. % f(f(x,f(f(y,z),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,z),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,z),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,z),z)),f(f(y,u),x)) = x. % f(f(f(x,f(y,z)),u),f(u,f(z,y))) = u. % f(f(f(x,f(y,z)),u),f(f(z,y),u)) = u. % f(f(f(x,f(x,y)),z),f(z,f(u,y))) = z. % f(f(f(x,f(x,y)),z),f(z,f(y,u))) = z. % f(f(f(x,f(x,y)),z),f(f(u,y),z)) = z. % f(f(f(x,f(x,y)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),z),u),f(u,f(y,x))) = u. % f(f(f(f(x,y),z),u),f(f(y,x),u)) = u. % f(f(f(x,f(y,x)),z),f(z,f(u,y))) = z. % f(f(f(f(x,y),x),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,x)),z),f(z,f(y,u))) = z. % f(f(f(f(x,y),x),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,x)),z),f(f(u,y),z)) = z. % f(f(f(f(x,y),x),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,x)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),x),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),y),z),f(z,f(u,x))) = z. % f(f(f(f(x,y),y),z),f(z,f(x,u))) = z. % f(f(f(f(x,y),y),z),f(f(u,x),z)) = z. % f(f(f(f(x,y),y),z),f(f(x,u),z)) = z. % f(f(x,f(f(x,y),z)),f(x,f(u,y))) = x. % f(f(x,f(f(x,y),z)),f(x,f(y,u))) = x. % f(f(x,f(f(x,y),z)),f(f(u,y),x)) = x. % f(f(x,f(f(x,y),z)),f(f(y,u),x)) = x. % f(f(x,f(y,f(x,z))),f(x,f(u,z))) = x. % f(f(x,f(y,f(x,z))),f(x,f(z,u))) = x. % f(f(x,f(y,f(x,z))),f(f(u,z),x)) = x. % f(f(x,f(y,f(x,z))),f(f(z,u),x)) = x. % f(f(x,f(y,f(z,x))),f(x,f(u,z))) = x. % f(f(x,f(y,f(z,x))),f(x,f(z,u))) = x. % f(f(x,f(y,f(z,x))),f(f(u,z),x)) = x. % f(f(x,f(y,f(z,x))),f(f(z,u),x)) = x. % f(f(x,f(f(y,x),z)),f(x,f(u,y))) = x. % f(f(x,f(f(y,x),z)),f(x,f(y,u))) = x. % f(f(x,f(f(y,x),z)),f(f(u,y),x)) = x. % f(f(x,f(f(y,x),z)),f(f(y,u),x)) = x. % f(f(f(f(x,y),z),x),f(x,f(u,y))) = x. % f(f(f(f(x,y),z),x),f(x,f(y,u))) = x. % f(f(f(f(x,y),z),x),f(f(u,y),x)) = x. % f(f(f(f(x,y),z),x),f(f(y,u),x)) = x. % f(f(f(x,f(y,z)),y),f(y,f(u,z))) = y. % f(f(f(x,f(y,z)),y),f(y,f(z,u))) = y. % f(f(f(x,f(y,z)),y),f(f(u,z),y)) = y. % f(f(f(x,f(y,z)),y),f(f(z,u),y)) = y. % f(f(f(x,f(y,z)),z),f(z,f(u,y))) = z. % f(f(f(x,f(y,z)),z),f(z,f(y,u))) = z. % f(f(f(x,f(y,z)),z),f(f(u,y),z)) = z. % f(f(f(x,f(y,z)),z),f(f(y,u),z)) = z. % f(f(f(f(x,y),z),y),f(y,f(u,x))) = y. % f(f(f(f(x,y),z),y),f(y,f(x,u))) = y. % f(f(f(f(x,y),z),y),f(f(u,x),y)) = y. % f(f(f(f(x,y),z),y),f(f(x,u),y)) = y. % f(f(f(f(x,f(y,y)),y),y),f(z,z)) = z. % 1 2 f(f(x,f(f(y,f(x,x)),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(y,f(x,x))),x),f(z,z)) = z. % 1 2 f(f(x,f(x,f(y,f(x,x)))),f(z,z)) = z. % 1 2 f(f(f(f(f(x,x),y),x),x),f(z,z)) = z. % 1 2 f(f(x,f(f(f(x,x),y),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(f(x,x),y)),x),f(z,z)) = z. % 1 2 f(f(x,f(x,f(f(x,x),y))),f(z,z)) = z. % 1 2 f(f(x,f(x,f(y,f(y,y)))),f(z,z)) = z. % 1 2 f(f(x,f(x,f(f(y,y),y))),f(z,z)) = z. % 1 2 f(f(f(f(x,f(x,y)),y),y),f(z,z)) = z. % 2 f(f(f(f(x,f(y,x)),y),y),f(z,z)) = z. % 2 f(f(f(f(f(x,y),x),y),y),f(z,z)) = z. % 2 f(f(x,f(f(y,f(y,y)),x)),f(z,z)) = z. % 1 2 f(f(x,f(f(f(y,y),y),x)),f(z,z)) = z. % 1 2 f(f(f(x,f(y,f(y,y))),x),f(z,z)) = z. % 1 2 f(f(f(x,f(f(y,y),y)),x),f(z,z)) = z. % 1 2 f(f(x,f(f(y,f(y,x)),x)),f(z,z)) = z. % 2 f(f(f(x,f(y,f(y,x))),x),f(z,z)) = z. % 2 f(f(f(f(f(x,y),y),x),x),f(z,z)) = z. % 2 f(f(x,f(f(y,f(x,y)),x)),f(z,z)) = z. % 2 f(f(x,f(f(f(y,x),y),x)),f(z,z)) = z. % 2 f(f(f(x,f(y,f(x,y))),x),f(z,z)) = z. % 2 f(f(f(x,f(f(y,x),y)),x),f(z,z)) = z. % 2 f(f(x,f(x,f(y,f(y,x)))),f(z,z)) = z. % 2 f(f(x,f(f(f(x,y),y),x)),f(z,z)) = z. % 2 f(f(f(x,f(f(x,y),y)),x),f(z,z)) = z. % 2 f(f(x,f(x,f(y,f(x,y)))),f(z,z)) = z. % 2 f(f(x,f(x,f(f(y,x),y))),f(z,z)) = z. % 2 f(f(x,f(x,f(f(x,y),y))),f(z,z)) = z. % 2 f(f(f(f(x,f(x,x)),y),y),f(z,z)) = z. % 1 2 f(f(f(f(f(x,x),x),y),y),f(z,z)) = z. % 1 2 f(f(x,f(f(f(y,z),u),u)),f(x,z)) = x. % f(f(x,f(f(f(y,z),u),u)),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),y))),f(x,u)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(x,u)) = x. % f(f(x,f(y,f(f(z,u),y))),f(u,x)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(u,x)) = x. % f(f(x,f(f(f(y,z),u),u)),f(x,y)) = x. % f(f(x,f(f(f(y,z),u),u)),f(y,x)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(x,u)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(u,x)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(x,z)) = x. % f(f(x,f(y,f(y,f(z,u)))),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),y))),f(x,z)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(x,z)) = x. % f(f(x,f(y,f(f(z,u),y))),f(z,x)) = x. % f(f(x,f(f(y,f(z,u)),y)),f(z,x)) = x. % f(f(f(f(f(x,y),z),z),u),f(u,y)) = u. % f(f(f(f(f(x,y),z),z),u),f(y,u)) = u. % f(f(f(x,f(f(y,z),x)),u),f(u,z)) = u. % f(f(f(f(x,f(y,z)),x),u),f(u,z)) = u. % f(f(f(x,f(f(y,z),x)),u),f(z,u)) = u. % f(f(f(f(x,f(y,z)),x),u),f(z,u)) = u. % f(f(f(f(f(x,y),z),z),u),f(u,x)) = u. % f(f(f(f(f(x,y),z),z),u),f(x,u)) = u. % f(f(f(x,f(x,f(y,z))),u),f(u,z)) = u. % f(f(f(x,f(x,f(y,z))),u),f(z,u)) = u. % f(f(f(x,f(x,f(y,z))),u),f(u,y)) = u. % f(f(f(x,f(x,f(y,z))),u),f(y,u)) = u. % f(f(f(x,f(f(y,z),x)),u),f(u,y)) = u. % f(f(f(f(x,f(y,z)),x),u),f(u,y)) = u. % f(f(f(x,f(f(y,z),x)),u),f(y,u)) = u. % f(f(f(f(x,f(y,z)),x),u),f(y,u)) = u. % f(f(x,f(f(x,f(y,z)),u)),f(x,z)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(z,x)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(x,y)) = x. % f(f(x,f(f(x,f(y,z)),u)),f(y,x)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(x,u)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(u,x)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(x,z)) = x. % f(f(x,f(y,f(x,f(z,u)))),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),x))),f(x,u)) = x. % f(f(x,f(y,f(f(z,u),x))),f(u,x)) = x. % f(f(x,f(f(f(y,z),x),u)),f(x,z)) = x. % f(f(x,f(f(f(y,z),x),u)),f(z,x)) = x. % f(f(x,f(y,f(f(z,u),x))),f(x,z)) = x. % f(f(f(f(x,f(y,z)),u),x),f(x,z)) = x. % f(f(x,f(y,f(f(z,u),x))),f(z,x)) = x. % f(f(f(f(x,f(y,z)),u),x),f(z,x)) = x. % f(f(x,f(f(f(y,z),x),u)),f(x,y)) = x. % f(f(x,f(f(f(y,z),x),u)),f(y,x)) = x. % f(f(f(f(x,f(y,z)),u),x),f(x,y)) = x. % f(f(f(f(x,f(y,z)),u),x),f(y,x)) = x. % f(f(f(x,f(y,f(z,u))),y),f(y,u)) = y. % f(f(f(x,f(y,f(z,u))),y),f(u,y)) = y. % f(f(f(x,f(y,f(z,u))),y),f(y,z)) = y. % f(f(f(x,f(y,f(z,u))),y),f(z,y)) = y. % f(f(f(x,f(f(y,z),u)),u),f(u,z)) = u. % f(f(f(x,f(f(y,z),u)),u),f(z,u)) = u. % f(f(f(f(f(x,y),z),u),z),f(z,y)) = z. % f(f(f(f(f(x,y),z),u),z),f(y,z)) = z. % f(f(f(x,f(f(y,z),u)),u),f(u,y)) = u. % f(f(f(x,f(f(y,z),u)),u),f(y,u)) = u. % f(f(f(f(f(x,y),z),u),z),f(z,x)) = z. % f(f(f(f(f(x,y),z),u),z),f(x,z)) = z. % f(f(f(f(x,y),f(x,z)),u),f(x,x)) = x. % 1 2 f(f(f(f(x,y),f(z,x)),u),f(x,x)) = x. % 1 2 f(f(f(f(x,y),f(y,z)),u),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(y,u))),f(y,y)) = y. % 1 2 f(f(f(f(x,y),f(z,y)),u),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(u,y))),f(y,y)) = y. % 1 2 f(f(x,f(f(y,z),f(z,u))),f(z,z)) = z. % 1 2 f(f(x,f(f(y,z),f(u,z))),f(z,z)) = z. % 1 2 % interp 1 models 60 clauses. % interp 2 models 76 clauses. LADR-2009-11A/apps.examples/backup.Jan14/OL.8.out0000644000175000017500000000415510171772405020141 0ustar mccunemccuneinterpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,0,0,0,0,3,0,3,0,0,0,0,0,4,0,0,4,0,0,0,0,5,0,0,0,5,0,0,0,6,0,0,0,0,6,0,0,7,0,0,0,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,3,1,1,3,1,1,1,1,4,1,1,1,4,1,1,1,5,1,1,1,1,5,1,1,6,1,1,1,1,1,6,1,7,1,1,1,1,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,1,1,1,1,2,1,2,1,1,1,1,1,5,1,1,5,1,1,1,1,4,1,1,1,4,1,1,1,7,1,1,1,1,7,1,1,6,1,1,1,1,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,0,0,0,0,3,0,3,0,0,0,0,0,4,0,0,4,0,0,7,0,5,0,0,0,5,5,0,0,6,0,0,0,5,6,0,0,7,0,0,7,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,3,1,1,3,1,1,1,1,4,1,1,1,4,1,1,4,5,1,1,1,1,5,6,1,6,1,1,1,1,6,6,1,7,1,1,1,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,1,1,1,1,2,1,2,1,1,1,1,1,5,1,1,5,1,1,6,1,4,1,1,1,4,4,1,1,7,1,1,1,4,7,1,1,6,1,1,6,1,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,7,0,7,0,3,0,3,0,0,3,0,0,4,0,0,4,0,4,0,0,5,7,0,0,5,0,7,0,6,0,3,4,0,6,0,0,7,7,0,0,7,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1,2,3,1,1,3,6,1,6,1,4,1,1,6,4,1,6,1,5,1,1,1,1,5,1,5,6,1,1,6,6,1,6,1,7,1,2,1,1,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,6,1,6,1,2,1,2,1,1,2,1,1,5,1,1,5,1,5,1,1,4,6,1,1,4,1,6,1,7,1,2,5,1,7,1,1,6,6,1,1,6,1,6])]). interpretation(8, [ function(^(_,_), [0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0,2,2,0,0,5,2,0,0,3,0,3,3,0,0,7,0,4,0,3,4,0,0,7,0,5,5,0,0,5,5,0,0,6,2,0,0,5,6,0,0,7,0,7,7,0,0,7]), function(v(_,_), [0,1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,2,1,2,1,1,2,6,1,3,1,1,3,4,1,1,3,4,1,1,4,4,1,1,4,5,1,2,1,1,5,6,1,6,1,6,1,1,6,6,1,7,1,1,3,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [1,1,1,1,1,1,1,1,1,0,3,2,5,4,7,6,1,3,3,1,1,4,3,1,1,2,1,2,2,1,1,6,1,5,1,2,5,1,1,6,1,4,4,1,1,4,4,1,1,7,3,1,1,4,7,1,1,6,1,6,6,1,1,6])]). % interpfilter distributivity some_false: checked 5, passed 4, 0.01 seconds. LADR-2009-11A/apps.examples/backup.Jan14/OL.80000644000175000017500000000724710171772405017340 0ustar mccunemccune interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,0,0,0, 0,3,0,3,0,0,0,0, 0,4,0,0,4,0,0,0, 0,5,0,0,0,5,0,0, 0,6,0,0,0,0,6,0, 0,7,0,0,0,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,1, 3,1,1,3,1,1,1,1, 4,1,1,1,4,1,1,1, 5,1,1,1,1,5,1,1, 6,1,1,1,1,1,6,1, 7,1,1,1,1,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,1,1,1, 1,2,1,2,1,1,1,1, 1,5,1,1,5,1,1,1, 1,4,1,1,1,4,1,1, 1,7,1,1,1,1,7,1, 1,6,1,1,1,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,0,0,0, 0,3,0,3,0,0,0,0, 0,4,0,0,4,0,0,7, 0,5,0,0,0,5,5,0, 0,6,0,0,0,5,6,0, 0,7,0,0,7,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,1, 3,1,1,3,1,1,1,1, 4,1,1,1,4,1,1,4, 5,1,1,1,1,5,6,1, 6,1,1,1,1,6,6,1, 7,1,1,1,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,1,1,1, 1,2,1,2,1,1,1,1, 1,5,1,1,5,1,1,6, 1,4,1,1,1,4,4,1, 1,7,1,1,1,4,7,1, 1,6,1,1,6,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,7,0,7, 0,3,0,3,0,0,3,0, 0,4,0,0,4,0,4,0, 0,5,7,0,0,5,0,7, 0,6,0,3,4,0,6,0, 0,7,7,0,0,7,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,1,1,2, 3,1,1,3,6,1,6,1, 4,1,1,6,4,1,6,1, 5,1,1,1,1,5,1,5, 6,1,1,6,6,1,6,1, 7,1,2,1,1,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,6,1,6, 1,2,1,2,1,1,2,1, 1,5,1,1,5,1,5,1, 1,4,6,1,1,4,1,6, 1,7,1,2,5,1,7,1, 1,6,6,1,1,6,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,5,2,0, 0,3,0,3,3,0,0,7, 0,4,0,3,4,0,0,7, 0,5,5,0,0,5,5,0, 0,6,2,0,0,5,6,0, 0,7,0,7,7,0,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,1,2,6,1, 3,1,1,3,4,1,1,3, 4,1,1,4,4,1,1,4, 5,1,2,1,1,5,6,1, 6,1,6,1,1,6,6,1, 7,1,1,3,4,1,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,4,3,1, 1,2,1,2,2,1,1,6, 1,5,1,2,5,1,1,6, 1,4,4,1,1,4,4,1, 1,7,3,1,1,4,7,1, 1,6,1,6,6,1,1,6])]). interpretation(8, [ function(^(_,_), [ 0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7, 0,2,2,0,0,2,2,0, 0,3,0,3,4,7,4,7, 0,4,0,4,4,0,4,0, 0,5,2,7,0,5,2,7, 0,6,2,4,4,2,6,0, 0,7,0,7,0,7,0,7]), function(v(_,_), [ 0,1,2,3,4,5,6,7, 1,1,1,1,1,1,1,1, 2,1,2,1,6,5,6,5, 3,1,1,3,3,1,1,3, 4,1,6,3,4,1,6,3, 5,1,5,1,1,5,1,5, 6,1,6,1,6,1,6,1, 7,1,5,3,3,5,1,7]), function(c(_), [1,0,3,2,5,4,7,6]), function(f(_,_), [ 1,1,1,1,1,1,1,1, 1,0,3,2,5,4,7,6, 1,3,3,1,1,3,3,1, 1,2,1,2,5,6,5,6, 1,5,1,5,5,1,5,1, 1,4,3,6,1,4,3,6, 1,7,3,5,5,3,7,1, 1,6,1,6,1,6,1,6])]). % isofilter: input=61, kept=5, checks=56, perms=80, 0.13 seconds. LADR-2009-11A/apps.examples/backup.Jan14/mjc01s-equations.out0000644000175000017500000000056610171772406022567 0ustar mccunemccunex v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. x ^ c(x) = 0. c(x ^ y) = c(x) v c(y). c(x v y) = c(x) ^ c(y). c(c(x)) = x. f(f(x,x),f(x,y)) = x. f(x,f(x,x)) = f(y,f(y,y)). f(x,f(f(y,z),f(y,z))) = f(z,f(f(y,x),f(y,x))). % olfilter: checked 16, passed 11, user 0.00, system 0.00. LADR-2009-11A/apps.examples/lattice.rules0000644000175000017500000000036307672121046017306 0ustar mccunemccuneop(400, infix, ^). op(400, infix, v). assoc_comm(^). % meet is associative and commutative assoc_comm(v). % join is associative and commutative clauses(theory). x ^ x = x. x ^ (x v y) = x. x v x = x. x v (x ^ y) = x. end_of_list. LADR-2009-11A/apps.examples/README0000644000175000017500000000020407672357610015467 0ustar mccunemccuneThis directory has examples of running the auxiliary programs described in the MACE4 manual. See the files run-all and index.html. LADR-2009-11A/apps.examples/mjc01s-equations0000644000175000017500000000124007671675573017650 0ustar mccunemccune% These are OL identities x v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. (((y v x) ^ x) v (((z ^ (x v x)) v (u ^ x)) ^ v)) ^ (w v ((v6 v x) ^ (x v v7))) = x. % A1 x ^ c(x) = 0. c(x ^ y) = c(x) v c(y). c(x v y) = c(x) ^ c(y). c(c(x)) = x. f(f(x,x),f(x,y)) = x. % f is the Sheffer stroke f(x,f(x,x)) = f(y,f(y,y)). f(x,f(f(y,z),f(y,z))) = f(z,f(f(y,x),f(y,x))). % These are not OL identities x v (y ^ (x v z)) = (x v y) ^ (x v z). % Modularity x v (y ^ z) = (x v y) ^ (x v z). % Distributivity x v (c(x) ^ (x v y)) = x v y. % OML law f(x,f(x,f(x,y))) = f(x,y). % OML law f(x,f(y,f(x,f(z,z)))) = f(x,f(z,f(x,f(y,y)))). % Modularity LADR-2009-11A/apps.examples/index.html0000644000175000017500000000541307672362155016613 0ustar mccunemccune Miscellaneous LADR Applications

    Miscellaneous LADR Applications


    Here are examples of running the auxiliary programs described in the MACE4 manual. You can get a synopsis of each program by giving it an argument "help".

    These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory. LADR-2009-11A/bin/0000755000175000017500000000000011274373242012573 5ustar mccunemccuneLADR-2009-11A/README.release-reminder0000644000175000017500000000044210547025264016125 0ustar mccunemccuneWhen releaseing a new version, update the files Changelog (last entry should be release note) VERSION_DATE.h ----------------- Run examples Update manual ----------------- Rename this directory, e.g., LADR-January-2007 % trash; trashr % make realclean % packup LADR-2009-11A/mace4.examples/0000755000175000017500000000000010707200156014622 5ustar mccunemccuneLADR-2009-11A/mace4.examples/rw1.in0000644000175000017500000000132210707177674015703 0ustar mccunemccune formulas(assumptions). % A problem from Norm Megill, on weak orthomodular lattices (WOM). % Mace4 should produce a counterexample in a few seconds. % Lattice Axioms x ^ y = y ^ x. (x ^ y) ^ z = x ^ (y ^ z). x v y = y v x. (x v y) v z = x v (y v z). x v (x ^ y) = x. x ^ (x v y) = x. % The following gives us ortholattices. x' ^ x = 0. x' v x = 1. x'' = x. x ^ y = (x' v y')'. % Ortholattice lemmas. % 1 v x = 1. % 1 ^ x = x. % 0 ^ x = 0. % 0 v x = x. % Weak orthomodular law (*1 of mail 68). (x' ^ (x v y)) v (y' v (x ^ y)) = 1 # label(mail_68_1). end_of_list. formulas(goals). % Equation in question (*3 of mail 68). x ^ (y v (x ^ (x' v (x ^ y)))) = x ^ (x' v (x ^ y)) # label(mail_68_3). end_of_list. LADR-2009-11A/mace4.examples/group2.in0000644000175000017500000000113110455265365016401 0ustar mccunemccuneassign(iterate_up_to, 12). set(verbose). % This list of formulas specifies a noncommutative group. % % Normally we would write the group axioms with clauses % (as in the example ncg-48.in). Here we use quantified % formulas. formulas(theory). % Associativity all x all y all z ((x * y) * z = x * (y * z)). % There is a left identity element, and every element has a left inverse. exists e ((all x (e * x = x)) & (all x exists y (y * x = e))). % So far, we have group theory. Now, state that % there are two noncommuting elements. exists a exists b (a * b != b * a). end_of_list. LADR-2009-11A/mace4.examples/README0000644000175000017500000000012010707200156015473 0ustar mccunemccuneSee the Web page http://www.cs.unm.edu/~mccune/prover9/ for more examples. LADR-2009-11A/.gdb_history0000600000175000017500000000100610066573515014331 0ustar mccunemccunebreak fatal_error run < b4.in print message up up call p_clause(c) print *c up up break prover6.c:958 if (old->id == 526) run call p_clause(old) next call p_clause(new) print *old next file prover6 run print *old call p_just(justification) call p_just(old->justification) print *old call p_just(old->justification) call p_just(old->justification) call p_just(old->justification) file prover6 run call p_just(old->justification) next call p_just(new->justification) print *new next call p_just(new->justification) next LADR-2009-11A/bob/0000755000175000017500000000000011013310725012551 5ustar mccunemccuneLADR-2009-11A/bob/ioutil.c0000644000175000017500000004716411013107066014240 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "ioutil.h" /* Private definitions and types */ /************* * * fwrite_formula() * *************/ /* DOCUMENTATION This routine prints a formula, followed by ".\n" to a file. This version does not print extra parentheses (it first translates the formula to a term, then prints the term, then frees the term). To print the formula directly, with extra parentheses, call fprint_formula() instead. */ /* PUBLIC */ void fwrite_formula(FILE *fp, Formula f) { Term t = formula_to_term(f); if (t == NULL) fatal_error("fwrite_formula, formula_to_term returns NULL."); fwrite_term_nl(fp, t); fflush(fp); zap_term(t); } /* fwrite_formula */ /************* * * read_clause() * *************/ /* DOCUMENTATION This routine reads a clause from FILE *fin. If there are no more clauses in *fin, NULL is returned.

    If any error occurs, a message is sent to FILE *fout and a fatal_error occurs.

    Variables are "set", upward links ar made from all subterms to the clause, and ac_canonical() is called on each atom. */ /* PUBLIC */ Topform read_clause(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Topform c = term_to_clause(t); zap_term(t); clause_set_variables(c, MAX_VARS); /* fatal if too many vars */ return c; } } /* read_clause */ /************* * * parse_clause_from_string() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform parse_clause_from_string(char *s) { Term t = parse_term_from_string(s); Topform c = term_to_clause(t); zap_term(t); clause_set_variables(c, MAX_VARS); /* fatal if too many vars */ return c; } /* parse_clause_from_string */ /************* * * end_of_list_clause() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL end_of_list_clause(Topform c) { if (c == NULL) return FALSE; else if (number_of_literals(c->literals) != 1) return FALSE; else { Term a = c->literals->atom; if (!CONSTANT(a)) return FALSE; else return is_symbol(SYMNUM(a), "end_of_list", 0); } } /* end_of_list_clause */ /************* * * read_clause_clist() * *************/ /* DOCUMENTATION This routine reads a list of clauses from FILE *fin. If you wish the list to have a name, send a string; othersize send NULL. (You can name the list later with name_clist().) If there are no more clauses in *fin, an empty Clist is returned.

    If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Clist read_clause_clist(FILE *fin, FILE *fout, char *name, BOOL assign_id) { Clist lst = clist_init(name); Topform c; c = read_clause(fin, fout); while (c != NULL && !end_of_list_clause(c)) { if (assign_id) assign_clause_id(c); c->justification = input_just(); clist_append(c, lst); c = read_clause(fin, fout); } if (c != NULL) zap_topform(c); /* end_of_list_clause */ return lst; } /* read_clause_clist */ /************* * * read_clause_list() * *************/ /* DOCUMENTATION Read clauses, up to end_of_list (or EOF), and return them in a Plist. */ /* PUBLIC */ Plist read_clause_list(FILE *fin, FILE *fout, BOOL assign_id) { Clist a = read_clause_clist(fin, fout, NULL, assign_id); return move_clist_to_plist(a); } /* read_clause_list */ /************* * * sb_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. */ /* PUBLIC */ void sb_write_clause_jmap(String_buf sb, Topform c, int format, I3list map) { Term t; if (c->compressed) t = NULL; else t = topform_to_term(c); if (format == CL_FORM_BARE) { if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, "."); } else { if (c->id != 0) { sb_append_id(sb, c->id, map); sb_append(sb, " "); } if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, ". "); if (format == CL_FORM_STD) sb_write_just(sb, c->justification, map); else { /* CL_FORM_PARENTS */ Ilist parents = get_parents(c->justification, TRUE); Ilist p; sb_append(sb, "["); for (p = parents; p; p = p->next) { sb_append_id(sb, p->i, map); if (p->next) sb_append(sb, ","); } sb_append(sb, "]."); } } sb_append(sb, "\n"); if (t) zap_term(t); } /* sb_write_clause_jmap */ /************* * * sb_write_clause() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void sb_write_clause(String_buf sb, Topform c, int format) { sb_write_clause_jmap(sb, c, format, NULL); } /* sb_write_clause */ /************* * * sb_xml_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. It is written in XML format. */ /* PUBLIC */ void sb_xml_write_clause_jmap(String_buf sb, Topform c, I3list map) { sb_append(sb, "\n id, map); sb_append(sb, "\""); if (c->justification && c->justification->type == GOAL_JUST) sb_append(sb, " type=\"goal\""); else if (c->justification && c->justification->type == DENY_JUST) sb_append(sb, " type=\"deny\""); else if (c->justification && c->justification->type == INPUT_JUST) sb_append(sb, " type=\"assumption\""); else if (c->justification && c->justification->type == CLAUSIFY_JUST) sb_append(sb, " type=\"clausify\""); else if (c->justification && c->justification->type == EXPAND_DEF_JUST) sb_append(sb, " type=\"expand_def\""); sb_append(sb, ">\n"); if (c->compressed) sb_append(sb, " clause_is_compressed\n"); else { Literals lit; Term atts; if (c->literals == NULL) { sb_append(sb, " \n"); } else { for (lit = c->literals; lit; lit = lit->next) { Term t = literal_to_term(lit); sb_append(sb, " \n"); zap_term(t); } } atts = attributes_to_term(c->attributes, attrib_sym()); if (atts) { Term t = atts; while (is_term(t, attrib_sym(), 2)) { sb_append(sb, " \n"); t = ARG(t,1); } sb_append(sb, " \n"); zap_term(atts); } } sb_xml_write_just(sb, c->justification, map); sb_append(sb, " \n"); } /* sb_xml_write_clause_jmap */ /************* * * fwrite_clause_jmap() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void fwrite_clause_jmap(FILE *fp, Topform c, int format, I3list map) { if (c == NULL) fprintf(fp, "fwrite_clause_jmap: NULL clause\n"); else { String_buf sb = get_string_buf(); if (format == CL_FORM_XML) sb_xml_write_clause_jmap(sb, c, map); else if (format == CL_FORM_IVY) sb_ivy_write_clause_jmap(sb, c, map); /* BV(2007-aug-20): tagged proof format */ else if (format == CL_FORM_TAGGED) sb_tagged_write_clause_jmap(sb, c, format, map); else sb_write_clause_jmap(sb, c, format, map); fprint_sb(fp, sb); zap_string_buf(sb); } fflush(fp); } /* fwrite_clause_jmap */ /************* * * fwrite_clause() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a clause in mixfix form, followed by ".\n". */ /* PUBLIC */ void fwrite_clause(FILE *fp, Topform c, int format) { fwrite_clause_jmap(fp, c, format, NULL); } /* fwrite_clause */ /************* * * f_clause() * *************/ /* DOCUMENTATION Write a clause to stdout, with id, with justification last. */ /* PUBLIC */ void f_clause(Topform c) { fwrite_clause(stdout, c, CL_FORM_STD); } /* f_clause */ /************* * * fwrite_clause_clist() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Clist of clauses in mixfix form. Example:

    list(sos).
    a = b.
    end_of_list.
    
    If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_clause_clist(FILE *fp, Clist lst, int format) { Clist_pos p; if (lst->name == NULL || str_ident(lst->name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", lst->name); for (p = lst->first; p != NULL; p = p->next) fwrite_clause(fp, p->c, format); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_clause_clist */ /************* * * fwrite_demod_clist() * *************/ /* DOCUMENTATION Similar to fwirte_clause_clist, except that lex-dep demodulators are noted. */ /* PUBLIC */ void fwrite_demod_clist(FILE *fp, Clist lst, int format) { Clist_pos p; if (lst->name == NULL || str_ident(lst->name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", lst->name); for (p = lst->first; p != NULL; p = p->next) { Topform c = p->c; fwrite_clause(fp, c, format); if (unit_clause(c->literals)&& pos_eq(c->literals) && !oriented_eq(c->literals->atom)) { fprintf(fp, " %% (lex-dep)\n"); } } fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_demod_clist */ /************* * * fwrite_clause_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a Plist of clauses in mixfix form. Example:
    list(sos).
    a = b.
    end_of_list.
    
    If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_clause_list(FILE *fp, Plist lst, char *name, int format) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", name); for (p = lst; p != NULL; p = p->next) fwrite_clause(fp, p->v, format); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_clause_list */ /************* * * f_clauses() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void f_clauses(Plist p) { fwrite_clause_list(stdout, p, "", CL_FORM_STD); } /* f_clauses */ /************* * * read_formula() * *************/ /* DOCUMENTATION This routine reads a formula from FILE *fin. If there are no more formulas in *fin, NULL is returned.

    If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Formula read_formula(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Formula f = term_to_formula(t); zap_term(t); return f; } } /* read_formula */ /************* * * end_of_list_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ BOOL end_of_list_formula(Formula f) { if (f == NULL) return FALSE; else if (f->type != ATOM_FORM) return FALSE; else { Term a = f->atom; if (!CONSTANT(a)) return FALSE; else return is_symbol(SYMNUM(a), "end_of_list", 0); } } /* end_of_list_formula */ /************* * * read_formula_list() * *************/ /* DOCUMENTATION This routine reads a list of formulas from FILE *fin. If there are no more formulas in *fin, NULL is returned.

    If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Plist read_formula_list(FILE *fin, FILE *fout) { Plist p = NULL; Formula f; f = read_formula(fin, fout); while (f != NULL && !end_of_list_formula(f)) { p = plist_prepend(p, f); f = read_formula(fin, fout); } if (f != NULL) zap_formula(f); p = reverse_plist(p); return p; } /* read_formula_list */ /************* * * fwrite_formula_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a list of formulas in mixfix form. Example:

    list(sos).
    a = b.
    end_of_list.
    
    If the name of the list is "", it is written as list(anonymous). */ /* PUBLIC */ void fwrite_formula_list(FILE *fp, Plist lst, char *name) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nformulas(anonymous).\n"); else fprintf(fp, "\nformulas(%s).\n", name); for (p = lst; p != NULL; p = p->next) fwrite_formula(fp, p->v); fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_formula_list */ /************* * * zap_formula_list() * *************/ /* DOCUMENTATION Free a Plist of formulas. */ /* PUBLIC */ void zap_formula_list(Plist lst) { Plist p = lst; while (p != NULL) { Plist p2 = p; p = p->next; zap_formula(p2->v); free_plist(p2); } } /* zap_formula_list */ /************* * * end_of_list_term() * *************/ /* DOCUMENTATION Check if a term is the constant "end_of_list". */ /* PUBLIC */ BOOL end_of_list_term(Term t) { if (t == NULL) return FALSE; else if (!CONSTANT(t)) return FALSE; else return is_symbol(SYMNUM(t), "end_of_list", 0); } /* end_of_list_term */ /************* * * end_of_commands_term() * *************/ /* DOCUMENTATION Check if a term is the constant "end_of_commands". */ /* PUBLIC */ BOOL end_of_commands_term(Term t) { if (t == NULL) return FALSE; else if (!CONSTANT(t)) return FALSE; else return is_symbol(SYMNUM(t), "end_of_commands", 0); } /* end_of_commands_term */ /************* * * read_term_list() * *************/ /* DOCUMENTATION This routine reads a list of terms from FILE *fin. If there are no more terms in *fin, NULL is returned.

    None of the returned terms or their subterms will have type VARIABLE, even if it looks like a variable (e.g., x).

    If any error occurs, a message is sent to FILE *fout and a fatal_error occurs. */ /* PUBLIC */ Plist read_term_list(FILE *fin, FILE *fout) { Plist p = NULL; Term t; t = read_term(fin, fout); while (t != NULL && !end_of_list_term(t)) { p = plist_prepend(p, t); t = read_term(fin, fout); } if (t != NULL) zap_term(t); p = reverse_plist(p); return p; } /* read_term_list */ /************* * * fwrite_term_list() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) a list of terms in mixfix form. Example:

    list(sos).
    a = b.
    end_of_list.
    
    If the name of the list is "" or NULL, it is written as list(anonymous). */ /* PUBLIC */ void fwrite_term_list(FILE *fp, Plist lst, char *name) { Plist p; if (name == NULL || str_ident(name, "")) fprintf(fp, "\nlist(anonymous).\n"); else fprintf(fp, "\nlist(%s).\n", name); for (p = lst; p != NULL; p = p->next) { fwrite_term(fp, p->v); fprintf(fp, ".\n"); } fprintf(fp, "end_of_list.\n"); fflush(fp); } /* fwrite_term_list */ /************* * * term_reader() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A term is read from stdin (NULL if there are none). Errors are fatal. */ /* PUBLIC */ Term term_reader(BOOL fast) { if (fast) return fast_read_term(stdin, stderr); else return read_term(stdin, stderr); } /* term_reader */ /************* * * term_writer() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The term is written to stdout, with a period and newline. */ /* PUBLIC */ void term_writer(Term t, BOOL fast) { if (fast) fast_fwrite_term_nl(stdout, t); else fwrite_term_nl(stdout, t); fflush(stdout); } /* term_writer */ /************* * * clause_reader() * *************/ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. A clause is read from stdin (NULL if there are none). Errors are fatal. */ /* PUBLIC */ Topform clause_reader(BOOL fast) { if (fast) return fast_read_clause(stdin, stderr); else return read_clause(stdin, stderr); } /* clause_reader */ /* DOCUMENTATION If your program has optional fast parsing/writing, you can use this routine to save a few lines of code. The flag "fast" says whether or not to use fast parse form. The clause is written to stdout, with a period and newline. */ /* PUBLIC */ void clause_writer(Topform c, BOOL fast) { if (fast) fast_fwrite_clause(stdout, c); else fwrite_clause(stdout, c, CL_FORM_BARE); fflush(stdout); } /* clause_writer */ /************* * * term_to_topform2() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform term_to_topform2(Term t) { Formula f = term_to_formula(t); Topform tf; if (clausal_formula(f)) { tf = formula_to_clause(f); tf->attributes = copy_attributes(f->attributes); zap_formula(f); clause_set_variables(tf, MAX_VARS); } else { tf = get_topform(); tf->is_formula = TRUE; tf->attributes = f->attributes; f->attributes = NULL; tf->formula = universal_closure(f); } return tf; } /* term_to_topform2 */ /************* * * read_clause_or_formula() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform read_clause_or_formula(FILE *fin, FILE *fout) { Term t = read_term(fin, fout); if (t == NULL) return NULL; else { Topform tf = term_to_topform2(t); zap_term(t); return tf; } } /* read_clause_or_formula */ /************* * * read_clause_or_formula_list() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Plist read_clause_or_formula_list(FILE *fin, FILE *fout) { Plist lst = NULL; Topform tf = read_clause_or_formula(fin, fout); while (tf != NULL && !end_of_list_clause(tf)) { lst = plist_prepend(lst, tf); tf = read_clause_or_formula(fin, fout); } if (tf) zap_topform(tf); return reverse_plist(lst); } /* read_clause_or_formula_list */ /* *************************************************************************** BV(2007-aug-20): new functions to support tagged proofs (prooftrans) **************************************************************************/ /************* * * sb_tagged_write_clause_jmap() * *************/ /* DOCUMENTATION This routine writes a clause (in mixfix form, with ".\n") to a String_buf. */ /* PUBLIC */ void sb_tagged_write_clause_jmap(String_buf sb, Topform c, int format, I3list map) { Term t; if (c->compressed) t = NULL; else t = topform_to_term(c); if (c->id != 0) { /* BV(2007-jul-13) */ sb_append(sb, "c "); sb_append_id(sb, c->id, map); sb_append(sb, " "); } if (t == NULL) sb_append(sb, "clause_is_compressed"); else sb_write_term(sb, t); sb_append(sb, "\n"); sb_tagged_write_just(sb, c->justification, map); // sb_append(sb, " *** call to sb_tagged_write_just ***\n"); sb_append(sb, "e\n"); if (t) zap_term(t); } /* sb_tagged_write_clause_jmap */ LADR-2009-11A/bob/just.c0000644000175000017500000013655211013103314013710 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "just.h" /* Private definitions and types */ /* * memory management */ #define PTRS_JUST PTRS(sizeof(struct just)) static unsigned Just_gets, Just_frees; #define PTRS_PARAJUST PTRS(sizeof(struct parajust)) static unsigned Parajust_gets, Parajust_frees; #define PTRS_INSTANCEJUST PTRS(sizeof(struct instancejust)) static unsigned Instancejust_gets, Instancejust_frees; #define PTRS_IVYJUST PTRS(sizeof(struct ivyjust)) static unsigned Ivyjust_gets, Ivyjust_frees; /************* * * Just get_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just get_just(void) { Just p = get_cmem(PTRS_JUST); Just_gets++; return(p); } /* get_just */ /************* * * free_just() * *************/ static void free_just(Just p) { free_mem(p, PTRS_JUST); Just_frees++; } /* free_just */ /************* * * Parajust get_parajust() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Parajust get_parajust(void) { Parajust p = get_cmem(PTRS_PARAJUST); Parajust_gets++; return(p); } /* get_parajust */ /************* * * free_parajust() * *************/ static void free_parajust(Parajust p) { free_mem(p, PTRS_PARAJUST); Parajust_frees++; } /* free_parajust */ /************* * * Instancejust get_instancejust() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Instancejust get_instancejust(void) { Instancejust p = get_cmem(PTRS_INSTANCEJUST); Instancejust_gets++; return(p); } /* get_instancejust */ /************* * * free_instancejust() * *************/ static void free_instancejust(Instancejust p) { free_mem(p, PTRS_INSTANCEJUST); Instancejust_frees++; } /* free_instancejust */ /************* * * Ivyjust get_ivyjust() * *************/ static Ivyjust get_ivyjust(void) { Ivyjust p = get_mem(PTRS_IVYJUST); Ivyjust_gets++; return(p); } /* get_ivyjust */ /************* * * free_ivyjust() * *************/ static void free_ivyjust(Ivyjust p) { free_mem(p, PTRS_IVYJUST); Ivyjust_frees++; } /* free_ivyjust */ /************* * * fprint_just_mem() * *************/ /* DOCUMENTATION This routine prints (to FILE *fp) memory usage statistics for data types associated with the just package. The Boolean argument heading tells whether to print a heading on the table. */ /* PUBLIC */ void fprint_just_mem(FILE *fp, BOOL heading) { int n; if (heading) fprintf(fp, " type (bytes each) gets frees in use bytes\n"); n = sizeof(struct just); fprintf(fp, "just (%4d) %11u%11u%11u%9.1f K\n", n, Just_gets, Just_frees, Just_gets - Just_frees, ((Just_gets - Just_frees) * n) / 1024.); n = sizeof(struct parajust); fprintf(fp, "parajust (%4d) %11u%11u%11u%9.1f K\n", n, Parajust_gets, Parajust_frees, Parajust_gets - Parajust_frees, ((Parajust_gets - Parajust_frees) * n) / 1024.); n = sizeof(struct instancejust); fprintf(fp, "instancejust (%4d) %11u%11u%11u%9.1f K\n", n, Instancejust_gets, Instancejust_frees, Instancejust_gets - Instancejust_frees, ((Instancejust_gets - Instancejust_frees) * n) / 1024.); n = sizeof(struct ivyjust); fprintf(fp, "ivyjust (%4d) %11u%11u%11u%9.1f K\n", n, Ivyjust_gets, Ivyjust_frees, Ivyjust_gets - Ivyjust_frees, ((Ivyjust_gets - Ivyjust_frees) * n) / 1024.); } /* fprint_just_mem */ /************* * * p_just_mem() * *************/ /* DOCUMENTATION This routine prints (to stdout) memory usage statistics for data types associated with the just package. */ /* PUBLIC */ void p_just_mem() { fprint_just_mem(stdout, TRUE); } /* p_just_mem */ /* * end of memory management */ /************* * * ivy_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just ivy_just(Just_type type, int parent1, Ilist pos1, int parent2, Ilist pos2, Plist pairs) { Just j = get_just(); j->type = IVY_JUST; j->u.ivy = get_ivyjust(); j->u.ivy->type = type; j->u.ivy->parent1 = parent1; j->u.ivy->parent2 = parent2; j->u.ivy->pos1 = pos1; j->u.ivy->pos2 = pos2; j->u.ivy->pairs = pairs; return j; } /* ivy_just */ /************* * * input_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for input. */ /* PUBLIC */ Just input_just(void) { /* (INPUT_JUST) */ Just j = get_just(); j->type = INPUT_JUST; return j; } /* input_just */ /************* * * goal_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for goal. */ /* PUBLIC */ Just goal_just(void) { /* (GOAL_JUST) */ Just j = get_just(); j->type = GOAL_JUST; return j; } /* goal_just */ /************* * * deny_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for deny. */ /* PUBLIC */ Just deny_just(Topform tf) { /* (DENY_JUST) */ Just j = get_just(); j->type = DENY_JUST; j->u.id = tf->id; return j; } /* deny_just */ /************* * * clausify_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for clausify. */ /* PUBLIC */ Just clausify_just(Topform tf) { /* (CLAUSIFY_JUST) */ Just j = get_just(); j->type = CLAUSIFY_JUST; j->u.id = tf->id; return j; } /* clausify_just */ /************* * * expand_def_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for expand_def. */ /* PUBLIC */ Just expand_def_just(Topform tf, Topform def) { /* (expand_def_JUST) */ Just j = get_just(); j->type = EXPAND_DEF_JUST; j->u.lst = ilist_append(ilist_append(NULL, tf->id), def->id); return j; } /* expand_def_just */ /************* * * copy_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for copy. */ /* PUBLIC */ Just copy_just(Topform c) { /* (COPY_JUST parent_id) */ Just j = get_just(); j->type = COPY_JUST; j->u.id = c->id; return j; } /* copy_just */ /************* * * propositional_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for propositional. */ /* PUBLIC */ Just propositional_just(Topform c) { /* (PROPOSITIONAL_JUST parent_id) */ Just j = get_just(); j->type = PROPOSITIONAL_JUST; j->u.id = c->id; return j; } /* propositional_just */ /************* * * new_symbol_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for new_symbol inference. */ /* PUBLIC */ Just new_symbol_just(Topform c) { /* (NEW_SYMBOL_JUST parent_id) */ Just j = get_just(); j->type = NEW_SYMBOL_JUST; j->u.id = c->id; return j; } /* new_symbol_just */ /************* * * back_demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_demod. */ /* PUBLIC */ Just back_demod_just(Topform c) { /* (BACK_DEMOD_JUST parent_id) */ Just j = get_just(); j->type = BACK_DEMOD_JUST; j->u.id = c->id; return j; } /* back_demod_just */ /************* * * back_unit_deletion_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for back_unit_deletion. */ /* PUBLIC */ Just back_unit_deletion_just(Topform c) { /* (BACK_UNIT_DEL_JUST parent_id) */ Just j = get_just(); j->type = BACK_UNIT_DEL_JUST; j->u.id = c->id; return j; } /* back_unit_deletion_just */ /************* * * binary_res_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for binary resolution. (Binary res justifications may also be constructed in resolve(), along with hyper and UR.) */ /* PUBLIC */ Just binary_res_just(Topform c1, int n1, Topform c2, int n2) { /* (BINARY_RES_JUST (id1 lit1 id2 lit2) */ Just j = get_just(); j->type = BINARY_RES_JUST; j->u.lst = ilist_append( ilist_append( ilist_append( ilist_append(NULL,c1->id),n1),c2->id),n2); return j; } /* binary_res_just */ /************* * * binary_res_just_by_id() * *************/ /* DOCUMENTATION Similar to binary_res_just, except that IDs are given instead of clauses. */ /* PUBLIC */ Just binary_res_just_by_id(int c1, int n1, int c2, int n2) { /* (BINARY_RES_JUST (id1 lit1 id2 lit2) */ Just j = get_just(); j->type = BINARY_RES_JUST; j->u.lst = ilist_append( ilist_append( ilist_append( ilist_append(NULL,c1),n1),c2),n2); return j; } /* binary_res_just_by_id */ /************* * * factor_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just factor_just(Topform c, int lit1, int lit2) { /* (FACTOR_JUST (clause_id lit1 lit2)) */ Just j = get_just(); j->type = FACTOR_JUST; j->u.lst = ilist_append(ilist_append(ilist_append(NULL,c->id),lit1),lit2); return j; } /* factor_just */ /************* * * xxres_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for resolution with x=x. */ /* PUBLIC */ Just xxres_just(Topform c, int lit) { /* (XXRES_JUST (clause_id lit)) */ Just j = get_just(); j->type = XXRES_JUST; j->u.lst = ilist_append(ilist_append(NULL,c->id),lit); return j; } /* xxres_just */ /************* * * resolve_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for resolution rules. This handles binary, hyper, ur, and maybe others. */ /* PUBLIC */ Just resolve_just(Ilist g, Just_type type) { Just j = get_just(); j->type = type; j->u.lst = g; return j; } /* resolve_just */ /************* * * demod_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for a demodulation. */ /* PUBLIC */ Just demod_just(I3list steps) { Just j = get_just(); j->type = DEMOD_JUST; j->u.demod = steps; return j; } /* demod_just */ /************* * * para_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are not copied. */ /* PUBLIC */ Just para_just(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec) { Just j = get_just(); j->type = rule; j->u.para = get_parajust(); j->u.para->from_id = from->id; j->u.para->into_id = into->id; j->u.para->from_pos = from_vec; j->u.para->into_pos = into_vec; return j; } /* para_just */ /************* * * instance_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for an instance inference. The list of pairs is not copied. */ /* PUBLIC */ Just instance_just(Topform parent, Plist pairs) { Just j = get_just(); j->type = INSTANCE_JUST; j->u.instance = get_instancejust(); j->u.instance->parent_id = parent->id; j->u.instance->pairs = pairs; return j; } /* instance_just */ /************* * * para_just_rev_copy() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a paramodulation inference. The position vectors are copied and reversed. */ /* PUBLIC */ Just para_just_rev_copy(Just_type rule, Topform from, Ilist from_vec, Topform into, Ilist into_vec) { return para_just(rule, from, reverse_ilist(copy_ilist(from_vec)), into, reverse_ilist(copy_ilist(into_vec))); } /* para_just_rev_copy */ /************* * * unit_del_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification list for a factorization. */ /* PUBLIC */ Just unit_del_just(Topform deleter, int literal_num) { /* UNIT_DEL (literal-num clause-id) */ Just j = get_just(); j->type = UNIT_DEL_JUST; j->u.lst = ilist_append(ilist_append(NULL, literal_num), deleter->id); return j; } /* cd_just */ /************* * * flip_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for equality flipping. */ /* PUBLIC */ Just flip_just(int n) { Just j = get_just(); j->type = FLIP_JUST; j->u.id = n; return j; } /* flip_just */ /************* * * xx_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the XX rule, which removes literals that are instances of x!=x. */ /* PUBLIC */ Just xx_just(int n) { Just j = get_just(); j->type = XX_JUST; j->u.id = n; return j; } /* xx_just */ /************* * * merge_just() * *************/ /* DOCUMENTATION This routine builds and returns a justification for the merging a literal. The n-th literal has been removed because it is identical to another literal. */ /* PUBLIC */ Just merge_just(int n) { Just j = get_just(); j->type = MERGE_JUST; j->u.id = n; return j; } /* merge_just */ /************* * * append_just() * *************/ /* DOCUMENTATION This appends two justifications. No copying occurs. */ /* PUBLIC */ Just append_just(Just j1, Just j2) { if (j1 == NULL) return j2; else { j1->next = append_just(j1->next, j2); return j1; } } /* append_just */ /************* * * copy_justification() * *************/ /* DOCUMENTATION Copy a justification. */ /* PUBLIC */ Just copy_justification(Just j) { if (j == NULL) return NULL; else { Just j2 = get_just(); j2->type = j->type; j2->next = copy_justification(j->next); switch (j->type) { case INPUT_JUST: case GOAL_JUST: break; case DENY_JUST: case CLAUSIFY_JUST: case COPY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: j2->u.id = j->u.id; break; case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: j2->u.lst = copy_ilist(j->u.lst); break; case DEMOD_JUST: j2->u.demod = copy_i3list(j->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: j2->u.para = get_parajust(); j2->u.para->from_id = j->u.para->from_id; j2->u.para->into_id = j->u.para->into_id; j2->u.para->from_pos = copy_ilist(j->u.para->from_pos); j2->u.para->into_pos = copy_ilist(j->u.para->into_pos); break; case INSTANCE_JUST: j2->u.instance = get_instancejust(); j2->u.instance->parent_id = j->u.instance->parent_id; j2->u.instance->pairs = copy_plist_of_terms(j->u.instance->pairs); break; case IVY_JUST: j2->u.ivy = get_ivyjust(); j2->u.ivy->type = j->u.ivy->type; j2->u.ivy->parent1 = j->u.ivy->parent1; j2->u.ivy->parent2 = j->u.ivy->parent2; j2->u.ivy->pos1 = copy_ilist(j->u.ivy->pos1); j2->u.ivy->pos2 = copy_ilist(j->u.ivy->pos2); j2->u.ivy->pairs = copy_plist_of_terms(j->u.ivy->pairs); break; default: fatal_error("copy_justification: unknown type"); } return j2; } } /* copy_justification */ /************* * * jstring() - strings for printing justifications * *************/ /* DOCUMENTATION What is the string, e.g., "resolve" associated with a justification node? */ /* PUBLIC */ char *jstring(Just j) { switch (j->type) { /* primary justifications */ case INPUT_JUST: return "assumption"; case GOAL_JUST: return "goal"; case DENY_JUST: return "deny"; case CLAUSIFY_JUST: return "clausify"; case COPY_JUST: return "copy"; case PROPOSITIONAL_JUST: return "propositional"; case NEW_SYMBOL_JUST: return "new_symbol"; case BACK_DEMOD_JUST: return "back_rewrite"; case BACK_UNIT_DEL_JUST: return "back_unit_del"; case EXPAND_DEF_JUST: return "expand_def"; case BINARY_RES_JUST: return "resolve"; case HYPER_RES_JUST: return "hyper"; case UR_RES_JUST: return "ur"; case FACTOR_JUST: return "factor"; case XXRES_JUST: return "xx_res"; case PARA_JUST: return "para"; case PARA_FX_JUST: return "para_fx"; case PARA_IX_JUST: return "para_ix"; case PARA_FX_IX_JUST: return "para_fx_ix"; case INSTANCE_JUST: return "instantiate"; case IVY_JUST: return "ivy"; /* secondary justifications */ case FLIP_JUST: return "flip"; case XX_JUST: return "xx"; case MERGE_JUST: return "merge"; case DEMOD_JUST: return "rewrite"; case UNIT_DEL_JUST: return "unit_del"; case UNKNOWN_JUST: return "unknown"; } return "unknown"; } /* jstring */ /************* * * jstring_to_jtype() - strings for printing justifications * *************/ static int jstring_to_jtype(char *s) { if (str_ident(s, "assumption")) return INPUT_JUST; else if (str_ident(s, "goal")) return GOAL_JUST; else if (str_ident(s, "deny")) return DENY_JUST; else if (str_ident(s, "clausify")) return CLAUSIFY_JUST; else if (str_ident(s, "copy")) return COPY_JUST; else if (str_ident(s, "propositional")) return PROPOSITIONAL_JUST; else if (str_ident(s, "new_symbol")) return NEW_SYMBOL_JUST; else if (str_ident(s, "back_rewrite")) return BACK_DEMOD_JUST; else if (str_ident(s, "back_unit_del")) return BACK_UNIT_DEL_JUST; else if (str_ident(s, "expand_def")) return EXPAND_DEF_JUST; else if (str_ident(s, "resolve")) return BINARY_RES_JUST; else if (str_ident(s, "hyper")) return HYPER_RES_JUST; else if (str_ident(s, "ur")) return UR_RES_JUST; else if (str_ident(s, "factor")) return FACTOR_JUST; else if (str_ident(s, "xx_res")) return XXRES_JUST; else if (str_ident(s, "para")) return PARA_JUST; else if (str_ident(s, "para_fx")) return PARA_FX_JUST; else if (str_ident(s, "para_ix")) return PARA_IX_JUST; else if (str_ident(s, "instantiate")) return INSTANCE_JUST; else if (str_ident(s, "para_fx_ix")) return PARA_FX_IX_JUST; else if (str_ident(s, "flip")) return FLIP_JUST; else if (str_ident(s, "xx")) return XX_JUST; else if (str_ident(s, "merge")) return MERGE_JUST; else if (str_ident(s, "rewrite")) return DEMOD_JUST; else if (str_ident(s, "unit_del")) return UNIT_DEL_JUST; else if (str_ident(s, "ivy")) return IVY_JUST; else return UNKNOWN_JUST; } /* jstring_to_jtype */ /************* * * itoc() * *************/ static char itoc(int i) { if (i <= 0) return '?'; else if (i <= 26) return 'a' + i - 1; else if (i <= 52) return 'A' + i - 27; else return '?'; } /* itoc */ /************* * * ctoi() * *************/ static int ctoi(char c) { if (c >= 'a' && c <= 'z') return c - 'a' + 1; else if (c >= 'A' && c <= 'Z') return c - 'A' + 27; else return INT_MIN; } /* ctoi */ /************* * * jmap1() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns the first. If i is not in the map, i is returned. */ /* PUBLIC */ int jmap1(I3list map, int i) { int id = assoc2a(map, i); return (id == INT_MIN ? i : id); } /* jmap1 */ /************* * * jmap2() * *************/ /* DOCUMENTATION A jmap maps ints to pairs of ints. This returns a string representation of the second. If i is not in the map, or if the int value of is INT_MIN, "" is returned. Starting with 0, the strings are "A" - "Z", "A26", "A27", ... . The argument *a must point to available space for the result. The result is returned. */ /* PUBLIC */ char *jmap2(I3list map, int i, char *a) { int n = assoc2b(map, i); if (n == INT_MIN) a[0] = '\0'; else if (n >= 0 && n <= 25) { /* "A" -- "Z" */ a[0] = 'A' + n; a[1] = '\0'; } else { /* "A26", ... */ a[0] = 'A'; sprintf(a+1, "%d", n); } return a; } /* jmap2 */ /************* * * sb_append_id() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_append_id(String_buf sb, int id, I3list map) { char s[21]; sb_append_int(sb, jmap1(map, id)); sb_append(sb, jmap2(map, id, s)); } /* sb_append_id */ /************* * * sb_write_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void sb_write_res_just(String_buf sb, Just g, I3list map) { Ilist q; Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); for (q = p->next; q != NULL; q = q->next->next->next) { int nuc_lit = q->i; int sat_id = q->next->i; int sat_lit = q->next->next->i; sb_append(sb, ","); sb_append_char(sb, itoc(nuc_lit)); if (sat_id == 0) sb_append(sb, ",xx"); else { sb_append(sb, ","); sb_append_id(sb, sat_id, map); sb_append(sb, ","); if (sat_lit > 0) sb_append_char(sb, itoc(sat_lit)); else { sb_append_char(sb, itoc(-sat_lit)); sb_append(sb, "(flip)"); } } } sb_append(sb, ")"); } /* sb_write_res_just */ /************* * * sb_write_position() - like this (a,2,1,3) * *************/ static void sb_write_position(String_buf sb, Ilist p) { Ilist q; sb_append(sb, "("); sb_append_char(sb, itoc(p->i)); for (q = p->next; q != NULL; q = q->next) { sb_append(sb, ","); sb_append_int(sb, q->i); } sb_append(sb, ")"); } /* sb_write_position */ /************* * * sb_write_ids() - separated by space * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_write_ids(String_buf sb, Ilist p, I3list map) { Ilist q; for (q = p; q; q = q->next) { sb_append_id(sb, q->i, map); if (q->next) sb_append(sb, " "); } } /* sb_write_ids */ /************* * * sb_write_just() * *************/ /* DOCUMENTATION This routine writes (to a String_buf) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void sb_write_just(String_buf sb, Just just, I3list map) { Just g = just; sb_append(sb, "["); while (g != NULL) { Just_type rule = g->type; if (rule == INPUT_JUST || rule == GOAL_JUST) sb_append(sb, jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { sb_write_res_just(sb, g, map); } else if (rule == DEMOD_JUST) { I3list p; sb_append(sb, jstring(g)); sb_append(sb, "(["); for (p = g->u.demod; p; p = p->next) { sb_append_int(sb, p->i); sb_append(sb, "("); sb_append_int(sb, p->j); if (p->k == 2) sb_append(sb, ",R"); sb_append(sb, ")"); sb_append(sb, p->next ? "," : ""); } sb_append(sb, "])"); } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; int n = p->i; int id = p->next->i; sb_append(sb, jstring(g)); sb_append(sb, "("); if (n < 0) { sb_append_char(sb, itoc(-n)); sb_append(sb, "(flip),"); } else { sb_append_char(sb, itoc(n)); sb_append(sb, ","); } sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->next->i)); sb_append(sb, ")"); } else if (rule == XXRES_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ")"); } else if (rule == EXPAND_DEF_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_id(sb, p->next->i, map); sb_append(sb, ")"); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == NEW_SYMBOL_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_char(sb, itoc(id)); sb_append(sb, ")"); } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->from_id, map); sb_write_position(sb, p->from_pos); sb_append(sb, ","); sb_append_id(sb, p->into_id, map); sb_write_position(sb, p->into_pos); sb_append(sb, ")"); } else if (rule == INSTANCE_JUST) { Plist p; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_int(sb, g->u.instance->parent_id); sb_append(sb, ",["); for (p = g->u.instance->pairs; p; p = p->next) { sb_write_term(sb, p->v); if (p->next) sb_append(sb, ","); } sb_append(sb, "])"); } else if (rule == IVY_JUST) { sb_append(sb, jstring(g)); } else { printf("\nunknown rule: %d\n", rule); fatal_error("sb_write_just: unknown rule"); } g = g->next; if (g) sb_append(sb, ","); } sb_append(sb, "]."); } /* sb_write_just */ /************* * * sb_xml_write_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void sb_xml_write_just(String_buf sb, Just just, I3list map) { Just g; /* Put the standard form into an attribute. */ String_buf sb_standard = get_string_buf(); sb_write_just(sb_standard, just, map); sb_append(sb, " \n"); /* Put an abbreviated form (rule, parents) into an XML elements. */ for (g = just; g; g = g->next) { Ilist parents = get_parents(g, FALSE); /* for this node only */ if (g == just) sb_append(sb, " \n"); /* close the \n"); } /* sb_xml_write_just */ /************* * * p_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void p_just(Just j) { String_buf sb = get_string_buf(); sb_write_just(sb, j, NULL); sb_append(sb, "\n"); fprint_sb(stdout, sb); zap_string_buf(sb); } /* p_just */ /************* * * zap_parajust() * *************/ static void zap_parajust(Parajust p) { zap_ilist(p->from_pos); zap_ilist(p->into_pos); free_parajust(p); } /* zap_parajust */ /************* * * zap_instancejust() * *************/ static void zap_instancejust(Instancejust p) { zap_plist_of_terms(p->pairs); free_instancejust(p); } /* zap_instancejust */ /************* * * zap_ivyjust() * *************/ static void zap_ivyjust(Ivyjust p) { zap_ilist(p->pos1); zap_ilist(p->pos2); zap_plist_of_terms(p->pairs); free_ivyjust(p); } /* zap_ivyjust */ /************* * * zap_just() * *************/ /* DOCUMENTATION This routine frees a justification list, including any sublists. */ /* PUBLIC */ void zap_just(Just just) { if (just != NULL) { zap_just(just->next); switch (just->type) { case INPUT_JUST: case GOAL_JUST: case DENY_JUST: case CLAUSIFY_JUST: case COPY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: case FLIP_JUST: case XX_JUST: case MERGE_JUST: break; /* nothing to do */ case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case UNIT_DEL_JUST: case FACTOR_JUST: case XXRES_JUST: zap_ilist(just->u.lst); break; case DEMOD_JUST: zap_i3list(just->u.demod); break; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: zap_parajust(just->u.para); break; case INSTANCE_JUST: zap_instancejust(just->u.instance); break; case IVY_JUST: zap_ivyjust(just->u.ivy); break; default: fatal_error("zap_just: unknown type"); } free_just(just); } } /* zap_just */ /************* * * get_parents() * *************/ /* DOCUMENTATION This routine returns an Ilist of parent IDs. If (all), get parents from the whole justification; otherwise get parents from the first node only. */ /* PUBLIC */ Ilist get_parents(Just just, BOOL all) { Ilist parents = NULL; Just g = just; while (g) { Just_type rule = g->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid nuclit sat1id sat1lit nuclit2 sat2id sat2lit ...)] */ Ilist p = g->u.lst; int nuc_id = p->i; parents = ilist_prepend(parents, nuc_id); p = p->next; while (p != NULL) { int sat_id = p->next->i; if (sat_id == 0) ; /* resolution with x=x */ else parents = ilist_prepend(parents, sat_id); p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; parents = ilist_prepend(parents, p->from_id); parents = ilist_prepend(parents, p->into_id); } else if (rule == INSTANCE_JUST) { parents = ilist_prepend(parents, g->u.instance->parent_id); } else if (rule == EXPAND_DEF_JUST) { parents = ilist_prepend(parents, g->u.lst->i); parents = ilist_prepend(parents, g->u.lst->next->i); } else if (rule == FACTOR_JUST || rule == XXRES_JUST) { int parent_id = g->u.lst->i; parents = ilist_prepend(parents, parent_id); } else if (rule == UNIT_DEL_JUST) { int parent_id = g->u.lst->next->i; parents = ilist_prepend(parents, parent_id); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST || rule == NEW_SYMBOL_JUST || rule == BACK_UNIT_DEL_JUST) { int parent_id = g->u.id; parents = ilist_prepend(parents, parent_id); } else if (rule == DEMOD_JUST) { I3list p; /* list of triples: (i=ID, j=position, k=direction) */ for (p = g->u.demod; p; p = p->next) parents = ilist_prepend(parents, p->i); } else if (rule == IVY_JUST) { if (g->u.ivy->type == FLIP_JUST || g->u.ivy->type == BINARY_RES_JUST || g->u.ivy->type == PARA_JUST || g->u.ivy->type == INSTANCE_JUST || g->u.ivy->type == PROPOSITIONAL_JUST) parents = ilist_prepend(parents, g->u.ivy->parent1); if (g->u.ivy->type == BINARY_RES_JUST || g->u.ivy->type == PARA_JUST) parents = ilist_prepend(parents, g->u.ivy->parent2); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == GOAL_JUST || rule == INPUT_JUST) ; /* do nothing */ else fatal_error("get_parents, unknown rule."); g = (all ? g->next : NULL); } return reverse_ilist(parents); } /* get_parents */ /************* * * first_negative_parent() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Topform first_negative_parent(Topform c) { Ilist parents = get_parents(c->justification, TRUE); Ilist p; Topform first_neg = NULL; for (p = parents; p && first_neg == NULL; p = p->next) { Topform c = find_clause_by_id(p->i); if (negative_clause_possibly_compressed(c)) first_neg = c; } zap_ilist(p); return first_neg; } /* first_negative_parent */ /************* * * get_clanc() * *************/ static Plist get_clanc(int id, Plist anc) { Topform c = find_clause_by_id(id); if (c == NULL) { printf("get_clanc, clause with id=%d not found.\n", id); fatal_error("get_clanc, clause not found."); } if (!plist_member(anc, c)) { Ilist parents, p; anc = insert_clause_into_plist(anc, c, TRUE); parents = get_parents(c->justification, TRUE); for (p = parents; p; p = p->next) { anc = get_clanc(p->i, anc); } zap_ilist(parents); } return anc; } /* get_clanc */ /************* * * get_clause_ancestors() * *************/ /* DOCUMENTATION This routine returns the Plist of clauses that are ancestors of Topform c, including clause c. The result is sorted (increasing) by ID. If any of the ancestors are compressed, they are uncompressed (in place) and left uncompressed. */ /* PUBLIC */ Plist get_clause_ancestors(Topform c) { Plist ancestors = get_clanc(c->id, NULL); return ancestors; } /* get_clause_ancestors */ /************* * * proof_length() * *************/ /* DOCUMENTATION */ /* PUBLIC */ int proof_length(Plist proof) { return plist_count(proof); } /* proof_length */ /************* * * map_id() * *************/ static int map_id(I2list a, int arg) { int val = assoc(a, arg); return val == INT_MIN ? arg : val; } /* map_id */ /************* * * map_just() * *************/ /* DOCUMENTATION Update the clause IDs in a justification according to the map. */ /* PUBLIC */ void map_just(Just just, I2list map) { Just j; for (j = just; j; j = j->next) { Just_type rule = j->type; if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { /* [rule (nucid n sat1id n n sat2id n ...)] */ Ilist p = j->u.lst; p->i = map_id(map, p->i); /* nucleus */ p = p->next; while (p != NULL) { int sat_id = p->next->i; if (sat_id == 0) ; /* resolution with x=x */ else p->next->i = map_id(map, p->next->i); /* satellite */ p = p->next->next->next; } } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = j->u.para; p->from_id = map_id(map, p->from_id); p->into_id = map_id(map, p->into_id); } else if (rule == INSTANCE_JUST) { Instancejust p = j->u.instance; p->parent_id = map_id(map, p->parent_id); } else if (rule == EXPAND_DEF_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); p->next->i = map_id(map, p->next->i); } else if (rule == FACTOR_JUST || rule == XXRES_JUST) { Ilist p = j->u.lst; p->i = map_id(map, p->i); } else if (rule == UNIT_DEL_JUST) { Ilist p = j->u.lst; p->next->i = map_id(map, p->next->i); } else if (rule == BACK_DEMOD_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST || rule == NEW_SYMBOL_JUST || rule == BACK_UNIT_DEL_JUST) { j->u.id = map_id(map, j->u.id); } else if (rule == DEMOD_JUST) { I3list p; /* list of triples: */ for (p = j->u.demod; p; p = p->next) p->i = map_id(map, p->i); } else if (rule == IVY_JUST) { if (j->u.ivy->type == FLIP_JUST || j->u.ivy->type == BINARY_RES_JUST || j->u.ivy->type == PARA_JUST || j->u.ivy->type == INSTANCE_JUST || j->u.ivy->type == PROPOSITIONAL_JUST) j->u.ivy->parent1 = map_id(map, j->u.ivy->parent1); if (j->u.ivy->type == BINARY_RES_JUST || j->u.ivy->type == PARA_JUST) j->u.ivy->parent2 = map_id(map, j->u.ivy->parent2); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST || rule == GOAL_JUST || rule == INPUT_JUST) ; /* do nothing */ else fatal_error("get_clanc, unknown rule."); } } /* map_just */ /************* * * just_count() * *************/ /* DOCUMENTATION Return the number of justification elements in a justtification. */ /* PUBLIC */ int just_count(Just j) { if (j == 0) return 0; else return 1 + just_count(j->next); } /* just_count */ /************* * * mark_parents_as_used() * *************/ /* DOCUMENTATION */ /* PUBLIC */ void mark_parents_as_used(Topform c) { Ilist parents = get_parents(c->justification, TRUE); Ilist p; for (p = parents; p; p = p->next) { Topform parent = find_clause_by_id(p->i); parent->used = TRUE; } zap_ilist(parents); } /* mark_parents_as_used */ /************* * * cl_level() * *************/ static I2list cl_level(Topform c, I2list others) { int level = assoc(others, c->id); if (level != INT_MIN) return others; else { Ilist parents = get_parents(c->justification, TRUE); Ilist p; int max = -1; for (p = parents; p; p = p->next) { Topform parent = find_clause_by_id(p->i); int parent_level; others = cl_level(parent, others); parent_level = assoc(others, parent->id); max = IMAX(max, parent_level); } others = alist_insert(others, c->id, max+1); return others; } } /* cl_level */ /************* * * clause_level() * *************/ /* DOCUMENTATION Return the level of a clause. Input clauses have level=0, and a derived clause has level 1 more than the max of the levels of its parents. */ /* PUBLIC */ int clause_level(Topform c) { I2list ancestors = cl_level(c, NULL); int level = assoc(ancestors, c->id); zap_i2list(ancestors); return level; } /* clause_level */ /************* * * lit_string_to_int() * *************/ static int lit_string_to_int(char *s) { int i; if (str_to_int(s, &i)) return i; else if (strlen(s) > 1) return INT_MIN; else return ctoi(s[0]); } /* lit_string_to_int */ /************* * * args_to_ilist() * *************/ static Ilist args_to_ilist(Term t) { Ilist p = NULL; int i; for (i = 0; i < ARITY(t); i++) { Term a = ARG(t,i); char *s = sn_to_str(SYMNUM(a)); int x = lit_string_to_int(s); if (x > 0) { if (ARITY(a) == 1 && is_constant(ARG(a,0), "flip")) p = ilist_append(p, -x); else p = ilist_append(p, x); } else if (str_ident(s, "xx")) p = ilist_append(ilist_append(p, 0), 0); else fatal_error("args_to_ilist, bad arg"); } return p; } /* args_to_ilist */ /************* * * term_to_just() * *************/ /* DOCUMENTATION */ /* PUBLIC */ Just term_to_just(Term lst) { if (nil_term(lst)) return NULL; else { Term t = ARG(lst,0); Just j = get_just(); j->next = term_to_just(ARG(lst,1)); /* do the tail */ j->type = jstring_to_jtype(sn_to_str(SYMNUM(t))); switch (j->type) { /* primary and secondary are mixed */ case INPUT_JUST: case GOAL_JUST: return j; case COPY_JUST: case DENY_JUST: case CLAUSIFY_JUST: case PROPOSITIONAL_JUST: case NEW_SYMBOL_JUST: case BACK_DEMOD_JUST: case BACK_UNIT_DEL_JUST: { int id; if (term_to_int(ARG(t,0), &id)) j->u.id = id; else fatal_error("term_to_just, bad just id"); return j; } case FLIP_JUST: /* secondary */ case XX_JUST: /* secondary */ case MERGE_JUST: /* secondary */ { j->u.id = lit_string_to_int(sn_to_str(SYMNUM(ARG(t,0)))); return j; } case DEMOD_JUST: /* secondary, rewrite([id(pos,side), ... ]) */ { I3list p = NULL; Term lst = ARG(t,0); if (!proper_listterm(lst)) fatal_error("term_to_just: rewrites must be proper list"); while(cons_term(lst)) { Term a = ARG(lst,0); int i, j; int k = 0; char *s = sn_to_str(SYMNUM(a)); if (ARITY(a) == 2 && str_to_int(s,&i) & term_to_int(ARG(a,0),&j)) { if (is_constant(ARG(a,1), "L")) k = 1; else if (is_constant(ARG(a,1), "R")) k = 2; else fatal_error("term_to_just: bad justification term (demod 1)"); p = i3list_append(p, i, j, k); } else if (ARITY(a) == 1 && str_to_int(s,&i) & term_to_int(ARG(a,0),&j)) { p = i3list_append(p, i, j, 1); } else fatal_error("term_to_just: bad justification term (demod 2)"); lst = ARG(lst,1); } j->u.demod = p; return j; } case EXPAND_DEF_JUST: case BINARY_RES_JUST: case HYPER_RES_JUST: case UR_RES_JUST: case FACTOR_JUST: case XXRES_JUST: case UNIT_DEL_JUST: /* secondary */ j->u.lst = args_to_ilist(t); return j; case PARA_JUST: case PARA_FX_JUST: case PARA_IX_JUST: case PARA_FX_IX_JUST: { int id; Term from = ARG(t,0); Term into = ARG(t,1); Parajust p = get_parajust(); j->u.para = p; if (str_to_int(sn_to_str(SYMNUM(from)), &id)) p->from_id = id; else fatal_error("term_to_just, bad from_id"); p->from_pos = args_to_ilist(from); if (str_to_int(sn_to_str(SYMNUM(into)), &id)) p->into_id = id; else fatal_error("term_to_just, bad into_id"); p->into_pos = args_to_ilist(into); return j; } case INSTANCE_JUST: { int id; Term parent = ARG(t,0); Term pairs = ARG(t,1); Instancejust ij = get_instancejust(); j->u.instance = ij; if (str_to_int(sn_to_str(SYMNUM(parent)), &id)) ij->parent_id = id; else fatal_error("term_to_just, bad parent_id"); ij->pairs = NULL; while (cons_term(pairs)) { ij->pairs = plist_append(ij->pairs, copy_term(ARG(pairs,0))); pairs = ARG(pairs,1); } return j; } case IVY_JUST: fatal_error("term_to_just, IVY_JUST not handled"); return NULL; case UNKNOWN_JUST: default: printf("unknown: %d, %s\n", j->type, jstring(j)); fatal_error("term_to_just, unknown justification"); return NULL; } } } /* term_to_just */ /************* * * has_input_just() * *************/ /* DOCUMENTATION Does a clause have justtification "input"? */ /* PUBLIC */ BOOL has_input_just(Topform c) { return c->justification && c->justification->type == INPUT_JUST; } /* has_input_just */ /************* * * has_copy_just() * *************/ /* DOCUMENTATION Does a clause have justification "copy"? */ /* PUBLIC */ BOOL has_copy_just(Topform c) { return c->justification && c->justification->type == COPY_JUST; } /* has_copy_just */ /************* * * has_copy_flip_just() * *************/ /* DOCUMENTATION Does a clause have justification "copy, flip", and nothing else? */ /* PUBLIC */ BOOL has_copy_flip_just(Topform c) { return (c->justification && c->justification->type == COPY_JUST && c->justification->next && c->justification->next->type == FLIP_JUST && c->justification->next->next == NULL); } /* has_copy_flip_just */ /* ************************************************************************ BV(2007-aug-20): new functions to support tagged proofs (prooftrans) ***********************************************************************/ static void sb_tagged_write_res_just(String_buf sb, Just g, I3list map); /************* * * sb_tagged_write_just() * *************/ /* DOCUMENTATION This routine writes (to a String_buf) a clause justification. No whitespace is printed before or after. */ /* PUBLIC */ void sb_tagged_write_just(String_buf sb, Just just, I3list map) { Just g = just; // sb_append(sb, "["); while (g != NULL) { Just_type rule = g->type; sb_append(sb, "i "); if (rule == INPUT_JUST || rule == GOAL_JUST) sb_append(sb, jstring(g)); else if (rule==BINARY_RES_JUST || rule==HYPER_RES_JUST || rule==UR_RES_JUST) { sb_tagged_write_res_just(sb, g, map); } else if (rule == DEMOD_JUST) { I3list p; sb_append(sb, jstring(g)); for (p = g->u.demod; p; p = p->next) { sb_append(sb, "\np "); sb_append_int(sb, p->i); } } else if (rule == UNIT_DEL_JUST) { Ilist p = g->u.lst; int n = p->i; int id = p->next->i; sb_append(sb, jstring(g)); sb_append(sb, "("); if (n < 0) { sb_append_char(sb, itoc(-n)); sb_append(sb, "(flip),"); } else { sb_append_char(sb, itoc(n)); sb_append(sb, ","); } sb_append_id(sb, id, map); sb_append(sb, ")"); } else if (rule == FACTOR_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->next->i)); sb_append(sb, ")"); } else if (rule == XXRES_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_char(sb, itoc(p->next->i)); sb_append(sb, ")"); } else if (rule == EXPAND_DEF_JUST) { Ilist p = g->u.lst; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_id(sb, p->i, map); sb_append(sb, ","); sb_append_id(sb, p->next->i, map); sb_append(sb, ")"); } else if (rule == BACK_DEMOD_JUST || rule == BACK_UNIT_DEL_JUST || rule == NEW_SYMBOL_JUST || rule == COPY_JUST || rule == DENY_JUST || rule == CLAUSIFY_JUST || rule == PROPOSITIONAL_JUST) { int id = g->u.id; sb_append(sb, jstring(g)); sb_append(sb, "\np "); sb_append_id(sb, id, map); } else if (rule == FLIP_JUST || rule == XX_JUST || rule == MERGE_JUST) { int id = g->u.id; #if 1 /* BV(2007-jul-10) */ sb_append(sb, "(flip)"); // break; #endif } else if (rule == PARA_JUST || rule == PARA_FX_JUST || rule == PARA_IX_JUST || rule == PARA_FX_IX_JUST) { Parajust p = g->u.para; #if 1 /* BV(2007-jul-10) */ sb_append(sb, "para"); sb_append(sb, "\np "); sb_append_id(sb, p->from_id, map); sb_append(sb, "\np "); sb_append_id(sb, p->into_id, map); // break; #endif } else if (rule == INSTANCE_JUST) { Plist p; sb_append(sb, jstring(g)); sb_append(sb, "("); sb_append_int(sb, g->u.instance->parent_id); sb_append(sb, ",["); for (p = g->u.instance->pairs; p; p = p->next) { sb_write_term(sb, p->v); if (p->next) sb_append(sb, ","); } sb_append(sb, "])"); } else if (rule == IVY_JUST) { sb_append(sb, jstring(g)); } else { printf("\nunknown rule: %d\n", rule); fatal_error("sb_write_just: unknown rule"); } g = g->next; // if (g) // sb_append(sb, ","); sb_append(sb, "\n"); } // sb_append(sb, "]."); } /* sb_tagged_write_just */ /************* * * sb_tagged_write_res_just() -- (1 a 2 b c 3 d e 4 f) * * Assume input is well-formed, that is, length is 3n+1 for n>1. * *************/ static void sb_tagged_write_res_just(String_buf sb, Just g, I3list map) { Ilist q; Ilist p = g->u.lst; #if 1 /* BV(2007-jul-10) */ sb_append(sb, jstring(g)); sb_append(sb, "\np "); sb_append_id(sb, p->i, map); for (q = p->next; q != NULL; q = q->next->next->next) { int sat_id = q->next->i; sb_append(sb, "\np "); if (sat_id == 0) sb_append(sb, ",xx"); else sb_append_id(sb, sat_id, map); } return; #endif } /* sb_tagged_write_res_just */ LADR-2009-11A/bob/ChangelogBV0000644000175000017500000000105411013103314014605 0ustar mccunemccune************************ Changes to LADR-Aug-2007 ************************ 2007-aug-20 apps.src/prooftrans.c add tagged proof option ladr/ioutil.h add format TAGGED add prototype for function sb_tagged_write_clause_jmap() ladr/just.c new functions (at end of file) ladr/ioutil.c add code for call in function fwrite_clause_jmap() new functions (at end of file) ************************ Changes to LADR-Jan-2008 ************************ 2008-jan-26 Previous BV changes ported to new release. LADR-2009-11A/bob/prooftrans.c0000644000175000017500000003035311013104341015111 0ustar mccunemccune/* Copyright (C) 2006, 2007 William McCune This file is part of the LADR Deduction Library. The LADR Deduction Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. The LADR Deduction Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the LADR Deduction Library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /* Transform and format proofs in various ways. */ #include "../ladr/top_input.h" #include "../ladr/xproofs.h" #include "../ladr/ivy.h" #include "../ladr/banner.h" #define PROGRAM_NAME "prooftrans" #include "../VERSION_DATE.h" static char Help_string[] = "\nprooftrans [expand] [renumber] [striplabels] [-f ]\n" "prooftrans parents_only [expand] [renumber] [striplabels] [-f ]\n" "prooftrans xml [expand] [renumber] [striplabels] [-f ]\n" "prooftrans ivy [renumber] [-f ]\n" "prooftrans hints [-label