void ana_ExploitSortAnalysis(FLAGSTORE Flags) /************************************************************** INPUT: A flag store. EFFECT: If all equations are many sorted and or no positive equations occur at all and the problem contains sort information, static soft typing is activated. ***************************************************************/ { if (ana_SORTRES && (!ana_PEQUATIONS || ana_SORTMANYEQUATIONS)) flag_SetFlagValue(Flags, flag_RSST, flag_RSSTON); }
void flag_InitFlotterSubproofFlags(FLAGSTORE Source, FLAGSTORE Target) /************************************************************** INPUT: Two flag stores. RETURNS: Nothing. EFFECT: Initializes the flag store <Target> to the values required by a Flotter subproof. The other flag store is needed to take over some flags, e.g. DOCPROOF. ***************************************************************/ { /* Deactivate printing */ flag_ClearPrinting(Target); /* Deactivate inference rules */ flag_ClearInferenceRules(Target); /* Set reductions to default values */ flag_SetReductionsToDefaults(Target); flag_SetFlagToDefault(Target, flag_CNFFEQREDUCTIONS); flag_SetFlagToDefault(Target, flag_RINPUT); /* Copy flag_DOCPROOF and flag_CNFPROOFSTEPS */ flag_TransferFlag(Source, Target, flag_DOCPROOF); flag_TransferFlag(Source, Target, flag_CNFPROOFSTEPS); /* Activate BoundedDepthUnitResolution */ flag_SetFlagValue(Target, flag_IBUR, flag_BOUNDEDDEPTHUNITRESOLUTIONON); /* Activate KBO */ flag_SetFlagValue(Target, flag_ORD, flag_ORDKBO); /* Transfer Weights for Terms */ flag_TransferFlag(Source, Target, flag_FUNCWEIGHT); flag_TransferFlag(Source, Target, flag_VARWEIGHT); /* Transfer Selection Strategy, not needed for depth bounded */ /* unit resolution (see above) but for other potentially useful inference rules */ flag_TransferFlag(Source, Target, flag_SELECT); }
void flag_ClearInferenceRules(FLAGSTORE Store) /************************************************************** INPUT: A FlagStore. RETURNS: Nothing. EFFECT: Turns all inference rules off. ***************************************************************/ { FLAG_ID i; for (i = (FLAG_ID) 0; i < flag_MAXFLAG; i++) { if (flag_IsInference(i)) flag_SetFlagValue(Store, i, flag_OFF); } }
void flag_ClearPrinting(FLAGSTORE Store) /************************************************************** INPUT: A FlagStore. RETURNS: Nothing. EFFECT: Turns all printing off. ***************************************************************/ { FLAG_ID i; for (i = (FLAG_ID) 0; i < flag_MAXFLAG; i++) { if (flag_IsPrinting(i)) flag_SetFlagValue(Store, i, flag_OFF); } }
void flag_ClearReductionRules(FLAGSTORE Store) /************************************************************** INPUT: A FlagStore. RETURNS: Nothing. EFFECT: Turns all reduction rules off. ***************************************************************/ { FLAG_ID i; for (i = (FLAG_ID) 0; i < flag_MAXFLAG; i++) { if (flag_IsReduction(i)) { flag_SetFlagValue(Store, i, flag_OFF); } } }
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_SetFlagValue(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; }
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_SetFlagValue(Flags, flag_ROBV, flag_ROBVON); flag_SetFlagValue(Flags, flag_RTAUT, flag_RTAUTSYNTACTIC); flag_SetFlagValue(Flags, flag_RFSUB, flag_RFSUBON); flag_SetFlagValue(Flags, flag_RBSUB, flag_RBSUBON); flag_SetFlagValue(Flags, flag_RFMRR, flag_RFMRRON); flag_SetFlagValue(Flags, flag_RBMRR, flag_RBMRRON); flag_SetFlagValue(Flags, flag_RUNC, flag_RUNCON); flag_SetFlagValue(Flags, flag_FULLRED, flag_FULLREDON); /*flag_SetFlagValue(Flags, flag_FUNCWEIGHT,1); flag_SetFlagValue(Flags, flag_VARWEIGHT,1);*/ flag_SetFlagValue(Flags, flag_WDRATIO,5); if (ana_NEQUATIONS) { flag_SetFlagValue(Flags, flag_IEQR, flag_EQUALITYRESOLUTIONON); if (ana_NONUNIT) { if (ana_NONTRIVDOMAIN) flag_SetFlagValue(Flags, flag_RAED, flag_RAEDPOTUNSOUND); else flag_SetFlagValue(Flags, flag_RAED, flag_RAEDSOUND); } } if (ana_PEQUATIONS) { flag_SetFlagValue(Flags, flag_ISPR, flag_SUPERPOSITIONRIGHTON); flag_SetFlagValue(Flags, flag_ISPL, flag_SUPERPOSITIONLEFTON); if (ana_NONHORNCLAUSES > 0) flag_SetFlagValue(Flags, flag_IEQF, flag_EQUALITYFACTORINGON); if (ana_NONUNIT) flag_SetFlagValue(Flags, flag_RCON, flag_RCONON); flag_SetFlagValue(Flags, flag_RFREW, flag_RFREWON); flag_SetFlagValue(Flags, flag_RBREW, flag_RBREWON); flag_SetFlagValue(Flags, flag_RFCRW, flag_RFCRWOFF); /* Here we could activate contextual rewriting */ flag_SetFlagValue(Flags, flag_RBCRW, flag_RBCRWOFF); } if (ana_SORTRES) { flag_SetFlagValue(Flags, flag_SORTS, flag_SORTSMONADICWITHVARIABLE); flag_SetFlagValue(Flags, flag_IEMS, flag_EMPTYSORTON); flag_SetFlagValue(Flags, flag_ISOR, flag_SORTRESOLUTIONON); flag_SetFlagValue(Flags, flag_RSSI, flag_RSSION); if (!ana_PEQUATIONS || ana_SORTMANYEQUATIONS) flag_SetFlagValue(Flags, flag_RSST, flag_RSSTON); } else flag_SetFlagValue(Flags, flag_SORTS, flag_SORTSOFF); if (ana_MONADIC || ana_NONMONADIC) { /* Problem contains real predicates */ flag_SetFlagValue(Flags, flag_IORE, flag_ORDEREDRESOLUTIONNOEQUATIONS); if (ana_NONHORNCLAUSES > 0) flag_SetFlagValue(Flags, flag_IOFC, flag_FACTORINGONLYRIGHT); if (ana_NONUNIT) flag_SetFlagValue(Flags, flag_RCON, flag_RCONON); } if (!ana_FUNCTIONS) flag_SetFlagValue(Flags, flag_SELECT, flag_SELECTALWAYS); else if (ana_NONUNIT) flag_SetFlagValue(Flags, flag_SELECT, flag_SELECTIFSEVERALMAXIMAL); else flag_SetFlagValue(Flags, flag_SELECT, flag_SELECTOFF); if (ana_CONCLAUSES < ana_AXIOMCLAUSES || (ana_CONGROUND && !ana_PUREPROPOSITIONAL)) flag_SetFlagValue(Flags, flag_SATINPUT, flag_SATINPUTON); else flag_SetFlagValue(Flags, flag_SATINPUT, flag_SATINPUTOFF); if (ana_NONHORNCLAUSES > 0) flag_SetFlagValue(Flags, flag_SPLITS, flag_SPLITSUNLIMITED); else flag_SetFlagValue(Flags, flag_SPLITS, flag_SPLITSOFF); }