1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* 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/top_input.h"
#include "../ladr/demod.h"
#define PROGRAM_NAME "idfilter"
#include "../VERSION_DATE.h"
static char Help_string[] =
"\nThis program takes a file of demodulators (arg 1) and a\n"
"stream of equations (stdin). Each equation is rewritten.\n"
"If it rewrites to an instance of x=x, it is discarded;\n"
"otherwise it (in the unrewritten form) is send to stdout.\n"
"For example,\n\n"
" idfilter demods < terms.in > terms.out\n\n"
"The file of demodulators contains optional commands\n"
"then a list of demodulators. The commands can be used to\n"
"declare infix operations and associativity/commutativity.\n"
"Example file of demodulators:\n\n"
" op(400, infix, ^).\n"
" op(400, infix, v).\n"
" assoc_comm(^).\n"
" assoc_comm(v).\n"
" formulas(demodulator).\n"
" x ^ x = x.\n"
" x ^ (x v y) = x.\n"
" x v x = x.\n"
" x v (x ^ y) = x.\n"
" end_of_list.\n\n";
int main(int argc, char **argv)
{
FILE *head_fp;
Ilist just;
Plist demodulators, p;
Mindex idx;
Term t;
int tested = 0;
int passed = 0;
Uniftype unification_type;
BOOL fast_parse = string_member("fast", argv, argc);
BOOL backward = string_member("x", argv, argc);
BOOL verbose = string_member("verbose", argv, argc);;
if (string_member("help", argv, argc) ||
string_member("-help", argv, argc) ||
argc < 2) {
printf("\n%s, version %s, %s\n",PROGRAM_NAME,PROGRAM_VERSION,PROGRAM_DATE);
printf("%s", Help_string);
exit(1);
}
init_standard_ladr();
if (fast_parse)
fast_set_defaults(); /* Declare the symbols for fastparse. */
head_fp = fopen(argv[1], "r");
if (head_fp == NULL)
fatal_error("demodulator file can't be opened for reading");
t = read_commands(head_fp, stderr, FALSE, KILL_UNKNOWN);
if (!is_term(t, "clauses", 1) && !is_term(t, "formulas", 1))
fatal_error("formulas(demodulators) not found");
if (assoc_comm_symbols() || comm_symbols())
unification_type = BACKTRACK_UNIF;
else
unification_type = ORDINARY_UNIF;
/* Read list of demodulators. */
demodulators = read_clause_list(head_fp, stderr, TRUE);
fclose(head_fp);
/* AC-canonicalize and index the demodulators. */
idx = mindex_init(DISCRIM_WILD, unification_type, 0);
for (p = demodulators; p != NULL; p = p->next) {
/* assume positive equality unit */
Topform d = p->v;
Literals lit = d->literals;
Term alpha = lit->atom->args[0];
mark_oriented_eq(lit->atom); /* don not check for termination */
if (assoc_comm_symbols())
ac_canonical(lit->atom, -1);
mindex_update(idx, alpha, INSERT);
}
if (verbose)
fwrite_clause_list(stdout, demodulators, "demodulators", CL_FORM_BARE);
/* Read and demodulate terms. */
t = term_reader(fast_parse);
while (t != NULL) {
Term tcopy = copy_term(t);
BOOL ident;
tested++;
if (verbose) {
fprintf(stdout, "\nBefore: "); fwrite_term_nl(stdout, t);
}
if (assoc_comm_symbols())
ac_canonical(tcopy, -1);
just = NULL;
tcopy = demodulate(tcopy, idx, &just, FALSE);
if (verbose) {
fprintf(stdout, "After: "); fwrite_term_nl(stdout, tcopy);
}
ident = (is_term(t, "=", 2) && term_ident(ARG(tcopy,0),ARG(tcopy,1)));
if ((ident && !backward) ||
(!ident && backward)) {
passed++;
term_writer(t, fast_parse);
fflush(stdout);
}
zap_ilist(just);
zap_term(t);
zap_term(tcopy);
t = term_reader(fast_parse);
}
printf("%% %s %s %s: tested %d, passed %d in %.2f seconds.\n",
PROGRAM_NAME,
argv[1], backward ? "x" : "",
tested, passed,
user_seconds());
exit(0);
} /* main */
|