Esempio n. 1
0
void OverlapIndexInsertIntoClause2(OverlapIndex_p tindex, 
                                   OverlapIndex_p naindex, 
                                   Clause_p clause) 
{
   PStack_p terms = PStackAlloc();
   PStack_p natoms = PStackAlloc();
   CompactPos pos;
   Term_p     term;
   
   ClauseCollectIntoTermsPos2(clause, terms, natoms);
   while(!PStackEmpty(terms))
   {
      pos  = PStackPopInt(terms);
      term = PStackPopP(terms);
      OverlapIndexInsertPos(tindex, clause, pos, term);
   }
   while(!PStackEmpty(natoms))
   {
      pos  = PStackPopInt(natoms);
      term = PStackPopP(natoms);
      OverlapIndexInsertPos(naindex, clause, pos, term);
   }
   PStackFree(natoms);
   PStackFree(terms);
}
Esempio n. 2
0
double sim_eqn_weight(Eqn_p eqn, SimParam_p parms)
{
   double   eq_weight = 0.0, clash_weight = 0.0;
   PStack_p stack = PStackAlloc();
   Term_p   lside, rside;
   int      i;
   
   lside = eqn->lterm;
   rside = eqn->rterm;
   PStackPushP(stack, lside);
   PStackPushP(stack, rside);
   
   while(!PStackEmpty(stack))
   {
      rside = PStackPopP(stack);
      lside = PStackPopP(stack);
      
      if(lside->f_code == rside->f_code)
      {
	 eq_weight += parms->equal_weight;
	 for(i=0; i<lside->arity; i++)
	 {
	    PStackPushP(stack, lside->args[i]);
	    PStackPushP(stack, rside->args[i]);    
	 }
      }
      else
      {
	 if(TermIsVar(lside))
	 {
	    if(TermIsVar(rside))
	    {
	       clash_weight += parms->var_var_clash;
	    }
	    else
	    {
	       clash_weight += parms->var_term_clash;
	    }
	 }
	 else
	 {
	    if(TermIsVar(rside))
	    {
	       clash_weight += parms->var_term_clash;
	    }
	    else
	    {
	       clash_weight += parms->term_term_clash * 
		  (TermWeight(lside, 1, 1)+TermWeight(rside, 1, 1));
	    }
	 }
      }
   }
   PStackFree(stack);
   return clash_weight;	 
}
Esempio n. 3
0
static void pdtree_backtrack(PDTree_p tree, Subst_p subst)
{
   PDTNode_p handle = tree->tree_pos;
   bool      succ;

   if(handle->variable)
   {
      tree->term_weight  += (TermStandardWeight(handle->variable->binding) -
                             TermStandardWeight(handle->variable));
      PStackPushP(tree->term_stack, handle->variable->binding);
      if(handle->bound)
      {
	 succ = SubstBacktrackSingle(subst);
	 (void)succ; assert(succ);
      }
   }
   else if(handle->parent)
   {
      Term_p t = PStackPopP(tree->term_proc);
      
      (void)t; assert(t);
      TermLRTraversePrev(tree->term_stack,t);
			 
   }
   tree->tree_pos = handle->parent;
}
Esempio n. 4
0
static long  delete_clause_entries(PTree_p *root, Clause_p clause)
{
   long        res = 0;
   PStack_p    trav_stack;
   PStack_p    store = PStackAlloc();
   PTree_p     handle; 
   ClausePos_p pos;
   
   trav_stack = PTreeTraverseInit(*root);
   while((handle = PTreeTraverseNext(trav_stack)))
   {
      pos = handle->key;
      if(pos->clause == clause)
      {
	 PStackPushP(store, pos);
      }
   }
   PTreeTraverseExit(trav_stack);
   
   while(!PStackEmpty(store))
   {
      pos = PStackPopP(store);
      PTreeDeleteEntry(root, pos);
      ClausePosCellFree(pos);
      res++;
   }
   PStackFree(store);
   return res;
}
Esempio n. 5
0
bool PTreeMerge(PTree_p *root, PTree_p add)
{
   PStack_p stack = PStackAlloc();
   PTree_p  tmp;
   bool     res = false;

   PStackPushP(stack, add);

   while(!PStackEmpty(stack))
   {
      add = PStackPopP(stack);
      if(add)
      {
	 PStackPushP(stack, add->lson);
	 PStackPushP(stack, add->rson);
	 tmp = PTreeInsert(root, add);
	 if(tmp)
	 {
	    PTreeCellFree(add);
	 }
	 else
	 {
	    res = true;
	 }
      }
   } 
   PStackFree(stack);
   return res;
}
Esempio n. 6
0
void* PTreeSharedElement(PTree_p *tree1, PTree_p tree2)
{
   PStack_p stack = PStackAlloc();
   PTree_p handle, tmp;
   void* res = NULL;

   PStackPushP(stack, tree2);

   while(!PStackEmpty(stack))
   {
      handle = PStackPopP(stack);
      if(handle)
      {
	 tmp = PTreeFind(tree1, handle->key);
	 if(tmp)
	 {
	    res = tmp->key;
	    break;
	 }
	 PStackPushP(stack,handle->lson);
	 PStackPushP(stack,handle->rson);
      }
   } 
   PStackFree(stack);
   return res;
}
Esempio n. 7
0
static void term_del_prop_level(Term_p term, int depth, TermProperties prop)
{
   PStack_p stack = PStackAlloc();
   int      i;

   PStackPushP(stack, term);
   PStackPushInt(stack, depth);

   if(depth>=0) /* Special case depth = -1 can happen -> Do nothing */
   {
      while(!PStackEmpty(stack))
      {
	 depth = PStackPopInt(stack);
	 term =  PStackPopP(stack);
	 TermCellDelProp(term, prop);
	 if(depth!=0)
	 {
	    for(i=0; i<term->arity; i++)
	    {
	       assert(!TermIsVar(term));
	       PStackPushP(stack, term->args[i]);
	       PStackPushInt(stack, depth-1);
	    }
	 }
      }
   }
   PStackFree(stack);
}
Esempio n. 8
0
static void term_set_prop_at_level(Term_p term, int depth,
				   TermProperties prop)
{
   PStack_p stack = PStackAlloc();
   int      i;

   PStackPushP(stack, term);
   PStackPushInt(stack, depth);

   while(!PStackEmpty(stack))
   {
      depth = PStackPopInt(stack);
      term =  PStackPopP(stack);
      if(depth!=0)
      {
	 for(i=0; i<term->arity; i++)
	 {
	    assert(!TermIsVar(term));
	    PStackPushP(stack, term->args[i]);
	    PStackPushInt(stack, depth-1);
	 }
      }
      else
      {
	 TermCellSetProp(term, prop);	 
      }
   }
   PStackFree(stack);
}
Esempio n. 9
0
void VarHashAddVarDistrib(VarHash_p hash, Term_p term, DerefType
			  deref, long add)
{
   PStack_p stack = PStackAlloc();
   int      i;

   PStackPushP(stack, term);
   PStackPushInt(stack, deref);

   while(!PStackEmpty(stack))
   {
      deref = PStackPopInt(stack);
      term = PStackPopP(stack);
      term = TermDeref(term, &deref);
      
      if(TermIsVar(term))
      {
	 VarHashAddValue(hash, term, add);
      }
      else
      {
	 for(i=0; i<term->arity; i++)
	 {
	    PStackPushP(stack, term->args[i]);
	    PStackPushInt(stack, deref);
	 }
      }
   }
   PStackFree(stack);
}
Esempio n. 10
0
void TermVarDelProp(Term_p term, DerefType deref, TermProperties prop)
{
   PStack_p stack = PStackAlloc();
   int i;

   PStackPushP(stack, term);
   PStackPushInt(stack, deref);
   
   while(!PStackEmpty(stack))
   {
      deref = PStackPopInt(stack);
      term  = PStackPopP(stack);
      term  = TermDeref(term, &deref);
      if(TermIsVar(term))
      {
	 TermCellDelProp(term, prop);
      }
      for(i=0; i<term->arity; i++)
      {
	 PStackPushP(stack, term->args[i]);
	 PStackPushInt(stack, deref);
      }
   }
   PStackFree(stack);
}
Esempio n. 11
0
long PTreeDebugPrint(FILE* out, PTree_p root)
{
   PStack_p stack = PStackAlloc();
   long     res   = 0;
   
   PStackPushP(stack, root);
   
   while(!PStackEmpty(stack))
   {      
      root = PStackPopP(stack);
      if(root)
      {
	 if(res % 10 == 0)
	 {
	    fprintf(out, "\n#");
	 }
	 fprintf(out, " %7p", root->key);
	 PStackPushP(stack, root->lson);
	 PStackPushP(stack, root->rson);
	 res++;
      }
   }
   PStackFree(stack);
   fprintf(out, "\n");
   
   return res;   
}
Esempio n. 12
0
void PDArrayAddVarDistrib(PDArray_p array, Term_p term, DerefType
			  deref, long add)
{
   PStack_p stack = PStackAlloc();
   int      i;
   long     tmp;
   
   PStackPushP(stack, term);
   PStackPushInt(stack, deref);
   
   while(!PStackEmpty(stack))
   {
      deref = PStackPopInt(stack);
      term = PStackPopP(stack);
      term = TermDeref(term, &deref);
      
      if(TermIsVar(term))
      {
	 tmp = PDArrayElementInt(array, (-(term->f_code)));
	 PDArrayAssignInt(array, (-(term->f_code)), tmp+add);
      }
      else
      {
	 for(i=0; i<term->arity; i++)
	 {
	    PStackPushP(stack, term->args[i]);
	    PStackPushInt(stack, deref);
	 }
      }
   }
   PStackFree(stack);
}
Esempio n. 13
0
bool TermVarSearchProp(Term_p term, DerefType deref, TermProperties prop)
{
   PStack_p stack = PStackAlloc();
   int i;
   bool res = false;

   PStackPushP(stack, term);
   PStackPushInt(stack, deref);
   
   while(!PStackEmpty(stack))
   {
      deref = PStackPopInt(stack);
      term  = PStackPopP(stack);
      term  = TermDeref(term, &deref);
      if(TermIsVar(term) && TermCellQueryProp(term, prop))
      {
	 res = true;
	 break;
      }
      for(i=0; i<term->arity; i++)
      {
	 PStackPushP(stack, term->args[i]);
	 PStackPushInt(stack, deref);
      }
   }
   PStackFree(stack);
   return res;
}
Esempio n. 14
0
void HCBAdminFree(HCBAdmin_p junk)
{
   char* name;

   assert(junk);
   assert(junk->names);
   assert(junk->hcb_set);
   
   while(!PStackEmpty(junk->names))
   {
      name = PStackPopP(junk->names);
      FREE(name);      
   }
   PStackFree(junk->names);
   
   while(!PStackEmpty(junk->hcb_set))
   {
      HCBFree(PStackPopP(junk->hcb_set));      
   }
   PStackFree(junk->hcb_set);

   HCBAdminCellFree(junk);
}
Esempio n. 15
0
Term_p TermLRTraversePrev(PStack_p stack, Term_p term)
{
   Term_p tmp;
   int    i;

   for(i=0; i<term->arity; i++)
   {
      tmp = PStackPopP(stack);
      (void)tmp; assert(tmp == term->args[i]);
   }
   PStackPushP(stack, term);

   return term;
}
Esempio n. 16
0
static 
ClausePos_p unit_clause_set_strongsubsumes_termpair(ClauseSet_p set, 
						    Term_p t1, Term_p t2,
						    bool positive)
{
   PStack_p stack = PStackAlloc();
   int      i;
   ClausePos_p res = NULL;
   
   PStackPushP(stack, t1);
   PStackPushP(stack, t2);
   
   while(!PStackEmpty(stack))
   {
      t2 = PStackPopP(stack);
      t1 = PStackPopP(stack);
      res = FindSignedTopSimplifyingUnit(set, t1, t2, positive);
      if(!res)
      {
	 if(t1->f_code != t2->f_code || !t1->arity)
	 {
	    break;
	 }
	  for(i=0; i<t1->arity; i++)
	  {
	     if(!TBTermEqual(t1->args[i], t2->args[i]))
	     {
		PStackPushP(stack, t1->args[i]);
		PStackPushP(stack, t2->args[i]);
	     }
	  }
      }
      
   }
   PStackFree(stack);
   return res;
}
Esempio n. 17
0
void OverlapIndexInsertIntoClause(OverlapIndex_p index, Clause_p clause)
{
   PStack_p collector = PStackAlloc();
   CompactPos pos;
   Term_p     term;
   
   ClauseCollectIntoTermsPos(clause, collector);
   while(!PStackEmpty(collector))
   {
      pos  = PStackPopInt(collector);
      term = PStackPopP(collector);
      OverlapIndexInsertPos(index, clause, pos, term);
   }
   PStackFree(collector);
}
Esempio n. 18
0
Eval_p EvalTreeTraverseNext(PStack_p state, int pos)
{
   Eval_p handle, res;

   if(PStackEmpty(state))
   {
      return NULL;
   }
   res = PStackPopP(state);
   handle = res->evals[pos].rson;
   while(handle)
   {
      PStackPushP(state, handle);
      handle = handle->evals[pos].lson;
   }
   return res;
}
Esempio n. 19
0
Term_p TermLRTraverseNext(PStack_p stack)
{
   int    i;
   Term_p handle;
   
   if(PStackEmpty(stack))
   {
      return NULL;
   }
   handle = PStackPopP(stack);
   for(i=handle->arity-1; i>=0; i--)
   {
      PStackPushP(stack, handle->args[i]);
   }
   
   return handle;
}
Esempio n. 20
0
void PTreeInsertTree(PTree_p *root, PTree_p add)
{
   PStack_p stack = PStackAlloc();

   PStackPushP(stack, add);

   while(!PStackEmpty(stack))
   {
      add = PStackPopP(stack);
      if(add)
      {
	 PStackPushP(stack, add->lson);
	 PStackPushP(stack, add->rson);
	 PTreeStore(root, add->key);
      }
   } 
   PStackFree(stack);
}
Esempio n. 21
0
Term_p TBTermPosReplace(TB_p bank, Term_p repl, TermPos_p pos,
			DerefType deref)
{
   Term_p        handle, old;
   int           subscript;
   PStackPointer i;
   PStack_p      store = PStackAlloc();


   assert(bank);
   assert(repl);
   assert(pos);
   
   i = PStackGetSP(pos);
   
   
   /* Note that we start inside-out here - the first term handled is
      the actual subterm replaced, at the end repl is the complete
      term generated.*/
   while(i)
   {
      i--;
      subscript = PStackElementInt(pos, i);
      assert(i);
      i--;
      
      old = PStackElementP(pos, i);
      handle = TermTopCopy(old);
      assert(handle->arity > subscript);
      handle->args[subscript] = repl;
      PStackPushP(store, handle);
      repl = handle;
   }
   repl = TBInsertNoProps(bank, repl, deref);

   while(!PStackEmpty(store))
   {
      handle = PStackPopP(store);
      TermTopFree(handle);
   }
   PStackFree(store);

   return repl;
}
Esempio n. 22
0
Term_p AltTermTop(Term_p term, int depth, VarBank_p freshvars)
{
   PStack_p bindings = PStackAlloc();
   Term_p   handle, res;

   assert(TermIsShared(term));
   VarBankSetVCount(freshvars, FRESH_VAR_LIMIT);

   res = alt_rek_term_top(term, depth, freshvars, bindings);

   while(!PStackEmpty(bindings))
   {
      handle = PStackPopP(bindings);
      assert(handle->binding);
      handle->binding = NULL;
   }
   PStackFree(bindings);
   return res;
}
Esempio n. 23
0
void DPLLFormulaFree(DPLLFormula_p junk)
{
   int i;

   for(i=0; i<junk->atom_no; i++)
   {
      PTreeFree(junk->atoms[i].pos_active);
      PTreeFree(junk->atoms[i].neg_active);
   }
   FREE(junk->atoms);
   while(!PStackEmpty(junk->clauses))
   {
      DPLLClauseFree(PStackPopP(junk->clauses));
   }
   PStackFree(junk->clauses);
   PropSigFree(junk->sig);
   
   DPLLFormulaCellFree(junk);
}
Esempio n. 24
0
void FileVarsFree(FileVars_p handle)
{
   PStack_p  stack;
   StrTree_p cell; 
   char*     name;

   while(!PStackEmpty(handle->names))
   {      
      name = PStackPopP(handle->names);
      FREE(name);
   }
   PStackFree(handle->names);
   stack = StrTreeTraverseInit(handle->vars);
   while((cell = StrTreeTraverseNext(stack)))
   {
      FREE(cell->val1.p_val);
   }
   StrTreeFree(handle->vars);
   FileVarsCellFree(handle);   
}
Esempio n. 25
0
PTree_p PTreeCopy(PTree_p tree)
{
   PTree_p res = NULL, handle;
   PStack_p stack = PStackAlloc();   

   PStackPushP(stack, tree);
   
   while(!PStackEmpty(stack))
   {
      handle = PStackPopP(stack);
      if(handle)
      {
	 PTreeStore(&res, handle->key);
	 PStackPushP(stack,handle->lson);
	 PStackPushP(stack,handle->rson);
      }
   }    
   PStackFree(stack);
   return res;
}
Esempio n. 26
0
long NumTreeNodes(NumTree_p root)
{
   PStack_p stack = PStackAlloc();
   long     res   = 0;

   PStackPushP(stack, root);
   
   while(!PStackEmpty(stack))
   {
      root = PStackPopP(stack);
      if(root)
      {
	 PStackPushP(stack, root->lson);
	 PStackPushP(stack, root->rson);
	 res++;
      }
   }
   PStackFree(stack);

   return res;   
}
Esempio n. 27
0
static long remove_subsumed(GlobalIndices_p indices, 
                            FVPackedClause_p subsumer, 
                            ClauseSet_p set,
                            ClauseSet_p archive)
{
   Clause_p handle;
   long     res;
   PStack_p stack = PStackAlloc();
            
   res = ClauseSetFindFVSubsumedClauses(set, subsumer, stack);
   
   while(!PStackEmpty(stack))
   {
      handle = PStackPopP(stack);
      if(ClauseQueryProp(handle, CPWatchOnly))
      {
	 DocClauseQuote(GlobalOut, OutputLevel, 6, handle,
			"extract_wl_subsumed", subsumer->clause);
         
      }
      else
      {
	 DocClauseQuote(GlobalOut, OutputLevel, 6, handle,
			"subsumed", subsumer->clause);
      }
      ClauseKillChildren(handle);
      GlobalIndicesDeleteClause(indices, handle);
      if(BuildProofObject||ClauseIsDemodulator(handle))
      {
         ClauseSetExtractEntry(handle);
         ClauseSetInsert(archive, handle);
      }
      else
      {
         ClauseSetDeleteEntry(handle);  
      }
   }
   PStackFree(stack);
   return res;
}
Esempio n. 28
0
void PTreeObjMerge(PObjTree_p *root, PObjTree_p add, ComparisonFunctionType
		cmpfun)
{
   PStack_p stack = PStackAlloc();
   PObjTree_p  res;

   PStackPushP(stack, add);

   while(!PStackEmpty(stack))
   {
      add = PStackPopP(stack);
      if(add)
      {
	 PStackPushP(stack, add->lson);
	 PStackPushP(stack, add->rson);
	 res = PTreeObjInsert(root, add, cmpfun);
	 (void)res; assert(!res); /* Pointers should never be in two trees at
                                     once for my intended application */
      }
   } 
   PStackFree(stack);
}
Esempio n. 29
0
Term_p ESTermTop(Term_p term, int depth, VarBank_p freshvars)
{
   PStack_p bindings = PStackAlloc();
   Term_p   handle, res;

   assert(TermIsShared(term));
   VarBankSetVCount(freshvars, FRESH_VAR_LIMIT);

   term_set_prop_at_level(term, depth, TPOpFlag);
   term_del_prop_level(term, depth-1, TPOpFlag);

   res = term_top_marked(term, freshvars, bindings);

   while(!PStackEmpty(bindings))
   {
      handle = PStackPopP(bindings);
      assert(handle->binding);
      handle->binding = NULL;
   }
   PStackFree(bindings);
   return res;
}
Esempio n. 30
0
long PTreeToPStack(PStack_p target_stack, PTree_p root)
{
   long res = 0;
   PStack_p stack = PStackAlloc();
   PTree_p handle;

   PStackPushP(stack, root);
   
   while(!PStackEmpty(stack))
   {
      handle = PStackPopP(stack);
      if(handle)
      {	 
	 PStackPushP(target_stack, handle->key);
	 res++;
	 PStackPushP(stack,handle->lson);
	 PStackPushP(stack,handle->rson);
      }
   } 
   PStackFree(stack);
   
   return res;
}