void Menu_Game_Exit(void *info) { Base_State *gState = info; struct menu_Game *menu = gState->info; while(menu->nameList != NULL) { mem_Free(menu->nameList->data); list_Pop(&menu->nameList); } while(menu->campaignNameList != NULL) { mem_Free(menu->campaignNameList->data); list_Pop(&menu->campaignNameList); } /*Clear up ui*/ uiSpine_Clean(&menu->spine); /*Remove any graphics that should not be drawn*/ gKer_FlushGraphics(); mem_Free(menu); return; }
static void graph_InternSCC(GRAPH Graph, GRAPHNODE Node) /************************************************************** INPUT: A graph and a node of the graph. RETURNS: Nothing. EFFECT: This is an internal function used by graph_StronglyConnnectedComponents. It sets information in the graph structure which specifies the strongly connected components of the graph. ***************************************************************/ { GRAPHNODE n; LIST scan; NAT act_dfs; act_dfs = (Graph->dfscount)++; graph_NodeSetDfsNum(Node, act_dfs); graph_UNFINISHED = list_Push(Node, graph_UNFINISHED); graph_ROOTS = list_Push(Node, graph_ROOTS); /* putchar('\n'); list_Apply(graph_NodePrint, graph_UNFINISHED); putchar('\n'); list_Apply(graph_NodePrint, graph_ROOTS); fflush(stdout); DBG */ for (scan = graph_NodeNeighbors(Node); !list_Empty(scan); scan = list_Cdr(scan)) { n = list_Car(scan); if (!graph_NodeVisited(n)) { graph_InternSCC(Graph, n); /* Visit <n> */ } else if (!graph_NodeCompleted(n)) { /* <n> was visited but is not yet in a permanent component */ NAT dfs_num_of_n = graph_NodeDfsNum(n); while (!list_StackEmpty(graph_ROOTS) && graph_NodeDfsNum(list_Top(graph_ROOTS)) > dfs_num_of_n) graph_ROOTS = list_Pop(graph_ROOTS); /* putchar('\n'); list_Apply(symbol_Print, graph_UNFINISHED); putchar('\n'); list_Apply(symbol_Print, graph_ROOTS); fflush(stdout); DBG */ } } /* printf("\nDFS(%u) complete.", graph_NodeNumber(Node)); DBG */ if (Node == list_Top(graph_ROOTS)) { /* Node is root of a component, so make this component permanent */ while (!list_StackEmpty(graph_UNFINISHED) && graph_NodeDfsNum(list_Top(graph_UNFINISHED)) >= act_dfs) { n = list_Top(graph_UNFINISHED); graph_UNFINISHED = list_Pop(graph_UNFINISHED); graph_NodeSetCompNum(n, Graph->compcount); } Graph->compcount++; graph_ROOTS = list_Pop(graph_ROOTS); } /* putchar('\n'); list_Apply(graph_NodePrint, graph_UNFINISHED); putchar('\n'); list_Apply(graph_NodePrint, graph_ROOTS); fflush(stdout); DBG */ }
/* Function: drawType_ReleaseExcess Description - If there are any unused nodes with a specific type then it will delete them. The maximum total layers that will be deleted is specified by 'amount'. Returns the amount of nodes that have been deleted. 2 arguments: Draw_Layer *dT - The type of unused nodes to remove. int amount - The maximum amount of unused nodes to remove, if < 0 then all will be removed. */ int drawType_ReleaseExcess(Draw_Type *dT, int amount) { int x = 0; if(amount < 0) amount = dT->totalFree; if(dT->totalFree > 0) { for(x = 0; x < amount; x++) { /*Delete all the unused nodes*/ drawObject_Clean(dT->unusedObjectList->data); mem_Free(dT->unusedObjectList->data); list_Pop(&dT->unusedObjectList); dT->totalFree --; if(dT->totalFree == 0) { x ++; break; } } *dT->totalObjectLocations = *dT->totalObjectLocations - x; return x; } return 0; }
void list_Clear(struct list **listHead) { while(*listHead != NULL) list_Pop(listHead); return; }
/* Function: control_Clean Description - Cleans up a control event, removing any malloced memory used. This will only happen if the control has a single reference left. Otherwise the reference count will be decreased by 1. 1 argument: Control_Event *event - the event to clean up. */ int control_Clean(Control_Event *event) { Control_Event *linkedEvent = NULL; if(event->references > 0) { printf("Removing reference to event %s (%d)\n", event->name, event->references); event->references --; return (event->references + 1); } control_Clear(event); while(event->timerLinks != NULL) { linkedEvent = event->timerLinks->data; depWatcher_Remove(&linkedEvent->dW, &event->timerLinks); list_Pop(&event->timerLinks); } depWatcher_Clean(&event->dW); return 0; }
static ord_RESULT rpos_MulGreaterEqual(TERM T1, TERM T2, BOOL VarIsConst) /************************************************************** INPUT: Two terms with equal top symbols and multiset status. RETURNS: ord_GREATER_THAN if <T1> is greater than <T2>, ord_EQUAL if both terms are equal and ord_UNCOMPARABLE otherwise. CAUTION: If <VarIsConst> is set then variables are interpreted as constants with lowest precedence. They are ranked to each other using their variable index. ***************************************************************/ { LIST l1, l2; l1 = rpos_MultisetDifference(T1, T2); if (list_Empty(l1)) /* If |M| = |N| and M-N = {} then N-M = {} */ return ord_Equal(); /* Terms are equal */ else { LIST scan; BOOL greater; l2 = rpos_MultisetDifference(T2, T1); for (greater = TRUE; !list_Empty(l2) && greater; l2 = list_Pop(l2)) { for (scan = l1, greater = FALSE; !list_Empty(scan) && !greater; scan = list_Cdr(scan)) greater = rpos_Greater(list_Car(scan), list_Car(l2), VarIsConst); } list_Delete(l1); /* l2 was freed in the outer for loop */ if (greater) return ord_GreaterThan(); else return ord_Uncomparable(); } }
static ord_RESULT rpos_MulGreaterEqual(TERM T1, TERM T2) /************************************************************** INPUT: Two terms with equal top symbols and multiset status. RETURNS: ord_GREATER_THAN if <T1> is greater than <T2>, ord_EQUAL if both terms are equal and ord_UNCOMPARABLE otherwise. ***************************************************************/ { LIST l1, l2; l1 = rpos_MultisetDifference(T1, T2); if (list_Empty(l1)) /* If |M| = |N| and M-N = {} then N-M = {} */ return ord_Equal(); /* Terms are equal */ else { LIST scan; BOOL greater; l2 = rpos_MultisetDifference(T2, T1); for (greater = TRUE; !list_Empty(l2) && greater; l2 = list_Pop(l2)) { for (scan = l1, greater = FALSE; !list_Empty(scan) && !greater; scan = list_Cdr(scan)) greater = rpos_Greater(list_Car(scan), list_Car(l2)); } list_Delete(l1); /* l2 was freed in the outer for loop */ if (greater) return ord_GreaterThan(); else return ord_Uncomparable(); } }
void daemon_free_parameters(list *parameters) { while(!list_IsEmpty(parameters)) { daemon_free_parameter((struct razer_parameter*)list_Pop(parameters)); } list_Close(parameters); }
void drawManager_CleanLayers(Draw_Manager *dM) { while(dM->layers != NULL) { drawLayer_Clean(dM->layers->data); mem_Free(dM->layers->data); list_Pop(&dM->layers); } return; }
void aiModule_Clean(Ai_Module *aiMod) { while(aiMod->globalList != NULL) { aiState_Clean(aiMod->globalList->data); mem_Free(aiMod->globalList->data); list_Pop(&aiMod->globalList); } while(aiMod->localList != NULL) { aiState_Clean(aiMod->localList->data); mem_Free(aiMod->localList->data); list_Pop(&aiMod->localList); } aiMod->highestPriority = aiMod->lowestPriority = NULL; return; }
void graph_Delete(GRAPH Graph) /************************************************************** INPUT: A graph. RETURNS: Nothing. EFFECT: All memory required by the graph and its nodes is freed. ***************************************************************/ { for ( ; !list_Empty(Graph->nodes); Graph->nodes = list_Pop(Graph->nodes)) { list_Delete(graph_NodeNeighbors(list_Car(Graph->nodes))); memory_Free(list_Car(Graph->nodes), sizeof(GRAPHNODE_STRUCT)); } memory_Free(Graph, sizeof(GRAPH_STRUCT)); }
void uiButtonChain_Clean(Ui_ButtonChain *bChain) { bChain->currentList = NULL; bChain->currentButton = NULL; while(bChain->bList != NULL) { uiButton_Clean(bChain->bList->data); mem_Free(bChain->bList->data); list_Pop(&bChain->bList); } return; }
int surf_Free_All(void) { SDL_Surface *freeImage = NULL; while(surf_C.surfaceList != NULL) { freeImage = surf_C.surfaceList->data; if(freeImage != NULL) SDL_FreeSurface(freeImage); freeImage = NULL; list_Pop(&surf_C.surfaceList); } return 0; }
static ord_RESULT rpos_ContMulGreaterEqual(CONTEXT GlobalC1, CONTEXT TermC1, TERM T1, CONTEXT GlobalC2, CONTEXT TermC2, TERM T2, BOOL VarIsConst) /************************************************************** INPUT: Two contexts and two terms with equal top symbols and multiset status. RETURNS: ord_GREATER_THAN if <T1> is greater than <T2>, ord_EQUAL if both terms are equal and ord_UNCOMPARABLE otherwise. EFFECT: Variable bindings are considered. ASSUMPTION: All index variables of <T1> and <T2> are bound in <GlobalC1> and <GlobalCt2>, respectively ***************************************************************/ { LIST l1, l2; /* Don't apply bindings at top level, since that happened */ /* in rpos_ContGreaterEqual. */ l1 = rpos_ContMultisetDifference(GlobalC1, TermC1, T1, GlobalC2, TermC2, T2); if (list_Empty(l1)) /* If |M| = |N| and M-N = {} then N-M = {} */ return ord_Equal(); /* Terms are equal */ else { LIST scan; BOOL greater; l2 = rpos_ContMultisetDifference(GlobalC2, TermC2, T2, GlobalC1, TermC1, T1); for (greater = TRUE; !list_Empty(l2) && greater; l2 = list_Pop(l2)) { for (scan = l1, greater = FALSE; !list_Empty(scan) && !greater; scan = list_Cdr(scan)) greater = rpos_ContGreaterAux(GlobalC1, TermC1, list_Car(scan), GlobalC2, TermC2, list_Car(l2), VarIsConst); } list_Delete(l1); /* l2 was freed in the outer for loop */ if (greater) return ord_GreaterThan(); else return ord_Uncomparable(); } }
void list_ClearAll(struct list **listHead) { struct list *dataFetch; while(*listHead != NULL) { dataFetch = *listHead; #ifdef MEM_TRACK mem_Free(dataFetch->data); #else free(dataFetch->data); #endif list_Pop(listHead); } return; }
static LIST split_DeleteClausesDependingOnLevelFromSet(PROOFSEARCH PS, LIST ClauseList, int SplitLevel) /************************************************************** INPUT: A PROOFSEARCH object, a list of shared clauses and a split level. RETURNS: A list of clauses that have to be recovered possibly. EFFECT: Clauses from the clause list depending on <SplitLevel> are moved to the doc proof index of <PS>. All formerly redundant clauses that were reduced by a clause of the same split level as a clause from the list depending on <SplitLevel> are returned. ***************************************************************/ { LIST scan, delList, recover; CLAUSE clause; SPLIT reinsert; delList = recover = list_Nil(); for (scan = ClauseList; !list_Empty(scan); scan = list_Cdr(scan)){ clause = list_Car(scan); if (clause_DependsOnSplitLevel(clause, SplitLevel)) { reinsert = prfs_GetSplitOfLevel(clause_SplitLevel(clause), PS); recover = list_Nconc(prfs_SplitDeletedClauses(reinsert), recover); prfs_SplitSetDeletedClauses(reinsert, list_Nil()); delList = list_Cons(clause, delList); } } /* WARNING: The following move operations change the worked off */ /* and usable sets of the proof search object destructively. */ /* So it's impossible to move those function calls into the */ /* loop above. */ for ( ; !list_Empty(delList); delList = list_Pop(delList)) { clause = list_Car(delList); if (clause_GetFlag(clause, WORKEDOFF)) prfs_MoveWorkedOffDocProof(PS, clause); else prfs_MoveUsableDocProof(PS, clause); } return recover; }
static LIST inf_GetURPartnerLits(TERM Atom, LITERAL Lit, BOOL Unit, SHARED_INDEX Index) /************************************************************** INPUT: An atom, a literal, a boolean flag and a SHARED_INDEX. RETURNS: A list of literals with sign complementary to <Lit> that are unifiable with <Atom>. If <Unit> is true, only literals from unit clauses are returned, if <Unit> is false, only literals from non-unit clauses are returned. EFFECT: <Atom> is a copy of <Lit>'s atom where some substitution was applied and equality literals might have been swapped. <Lit> is just needed to check whether the unifiable literals are complementary. ***************************************************************/ { LIST Result, Unifiers, LitScan; LITERAL PLit; int length; Result = list_Nil(); Unifiers = st_GetUnifier(cont_LeftContext(), sharing_Index(Index), cont_RightContext(), Atom); for ( ; !list_Empty(Unifiers); Unifiers = list_Pop(Unifiers)) { if (!term_IsVariable(list_Car(Unifiers))) { for (LitScan = sharing_NAtomDataList(list_Car(Unifiers)); !list_Empty(LitScan); LitScan = list_Cdr(LitScan)) { PLit = list_Car(LitScan); length = clause_Length(clause_LiteralOwningClause(PLit)); if (clause_LiteralsAreComplementary(Lit, PLit) && ((Unit && length==1) || (!Unit && length!=1))) /* The partner literals must have complementary sign and if <Unit> == TRUE they must be from unit clauses, if <Unit> == FALSE they must be from non-unit clauses. */ Result = list_Cons(PLit, Result); } } } return Result; }
/* Function: control_Clear Description - Removes all keys in an event. Returns the number of keys removed. 1 argument: Control_Event *c - should point to the event that needs the keys removed. */ int control_Clear(Control_Event *c) { Control_Keys *keys = NULL; int numRemoved = 0; while(c->eventKeys != NULL) { keys = c->eventKeys->data; if(keys != NULL) { control_CleanKeys(keys); mem_Free(keys); } list_Pop(&c->eventKeys); numRemoved ++; } return numRemoved; }
static LIST red_GetTerminatorPartnerLits(TERM Atom, LITERAL Lit, BOOL UnitsOnly, LIST IndexList) /************************************************************** INPUT: An atom, a literal, a boolean flag and a list of SHARED_INDEXes. RETURNS: A list of literals with sign complementary to <Lit> that are unifiable with <Atom>. The literals are searched in all SHARED_INDEXes from <IndexList>. Additionally, if <Unitsonly> is true, only literals from unit clauses are returned. EFFECT: <Atom> is a copy of <Lit> where some substitution was applied and equality literals might have been swapped. <Lit> is just needed to check whether the unifiable literals are complementary. ***************************************************************/ { LIST Result, Unifiers, LitScan; LITERAL NextLit; Result = list_Nil(); for ( ; !list_Empty(IndexList); IndexList = list_Cdr(IndexList)) { Unifiers = st_GetUnifier(cont_LeftContext(), sharing_Index(list_Car(IndexList)), cont_RightContext(), Atom); for ( ; !list_Empty(Unifiers); Unifiers = list_Pop(Unifiers)) { if (!term_IsVariable(list_Car(Unifiers))) { for (LitScan = sharing_NAtomDataList(list_Car(Unifiers)); !list_Empty(LitScan); LitScan = list_Cdr(LitScan)) { NextLit = list_Car(LitScan); if (clause_LiteralsAreComplementary(Lit, NextLit) && (!UnitsOnly || clause_Length(clause_LiteralOwningClause(NextLit))==1)) /* The partner literals must have complementary sign and if <UnitsOnly> == TRUE they must be from unit clauses. */ Result = list_Cons(NextLit, Result); } } } } return Result; }
/* Function: drawLayer_Clean Description - Removes and cleans up all objects in the layer. 1 argument: Draw_Layer *layer - The layer to clean up. */ void drawLayer_Clean(Draw_Layer *layer) { Draw_Object *drawObj = NULL; while(layer->objectList != NULL) { drawObj = layer->objectList->data; if(drawObj->type->cleanFunction != NULL) { drawObj->type->cleanFunction(drawObj); } drawObject_Clean(drawObj); mem_Free(drawObj); *layer->totalObjectLocations = *layer->totalObjectLocations - 1; list_Pop(&layer->objectList); } return; }
LIST list_PointerDeleteOneElement(LIST List, POINTER Element) /************************************************************** INPUT: A list and an element pointer. RETURNS: The list where one occurrence of Element is deleted from List with respect to pointer equality. EFFECTS: If List contains Element with respect to pointer equality, Element is deleted from List. CAUTION: Destructive. Be careful, the first element of a list cannot be changed destructively by call by reference. ***************************************************************/ { LIST Scan1,Scan2; if (list_Empty(List)) return List; else { if (Element == list_Car(List)) return list_Pop(List); } Scan2 = List; Scan1 = list_Cdr(List); while (!list_Empty(Scan1)) { if (Element == list_Car(Scan1)) { list_Rplacd(Scan2, list_Cdr(Scan1)); list_Free(Scan1); Scan1 = list_Cdr(Scan2); return List; } else { Scan2 = Scan1; Scan1 = list_Cdr(Scan1); } } return List; }
LIST list_DeleteOneElement(LIST List, POINTER Element, BOOL (*Test)(POINTER, POINTER)) /************************************************************** INPUT: A list, an element pointer and an equality test for elements. RETURNS: The list where at most one element was deleted from <List> if the Test between <Element> and the element succeeds. EFFECT: The function needs time O(n*t) in the worst case, and time O(t) in the best case, where <n> is the length of the list and t is the time for a call of the test function. CAUTION: Destructive. Be careful, the first element of a list cannot be changed destructively by call by reference. The memory of the deleted element is not freed. ***************************************************************/ { LIST scan1, scan2; if (list_Empty(List)) return List; else { if (Test(Element, list_Car(List))) return list_Pop(List); } for (scan2 = List, scan1 = list_Cdr(List); !list_Empty(scan1); scan2 = scan1, scan1 = list_Cdr(scan1)) { if (Test(Element, list_Car(scan1))) { list_Rplacd(scan2, list_Cdr(scan1)); list_Free(scan1); scan1 = list_Cdr(scan2); return List; } } return List; }
static LIST inf_SearchURResolvents(CLAUSE Clause, int i, LIST FoundMap, LIST RestLits, SUBST Subst, SYMBOL GlobalMaxVar, SHARED_INDEX Index, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A non-unit clause, a literal index from <Clause>. <FoundMap> is a list of pairs (l1,l2) of unifiable literals, where l1 is from <Clause> and l2 is from a unit clause. <RestLits> is a list of literals from <Clause> where we haven't found unifiable literals from unit clauses so far. <Subst> is the overall substitution for <Clause> (not for the unit-clauses!). <GlobalMaxVar> is the maximal variable encountered so far. <Index> is used to search unifiable literals. The flag store and the precedence are needed to create the new clauses. RETURNS: A list of UR resolution resolvents. ***************************************************************/ { if (list_Empty(RestLits)) { /* Stop the recursion */ return list_List(inf_CreateURUnitResolvent(Clause, i, Subst, FoundMap, Flags, Precedence)); } else { LITERAL Lit, PLit; SYMBOL NewMaxVar; SUBST NewSubst, RightSubst; TERM AtomCopy, PAtom; LIST Result, Partners; BOOL Swapped; Result = list_Nil(); Swapped = FALSE; /* Choose the unmatched literal with the most symbols */ RestLits = clause_MoveBestLiteralToFront(list_Copy(RestLits), Subst, GlobalMaxVar, clause_HyperLiteralIsBetter); Lit = list_Car(RestLits); RestLits = list_Pop(RestLits); AtomCopy = subst_Apply(Subst, term_Copy(clause_LiteralAtom(Lit))); /* The following 'endless' loop runs twice for equality literals */ /* and only once for other literals. */ while (TRUE) { Partners = inf_GetURPartnerLits(AtomCopy, Lit, TRUE, Index); for ( ; !list_Empty(Partners); Partners = list_Pop(Partners)) { PLit = list_Car(Partners); /* Rename the atom */ PAtom = term_Copy(clause_LiteralAtom(PLit)); term_StartMaxRenaming(GlobalMaxVar); term_Rename(PAtom); /* Get the new global maximal variable */ NewMaxVar = term_MaxVar(PAtom); if (symbol_GreaterVariable(GlobalMaxVar, NewMaxVar)) NewMaxVar = GlobalMaxVar; /* Get the substitution */ cont_Check(); if (!unify_UnifyNoOC(cont_LeftContext(), AtomCopy, cont_RightContext(), PAtom)) { misc_StartErrorReport(); misc_ErrorReport("\n In inf_SearchURResolvents: Unification failed."); misc_FinishErrorReport(); } subst_ExtractUnifier(cont_LeftContext(), &NewSubst, cont_RightContext(), &RightSubst); cont_Reset(); subst_Delete(RightSubst); /* Forget substitution for unit clause */ term_Delete(PAtom); /* Was just needed to get the substitution */ /* Build the composition of the substitutions */ RightSubst = NewSubst; NewSubst = subst_Compose(NewSubst, subst_Copy(Subst)); subst_Delete(RightSubst); FoundMap = list_Cons(list_PairCreate(Lit, PLit), FoundMap); Result = list_Nconc(inf_SearchURResolvents(Clause,i,FoundMap,RestLits, NewSubst,NewMaxVar,Index, Flags, Precedence), Result); list_PairFree(list_Car(FoundMap)); FoundMap = list_Pop(FoundMap); subst_Delete(NewSubst); } /* loop control */ if (!fol_IsEquality(AtomCopy) || Swapped) break; else { term_EqualitySwap(AtomCopy); Swapped = TRUE; } } /* cleanup */ term_Delete(AtomCopy); list_Delete(RestLits); return Result; } }
static LIST ana_CalculateFunctionPrecedence(LIST Functions, LIST Clauses, FLAGSTORE Flags) /************************************************************** INPUT: A list of functions, a list of clauses and a flag store. RETURNS: A list of function symbols, which should be used for setting the symbol precedence. The list is sorted in descending order, that means function with highest precedence come first. EFFECT: Analyzes the clauses to build a directed graph G with function symbol as nodes. An edge (f,g) or in G means f should have lower precedence than g. An edge (f,g) or (g,f) is created if there's an equation equal(f(...), g(...)) in the clause list. The direction of the edge depends on the degree of the nodes and the symbol arity. Then find the strongly connected components of this graph. The "Ordering" flag will be set in the flag store. CAUTION: The value of "ana_PEQUATIONS" must be up to date. ***************************************************************/ { GRAPH graph; GRAPHNODE n1, n2; LIST result, scan, scan2, distrPairs; int i, j; SYMBOL s, Add, Mult; if (list_Empty(Functions)) return Functions; /* Problem contains no functions */ else if (!ana_PEQUATIONS) { Functions = list_NumberSort(Functions, (NAT (*)(POINTER)) symbol_PositiveArity); return Functions; } graph = graph_Create(); /* First create the nodes: one node for every function symbol. */ for (; !list_Empty(Functions); Functions = list_Pop(Functions)) graph_AddNode(graph, symbol_Index((SYMBOL)list_Car(Functions))); /* Now sort the node list wrt descending symbol arity. */ graph_SortNodes(graph, ana_NodeGreater); /* A list of pairs (add, multiply) of distributive symbols */ distrPairs = list_Nil(); /* Now add undirected edges: there's an undirected edge between */ /* two nodes if the symbols occur as top symbols in a positive */ /* equation. */ for (scan = Clauses; !list_Empty(scan); scan = list_Cdr(scan)) { CLAUSE c = list_Car(scan); for (i = clause_FirstSuccedentLitIndex(c); i <= clause_LastSuccedentLitIndex(c); i++) { if (clause_LiteralIsEquality(clause_GetLiteral(c, i))) { /* Consider only positive equations */ TERM t1, t2; if (fol_DistributiveEquation(clause_GetLiteralAtom(c,i), &Add, &Mult)) { /* Add a pair (Add, Mult) to <distrTerms> */ distrPairs = list_Cons(list_PairCreate((POINTER)Add, (POINTER)Mult), distrPairs); /*fputs("\nDISTRIBUTIVITY: ", stdout); term_PrintPrefix(clause_GetLiteralAtom(c,i)); fputs(" Add=", stdout); symbol_Print(Add); fputs(" Mult=", stdout); symbol_Print(Mult); fflush(stdout); DBG */ } t1 = term_FirstArgument(clause_GetLiteralAtom(c, i)); t2 = term_SecondArgument(clause_GetLiteralAtom(c, i)); if (!term_IsVariable(t1) && !term_IsVariable(t2) && !term_EqualTopSymbols(t1, t2) && /* No self loops! */ !term_HasSubterm(t1, t2) && /* No subterm property */ !term_HasSubterm(t2, t1)) { n1 = graph_GetNode(graph, symbol_Index(term_TopSymbol(t1))); n2 = graph_GetNode(graph, symbol_Index(term_TopSymbol(t2))); /* Create an undirected edge by adding two directed edges */ graph_AddEdge(n1, n2); graph_AddEdge(n2, n1); /* Use the node info for the degree of the node */ ana_IncNodeDegree(n1); ana_IncNodeDegree(n2); } } } } /* putchar('\n'); for (scan = graph_Nodes(graph); !list_Empty(scan); scan = list_Cdr(scan)) { n1 = list_Car(scan); printf("(%s,%d,%u), ", symbol_Name(symbol_GetSigSymbol(graph_NodeNumber(n1))), graph_NodeNumber(n1), ana_NodeDegree(n1)); } graph_Print(graph); fflush(stdout); DBG */ graph_DeleteDuplicateEdges(graph); /* Transform the undirected graph into a directed graph. */ for (scan = graph_Nodes(graph); !list_Empty(scan); scan = list_Cdr(scan)) { n1 = list_Car(scan); result = list_Nil(); /* Collect edges from n1 that shall be deleted */ for (scan2 = graph_NodeNeighbors(n1); !list_Empty(scan2); scan2 = list_Cdr(scan2)) { int a1, a2; n2 = list_Car(scan2); /* Get the node degrees in the undirected graph with multiple edges */ i = ana_NodeDegree(n1); j = ana_NodeDegree(n2); a1 = symbol_Arity(symbol_GetSigSymbol(graph_NodeNumber(n1))); a2 = symbol_Arity(symbol_GetSigSymbol(graph_NodeNumber(n2))); if (i > j || (i==j && a1 >= a2)) { /* symbol2 <= symbol1, so remove edge n1 -> n2 */ result = list_Cons(n2, result); } if (i < j || (i==j && a1 <= a2)) { /* symbol1 <= symbol2, so remove edge n2 -> n1 */ graph_DeleteEdge(n2, n1); } /* NOTE: If (i==j && a1==a2) both edges are deleted! */ } /* Now delete edges from n1 */ for ( ; !list_Empty(result); result = list_Pop(result)) graph_DeleteEdge(n1, list_Car(result)); } if (!list_Empty(distrPairs) && !ana_BidirectionalDistributivity(distrPairs)) { /* Enable RPO ordering, otherwise the default KBO will be used. */ flag_SetFlagIntValue(Flags, flag_ORD, flag_ORDRPOS); } /* Now examine the list of distribute symbols */ /* since they've highest priority. */ for ( ; !list_Empty(distrPairs); distrPairs = list_Pop(distrPairs)) { scan = list_Car(distrPairs); /* A pair (Add, Mult) */ /* Addition */ n1 = graph_GetNode(graph, symbol_Index((SYMBOL)list_PairFirst(scan))); /* Multiplication */ n2 = graph_GetNode(graph, symbol_Index((SYMBOL)list_PairSecond(scan))); /* Remove any edges between n1 and n2 */ graph_DeleteEdge(n1, n2); graph_DeleteEdge(n2, n1); /* Add one edge Addition -> Multiplication */ graph_AddEdge(n1, n2); list_PairFree(scan); } /* fputs("\n------------------------",stdout); graph_Print(graph); fflush(stdout); DBG */ /* Calculate the strongly connected components of the graph. */ /* <i> is the number of SCCs. */ i = graph_StronglyConnectedComponents(graph); /* Now create the precedence list by scanning the nodes. */ /* If there's a link between two strongly connected components */ /* c1 and c2 then component_num(c1) > component_num(c2), so the */ /* following code creates a valid precedence list in descending */ /* order. */ result = list_Nil(); while (i-- > 0) { /* for i = numberOfSCCs -1 dowto 0 */ for (scan = graph_Nodes(graph); !list_Empty(scan); scan = list_Cdr(scan)) { n1 = list_Car(scan); if (graph_NodeCompNum(n1) == i) { /* The symbol represented by the node <n> belongs to component <i> */ s = symbol_GetSigSymbol(graph_NodeNumber(n1)); result = list_Cons((POINTER)s, result); } } } /* putchar('\n'); for (scan = result; !list_Empty(scan); scan = list_Cdr(scan)) { s = (SYMBOL) list_Car(scan); symbol_Print(s); fputs(" > ", stdout); } putchar('\n'); fflush(stdout); DBG */ graph_Delete(graph); return result; }
static LIST ana_CalculatePredicatePrecedence(LIST Predicates, LIST Clauses) /************************************************************** INPUT: A list of predicates and a list of clauses. RETURNS: A list of predicate symbols, which should be used for setting the symbol precedence. The list is sorted in descending order, that means predicates with highest precedence come first. EFFECT: Analyze the clause list to build a directed graph G where the predicates are vertices. There's an edge (P,Q) in G iff a clause exists where P is a negative literal and Q is a positive literal and P != Q. Apply DFS to find the strongly connected components of this graph. The <Predicates> list is deleted. CAUTION: The predicate list must contain ALL predicates occurring in the clause list! ***************************************************************/ { GRAPH graph; LIST result, scan; int i, j; NAT count; SYMBOL s; /* clause_ListPrint(Clauses); DBG */ if (list_Empty(Predicates)) { return Predicates; } graph = graph_Create(); /* First create the nodes: one node for every predicate symbol. */ for ( ; !list_Empty(Predicates); Predicates = list_Pop(Predicates)) graph_AddNode(graph, symbol_Index((SYMBOL)list_Car(Predicates))); /* Now scan the clause clause list to create the edges */ /* An edge (P,Q) means P is smaller than Q */ for (scan = Clauses; !list_Empty(scan); scan = list_Cdr(scan)) { CLAUSE c = list_Car(scan); for (i = clause_FirstLitIndex(); i < clause_FirstSuccedentLitIndex(c); i++) { SYMBOL negPred = term_TopSymbol(clause_GetLiteralAtom(c, i)); if (!symbol_Equal(negPred, fol_Equality())) { /* negative predicate */ for (j = clause_FirstSuccedentLitIndex(c); j < clause_Length(c); j++) { SYMBOL posPred = term_TopSymbol(clause_GetLiteralAtom(c, j)); if (!symbol_Equal(posPred, fol_Equality()) && /* positive predicate */ negPred != posPred) { /* No self loops! */ graph_AddEdge(graph_GetNode(graph, symbol_Index(negPred)), graph_GetNode(graph, symbol_Index(posPred))); } } } } } /* graph_Print(graph); fflush(stdout); DBG */ /* Calculate the strongly connected components of the graph */ count = graph_StronglyConnectedComponents(graph); /* Now create the precedence list by scanning the nodes. */ /* If there's a link between two strongly connected components */ /* c1 and c2 then component_num(c1) > component_num(c2), so the */ /* following code creates a valid precedence list in descending */ /* order. */ result = list_Nil(); for (i = count - 1; i >= 0; i--) { for (scan = graph_Nodes(graph); !list_Empty(scan); scan = list_Cdr(scan)) { GRAPHNODE n = list_Car(scan); if (graph_NodeCompNum(n) == i) { /* The symbol represented by the node <<n> belongs to component <i> */ s = symbol_GetSigSymbol(graph_NodeNumber(n)); result = list_Cons((POINTER)s, result); } } } /* putchar('\n'); for (scan = result; !list_Empty(scan); scan = list_Cdr(scan)) { s = (SYMBOL) list_Car(scan); symbol_Print(s); putchar(' '); } putchar('\n'); fflush(stdout); DBG */ graph_Delete(graph); return result; }
void ana_AutoConfiguration(LIST Clauses, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A list of clauses, a flag store and a precedence. RETURNS: Nothing. EFFECT: Based on the values of the ana analysis module, an appropriate complete configuration of inference, reduction rules and other settings is established. ***************************************************************/ { LIST Scan, Functions, Predicates, Constants; Functions = symbol_GetAllFunctions(); Predicates = fol_GetNonFOLPredicates(); /* Set precedence */ Predicates = ana_CalculatePredicatePrecedence(Predicates, Clauses); Functions = ana_CalculateFunctionPrecedence(Functions, Clauses, Flags); Constants = list_Nil(); for (Scan=Functions; !list_Empty(Scan); Scan=list_Cdr(Scan)) if (symbol_IsConstant((SYMBOL)list_Car(Scan))) Constants = list_Cons(list_Car(Scan),Constants); Functions = list_NPointerDifference(Functions,Constants); Constants = list_NReverse(Constants); for ( ; !list_Empty(Functions); Functions = list_Pop(Functions)) symbol_SetIncreasedOrdering(Precedence, (SYMBOL)list_Car(Functions)); /* Predicates < Functions */ for ( ; !list_Empty(Predicates); Predicates = list_Pop(Predicates)) symbol_SetIncreasedOrdering(Precedence, (SYMBOL)list_Car(Predicates)); /* Constants < Predicates */ /* Predicates < Functions */ for ( ; !list_Empty(Constants); Constants = list_Pop(Constants)) symbol_SetIncreasedOrdering(Precedence, (SYMBOL)list_Car(Constants)); flag_ClearInferenceRules(Flags); flag_ClearReductionRules(Flags); flag_SetFlagIntValue(Flags, flag_ROBV, flag_ROBVON); flag_SetFlagIntValue(Flags, flag_RTAUT, flag_RTAUTSYNTACTIC); flag_SetFlagIntValue(Flags, flag_RFSUB, flag_RFSUBON); flag_SetFlagIntValue(Flags, flag_RBSUB, flag_RBSUBON); flag_SetFlagIntValue(Flags, flag_RFMRR, flag_RFMRRON); flag_SetFlagIntValue(Flags, flag_RBMRR, flag_RBMRRON); flag_SetFlagIntValue(Flags, flag_RUNC, flag_RUNCON); flag_SetFlagIntValue(Flags, flag_FULLRED, flag_FULLREDON); /*flag_SetFlagIntValue(Flags, flag_FUNCWEIGHT,1); flag_SetFlagIntValue(Flags, flag_VARWEIGHT,1);*/ flag_SetFlagIntValue(Flags, flag_WDRATIO,5); if (ana_NEQUATIONS) { flag_SetFlagIntValue(Flags, flag_IEQR, flag_EQUALITYRESOLUTIONON); if (ana_NONUNIT) { if (ana_NONTRIVDOMAIN) flag_SetFlagIntValue(Flags, flag_RAED, flag_RAEDPOTUNSOUND); else flag_SetFlagIntValue(Flags, flag_RAED, flag_RAEDSOUND); } } if (ana_PEQUATIONS) { flag_SetFlagIntValue(Flags, flag_ISPR, flag_SUPERPOSITIONRIGHTON); flag_SetFlagIntValue(Flags, flag_ISPL, flag_SUPERPOSITIONLEFTON); if (ana_NONHORNCLAUSES > 0) flag_SetFlagIntValue(Flags, flag_IEQF, flag_EQUALITYFACTORINGON); if (ana_NONUNIT) flag_SetFlagIntValue(Flags, flag_RCON, flag_RCONON); flag_SetFlagIntValue(Flags, flag_RFREW, flag_RFREWON); flag_SetFlagIntValue(Flags, flag_RBREW, flag_RBREWON); } if (ana_SORTRES) { flag_SetFlagIntValue(Flags, flag_SORTS, flag_SORTSMONADICWITHVARIABLE); flag_SetFlagIntValue(Flags, flag_IEMS, flag_EMPTYSORTON); flag_SetFlagIntValue(Flags, flag_ISOR, flag_SORTRESOLUTIONON); flag_SetFlagIntValue(Flags, flag_RSSI, flag_RSSION); if (!ana_PEQUATIONS || ana_SORTMANYEQUATIONS) flag_SetFlagIntValue(Flags, flag_RSST, flag_RSSTON); } else flag_SetFlagIntValue(Flags, flag_SORTS, flag_SORTSOFF); if (ana_MONADIC || ana_NONMONADIC) { /* Problem contains real predicates */ flag_SetFlagIntValue(Flags, flag_IORE, flag_ORDEREDRESOLUTIONNOEQUATIONS); if (ana_NONHORNCLAUSES > 0) flag_SetFlagIntValue(Flags, flag_IOFC, flag_FACTORINGONLYRIGHT); if (ana_NONUNIT) flag_SetFlagIntValue(Flags, flag_RCON, flag_RCONON); } if (!ana_FUNCTIONS) flag_SetFlagIntValue(Flags, flag_SELECT, flag_SELECTALWAYS); else if (ana_NONUNIT) flag_SetFlagIntValue(Flags, flag_SELECT, flag_SELECTIFSEVERALMAXIMAL); else flag_SetFlagIntValue(Flags, flag_SELECT, flag_SELECTOFF); if (ana_CONCLAUSES < ana_AXIOMCLAUSES || (ana_CONGROUND && !ana_PUREPROPOSITIONAL)) flag_SetFlagIntValue(Flags, flag_SATINPUT, flag_SATINPUTON); else flag_SetFlagIntValue(Flags, flag_SATINPUT, flag_SATINPUTOFF); if (ana_NONHORNCLAUSES > 0) flag_SetFlagIntValue(Flags, flag_SPLITS, flag_SPLITSUNLIMITED); else flag_SetFlagIntValue(Flags, flag_SPLITS, flag_SPLITSOFF); /* if (ana_PUREPROPOSITIONAL) */ /* flag_SetFlagIntValue(Flags, flag_SPLITHEURISTIC, flag_SPLITHEURISTICALWAYS); */ }
LIST dp_PrintProof(PROOFSEARCH Search, LIST Clauses, const char *FilePrefix) /********************************************************* INPUT: A proofsearch object, a list of empty clauses and the prefix of the output file name. RETURNS: The list of clauses required for the proof. MEMORY: The returned list must be freed. EFFECT: The proof is printed both to standard output and to the file <FilePrefix>.prf. **********************************************************/ { LIST ProofClauses,Scan,EmptyClauses,AllClauses, ReducedProof; LIST Missing, Incomplete, SplitClauses; FLAGSTORE Flags; Flags = prfs_Store(Search); Missing = pcheck_ConvertParentsInSPASSProof(Search, Clauses); if (!list_Empty(Missing)) { puts("\nNOTE: clauses with following numbers have not been found:"); for (; !list_Empty(Missing); Missing = list_Pop(Missing)) printf("%d ", (int)list_Car(Missing)); putchar('\n'); } EmptyClauses = list_Copy(Clauses); ProofClauses = list_Nil(); AllClauses = list_Nconc(list_Copy(prfs_DocProofClauses(Search)), list_Nconc(list_Copy(prfs_UsableClauses(Search)), list_Copy(prfs_WorkedOffClauses(Search)))); /* * collect proof clauses by noodling upward in the * proof tree, starting from <EmptyClauses>. * Before, add all splitting clauses to avoid gaps in split tree */ SplitClauses = list_Nil(); for (Scan = AllClauses; !list_Empty(Scan); Scan = list_Cdr(Scan)) if (clause_IsFromSplitting(list_Car(Scan))) SplitClauses = list_Cons(list_Car(Scan), SplitClauses); /* mark all needed clauses */ pcheck_ClauseListRemoveFlag(EmptyClauses, MARKED); pcheck_ClauseListRemoveFlag(AllClauses, MARKED); pcheck_MarkRecursive(EmptyClauses); pcheck_MarkRecursive(SplitClauses); /* collect all marked clauses */ ProofClauses = list_Nil(); for (Scan = AllClauses; !list_Empty(Scan); Scan = list_Cdr(Scan)) { if (clause_GetFlag(list_Car(Scan), MARKED)) ProofClauses = list_Cons(list_Car(Scan), ProofClauses); } /* build reduced proof */ ProofClauses = list_Nconc(ProofClauses, list_Copy(EmptyClauses)); ProofClauses = pcheck_ClauseNumberMergeSort(ProofClauses); ReducedProof = pcheck_ReduceSPASSProof(ProofClauses); dp_SetProofDepth(pcheck_SeqProofDepth(ReducedProof)); pcheck_ParentPointersToParentNumbers(AllClauses); pcheck_ParentPointersToParentNumbers(Clauses); /* check reduced proof for clauses whose parents have been marked as incomplete (HIDDEN flag) by ConvertParentsInSPASSProof */ Incomplete = list_Nil(); for (Scan = ReducedProof; !list_Empty(Scan); Scan = list_Cdr(Scan)) { if (clause_GetFlag(list_Car(Scan), HIDDEN)) Incomplete = list_Cons(list_Car(Scan), Incomplete); } if (!list_Empty(Incomplete)) { puts("NOTE: Following clauses in reduced proof have incomplete parent sets:"); for (Scan = Incomplete; !list_Empty(Scan); Scan = list_Cdr(Scan)) printf("%d ", clause_Number(list_Car(Scan))); putchar('\n'); } printf("\n\nHere is a proof with depth %d, length %d :\n", dp_ProofDepth(), list_Length(ReducedProof)); clause_ListPrint(ReducedProof); if (flag_GetFlagValue(Flags, flag_FPDFGPROOF)) dp_FPrintDFGProof(ReducedProof, FilePrefix, Flags, prfs_Precedence(Search)); fflush(stdout); list_Delete(EmptyClauses); list_Delete(AllClauses); list_Delete(ProofClauses); list_Delete(SplitClauses); list_Delete(Incomplete); return ReducedProof; }
static CLAUSE red_SearchTerminator(NAT n, LIST RestLits, LIST FoundMap, SUBST Subst, SYMBOL GlobalMaxVar, LIST IndexList, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A natural number, a list of literals, a list of pairs, a substitution, the maximum variable occurring in all involved clauses, a list of SHARED_INDEXes, a flag store and a precedence. RETURNS: An empty clause, if a terminator situation was found, NULL otherwise. EFFECT: This recursive function implements the search for a terminator situation with at most <n> non-unit clauses. <RestLits> is the lists of literals actually missing a complementary partner literal. <FoundMap> is a list of pairs (l1,l2), where l1 and l2 are complementary, unifiable literals. <Subst> is the common substitution of all those pairs. <GlobalMaxVar> is the maximum variable from all involved clauses. To enable the search all involved clauses are made variable-disjoint. At the moment the function stops, if ANY terminator situation occurred. This might not be desirable if splitting is enabled, since there might be other terminator situations resulting in an empty clause of lower split level. The flag store and the precedence are needed to create the new clause. ***************************************************************/ { if (list_Empty(RestLits)) { /* We found a terminator situation, so stop the recursion */ return red_CreateTerminatorEmptyClause(FoundMap, Flags, Precedence); } else { CLAUSE Result, PClauseCopy; LITERAL Lit, PLit; SYMBOL NewMaxVar; SUBST NewSubst, RightSubst; TERM AtomCopy; LIST ClashList, ToDoList; BOOL Swapped; NAT Limit; int PLitInd; Swapped = FALSE; Result = clause_Null(); clause_MoveBestLiteralToFront(RestLits, Subst, GlobalMaxVar, red_TerminatorLitIsBetter); Lit = list_Car(RestLits); RestLits = list_Cdr(RestLits); AtomCopy = subst_Apply(Subst, term_Copy(clause_LiteralAtom(Lit))); /* The following 'endless' loop runs twice for equality literals */ /* and only once for other literals. */ while (TRUE) { ClashList = red_GetTerminatorPartnerLits(AtomCopy, Lit, n==0, IndexList); for (; !list_Empty(ClashList) && Result==NULL; ClashList = list_Pop(ClashList)) { PLit = list_Car(ClashList); PLitInd = clause_LiteralGetIndex(PLit); PClauseCopy = clause_Copy(clause_LiteralOwningClause(PLit)); Limit = clause_Length(PClauseCopy) == 1 ? n : n-1; clause_RenameVarsBiggerThan(PClauseCopy, GlobalMaxVar); PLit = clause_GetLiteral(PClauseCopy, PLitInd); FoundMap = list_Cons(list_PairCreate(Lit, PLit), FoundMap); ToDoList = clause_GetLiteralListExcept(PClauseCopy, PLitInd); ToDoList = list_Nconc(ToDoList, list_Copy(RestLits)); NewMaxVar = clause_SearchMaxVar(PClauseCopy); if (symbol_GreaterVariable(GlobalMaxVar, NewMaxVar)) NewMaxVar = GlobalMaxVar; cont_Check(); if (!unify_UnifyNoOC(cont_LeftContext(), AtomCopy, cont_RightContext(), clause_LiteralAtom(PLit))) { misc_StartErrorReport(); misc_ErrorReport("\n In red_SearchTerminator: Unification failed."); misc_FinishErrorReport(); } subst_ExtractUnifier(cont_LeftContext(), &NewSubst, cont_RightContext(), &RightSubst); cont_Reset(); /* The domains of both substitutions are disjoint */ /* so we do just a simple union operation. */ NewSubst = subst_NUnion(NewSubst, RightSubst); RightSubst = NewSubst; NewSubst = subst_Compose(NewSubst, subst_Copy(Subst)); subst_Delete(RightSubst); Result = red_SearchTerminator(Limit, ToDoList, FoundMap, NewSubst, NewMaxVar, IndexList, Flags, Precedence); clause_Delete(PClauseCopy); subst_Delete(NewSubst); list_Delete(ToDoList); list_PairFree(list_Car(FoundMap)); FoundMap = list_Pop(FoundMap); } /* loop control */ if (!fol_IsEquality(AtomCopy) || Swapped || Result!=NULL) break; else { list_Delete(ClashList); term_EqualitySwap(AtomCopy); Swapped = TRUE; } } /* cleanup */ term_Delete(AtomCopy); /* <ClashList> may be non-empty since the loop stops */ /* if a terminator was found. */ list_Delete(ClashList); return Result; } }
LIST inf_URResolution(CLAUSE Clause, SHARED_INDEX Index, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A clause, a shared index, a flag store and a precedence. RETURNS: The list of UR resolution resolvents. EFFECT: The flag store and the precedence are needed to create the resolvents. ***************************************************************/ { LIST Result; if (clause_Length(Clause) != 1) { /* Clause isn't unit clause */ Result = inf_NonUnitURResolution(Clause, -1, list_Nil(), subst_Nil(), clause_MaxVar(Clause), Index, Flags, Precedence); } else { /* Clause is unit clause, so search partner literals in non-unit clauses */ LITERAL Lit, PLit; TERM Atom; LIST Partners, FoundMap; SYMBOL MaxVar, PMaxVar; SUBST LeftSubst, RightSubst; CLAUSE PClause; int PLitInd; BOOL Swapped; Result = list_Nil(); Lit = clause_GetLiteral(Clause, clause_FirstLitIndex()); Atom = term_Copy(clause_LiteralAtom(Lit)); Swapped = FALSE; /* The following 'endless' loop runs twice for equality literals */ /* and only once for other literals. */ while (TRUE) { /* Get complementary literals from non-unit clauses */ Partners = inf_GetURPartnerLits(Atom, Lit, FALSE, Index); for ( ; !list_Empty(Partners); Partners = list_Pop(Partners)) { PLit = list_Car(Partners); PLitInd = clause_LiteralGetIndex(PLit); PClause = clause_LiteralOwningClause(PLit); /* non-unit clause */ PMaxVar = clause_MaxVar(PClause); term_StartMaxRenaming(PMaxVar); term_Rename(Atom); /* Rename atom from unit clause */ MaxVar = term_MaxVar(Atom); if (symbol_GreaterVariable(PMaxVar, MaxVar)) MaxVar = PMaxVar; /* Get the substitution */ cont_Check(); unify_UnifyNoOC(cont_LeftContext(), clause_LiteralAtom(PLit), cont_RightContext(), Atom); subst_ExtractUnifier(cont_LeftContext(), &LeftSubst, cont_RightContext(), &RightSubst); cont_Reset(); /* We don't need the substitution for the unit clause */ subst_Delete(RightSubst); FoundMap = list_List(list_PairCreate(PLit, Lit)); Result = list_Nconc(inf_NonUnitURResolution(PClause, PLitInd, FoundMap, LeftSubst, MaxVar, Index, Flags, Precedence), Result); list_DeletePairList(FoundMap); subst_Delete(LeftSubst); } /* loop control */ if (!fol_IsEquality(Atom) || Swapped) break; else { term_EqualitySwap(Atom); Swapped = TRUE; } } /* end of endless loop */ term_Delete(Atom); } return Result; }