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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
|
/*-----------------------------------------------------------------------
File : ccl_groundconstr.c
Author: Stephan Schulz
Contents
Computing constraints on the possible instances of groundable
clauses.
Copyright 1998, 1999 by the author.
This code is released under the GNU General Public Licence and
the GNU Lesser General Public License.
See the file COPYING in the main E directory for details..
Run "eprover -h" for contact information.
Changes
Created: Thu Jun 7 23:44:55 MEST 2001
-----------------------------------------------------------------------*/
#include "ccl_groundconstr.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: LitOccTableAlloc()
//
// Allocate a LitOccTable suitable for the signature. This wastes
// some memory, but except for pathological cases, this should be
// insignificant, and the time efficiency of the operations should
// be good.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
LitOccTable_p LitOccTableAlloc(Sig_p sig)
{
int arity, i, j;
LitOccTable_p handle = LitOccTableCellAlloc();
handle->sig_size = sig->f_count+1; /* To allow for element 0*/
arity = SigFindMaxPredicateArity(sig);
handle->maxarity = MAX(arity,2); /* To cover $eqn, which might be
special */
handle->matrix = SizeMalloc((handle->sig_size)
* (handle->maxarity+1)
* sizeof(LitConstrCell));
for(i=0; i< handle->sig_size; i++)
{
for(j=0; j<handle->maxarity; j++)
{
LIT_OCC_TABLE_ENTRY(handle, i, j).constrained = true;
LIT_OCC_TABLE_ENTRY(handle, i, j).constraints = NULL;
}
}
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: LitOccTableFree()
//
// Free a LitOccTable.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void LitOccTableFree(LitOccTable_p junk)
{
int i, j;
assert(junk);
assert(junk->matrix);
for(i=0; i< junk->sig_size; i++)
{
for(j=0; j<junk->maxarity; j++)
{
PTreeFree(LIT_OCC_TABLE_ENTRY(junk, i, j).constraints);
}
}
SizeFree(junk->matrix,((junk->sig_size)
* (junk->maxarity + 1)
* sizeof(LitConstrCell)));
LitOccTableCellFree(junk);
}
/*-----------------------------------------------------------------------
//
// Function: LitPosGetConstrState()
//
// Return true if the position described carries any constraints,
// false otherwise.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
bool LitPosGetConstrState(LitOccTable_p table, FunCode pred, int pos)
{
assert(table);
assert(pred < table->sig_size);
assert(pos < table->maxarity);
return LIT_OCC_TABLE_ENTRY(table, pred, pos).constrained;
}
/*-----------------------------------------------------------------------
//
// Function: LitPosSetConstrState()
//
// Return true if the position described carries any constraints,
// false otherwise.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
void LitPosSetConstrState(LitOccTable_p table, FunCode pred, int pos,
bool value)
{
assert(table);
assert(pred < table->sig_size);
assert(pos < table->maxarity);
LIT_OCC_TABLE_ENTRY(table, pred, pos).constrained = value;
}
/*-----------------------------------------------------------------------
//
// Function: LitPosGetConstraints()
//
// Return the constraints carried at the position described. This
// function can only be called on positions that carry constraints!
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
PTree_p LitPosGetConstraints(LitOccTable_p table, FunCode pred, int pos)
{
assert(table);
assert(pred < table->sig_size);
assert(pos < table->maxarity);
assert(LIT_OCC_TABLE_ENTRY(table, pred, pos).constrained);
return LIT_OCC_TABLE_ENTRY(table, pred, pos).constraints;
}
/*-----------------------------------------------------------------------
//
// Function: LitPosAddConstraint()
//
// Add the term to the set of disjunctive constraints at the
// described position. Return true if this makes the position
// unconstrained.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
bool LitPosAddConstraint(LitOccTable_p table, FunCode pred, int pos,
Term_p term)
{
if(TermIsVar(term))
{
LitPosSetConstrState(table, pred, pos, false);
return true;
}
else
{
PTreeStore(&(LIT_OCC_TABLE_ENTRY(table, pred, pos).constraints),
term);
return false;
}
}
/*-----------------------------------------------------------------------
//
// Function: LitOccAddLitAlt()
//
// Add the constraints induced by literal into the corresponding
// table.
//
// Global Variables: -
//
// Side Effects : Changes table.
//
/----------------------------------------------------------------------*/
void LitOccAddLitAlt(LitOccTable_p p_table, LitOccTable_p n_table,
Eqn_p eqn)
{
int i;
LitOccTable_p handle;
Term_p lit;
assert(!EqnIsEquLit(eqn));
if(EqnIsPositive(eqn))
{
handle = p_table;
}
else
{
handle = n_table;
}
lit = eqn->lterm;
for(i=0; i< lit->arity; i++)
{
LitPosAddConstraint(handle, lit->f_code, i, lit->args[i]);
}
}
/*-----------------------------------------------------------------------
//
// Function: LitOccAddClauseAlt()
//
// Add the constraints induced by clause to the constraint tables.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
void LitOccAddClauseAlt(LitOccTable_p p_table, LitOccTable_p n_table,
Clause_p clause)
{
Eqn_p handle;
for(handle = clause->literals; handle; handle=handle->next)
{
LitOccAddLitAlt(p_table, n_table, handle);
}
}
/*-----------------------------------------------------------------------
//
// Function: LitOccAddClauseSetAlt()
//
// Add the constraints induced by the clause set to the constraint
// tables.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
void LitOccAddClauseSetAlt(LitOccTable_p p_table, LitOccTable_p
n_table, ClauseSet_p set)
{
Clause_p handle;
for(handle = set->anchor->succ; handle!= set->anchor; handle =
handle->succ)
{
LitOccAddClauseAlt(p_table, n_table, handle);
}
}
/*-----------------------------------------------------------------------
//
// Function: SigCollectConstantTerms()
//
// Push terms corresponding to all constants in sig onto the
// stack. If sig contains no constant, insert a new skolem
// constant. If uniq is set, just push the one term corresponding to
// uniq.
//
// Global Variables: -
//
// Side Effects : Potentially changes sig and bank
//
/----------------------------------------------------------------------*/
long SigCollectConstantTerms(TB_p bank, PStack_p stack, FunCode uniq)
{
FunCode i;
long res = 0;
Term_p tmp, found;
if(uniq)
{
assert((uniq > 0) && (uniq <= bank->sig->f_count) &&
(SigFindArity(bank->sig,uniq)==0));
tmp = TermConstCellAlloc(uniq);
found = TBTermTopInsert(bank, tmp);
PStackPushP(stack, found);
res=1;
}
else
{
for(i=bank->sig->internal_symbols+1; i<=bank->sig->f_count; i++)
{
if(!SigIsPredicate(bank->sig, i) &&
!SigQueryProp(bank->sig, i, FPSpecial) &&
SigFindArity(bank->sig,i)==0)
{
tmp = TermConstCellAlloc(i);
found = TBTermTopInsert(bank, tmp);
PStackPushP(stack, found);
res++;
}
}
}
if(!res)
{
OUTPRINT(1, "# No constant in specification, "
"added new Skolem constant\n");
i = SigGetNewSkolemCode(bank->sig, 0);
tmp = TermConstCellAlloc(i);
found = TBTermTopInsert(bank, tmp);
PStackPushP(stack, found);
res++;
}
return res;
}
/*-----------------------------------------------------------------------
//
// Function: EqnCollectVarConstr()
//
// For all variables occuring in eqn, remove the alternatives not
// compatible with the constraints in the tables.
//
// Global Variables: -
//
// Side Effects : Changes the variable constraints.
//
/----------------------------------------------------------------------*/
void EqnCollectVarConstr(LitOccTable_p p_table, LitOccTable_p n_table,
PDArray_p var_constr, Eqn_p eqn)
{
int i;
PTree_p tree;
LitOccTable_p constr;
Term_p lit = eqn->lterm;
constr = EqnIsPositive(eqn)?n_table:p_table; /* Contraints are
induced by literals
of the opposite
sign! */
for(i=0; i<lit->arity; i++)
{
if(TermIsVar(lit->args[i]))
{
if(LitPosGetConstrState(constr,lit->f_code,i))
{
tree = PDArrayElementP(var_constr,
-(lit->args[i]->f_code));
(void)PTreeDestrIntersection(&tree,
LitPosGetConstraints(constr,
lit->f_code,
i));
PDArrayAssignP(var_constr,
-(lit->args[i]->f_code),
tree);
/* if(tmp)
{
printf("Constraints at work: %ld\n", tmp);
}*/
}
}
}
}
/*-----------------------------------------------------------------------
//
// Function: ClauseCollectVarConstr()
//
// Apply all variable constraints for clause to the initialized
// var_constr array return them.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
void ClauseCollectVarConstr(LitOccTable_p p_table, LitOccTable_p
n_table, Clause_p clause, PTree_p
ground_terms, PDArray_p var_constr)
{
Eqn_p handle;
for(handle = clause->literals; handle; handle = handle->next)
{
EqnCollectVarConstr(p_table, n_table, var_constr, handle);
}
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|