void split_DeleteClauseAtLevel(PROOFSEARCH PS, CLAUSE Clause, int Level) /************************************************************** INPUT: A clause, a level and a proofsearch object RETURNS: Nothing. EFFECT: <Clause> is deleted from the usable or worked off set and made unshared. ***************************************************************/ { if (clause_GetFlag(Clause,WORKEDOFF)) prfs_ExtractWorkedOff(PS, Clause); else prfs_ExtractUsable(PS, Clause); split_KeepClauseAtLevel(PS, Clause, Level); }
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 ana_AnalyzeProblem(PROOFSEARCH Search, LIST Clauses) /************************************************************** INPUT: A proofsearch object and a list of clauses. RETURNS: Void. EFFECT: Analyzes the clauses and sets the analyze variables. Recomputes the weight for the clauses. <Search> is modified according to clauses: non trivial domain number is set ***************************************************************/ { CLAUSE Clause; ana_EQUATIONS = FALSE; ana_PEQUATIONS = FALSE; /* Defaults for properties */ ana_NEQUATIONS = FALSE; ana_FUNCTIONS = FALSE; ana_FINDOMAIN = FALSE; ana_NONTRIVDOMAIN = FALSE; ana_MONADIC = FALSE; ana_NONMONADIC = FALSE; ana_PROP = FALSE; ana_GROUND = FALSE; ana_SORTRES = FALSE; ana_USORTRES = FALSE; ana_NONUNIT = FALSE; ana_CONGROUND = TRUE; ana_AXIOMCLAUSES = 0; ana_CONCLAUSES = 0; ana_NONHORNCLAUSES = 0; list_Delete(ana_FINITEMONADICPREDICATES); ana_FINITEMONADICPREDICATES = list_Nil(); if (list_Empty(Clauses)) return; ana_FINITEMONADICPREDICATES = clause_FiniteMonadicPredicates(Clauses); while (!list_Empty(Clauses)) { Clause = (CLAUSE)list_Car(Clauses); clause_UpdateWeight(Clause, prfs_Store(Search)); if (clause_GetFlag(Clause,CONCLAUSE)) ana_CONCLAUSES++; else ana_AXIOMCLAUSES++; if (clause_NumOfSuccLits(Clause) > 1) ana_NONHORNCLAUSES++; if (ana_CONGROUND && clause_GetFlag(Clause,CONCLAUSE) && clause_MaxVar(Clause) != symbol_GetInitialStandardVarCounter()) ana_CONGROUND = FALSE; if (!ana_PEQUATIONS && clause_ContainsPositiveEquations(Clause)) { ana_PEQUATIONS = TRUE; } if (!ana_NEQUATIONS && clause_ContainsNegativeEquations(Clause)) { ana_NEQUATIONS = TRUE; } if (!ana_MONADIC || !ana_NONMONADIC || !ana_PROP || !ana_GROUND) clause_ContainsFolAtom(Clause,&ana_PROP,&ana_GROUND,&ana_MONADIC,&ana_NONMONADIC); if (!ana_FUNCTIONS && clause_ContainsFunctions(Clause)) { ana_FUNCTIONS = TRUE; } if (!ana_FINDOMAIN && clause_ImpliesFiniteDomain(Clause)) { ana_FINDOMAIN = TRUE; } if (!ana_NONTRIVDOMAIN && clause_ImpliesNonTrivialDomain(Clause)) { prfs_SetNonTrivClauseNumber(Search, clause_Number(Clause)); ana_NONTRIVDOMAIN = TRUE; } if (!ana_NONUNIT && clause_Length(Clause) > 1) { ana_NONUNIT = TRUE; } if (!ana_SORTRES || !ana_USORTRES) clause_ContainsSortRestriction(Clause,&ana_SORTRES,&ana_USORTRES); Clauses = list_Cdr(Clauses); } ana_PUREEQUATIONAL = ((ana_PEQUATIONS || ana_NEQUATIONS) && !ana_MONADIC && !ana_NONMONADIC && !ana_PROP && !ana_GROUND); ana_EQUATIONS = (ana_PEQUATIONS || ana_NEQUATIONS); ana_PUREPROPOSITIONAL = (!ana_PEQUATIONS && !ana_NEQUATIONS &&!ana_MONADIC && !ana_NONMONADIC && ana_PROP); }
static void dp_FPrintDFGProof(LIST Clauses, const char *FilePrefix, FLAGSTORE Flags, PRECEDENCE Precedence) /********************************************************* INPUT: A list of clauses representing a proof, a string indicating a file name prefix, a flag store and a precedence. RETURNS: void. EFFECT: Outputs the proof in DFG proof format to <FilePrefix>.prf **********************************************************/ { FILE *Output; CLAUSE Clause; LIST AxClauses,ConClauses,ProofClauses,Scan; char *name; AxClauses = ConClauses = ProofClauses = list_Nil(); name = memory_Malloc(sizeof(char)*(strlen(FilePrefix)+5)); sprintf(name,"%s.prf", FilePrefix); Output = misc_OpenFile(name,"w"); fputs("begin_problem(Unknown).\n\n", Output); fputs("list_of_descriptions.\n", Output); fputs("name({*", Output); fputs(FilePrefix, Output); fputs("*}).\n", Output); fputs("author({*SPASS ", Output); fputs(misc_VERSION, Output); fputs("*}).\n", Output); fputs("status(unsatisfiable).\n", Output); fputs("description({*File generated by SPASS containing a proof.*}).\n", Output); fputs("end_of_list.\n\n", Output); fputs("list_of_symbols.\n", Output); fol_FPrintDFGSignature(Output); fputs("end_of_list.\n\n", Output); for (Scan=Clauses;!list_Empty(Scan);Scan=list_Cdr(Scan)) { Clause = (CLAUSE)list_Car(Scan); if (clause_IsFromInput(Clause)) { if (clause_GetFlag(Clause, CONCLAUSE)) ConClauses = list_Cons(Clause, ConClauses); else AxClauses = list_Cons(Clause, AxClauses); } else ProofClauses = list_Cons(Clause, ProofClauses); } ConClauses = list_NReverse(ConClauses); AxClauses = list_NReverse(AxClauses); ProofClauses = list_NReverse(ProofClauses); clause_FPrintCnfDFG(Output, FALSE, AxClauses, ConClauses, Flags, Precedence); fputs("\nlist_of_proof(SPASS).\n", Output); for (Scan=ProofClauses; !list_Empty(Scan); Scan=list_Cdr(Scan)) { clause_FPrintDFGStep(Output,list_Car(Scan),TRUE); } fputs("end_of_list.\n\n", Output); fputs("end_problem.\n\n", Output); misc_CloseFile(Output, name); fputs("\nDFG Proof printed to: ", stdout); puts(name); list_Delete(ConClauses); list_Delete(AxClauses); list_Delete(ProofClauses); memory_Free(name, sizeof(char)*(strlen(FilePrefix)+5)); }
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; }
int main(int argc, const char* argv[]) { LIST Clauses,Axioms,Conjectures,Sorts,Scan, UserPrecedence,UserSelection,ClAxRelation; FILE *Input; CLAUSE Clause; const char *Filename; FLAGSTORE Flags; PRECEDENCE Precedence; BOOL HasPlainClauses; DFGDESCRIPTION Description; memory_Init(memory__UNLIMITED); atexit(memory_FreeAllMem); symbol_Init(TRUE); stack_Init(); term_Init(); flag_Init(flag_SPASS); cmdlne_Init(); Flags = flag_CreateStore(); flag_InitStoreByDefaults(Flags); Precedence = symbol_CreatePrecedence(); Description = desc_Create(); fol_Init(TRUE, Precedence); eml_Init(Precedence); clause_Init(); if (argc < 2 || !cmdlne_Read(argc, argv)) { fputs("\n\t dfg2ascii Version ", stdout); fputs(DFG2ASCII__VERSION, stdout); puts("\n\t Usage: dfg2ascii <input-file>\n"); return EXIT_FAILURE; } if (!cmdlne_SetFlags(Flags)) return EXIT_FAILURE; Axioms = list_Nil(); Conjectures = list_Nil(); Sorts = list_Nil(); UserPrecedence = list_Nil(); UserSelection = list_Nil(); ClAxRelation = list_Nil(); Filename = cmdlne_GetInputFile(); Input = misc_OpenFile(Filename,"r"); Clauses = dfg_DFGParser(Input, Flags, Precedence, Description, &Axioms, &Conjectures, &Sorts, &UserPrecedence, &UserSelection, &ClAxRelation, &HasPlainClauses); misc_CloseFile(Input,Filename); Axioms = list_Nconc(Axioms, Sorts); if (!list_Empty(Axioms) || !list_Empty(Conjectures)) { puts("\n\n\t\t Axioms:\n"); if (list_Empty(Axioms)) puts("None.\n"); else for (Scan=Axioms; !list_Empty(Scan);Scan=list_Cdr(Scan)) { if (list_PairFirst(list_Car(Scan)) != NULL) printf("%s:\n",(char *)list_PairFirst(list_Car(Scan))); fol_PrettyPrintDFG(list_PairSecond(list_Car(Scan))); puts("\n"); } puts("\n\n\t\t Conjectures:\n"); if (list_Empty(Conjectures)) puts("None.\n"); else for (Scan=Conjectures; !list_Empty(Scan);Scan=list_Cdr(Scan)) { if (list_PairFirst(list_Car(Scan)) != NULL) printf("%s:\n",(char *)list_PairFirst(list_Car(Scan))); fol_PrettyPrintDFG(list_PairSecond(list_Car(Scan))); puts("\n"); } } else { BOOL SetExist; LIST ClauseScan; /* Before we sort the clauses, we need to make sure that they have been assigned a weight. */ for (ClauseScan = Clauses; !list_Empty(ClauseScan); ClauseScan = list_Cdr(ClauseScan)) { clause_UpdateWeight((CLAUSE) list_Car(ClauseScan), Flags); } Clauses = clause_ListSortWeighed(Clauses); clause_SetCounter(1); for (Scan = Clauses;!list_Empty(Scan);Scan=list_Cdr(Scan)) { Clause = (CLAUSE)list_Car(Scan); clause_SetSortConstraint(Clause, FALSE, Flags, Precedence); clause_NewNumber(Clause); clause_OrientAndReInit(Clause, Flags, Precedence); } puts("\n\n\t\t Axiom Clauses:\n"); SetExist = FALSE; for (Scan = Clauses;!list_Empty(Scan);Scan=list_Cdr(Scan)) { Clause = (CLAUSE)list_Car(Scan); if (!clause_GetFlag(Clause,CONCLAUSE)) { SetExist = TRUE; clause_Print(Clause); putchar('\n'); } } if (SetExist) SetExist = FALSE; else puts("None.\n"); puts("\n\n\t\t Conjecture Clauses:\n"); for (Scan = Clauses;!list_Empty(Scan);Scan=list_Cdr(Scan)) { Clause = (CLAUSE)list_Car(Scan); if (clause_GetFlag(Clause,CONCLAUSE)) { SetExist = TRUE; clause_Print(Clause); putchar('\n'); } } if (SetExist) SetExist = FALSE; else puts("None.\n"); } clause_DeleteClauseList(Clauses); dfg_StripLabelsFromList(Axioms); dfg_StripLabelsFromList(Conjectures); term_DeleteTermList(Axioms); term_DeleteTermList(Conjectures); eml_Free(); flag_DeleteStore(Flags); symbol_DeletePrecedence(Precedence); list_Delete(UserPrecedence); list_Delete(UserSelection); dfg_DeleteClAxRelation(ClAxRelation); desc_Delete(Description); /*symbol_Dump();*/ cmdlne_Free(); fol_Free(); symbol_FreeAllSymbols(); #ifdef CHECK memory_Print(); #endif return 0; }