/* unused */ void symbol_PrintPrecedence(PRECEDENCE Precedence) /************************************************************** INPUT: A precedence. RETURNS: Nothing. EFFECT: Prints the precedence to stdout. ***************************************************************/ { if (symbol_SignatureExists()) { LIST Symbols, Scan; int Index; SIGNATURE S; Symbols = list_Nil(); for (Index = 1; Index < symbol_ACTINDEX; Index++) { S = symbol_Signature(Index); if (S != NULL && (symbol_IsPredicate(S->info) || symbol_IsFunction(S->info))) Symbols = list_Cons((POINTER)S->info, Symbols); } Symbols = symbol_SortByPrecedence(Symbols, Precedence); for (Scan = Symbols; !list_Empty(Scan); Scan = list_Cdr(Scan)) { S = symbol_Signature(symbol_Index((SYMBOL)list_Car(Scan))); fputs(S->name, stdout); if (!list_Empty(list_Cdr(Scan))) fputs(" > ", stdout); } list_Delete(Symbols); } }
CLAUSE red_Terminator(CLAUSE RedClause, NAT n, SHARED_INDEX WoIndex, SHARED_INDEX UsIndex, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A clause, two shared indexes, a number <n> restricting the number of non-unit clauses in a possible terminator situation, a flag store and a precedence. RETURNS: An empty clause if a terminator with at most <n> non-unit clauses is found, NULL otherwise. EFFECT: See also description of red_SearchTerminator. ***************************************************************/ { LIST Rest, IndexList; CLAUSE Result; if (clause_Length(RedClause) > 1) /* non-unit clause */ n--; /* Pass the indexes as a list to sub-functions */ IndexList = list_Cons(WoIndex, list_List(UsIndex)); Rest = clause_GetLiteralList(RedClause); Result = red_SearchTerminator(n, Rest, list_Nil(), subst_Nil(), clause_MaxVar(RedClause), IndexList, Flags, Precedence); /* cleanup */ list_Delete(IndexList); list_Delete(Rest); return Result; }
BOOL cmdlne_SetArgument(const char* token, const char* value) /************************************************************** INPUT: two pointers RETURNS: TRUE if the argument <token> has not been added to the list of arguments before and FALSE otherwise. EFFECT: Adds argument <token> with value <value> to list of arguments (<cmdlne_ArgumentsList>) CAUTION: <value> has to be a character pointer pointing to a string representing an integer ***************************************************************/ { LIST Pair; LIST Scan; /* Check if Argument has already been defined */ for(Scan=cmdlne_ArgumentsList; !list_Empty(Scan); Scan = list_Cdr(Scan)) { if(string_Equal(list_PairFirst(list_Car(Scan)),token)) { misc_StartUserErrorReport(); misc_UserErrorReport("\n Option %s is multiply defined.\n\n", token); misc_FinishUserErrorReport(); return FALSE; } } /* Add <token> to argument list with value <value>*/ Pair = list_PairCreate(string_StringCopy(token), string_StringCopy(value)); cmdlne_ArgumentsList = list_Cons(Pair, cmdlne_ArgumentsList); return TRUE; }
static void st_NodeAddInner(st_INDEX StIndex, SUBST SubstOld, SUBST SubstNew, SUBST ComGen, st_MINMAX MinMax, POINTER Pointer) /************************************************************** INPUT: RETURNS: EFFECTS: ***************************************************************/ { st_INDEX OldIndexNode; OldIndexNode = st_Get(); OldIndexNode->subst = SubstOld; OldIndexNode->entries = StIndex->entries; OldIndexNode->subnodes = StIndex->subnodes; st_SetMax(OldIndexNode, st_Max(StIndex)); st_SetMin(OldIndexNode, st_Min(StIndex)); subst_Delete(StIndex->subst); StIndex->subst = ComGen; StIndex->entries = list_Nil(); StIndex->subnodes = list_Cons(st_NodeAddLeaf(SubstNew, MinMax, Pointer), list_List(OldIndexNode)); if (st_Max(StIndex) < MinMax) st_SetMax(StIndex, MinMax); else if (st_Min(StIndex) > MinMax) st_SetMin(StIndex, MinMax); }
LIST list_NReverse(LIST List) /************************************************************** INPUT: A list RETURNS: The same list with reversed order of items. CAUTION: Destructive. The function needs time O(n), where <n> is the length of the list. ***************************************************************/ { LIST ReverseList; LIST Scan1; LIST Scan2; ReverseList = list_Nil(); for (Scan1=List; !list_Empty(Scan1); Scan1=list_Cdr(Scan1)) ReverseList = list_Cons(list_Car(Scan1),ReverseList); for (Scan1=List, Scan2=ReverseList; !list_Empty(Scan1); Scan1=list_Cdr(Scan1), Scan2=list_Cdr(Scan2)) list_Rplaca(Scan1, list_Car(Scan2)); list_Delete(ReverseList); return List; }
void symbol_Delete(SYMBOL Symbol) /************************************************************** INPUT: A symbol. RETURNS: Nothing. SUMMARY: Deletes the symbol from the symbol table and frees its memory. ***************************************************************/ { #ifdef CHECK if (!symbol_SignatureExists()) { misc_StartErrorReport(); misc_ErrorReport("\n In symbol_Delete: Module was initialized without signature.\n"); misc_FinishErrorReport(); } if (!symbol_IsSymbol(Symbol)) { misc_StartErrorReport(); misc_ErrorReport("\n In symbol_Delete: Illegal input.\n"); misc_FinishErrorReport(); } #endif if (!symbol_IsVariable(Symbol)) { int Index; SIGNATURE Entry; Index = symbol_Index(Symbol); symbol_FREEDSYMBOLS = list_Cons((POINTER)Index,symbol_FREEDSYMBOLS); Entry = symbol_Signature(Index); symbol_SetSignature(Index, NULL); symbol_FreeSignature(Entry); } }
void symbol_RearrangePrecedence(PRECEDENCE Precedence, LIST UserPrecedence) /************************************************************** INPUT: A precedence and a list of symbols in the user specified precedence, sorted in decreasing order. RETURNS: Nothing. EFFECT: Modifies the given precedence to comply with the symbol precedence selected by the user. ***************************************************************/ { LIST Scan1, Scan2, Precedences; Precedences = list_Nil(); for (Scan1 = UserPrecedence; !list_Empty(Scan1); Scan1 = list_Cdr(Scan1)) { Precedences = list_Cons((POINTER) symbol_Ordering(Precedence, (SYMBOL) list_Car(Scan1)), Precedences); } Precedences = list_PointerSort(Precedences); Scan1 = UserPrecedence; Scan2 = Precedences; while (Scan1 != list_Nil() && Scan2 != list_Nil()) { symbol_SetOrdering(Precedence, (SYMBOL) list_Car(Scan1), (int) list_Car(Scan2)); Scan1 = list_Cdr(Scan1); Scan2 = list_Cdr(Scan2); } list_Delete(Precedences); }
static CLAUSE red_CreateTerminatorEmptyClause(LIST FoundMap, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A list of pairs (l1, l2), where l1 and l2 are unifiable literals with complementary sign and a flag store. More accurately, a substitution s exists, such that l1 s = l2 s for all pairs (l1,l2) in <FoundMap>. For all literals l from the involved clauses there exists one pair (l1,l2) in <FoundMap> with l1=l or l2=l. The flags store and the precedence are needed to create the new clause. RETURNS: A newly created empty clause, where the data (parents,...) is set according to <FoundMap>. ***************************************************************/ { CLAUSE Result, PClause; LITERAL Lit; LIST Parents; NAT depth; Result = clause_Create(list_Nil(), list_Nil(), list_Nil(), Flags, Precedence); Parents = list_Nil(); depth = 0; for (; !list_Empty(FoundMap); FoundMap = list_Cdr(FoundMap)) { Lit = list_PairSecond(list_Car(FoundMap)); PClause = clause_LiteralOwningClause(Lit); Parents = list_Cons(PClause, Parents); depth = misc_Max(depth, clause_Depth(PClause)); clause_AddParentClause(Result, clause_Number(PClause)); clause_AddParentLiteral(Result, clause_LiteralGetIndex(Lit)); Lit = list_PairFirst(list_Car(FoundMap)); PClause = clause_LiteralOwningClause(Lit); Parents = list_Cons(PClause, Parents); depth = misc_Max(depth, clause_Depth(PClause)); clause_AddParentClause(Result, clause_Number(PClause)); clause_AddParentLiteral(Result, clause_LiteralGetIndex(Lit)); } clause_SetFromTerminator(Result); clause_SetDepth(Result, depth+1); clause_SetSplitDataFromList(Result, Parents); list_Delete(Parents); return Result; }
void graph_AddEdge(GRAPHNODE From, GRAPHNODE To) /************************************************************** INPUT: Two graph nodes. RETURNS: Nothing. EFFECT: Adds a single (directed) edge (From, To). ***************************************************************/ { From->neighbors = list_Cons(To, From->neighbors); }
static CLAUSE inf_CreateURUnitResolvent(CLAUSE Clause, int i, SUBST Subst, LIST FoundMap, FLAGSTORE Flags, PRECEDENCE Precedence) /************************************************************** INPUT: A non-unit clause, a literal index from the clause, a substitution, a list of pairs (l1, l2) of literals, where l1 is from the non-unit clause and l2 is from a unit clause, a flag store and a precedence. RETURNS: The resolvent of this UR resolution inference. The clause consists of the literal at index <i> in <Clause> after application of <Subst>. EFFECT: The flag store and the precedence are needed to create the new clause. ***************************************************************/ { CLAUSE Result, PClause; LITERAL Lit; TERM Atom; LIST Parents; NAT depth; /* Create atom for resolvent */ Atom = subst_Apply(Subst, term_Copy(clause_GetLiteralAtom(Clause, i))); /* Create clause */ Parents = list_List(Atom); if (i <= clause_LastConstraintLitIndex(Clause)) Result = clause_Create(Parents, list_Nil(), list_Nil(), Flags, Precedence); else if (i <= clause_LastAntecedentLitIndex(Clause)) Result = clause_Create(list_Nil(), Parents, list_Nil(), Flags, Precedence); else Result = clause_Create(list_Nil(), list_Nil(), Parents, Flags, Precedence); list_Delete(Parents); /* Get parent clauses and literals, calculate depth of resolvent */ Parents = list_List(Clause); depth = clause_Depth(Clause); for ( ; !list_Empty(FoundMap); FoundMap = list_Cdr(FoundMap)) { Lit = list_PairSecond(list_Car(FoundMap)); /* Literal from unit */ PClause = clause_LiteralOwningClause(Lit); Parents = list_Cons(PClause, Parents); depth = misc_Max(depth, clause_Depth(PClause)); clause_AddParentClause(Result, clause_Number(PClause)); clause_AddParentLiteral(Result, clause_LiteralGetIndex(Lit)); Lit = list_PairFirst(list_Car(FoundMap)); /* Is from <Clause> */ clause_AddParentClause(Result, clause_Number(Clause)); clause_AddParentLiteral(Result, clause_LiteralGetIndex(Lit)); } clause_SetFromURResolution(Result); clause_SetDepth(Result, depth+1); clause_SetSplitDataFromList(Result, Parents); list_Delete(Parents); return Result; }
void split_KeepClauseAtLevel(PROOFSEARCH PS, CLAUSE Clause, int Level) /************************************************************** INPUT: A clause and a level as int. RETURNS: None. MEMORY: A copy of clause is made and kept within the split stack. ***************************************************************/ { SPLIT Split; Split = prfs_GetSplitOfLevel(Level, PS); prfs_SplitSetDeletedClauses(Split,list_Cons(Clause, prfs_SplitDeletedClauses(Split))); }
LIST cond_CondFast(CLAUSE c) /********************************************************** INPUT: A clause c. RETURNS: A list with indexes with respect to c that can be deleted due to condensing. CAUTION: None. ***********************************************************/ { int vec, i, j, k; LIST indexlist; indexlist = list_Nil(); vec = vec_ActMax(); for (i = 0; i < clause_Length(c); i++) { vec_Push((POINTER) i); } for (k = clause_Length(c) - 1; k >= 0; k--) { for (i = vec; i < vec_ActMax(); i++) { if ((int)vec_GetNth(i) != k) { cont_StartBinding(); if (unify_Match(cont_LeftContext(), clause_GetLiteralTerm(c,k), clause_GetLiteralTerm(c,(int)vec_GetNth(i)))) { cont_BackTrack(); for (j = vec; j < vec_ActMax(); j++) { if (k == (int)vec_GetNth(j)) { vec_Swap((vec_ActMax() -1) ,j); j = vec_ActMax(); } } if (subs_IdcRes(c,vec,(vec_ActMax() -1))) { indexlist = list_Cons((POINTER)k,indexlist); vec_Pop(); } i = vec_ActMax()+1; } else cont_BackTrack(); } } } vec_SetMax(vec); return indexlist; }
LIST list_Reverse(const LIST List) /************************************************************** INPUT: A list. RETURNS: A new list where the order of the elements is reversed. EFFECT: The function needs time O(n), where <n> is the length of the list. ***************************************************************/ { LIST ReverseList; LIST Scan; ReverseList = list_Nil(); for (Scan=List;!list_Empty(Scan);Scan=list_Cdr(Scan)) ReverseList = list_Cons(list_Car(Scan), ReverseList); return ReverseList; }
static LIST inf_NonUnitURResolution(CLAUSE Clause, int SpecialLitIndex, LIST FoundMap, 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. At this point the list has at most one element. <Subst> is the substitution for <Clause>. <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: The list of UR resolution resolvents. EFFECT: If inf_URResolution was called with a unit clause, <SpecialLitIndex> is the index of a literal from a non-unit clause, that is unifiable with the unit clause's literal, otherwise it is set to -1. ***************************************************************/ { LIST Result, RestLits; int i, last; Result = list_Nil(); RestLits = clause_GetLiteralListExcept(Clause, SpecialLitIndex); last = clause_LastLitIndex(Clause); for (i = clause_FirstLitIndex(); i <= last; i++) { /* <i> is the index of the literal that remains in the resolvent */ if (i != SpecialLitIndex) { RestLits = list_PointerDeleteOneElement(RestLits, clause_GetLiteral(Clause,i)); Result = list_Nconc(inf_SearchURResolvents(Clause, i, FoundMap, RestLits, Subst, GlobalMaxVar, Index, Flags, Precedence), Result); RestLits = list_Cons(clause_GetLiteral(Clause, i), RestLits); } } list_Delete(RestLits); return Result; }
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; }
void list_InsertNext(LIST List, POINTER Pointer) /************************************************************** INPUT: A list and a pointer to anything. RETURNS: A list with Pointer being added at the position that follows List. SUMMARY: We enqueue the element at position list_Cdr(List); The function needs time O(1). ***************************************************************/ { #ifdef CHECK if (Pointer == NULL) { misc_StartErrorReport(); misc_ErrorReport("\n In list_InsertNext: NULL Pointer. "); misc_FinishErrorReport(); } #endif list_Rplacd(List, list_Cons(Pointer, list_Cdr(List))); }
static void tab_ToSeqProofOrdered(TABLEAU T, LIST* Proof) /************************************************************** INPUT: A tableau <T>, a list of clauses <Proof> representing a proof by reference RETURNS: The sequential proof corresponding to the tableau. ***************************************************************/ { LIST Scan; BOOL RightSplitRead, LeftSplitRead; if (tab_IsEmpty(T)) return; Scan = tab_Clauses(T); RightSplitRead = LeftSplitRead = FALSE; while (!list_Empty(Scan)) { /* insert left and right splits and descendants controlled by clause number */ if (!RightSplitRead && !tab_RightBranchIsEmpty(T) && clause_Number(list_Car(Scan)) < clause_Number(list_Car(tab_RightSplitClauses(T)))) { tab_ToSeqProofOrdered(tab_RightBranch(T), Proof); RightSplitRead = TRUE; } if (!LeftSplitRead && !tab_LeftBranchIsEmpty(T) && clause_Number(list_Car(Scan)) < clause_Number(tab_LeftSplitClause(T))) { tab_ToSeqProofOrdered(tab_LeftBranch(T), Proof); LeftSplitRead = TRUE; } (*Proof) = list_Cons(list_Car(Scan), *Proof); Scan = list_Cdr(Scan); } /* if a split clause with descendants has not been inserted yet, it been generated after all other clauses */ if (!RightSplitRead) tab_ToSeqProofOrdered(tab_RightBranch(T), Proof); if (!LeftSplitRead) tab_ToSeqProofOrdered(tab_LeftBranch(T), Proof); }
GRAPHNODE graph_AddNode(GRAPH Graph, NAT Number) /************************************************************** INPUT: A graph and the ID of a node. RETURNS: A node with the requested number. EFFECT: If the graph has no such node, a new node is created. ***************************************************************/ { GRAPHNODE result; result = graph_GetNode(Graph, Number); if (result == NULL) { result = memory_Malloc(sizeof(GRAPHNODE_STRUCT)); Graph->nodes = list_Cons(result, Graph->nodes); result->number = Number; result->dfs_num = -1; result->comp_num = -1; result->info = NULL; result->neighbors = list_Nil(); } return result; }
void tab_CheckEmpties(TABLEAU T) /************************************************************** INPUT: A tableau RETURNS: Nothing. EFFECTS: Prints warnings if non-leaf nodes contain empty clauses (which should not be the case after pruning any more), of if leaf nodes contain more than one empty clause ***************************************************************/ { LIST Scan, Empties; BOOL Printem; if (tab_IsEmpty(T)) return; /* get all empty clauses in this node */ Empties = list_Nil(); for (Scan = tab_Clauses(T); !list_Empty(Scan); Scan = list_Cdr(Scan)) { if (clause_IsEmptyClause(list_Car(Scan))) Empties = list_Cons(list_Car(Scan), Empties); } Printem = FALSE; if (!list_Empty(Empties) && !tab_IsLeaf(T)) { puts("\nNOTE: non-leaf node contains empty clauses."); Printem = TRUE; } if (tab_IsLeaf(T) && list_Length(Empties) > 1) { puts("\nNOTE: Leaf contains more than one empty clauses."); Printem = TRUE; } if (Printem) { puts("Clauses:"); clause_PParentsListPrint(tab_Clauses(T)); } list_Delete(Empties); tab_CheckEmpties(tab_LeftBranch(T)); tab_CheckEmpties(tab_RightBranch(T)); }
LIST split_ExtractEmptyClauses(LIST Clauses, LIST* EmptyClauses) /************************************************************** INPUT: A list of clauses and a pointer to a list of empty clauses. RETURNS: <Clauses> without all empty clauses where the empty clauses are moved to <EmptyClauses> MEMORY: Destructive on <Clauses>. ***************************************************************/ { LIST Scan; CLAUSE Clause; for (Scan=Clauses;!list_Empty(Scan);Scan=list_Cdr(Scan)) { Clause = (CLAUSE)list_Car(Scan); if (clause_IsEmptyClause(Clause)) { *EmptyClauses = list_Cons(Clause,*EmptyClauses); list_Rplaca(Scan,NULL); } } Clauses = list_PointerDeleteElement(Clauses,NULL); return Clauses; }
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; }
void symbol_FPrintPrecedence(FILE *File, PRECEDENCE Precedence) /************************************************************** INPUT: A file pointer and a precedence. RETURNS: void EFFECT: Prints the current precedence as a setting command in DFG syntax to <File>. ***************************************************************/ { if (symbol_SignatureExists()) { LIST Symbols,Scan; int Index; SIGNATURE S; Symbols = list_Nil(); for (Index = 1; Index < symbol_ACTINDEX; Index++) { S = symbol_Signature(Index); if (S != NULL && (symbol_IsPredicate(S->info) || symbol_IsFunction(S->info))) Symbols = list_Cons((POINTER)S->info, Symbols); } Symbols = symbol_SortByPrecedence(Symbols, Precedence); Index = 0; fputs("set_precedence(", File); for (Scan = Symbols; !list_Empty(Scan); Scan = list_Cdr(Scan)) { S = symbol_Signature(symbol_Index((SYMBOL)list_Car(Scan))); fputs(S->name, File); if (!list_Empty(list_Cdr(Scan))) putc(',', File); if (Index > 15) { Index = 0; fputs("\n\t", File); } else Index++; } fputs(").", File); list_Delete(Symbols); } }
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; }
LIST symbol_GetAllFunctions(void) /************************************************************** INPUT: None. RETURNS: A list of all function symbols. ***************************************************************/ { LIST Result; Result = list_Nil(); if (symbol_SignatureExists()) { int Index; SIGNATURE S; for (Index = 1; Index < symbol_ACTINDEX; Index++) { S = symbol_Signature(Index); if (S != NULL && symbol_IsFunction(symbol_GetSigSymbol(Index))) Result = list_Cons((POINTER)symbol_GetSigSymbol(Index), Result); } } return Result; }
LIST list_NListTimes(LIST List1, LIST List2) /************************************************************** INPUT: Two lists of lists. RETURNS: The list of combinations of element lists. CAUTION: Destroys List1 and List2. ***************************************************************/ { LIST Result, Scan1, Scan2; Result = list_Nil(); if (!list_Empty(List2)) { for (Scan1=List1; !list_Empty(Scan1); Scan1=list_Cdr(Scan1)) for (Scan2=List2; !list_Empty(Scan2); Scan2=list_Cdr(Scan2)) Result = list_Cons(list_Append(((LIST)list_Car(Scan1)), list_Copy((LIST)list_Car(Scan2))), Result); } list_DeleteWithElement(List1, (void (*)(POINTER))list_Delete); list_DeleteWithElement(List2, (void (*)(POINTER))list_Delete); return Result; }
void tab_GetEarliestEmptyClauses(TABLEAU T, LIST* L) /************************************************************** INPUT : A tableau, a list of clauses by reference RETURNS: Nothing. EFFECTS: For each leaf node, adds empty clauses in leaf nodes to <L>. If the leaf node contains only one empty clause, it is added to <L> anyway. If the leaf node contains more than one empty clause, the earliest derived empty clause is added to <L>. ***************************************************************/ { CLAUSE FirstEmpty; LIST Scan; if (tab_IsEmpty(T)) return; if (tab_IsLeaf(T)) { FirstEmpty = clause_Null(); for (Scan = tab_Clauses(T); !list_Empty(Scan); Scan = list_Cdr(Scan)) { if (clause_IsEmptyClause(list_Car(Scan))) { if (FirstEmpty == clause_Null()) FirstEmpty = list_Car(Scan); else if (clause_Number(FirstEmpty) > clause_Number(list_Car(Scan))) FirstEmpty = list_Car(Scan); } } if (FirstEmpty != clause_Null()) (*L) = list_Cons(FirstEmpty, *L); } tab_GetEarliestEmptyClauses(tab_LeftBranch(T), L); tab_GetEarliestEmptyClauses(tab_RightBranch(T), L); }
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 split_Backtrack(PROOFSEARCH PS, CLAUSE EmptyClause, CLAUSE* SplitClause) /************************************************************** INPUT: A proofsearch object, an empty clause and a pointer to a clause used as return value. RETURNS: A list of clauses deleted in the backtracked split levels. <*SplitClause> is set to the split clause for the right branch of the splitting step, or NULL, if the tableau is finished. EFFECT: Backtracks the top of the split stack wrt the empty clause's level ***************************************************************/ { SPLIT ActBacktrackSplit; LIST RecoverList, Scan; int Backtracklevel; ActBacktrackSplit = (SPLIT)NULL; RecoverList = split_RemoveUnnecessarySplits(PS, EmptyClause); Backtracklevel = clause_SplitLevel(EmptyClause); *SplitClause = NULL; /* Backtrack all split levels bigger than the level of the empty clause */ while (!prfs_SplitStackEmpty(PS) && (prfs_ValidLevel(PS) > Backtracklevel)) { ActBacktrackSplit = prfs_SplitStackTop(PS); prfs_SplitStackPop(PS); if (prfs_SplitFatherClause(ActBacktrackSplit) != (CLAUSE)NULL) { RecoverList = list_Cons(prfs_SplitFatherClause(ActBacktrackSplit), RecoverList); prfs_SplitSetFatherClause(ActBacktrackSplit, NULL); } RecoverList = list_Nconc(prfs_SplitDeletedClauses(ActBacktrackSplit), RecoverList); clause_DeleteClauseList(prfs_SplitBlockedClauses(ActBacktrackSplit)); prfs_SplitFree(ActBacktrackSplit); prfs_DecValidLevel(PS); } /* Backtrack further for all right branches on top of the stack */ while (!prfs_SplitStackEmpty(PS) && list_Empty(prfs_SplitBlockedClauses(prfs_SplitStackTop(PS)))) { ActBacktrackSplit = prfs_SplitStackTop(PS); prfs_SplitStackPop(PS); if (prfs_SplitFatherClause(ActBacktrackSplit) != (CLAUSE)NULL) RecoverList = list_Cons(prfs_SplitFatherClause(ActBacktrackSplit), RecoverList); RecoverList = list_Nconc(prfs_SplitDeletedClauses(ActBacktrackSplit), RecoverList); prfs_SplitFree(ActBacktrackSplit); prfs_DecValidLevel(PS); } if (!prfs_SplitStackEmpty(PS)) { /* Enter the right branch of the splitting step */ int SplitMinus1; LIST RightClauses; SplitMinus1 = prfs_ValidLevel(PS) - 1; ActBacktrackSplit = prfs_SplitStackTop(PS); RecoverList = list_Nconc(prfs_SplitDeletedClauses(ActBacktrackSplit), RecoverList); prfs_SplitSetDeletedClauses(ActBacktrackSplit, list_Nil()); RecoverList = split_DeleteInvalidClausesFromList(PS, SplitMinus1, RecoverList); RightClauses = prfs_SplitBlockedClauses(ActBacktrackSplit); prfs_SplitSetBlockedClauses(ActBacktrackSplit, list_Nil()); for (Scan = RightClauses; !list_Empty(Scan); Scan = list_Cdr(Scan)) { if (clause_Number(list_Car(Scan)) == 0) { /* Found the right clause, the negation clauses have number -1. */ #ifdef CHECK if (*SplitClause != NULL) { misc_StartErrorReport(); misc_ErrorReport("\n In split_Backtrack:"); misc_ErrorReport(" Found two blocked clauses "); misc_ErrorReport("\n with clause number 0 (this marks the clause "); misc_ErrorReport("\n for the right branch of the tableau)."); misc_FinishErrorReport(); } #endif *SplitClause = list_Car(Scan); } clause_NewNumber((CLAUSE) list_Car(Scan)); clause_AddParentClause((CLAUSE) list_Car(Scan), clause_Number(EmptyClause)); clause_AddParentLiteral((CLAUSE) list_Car(Scan), 0); /* dummy literal */ } #ifdef CHECK if (*SplitClause == NULL) { misc_StartErrorReport(); misc_ErrorReport("\n In split_Backtrack: Didn´t find a blocked clause"); misc_ErrorReport("\n with clause number 0. (this marks the clause "); misc_ErrorReport("\n for the right branch of the tableau)."); misc_FinishErrorReport(); } #endif RecoverList = list_Nconc(RightClauses, RecoverList); /* Then, delete clauses from current level (Hack) */ prfs_DecValidLevel(PS); prfs_MoveInvalidClausesDocProof(PS); split_DeleteInvalidClausesFromStack(PS); prfs_IncValidLevel(PS); } else { /* Don't delete clauses from current level (split is top level) */ prfs_MoveInvalidClausesDocProof(PS); for (Scan = RecoverList; !list_Empty(Scan); Scan = list_Cdr(Scan)) prfs_InsertDocProofClause(PS, list_Car(Scan)); list_Delete(RecoverList); RecoverList = list_Nil(); } prfs_SetLastBacktrackLevel(PS, prfs_ValidLevel(PS)); return RecoverList; }