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
|
/*-----------------------------------------------------------------------
File : ccl_def_handling.c
Author: Stephan Schulz (schulz@eprover.org)
Contents
Handling of clausal definitons as used (up to now
implicietely) in splitting, i.e. data structures associating a
clause with a fresh constant predicate symbol or literal.
Copyright 2006 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
<1> Sun Jun 4 20:31:23 EEST 2006
New
-----------------------------------------------------------------------*/
#include "ccl_def_handling.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: DefStoreAlloc()
//
// Return an initialized definitions storage object. Note that the
// FVIndex in def_clauses still has to be set (this is an inherited
// uglyness I'll fix soon).
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
DefStore_p DefStoreAlloc(TB_p terms)
{
DefStore_p store = DefStoreCellAlloc();
store->terms = terms;
store->def_clauses = ClauseSetAlloc();
store->def_assocs = NULL;
store->def_archive = FormulaSetAlloc();
return store;
}
/*-----------------------------------------------------------------------
//
// Function: DefStoreFree()
//
// Free a definition storage object and all data it is responsible
// for (includes the FVIndex of def_clauses, but not the term
// bank).
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void DefStoreFree(DefStore_p junk)
{
ClauseSetFree(junk->def_clauses);
NumTreeFree(junk->def_assocs);
FormulaSetFree(junk->def_archive);
DefStoreCellFree(junk);
}
/*-----------------------------------------------------------------------
//
// Function: GenDefLit()
//
// Generate a definition literal with terms from bank.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
Eqn_p GenDefLit(TB_p bank, FunCode pred, bool positive,
PStack_p split_vars)
{
Term_p lside;
Eqn_p res;
assert(bank);
assert(pred > 0);
assert((split_vars &&
(SigFindArity(bank->sig, pred) == PStackGetSP(split_vars)))
||
(!split_vars && (SigFindArity(bank->sig, pred)==0)));
if(!split_vars || PStackEmpty(split_vars))
{
lside = TermConstCellAlloc(pred);
}
else
{
int arity = PStackGetSP(split_vars), i;
lside = TermDefaultCellArityAlloc(arity);
lside->f_code = pred;
lside->arity = arity;
for(i = 0; i < arity; ++i)
{
lside->args[i] = PStackElementP(split_vars, i);
}
}
lside->type = bank->sig->type_bank->bool_type;
lside = TBTermTopInsert(bank, lside);
res = EqnAlloc(lside, bank->true_term, bank, positive);
EqnSetProp(res, EPIsSplitLit);
return res;
}
/*-----------------------------------------------------------------------
//
// Function: GetClauseDefinition()
//
// Given a literal list and the definition predicate, generate one
// of the two clauses the equivalence definition splits into (namely
// the one we need to add for splitting). This recycles the literal
// list!
//
// Global Variables: -
//
// Side Effects : Memory operations.
//
/----------------------------------------------------------------------*/
Clause_p GetClauseDefinition(Eqn_p litlist, FunCode def_pred, WFormula_p parent)
{
Clause_p res;
Eqn_p def_lit;
assert(litlist);
assert(def_pred > 0);
def_lit = GenDefLit(litlist->bank, def_pred, true, NULL);
def_lit->next = litlist;
res = ClauseAlloc(def_lit);
ClausePushDerivation(res, DCSplitEquiv, parent, NULL);
DocIntroSplitDefRestDefault(res, parent);
return res;
}
/*-----------------------------------------------------------------------
//
// Function: GetFormulaDefinition()
//
// Given a literal list and the definition predicate, generate the
// equivalent defintion. This one leaves the literal list alone!
//
// Global Variables: -
//
// Side Effects : May create output, memory ops
//
/----------------------------------------------------------------------*/
WFormula_p GetFormulaDefinition(Eqn_p litlist, FunCode def_pred)
{
WFormula_p res;
Eqn_p def_lit;
Clause_p def_clause;
TFormula_p def, lit;
assert(litlist);
assert(def_pred > 0);
def_lit = GenDefLit(litlist->bank, def_pred, true, NULL);
EqnFlipProp(def_lit, EPIsPositive);
def_clause = ClauseAlloc(EqnListFlatCopy(litlist));
lit = TFormulaLitAlloc(def_lit);
EqnFree(def_lit);
def = TFormulaClauseClosedEncode(litlist->bank, def_clause);
def = TFormulaFCodeAlloc(litlist->bank, litlist->bank->sig->equiv_code, lit, def);
res = WTFormulaAlloc(litlist->bank, def);
ClauseFree(def_clause);
DocIntroSplitDefDefault(res);
WFormulaPushDerivation(res, DCIntroDef, NULL, NULL);
return res;
}
/*-----------------------------------------------------------------------
//
// Function: GetDefinitions()
//
// Given a literal list, provide (optionally) the full definition and
// the clause equivalent to the non-applied direction of the
// definition. Return defined predicate.
//
// If fresh is true, always return a fresh definition and do not
// insert the clause/predicate association into the store. If fresh
// is false, check if it is a variant of a known definiton and
// return the corresponding symbol. If not, store the new
// association.
//
// Global Variables: -
//
// Side Effects : May extend the clause store.
//
/----------------------------------------------------------------------*/
FunCode GetDefinitions(DefStore_p store, Eqn_p litlist,
WFormula_p* res_form, Clause_p* res_clause,
bool fresh)
{
Clause_p def_clause;
FunCode def_pred = 0;
assert(litlist);
*res_form = NULL;
*res_clause = NULL;
if(fresh)
{
def_pred = SigGetNewPredicateCode(store->terms->sig, 0);
SigDeclareType(store->terms->sig, def_pred, store->terms->sig->type_bank->bool_type);
*res_form = GetFormulaDefinition(litlist, def_pred);
FormulaSetInsert(store->def_archive, *res_form);
*res_clause = GetClauseDefinition(litlist, def_pred, *res_form);
}
else
{
Clause_p variant;
def_clause = ClauseAlloc(EqnListFlatCopy(litlist));
def_clause->weight = ClauseStandardWeight(def_clause);
ClauseSubsumeOrderSortLits(def_clause);
variant = ClauseSetFindVariantClause(store->def_clauses,
def_clause);
if(variant)
{
NumTree_p assoc = NumTreeFind(&(store->def_assocs),
variant->ident);
assert(assoc);
*res_clause = NULL; /* Clause already exists */
*res_form = assoc->val2.p_val;
def_pred = assoc->val1.i_val;
ClauseFree(def_clause);
EqnListFree(litlist);
}
else
{
IntOrP def_pred_store, def_form_store;
def_pred = SigGetNewPredicateCode(store->terms->sig, 0);
SigDeclareType(store->terms->sig, def_pred, store->terms->sig->type_bank->bool_type);
*res_form = GetFormulaDefinition(litlist, def_pred);
FormulaSetInsert(store->def_archive, *res_form);
*res_clause = GetClauseDefinition(litlist, def_pred, *res_form);
def_pred_store.i_val = def_pred;
def_form_store.p_val = *res_form;
NumTreeStore(&(store->def_assocs),
def_clause->ident,
def_pred_store,
def_form_store);
assert(def_clause->weight == ClauseStandardWeight(def_clause));
ClauseSetIndexedInsertClause(store->def_clauses,
def_clause);
}
}
return def_pred;
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|