void ac::StrobeAlphaShuffle(cv::Mat &frame) { cv::Mat copyf = frame.clone(), copyi = frame.clone(); ShuffleAlpha(copyf); static bool neg_ = true; if(neg_ == true) { Negate(copyf); neg_ = false; } else { neg_ = true; } AlphaBlend(copyf, copyi, frame, 0.5); AddInvert(frame); }
Quaternion2& Quaternion2::operator*=(const Quaternion2& q) { double wNew = w * q.w - (x * q.x + y * q.y + z * q.z); double xNew = w * q.x + q.w * x + (y * q.z - z * q.y); double yNew = w * q.y + q.w * y + (z * q.x - x * q.z); double zNew = w * q.z + q.w * z + (x * q.y - y * q.x); w = wNew; x = xNew; y = yNew; z = zNew; Negate(); return *this; }
void ac::FilterStrobeSubFilter(cv::Mat &frame) { if(subfilter == -1 || ac::draw_strings[subfilter] == "FilterStrobeSubFilter") return; static bool flash = true; if(flash == true) { CallFilter(subfilter, frame); Negate(frame); flash = false; } else { flash = true; CallFilter(subfilter, frame); } AddInvert(frame); }
static void DoCheck(BigInt Scratch, BigInt Num,int Which, size_t Len) {size_t z; if (Len < 1024) return; if (Sub(Scratch,Scratch,Num,Len)) Negate(Scratch,Len); z=FindFirstNonZero(Scratch,Len); if (z < Len-200/RawIntDigits) { fprintf(stderr,"The AGM self check #%d failed. Exp: %lu Got: %lu\n", Which,(ULINT)Len-200/RawIntDigits,(ULINT)z); /* ExitPrg(EXIT_FAILURE); */ } }
//Reflect the Vector of the coinciding vector void Vector3::Reflect( Vector3 _rhs) { if ( Math::isZero( Dot( _rhs ) )) { Negate(); } else { Vector3 normRhs; normRhs = _rhs.GetNormalization(); float result = Dot(normRhs); result *= 2.0f; normRhs *= result; xyz = normRhs - xyz; } }
//********************************************************************************************** //****************************** Операция взятия противоположного элемента *************** PolynomN6& PolynomN6::Negate() { return Negate(*this); }
//----------------------------------------------------------------------------- SZSResultType SZSSystemOnTPTP(LISTNODE Axioms,ANNOTATEDFORMULA Conjecture, char * System,SZSResultType DesiredResult,int QuietnessLevel,int TimeLimit, char * X2TSTPFlag,char * SystemOutputPrefix,int KeepOutputFiles, char * FilesDirectory,char * UsersOutputFileName,String OutputFileName, SZSOutputType * SZSOutput) { StatusType ConjectureRole; String ProblemFileName; String CopyUsersOutputFileName; String SystemResult; String SystemOutput; SZSResultType SZSResult; int NegatedConjecture; SZSResult = NOS; if (SZSOutput != NULL) { *SZSOutput = Non; } //----Negate conjecture to prove CTH. This is likely broken for full SZS //----compliance, but'll do for now. NegatedConjecture = 0; if (Conjecture != NULL && SZSIsA(DesiredResult,CTH) && !SZSIsA(DesiredResult,THM)) { if (!Negate(Conjecture,1)) { CodingError("Trying to negate for CTH"); } NegatedConjecture = 1; DesiredResult = THM; } //----For SAT with a conjecture, the role must be axiom ConjectureRole = conjecture; if (Conjecture != NULL && SZSIsA(DesiredResult,SAT)) { ConjectureRole = axiom; } //----Make the problem file if (!MakeProblemFile(FilesDirectory,UsersOutputFileName,".p", ProblemFileName,Axioms,axiom,Conjecture,ConjectureRole)) { SZSResult = ERR; } if (SZSResult == NOS) { //----Need to make a copy in case the same variable is used //----Set to empty if nothing given, to cause use of mktemp if (UsersOutputFileName == NULL) { strcpy(CopyUsersOutputFileName,""); } else { strcpy(CopyUsersOutputFileName,UsersOutputFileName); } if (SystemOnTPTPGetResult(QuietnessLevel,ProblemFileName,System, TimeLimit,X2TSTPFlag,SystemOutputPrefix,KeepOutputFiles,FilesDirectory, CopyUsersOutputFileName,OutputFileName,SystemResult,SystemOutput)) { SZSResult = StringToSZSResult(SystemResult); //----Promote to desired result if it is one if (SZSIsA(SZSResult,DesiredResult)) { SZSResult = DesiredResult; } if (SZSOutput != NULL) { *SZSOutput = StringToSZSOutput(SystemOutput); } } else { SZSResult = ERR; } } if (NegatedConjecture) { if (!Negate(Conjecture,1)) { CodingError("Trying to denegate for CTH"); } if (SZSResult == THM) { SZSResult = CTH; } } RemoveFile(ProblemFileName); if (SZSOutput != NULL) { *SZSOutput = StringToSZSOutput(SystemOutput); } return(SZSResult); }
void Ring_Element::negate() { for (int i=0; i<(*FFTD).phi_m(); i++) { Negate(element[i],element[i],(*FFTD).get_prD()); } }
void wDocument::AscMemberSingle(wAscBuffer *buffer,sBool allowpif) { if(Scan->IfName("pif")) { if(!allowpif) Scan->Error("pifs are not allowed in this type"); Scan->Match('('); wPredicate *pred = _Predicate(); Scan->Match(')'); wPredicate *old = Predicate; Predicate = Combine(pred,old); AscMemberBlock(buffer,allowpif); if(Scan->IfName("pelse")) { Predicate = Combine(Negate(pred),old); AscMemberBlock(buffer,allowpif); } Predicate = old; } else { wAscMember *mem = new wAscMember(); wAscType *type = new wAscType(); moreflags: if(Scan->Token==TokExtern) { Scan->Scan(); mem->Flags |= wMF_Extern; goto moreflags; } if(Scan->Token==TokStatic) { Scan->Scan(); mem->Flags |= wMF_Static; goto moreflags; } if(Scan->Token==TokUniform) { Scan->Scan(); mem->Flags |= wMF_Uniform; goto moreflags; } if(Scan->Token==TokVolatile) { Scan->Scan(); mem->Flags |= wMF_Volatile; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="nointerpolation") { Scan->Scan(); mem->Flags |= wMF_NoInterpolation; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="precise") { Scan->Scan(); mem->Flags |= wMF_Precise; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="groupshared") { Scan->Scan(); mem->Flags |= wMF_GroupShared; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="shared") { Scan->Scan(); mem->Flags |= wMF_Shared; goto moreflags; } if(Scan->IfName("row_major")) { } else if(Scan->IfName("column_major")) { type->ColumnMajor = 1; } sString<64> tname; Scan->ScanName(tname); sInt len = sGetStringLen(tname); if(len>0 && tname[len-1]>='1' && tname[len-1]<='4') { type->Columns = tname[len-1]-'0'; len--; if(len>1 && tname[len-1]=='x' && tname[len-2]>='1' && tname[len-2]<='4') { type->Rows = tname[len-2]-'0'; len-=2; } tname[len] = 0; } if(tname=="bool") type->Base = wTB_Bool; else if(tname=="int") type->Base = wTB_Int; else if(tname=="uint") type->Base = wTB_UInt; else if(tname=="float") type->Base = wTB_Float; else if(tname=="double") type->Base = wTB_Double; else if(tname=="min16float") type->Base = wTB_Min16Float; else if(tname=="min10float") type->Base = wTB_Min10Float; else if(tname=="min16int") type->Base = wTB_Min16Int; else if(tname=="min12int") type->Base = wTB_Min12Int; else if(tname=="min16uint") type->Base = wTB_Min16UInt; else Scan->Error("unknown type %q",tname); mem->Name = Scan->ScanName(); mem->Type = type; mem->Predicate = Predicate; if(Scan->IfToken('[')) { type->Array = Scan->ScanInt(); Scan->Match(']'); } if(Scan->IfToken(':')) mem->Binding = Scan->ScanName(); Scan->Match(';'); buffer->Members.AddTail(mem); } }
//----------------------------------------------------------------------------- int main(int argc, char *argv[]) { LISTNODE Head; LISTNODE AnotherHead; ROOTLIST RootListHead; String PutNamesHere; String CurrentFileName; SIGNATURE Signature; ANNOTATEDFORMULA AnnotatedFormula; ANNOTATEDFORMULA AnotherAnnotatedFormula; ANNOTATEDFORMULA DuplicatedAnnotatedFormula; FORMULA Literal; FORMULA AnotherLiteral; String SomeString; char * SymbolUsage; char * AnotherSymbolUsage; char * VariablesStartHere; int SymbolUsageLength = STRINGLENGTH; int VarCount,QuantCount; StatusType SubStatus; TERM ANewTerm; int Positive,Negative; READFILE Stream; ListStatisticsRecordType ListStatistics; int Universals,Existentials; int NumberRemoved; ContextType Context; LISTNODE Axioms; LISTNODE Conjectures; LISTNODE Target; String FormulaName; String OutputFileName; int Result; BTREENODE BTreeRoot; BTREENODE * SearchResult; TERMArray ArrayOfInfoTERMs; int NumberOfTerms; int Index; SZSResultType SZS1,SZS2; SZSOutputType SZSO1,SZSO2; //----One signature for all testing Signature = NewSignature(); //----Read from file or stdin SetNeedForNonLogicTokens(1); SetAllowFreeVariables(0); //----Test duplicate arity warnings SetWarnings(1); if (argc > 1) { Head = ParseFileOfFormulae(argv[1],NULL,Signature,1,NULL); } else { Head = ParseFILEOfFormulae(stdin,Signature,1,NULL); } PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----------------------------------------------------------------------------- //----Test comparison of first two formula for being the same AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); AnotherAnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,2); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintAnnotatedTSTPNode(stdout,AnotherAnnotatedFormula,tptp,1); if (SameFormulaInAnnotatedFormulae(AnnotatedFormula, AnotherAnnotatedFormula,0,1)) { printf("They are identical\n"); } else { if (SameFormulaInAnnotatedFormulae(AnnotatedFormula, AnotherAnnotatedFormula,1,1)) { printf("They are renamings\n"); } else { printf("They are quite different\n"); } } FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test list duplication AnotherHead = DuplicateListOfAnnotatedFormulae(Head,Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeListOfAnnotatedFormulae(&AnotherHead); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test reading header FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); SetNeedForNonLogicTokens(1); Head = ParseFileOfHeader(argv[1]); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); return(EXIT_SUCCESS); //----Test building root list RootListHead = BuildRootList(Head); PrintRootList(stdout,RootListHead); FreeRootList(&RootListHead,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test randomization RandomizeListOfAnnotatedFormulae(&Head,1); printf("------------ Randomized ---------------\n"); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test getting root list PrintListOfAnnotatedTSTPNodes(stdout,Signature,GetRootList(Head),tptp,1); return(EXIT_SUCCESS); //----Test vine of lemmas extraction printf("---- Vine of lemmas ---\n"); RootListHead = BuildRootList(Head); PrintRootList(stdout,RootListHead); if (GetRootLemmaList(RootListHead->TheTree,&Axioms,0)) { PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1); FreeListOfAnnotatedFormulae(&Axioms); } else { printf("Could not extract vine of axioms\n"); } FreeRootList(&RootListHead,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test dequoting PrintSignature(Signature); printf("---- Dequote ---\n"); DequoteSymbolsInSignature(Signature); PrintSignature(Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test aritizing PrintSignature(Signature); printf("---- Aritize ---\n"); AritizeSymbolsInSignature(Signature); PrintSignature(Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test expanding assumptions printf("---- Expand assumptions ---\n"); ExpandListAssumptions(Head,Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test formula duplication AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); if (AnnotatedFormula != NULL) { PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintVariableList(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); DuplicatedAnnotatedFormula = DuplicateAnnotatedFormula(AnnotatedFormula, Signature); PrintAnnotatedTSTPNode(stdout,DuplicatedAnnotatedFormula,tptp,1); PrintVariableList(DuplicatedAnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); } else { printf("Could not get formula dv\n"); } return(EXIT_SUCCESS); //----Test uninterpreting of integers UninterpretIntegersInSignature(Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); exit(EXIT_SUCCESS); //----Test getting inference rule AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if ((SymbolUsage = GetSource(AnnotatedFormula)) != NULL) { printf("The source is ==%s==\n",SymbolUsage); Free((void **)&SymbolUsage); } if ((SymbolUsage = GetSourceTerm(AnnotatedFormula,NULL)) != NULL) { printf("The source term is ==%s==\n",SymbolUsage); Free((void **)&SymbolUsage); } if ((SymbolUsage = GetInferenceRule(AnnotatedFormula,NULL)) != NULL) { printf("The inference rule is ==%s==\n",SymbolUsage); Free((void **)&SymbolUsage); } if ((SymbolUsage = GetParentNames(AnnotatedFormula,NULL)) != NULL) { printf("The parents are ==%s==\n",SymbolUsage); Free((void **)&SymbolUsage); } if ((SymbolUsage = GetSourceInfoTerm(AnnotatedFormula,"introduced","status", NULL)) != NULL) { printf("The status term is %s\n",SymbolUsage); Free((void **)&SymbolUsage); } FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test getting nested inference info PrintAnnotatedTSTPNode(stdout,Head->AnnotatedFormula,tptp,1); NumberOfTerms = 0; ArrayOfInfoTERMs = GetInferenceInfoTERMs(Head->AnnotatedFormula,"assumptions", &NumberOfTerms); for (Index = 0; Index < NumberOfTerms; Index++) { PrintTSTPTerm(stdout,ArrayOfInfoTERMs[Index],-1,1); printf("\n"); } if (ArrayOfInfoTERMs != NULL) { Free((void **)&ArrayOfInfoTERMs); } return(EXIT_SUCCESS); //----Test getting file source AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if (GetSource(AnnotatedFormula) != NULL) { printf("The source is %s\n",SomeString); if ((SymbolUsage = GetFileSourceNameAndNode(AnnotatedFormula,NULL)) != NULL) { printf("The file and node are %s\n",SymbolUsage); Free((void **)&SymbolUsage); } else { printf("No file and node\n"); } } else { printf("No source for file and node\n"); } FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); exit(EXIT_SUCCESS); //----Test useful info manipulation AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature, "useful(1)"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature, "useful([2,two,2],2-two)"); AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature, "useful(3)"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if ((SymbolUsage = GetUsefulInfoTerm(AnnotatedFormula,"useful",2,NULL)) != NULL) { printf("The second useful term is %s\n",SymbolUsage); Free((void **)&SymbolUsage); } UpdateUsefulInformationInAnnotatedFormula(AnnotatedFormula,Signature, "useful(4)"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature, "useful(5)"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); RemoveUsefulInformationFromAnnotatedFormula(AnnotatedFormula,Signature, "useful"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test sorting by useful info SortByUsefulInfoField(&Head,"sortby",'f',0); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); exit(EXIT_SUCCESS); //----Test binary trees printf("---- Binary tree ----\n"); BTreeRoot = ListToBTree(Head); PrintBTreeOfAnnotatedFormulae(BTreeRoot); printf("---- Search for %s\n","pel55_5"); if ((SearchResult = GetNodeFromBTreeByAnnotatedFormulaName(&BTreeRoot, "pel55_5")) == NULL) { printf("Not found\n"); } else { PrintAnnotatedTSTPNode(stdout,(*SearchResult)->AnnotatedFormula,tptp,1); } FreeBTreeOfAnnotatedFormulae(&BTreeRoot); assert(BTreeRoot == NULL); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test negation or universal fofify FOFifyList(Head,universal); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); PrintSignature(Signature); return(EXIT_SUCCESS); //----Look at the signature PrintSignature(Signature); FreeListOfAnnotatedFormulae(&Head); FreeSignature(&Signature); return(EXIT_SUCCESS); //----Test external processing AnotherHead = ApplyExternalProgram(Head,axiom,NULL,"cat %s",Signature); PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1); exit(EXIT_SUCCESS); //----Test set relationships AnotherHead = ParseFileOfFormulae(argv[2],NULL,Signature,1,NULL); printf("-------------------\n"); PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1); printf("===================\n"); Head = MergeInListOfAnnotatedFormulaeByFields(&Head,&AnotherHead,1,0,1); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1); printf("-------------------\n"); PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1); exit(EXIT_SUCCESS); //----Test getting by name AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"freddy"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); exit(EXIT_SUCCESS); //----Testing redirected printing PrintStringAnnotatedTSTPNode(SomeString,Head->AnnotatedFormula,tptp,1); printf("==%s==\n",SomeString); exit(EXIT_SUCCESS); //----Test negation AnnotatedFormula = Head->AnnotatedFormula; PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if (DeDoubleNegate(AnnotatedFormula)) { printf("Dedouble negated\n"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); } Negate(AnnotatedFormula,1); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); return(EXIT_SUCCESS); //----Test selection of nodes with status Axioms = GetListOfAnnotatedFormulaeWithType(Head,axiom_like); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1); return(EXIT_SUCCESS); //----Test use of SystemOnTPTP if (SystemOnTPTPAvailable()) { Axioms = GetListOfAnnotatedFormulaeWithType(Head,axiom_like); printf("Axioms are ...\n"); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1); Conjectures = GetListOfAnnotatedFormulaeWithType(Head,conjecture); Target = Conjectures; while (Target != NULL) { printf("Trying to prove %s\n",GetName(Target->AnnotatedFormula, FormulaName)); // strcpy(OutputFileName,FormulaName); // strcat(OutputFileName,".result"); // Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula, //"E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,">>",1,"", //OutputFileName,OutputFileName); Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula, "E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,"",1,"/tmp","output", OutputFileName); // Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula, //"E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,"",0,NULL,NULL,NULL); printf("The output file name is %s\n",OutputFileName); switch (Result) { case 1: printf("%s is a theorem\n",FormulaName); break; case -1: printf("%s is not a theorem\n",FormulaName); break; case 0: printf("%s is unknown\n",FormulaName); break; default: CodingError("SystemOnTPTP returned something weird"); break; } Target = Target->Next; } FreeListOfAnnotatedFormulae(&Axioms); FreeListOfAnnotatedFormulae(&Conjectures); } return(EXIT_SUCCESS); //----Test freeing PrintSignature(Signature); FreeListOfAnnotatedFormulae(&Head); assert(Head == NULL); PrintSignature(Signature); RemovedUnusedSymbols(Signature); printf("REMOVED THE UNUSED\n"); fflush(stdout); PrintSignature(Signature); FreeSignature(&Signature); assert(Signature == NULL); return(EXIT_SUCCESS); //----Test Foreign output PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,dfg,1); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,kif,1); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,otter,1); PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,xml,1); return(EXIT_SUCCESS); //----Test read-free alternation SetNeedForNonLogicTokens(0); if ((Stream = OpenReadFile(argv[1],CurrentFileName)) == NULL) { printf("Can't open file %s\n",argv[1]); return(EXIT_FAILURE); } while (!CheckTokenType(Stream,endeof)) { printf("Start ------------------\n"); AnnotatedFormula = ParseAndUseAnnotatedFormula(Stream,Signature); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintSignature(Signature); printf("Free ------------------\n"); FreeAnnotatedFormula(&AnnotatedFormula); PrintSignature(Signature); printf("End ------------------\n"); } CloseReadFile(Stream); return(EXIT_SUCCESS); //----Test signature iterator PrintSignatureTree(Signature->Predicates); printf("===========\n"); ListSignatureBySearch(Signature->Predicates); return(EXIT_SUCCESS); //----Test freeing PrintSignature(Signature); FreeListOfAnnotatedFormulae(&Head); assert(Head == NULL); PrintSignature(Signature); RemovedUnusedSymbols(Signature); printf("REMOVED THE UNUSED\n"); fflush(stdout); PrintSignature(Signature); FreeSignature(&Signature); assert(Signature == NULL); return(EXIT_SUCCESS); //----Test getting symbol usage in general AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); SymbolUsage = (char *)Malloc(sizeof(String)); if (GetAnnotatedFormulaSymbolUsage(AnnotatedFormula,&SymbolUsage, &AnotherSymbolUsage) != NULL) { printf("The total symbol usage is \n%s and the functors are \n%s\n", SymbolUsage,AnotherSymbolUsage); } else { printf("No total symbol usage collected\n"); } Free((void **)&SymbolUsage); return(EXIT_SUCCESS); //----Test internal formula copying AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); if (AnnotatedFormula != NULL) { PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintVariableList(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); Literal = AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Formula->FormulaUnion.QuantifiedFormula.Formula->FormulaUnion.BinaryFormula.LHS; Context.Signature = Signature; Context.Variables = &(AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables); AnotherLiteral = DuplicateInternalFormulaWithVariables( Literal,Context); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); printf("duplicate is ...\n"); PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,AnotherLiteral,0,1, outermost,0); printf("\n"); PrintVariableList(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); } else { printf("Could not get first formula\n"); } return(EXIT_SUCCESS); //----Test variable counting AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); if (AnnotatedFormula != NULL) { PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,0); VarCount = CountVariableUsageInFormula(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Formula, AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula. FormulaWithVariables->Variables,&QuantCount); printf("First variable occurs %d times, plus quantified %d times\n", VarCount,QuantCount); } else { printf("Could not get first formula\n"); } return(EXIT_SUCCESS); //----Test getting parents' names if (AnnotatedFormula != NULL) { printf("Parents are\n%s\n",GetParentNames(AnnotatedFormula, PutNamesHere)); } else { printf("Formula of that name not found\n"); } return(EXIT_SUCCESS); //----Test removal of vacuous quantifiers AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1); if (AnnotatedFormula != NULL) { PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,0); PrintVariableList(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); NumberRemoved = RemoveVacuousQuantifiersFromAnnotatedFormula( AnnotatedFormula); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintVariableList(AnnotatedFormula-> AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables, NULL); PrintSignature(Signature); printf("%d removed\n",NumberRemoved); } else { printf("Could not get first formula\n"); } return(EXIT_SUCCESS); //----Test uniqueify variable names AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"dv"); if (AnnotatedFormula != NULL) { PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintSignature(Signature); UniqueifyVariableNames(AnnotatedFormula); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); PrintSignature(Signature); } else { printf("Could not get formula dv\n"); } return(EXIT_SUCCESS); //----Test freeing FreeListOfAnnotatedFormulae(&Head); assert(Head == NULL); return(EXIT_SUCCESS); //----Test reading another file AnotherHead = ParseFileOfFormulae(argv[1],NULL,Signature,1,NULL); PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1); return(EXIT_SUCCESS); //----Test negation or universal fofify AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"22"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if (DeDoubleNegate(AnnotatedFormula)) { printf("Dedouble negated\n"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); } FOFify(AnnotatedFormula,universal); if (CheckAnnotatedFormula(AnnotatedFormula,tptp_cnf)) { FOFify(AnnotatedFormula,universal); } else { Negate(AnnotatedFormula,1); } printf("negated (FOF) or fofified (CNF)\n"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); return(EXIT_SUCCESS); //----Test stats if (GetListStatistics(Head,Signature,&ListStatistics) != NULL) { PrintListStatistics(stdout,ListStatistics); } else { printf("Could not get statistics\n"); } FreeListOfAnnotatedFormulae(&Head); assert(Head == NULL); return(EXIT_SUCCESS); AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"pel47_14"); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); Universals = CountAnnotatedFormulaUniqueVariablesByUse(AnnotatedFormula, -1,-1,universal); Existentials = CountAnnotatedFormulaUniqueVariablesByUse(AnnotatedFormula, -1,-1,existential); printf("Universals = %d Existentials = %d\n",Universals,Existentials); return(EXIT_SUCCESS); //----Test parsing of strings ANewTerm = ParseStringTerm("hello(there,my(BIG),friend)",nontype, Signature,0); printf("The term is =="); PrintTSTPTerm(stdout,ANewTerm,-1,0); printf("==\n"); //----Test getting inference status AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,10); PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if (GetSource(AnnotatedFormula) != NULL) { printf("The source is %s\n",SomeString); if (GetInferenceInfoTerm(AnnotatedFormula,"status",SomeString) != NULL) { printf("The status term is %s\n",SomeString); } else { printf("No status term\n"); } } else { printf("No source for status\n"); } //----Test getting by count printf("There are %d clauses\n",ListCount(Head,cnf_nodes)); AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,20); GetName(AnnotatedFormula,PutNamesHere); printf("Got the node for clause named %s\n",PutNamesHere); printf("The status is %s\n",StatusToString(GetRole(AnnotatedFormula, &SubStatus))); if (SubStatus != nonstatus) { printf("The substatus is %s\n",StatusToString(SubStatus)); } else { printf("It has no substatus\n"); } if (GetInferenceRule(AnnotatedFormula,SomeString) != NULL) { printf("The inference rule is %s\n",SomeString); } else { printf("No inference rule found\n"); } //----Print symbol extraction PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1); if (CountLiteralsOfPolarity(AnnotatedFormula,&Positive,&Negative)) { printf("The clause has %d literals, %d positive, %d negative\n", CountAnnotatedFormulaAtomsByPredicate(AnnotatedFormula,""),Positive,Negative); } if ((Literal = GetLiteralFromAnnotatedClauseByNumber(AnnotatedFormula,1)) != NULL) { printf("The literal is "); PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,Literal,0,1,none,0); printf("\n"); SymbolUsage = (char *)Malloc(sizeof(String)); GetLiteralSymbolUsage(Literal,&SymbolUsage,&VariablesStartHere); printf("The literal data is \n%s\n",SymbolUsage); printf("The variables are \n%s\n",VariablesStartHere); if ((AnotherLiteral = GetLiteralFromAnnotatedClauseByNumber( AnnotatedFormula,2)) != NULL) { printf("The literal is "); PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,AnotherLiteral, 0,1,none,0); printf("\n"); AnotherSymbolUsage = (char *)Malloc(sizeof(String)); if (GetLiteralSymbolUsage(AnotherLiteral,&AnotherSymbolUsage, NULL) != NULL) { printf("The literal data is \n%s\n",AnotherSymbolUsage); } ExtendString(&SymbolUsage,AnotherSymbolUsage,&SymbolUsageLength); NormalizeSymbolUsage(SymbolUsage); printf("The combined data is \n%s\n",SymbolUsage); Free((void **)&AnotherSymbolUsage); } else { printf("Could not get literal number 2\n"); } Free((void **)&SymbolUsage); } else { printf("Could not get literal number 1\n"); } FreeListOfAnnotatedFormulae(&Head); assert(Head == NULL); return(EXIT_SUCCESS); //----Test SZS hierarchy for (SZS1=SZS;SZS1<nonszsresult;SZS1++) { printf("%s (%s,%s) %s\n",SZSResultToString(SZS1), SZSResultToString(StringToSZSResult(SZSResultToString(SZS1))), SZSResultToString(StringToSZSResult(SZSResultToUserString(SZS1))), SZSResultToUserString(SZS1)); for (SZS2=SZS1;SZS2<nonszsresult;SZS2++) { if (SZSIsA(SZS2,SZS1)) { printf("%s isa %s\n",SZSResultToString(SZS2), SZSResultToString(SZS1)); } else { printf("%s nota %s\n",SZSResultToString(SZS2), SZSResultToString(SZS1)); } } } for (SZSO1=LDa;SZSO1<nonszsoutput;SZSO1++) { printf("%s (%s,%s) %s\n",SZSOutputToString(SZSO1), SZSOutputToString(StringToSZSOutput(SZSOutputToString(SZSO1))), SZSOutputToString(StringToSZSOutput(SZSOutputToUserString(SZSO1))), SZSOutputToUserString(SZSO1)); for (SZSO2=SZSO1;SZSO2<nonszsoutput;SZSO2++) { if (SZSOutputIsA(SZSO2,SZSO1)) { printf("%s isa %s\n",SZSOutputToString(SZSO2), SZSOutputToString(SZSO1)); } else { printf("%s nota %s\n",SZSOutputToString(SZSO2), SZSOutputToString(SZSO1)); } } } return(EXIT_SUCCESS); }
static int ComputeClassicAGM(size_t Len, size_t MaxPasses) { int Sign; size_t Pass; double Pow2; clock_t LoopTime,EndTime,StartTime; BigInt AGM_A, AGM_B, AGM_C, AGMWork; int Done; /* boolean */ AGM_A = CreateBigInt(Len); AGM_B = CreateBigInt(Len); AGM_C = CreateBigInt(Len); AGMWork = OldRoot; StartTime = clock(); Pow2 = 4.0; Pass = 0; if (!LoadData(AGM_A,AGM_B,AGM_C,NO_NUM,NO_NUM,NO_NUM, &StartTime,&Pow2,&Pass,Len,Cfg.PiFormulaToUse)) { fprintf(stderr, "Init : "); LoopTime = clock(); SetNum(AGM_A,Len,BI_One,0); SetNum(AGM_C,Len,BI_OneHalf,0); ClassicSqrt(AGM_B,AGM_C,Len); SetNum(AGM_C,Len,BI_One,0); EndTime = clock(); fprintf(stderr,"Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); if (Cfg.AlwaysSaveData) SaveData(AGM_A,AGM_B,AGM_C,NO_NUM,NO_NUM,NO_NUM, ((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); } /* DumpBigInt("AGM_A",AGM_A,Len); DumpBigInt("AGM_B",AGM_B,Len); DumpBigInt("AGM_C",AGM_C,Len); */ Done=0; MaxPasses+=Pass; while ((!Done) && (Pass < MaxPasses)) { fprintf(stderr, "Pass %4s: ", Num2Str(1<<(++Pass))); LoopTime = clock(); if (!Cfg.Macintosh) fprintf(stderr,"AGM Part1"); /* w = (a-b)/2 */ Sign = Sub(AGMWork, AGM_A, AGM_B, Len); if (Sign) Negate(AGMWork,Len); DivBy(AGMWork,AGMWork, 2, Len); if (!Cfg.Macintosh) BackSpace(9); /* m = w*w */ if (!Cfg.Macintosh) fprintf(stderr,"Sqr1"); if (IsZero(AGMWork,Len/2)) Done=1; if (Done) ClearBigInt(AGMWork,Len); else FullMul(AGMWork, AGMWork, AGMWork, Len); if (!Cfg.Macintosh) BackSpace(4); if (!Cfg.Macintosh) fprintf(stderr,"AGM Part2"); /* m = m* w^(J+1) */ MulByFloat(AGMWork,Pow2,Len); Pow2 *= 2.0; /* c = c - m */ if (Sign) Add(AGM_C, AGM_C, AGMWork, Len); else Sub(AGM_C, AGM_C, AGMWork, Len); /* See if it's done */ if (IsZero(AGMWork,Len-(Len/16))) Done=1; if (!Cfg.Macintosh) BackSpace(9); /* m = a*b */ if (!Cfg.Macintosh) fprintf(stderr,"Sqr2"); if (Pass==1) Copy(AGMWork,AGM_B,Len); /* first pass, AGM_A = 1.0 */ else if (!Done) /* If last iter, we can skip it. */ FullMul(AGMWork, AGM_A, AGM_B, Len); /* a = (a+b)/2 */ Add(AGM_A, AGM_A, AGM_B, Len); DivBy(AGM_A,AGM_A, 2, Len); if (!Cfg.Macintosh) BackSpace(4); /* b = sqrt(a*b) */ if (!Done) /* Optimization */ ClassicSqrt(AGM_B, AGMWork, Len); EndTime=clock(); /* DumpBigInt("AGM_A",AGM_A,Len); DumpBigInt("AGM_B",AGM_B,Len); DumpBigInt("AGM_C",AGM_C,Len); */ DumpDebug("Pass %u took:", Pass); fprintf(stderr, "Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); if (TestKeyboard()) break; if (Cfg.AlwaysSaveData) SaveData(AGM_A,AGM_B,AGM_C,NO_NUM,NO_NUM,NO_NUM, ((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); } LoopTime=clock(); if (Done) { fprintf(stderr,"Final : "); if (!Cfg.Macintosh) fprintf(stderr,"Sqr"); FullMul(AGM_A, AGM_A, AGM_A, Len); MulBy(AGM_A,AGM_A,4,Len); if (!Cfg.Macintosh) BackSpace(3); ClassicDivide(AGM_B, AGM_A, AGM_C,Len); EndTime=clock(); fprintf(stderr, "Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); PrintFormattedPi("Classic AGM",((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC, AGM_B, Len); DeleteSaveFile(); } else if (Pass >= FatalPasses) FatalError("The AGM didn't converge.\n"); else SaveData(AGM_A,AGM_B,AGM_C,NO_NUM,NO_NUM,NO_NUM, ((double)clock()-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); fprintf(stderr,"\nTotal Execution time: %0.2f seconds.\n\n",((double)clock()-(double)StartTime) /CLOCKS_PER_SEC); if (!Done) DumpTimings(((double)clock()-(double)StartTime) /CLOCKS_PER_SEC); return (Done); }
/* ***************************************************** ** The AGM itself ** ** ** ** A[n] = (A[n-1] + B[n-1])/2 ** ** B[n] = Sqrt(A[n-1]*B[n-1]) ** ** C[n] = (A[n-1]-B[n-1])/2 ** ** ** ** n ** ** PI[n] = 4A[n+1]^2 / (1-(Sum (2^(j+1))*C[j]^2)) ** ** j = 1 ** ***************************************************** */ static int ComputeSlowAGM(size_t Len, size_t MaxPasses) { int Sign; size_t Pass; double Pow2; clock_t LoopTime,StartTime,EndTime; BigInt AGM_A, AGM_B, AGM_C, AGMWork; int Done; /* boolean */ if ((Cfg.PiFormulaToUse != 2) && (Cfg.PiFormulaToUse != 3)) FatalError("SlowAGM was somehow called with pi formula %d\n", Cfg.PiFormulaToUse); AGM_A = CreateBigInt(Len); AGM_B = CreateBigInt(Len); AGM_C = CreateBigInt(Len); AGMWork = CreateBigInt(Len); Num1IsCached = Num2IsCached = 0; StartTime = clock(); Pow2 = 4.0; Pass = 0; if (!LoadData(AGM_A,AGM_B,AGM_C,OldRoot,NO_NUM,NO_NUM, &StartTime,&Pow2,&Pass,Len,Cfg.PiFormulaToUse)) { LoopTime = clock(); fprintf(stderr, "Init : "); if (Cfg.PiFormulaToUse==2) { SetNum(AGM_A,Len,BI_One,0); SetNum(AGM_C,Len,BI_One,0); ClearBigInt(OldRoot,Len); Sqrt05(AGM_B,Len); } else { Sqrt20(AGM_A,Len); Sqrt60(AGM_C,Len); if (!Cfg.Macintosh) fprintf(stderr,"Square"); Add(AGM_B,AGM_A,AGM_C,Len); DivBy(AGM_B,AGM_B,4,Len); if (!Cfg.Macintosh) BackSpace(6); if (!Cfg.Macintosh) fprintf(stderr,"Setting vars"); ClearBigInt(OldRoot,Len); SetNum(AGM_A,Len,BI_One,0); SetNum(AGM_C,Len,BI_One,0); if (!Cfg.Macintosh) BackSpace(12); Pass=1; } EndTime = clock(); fprintf(stderr,"Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); if (Cfg.AlwaysSaveData) SaveData(AGM_A,AGM_B,AGM_C,OldRoot,NO_NUM,NO_NUM, ((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); } /* DumpBigInt("AGM_A",AGM_A,Len); DumpBigInt("AGM_B",AGM_B,Len); DumpBigInt("AGM_C",AGM_C,Len); */ Done=0; MaxPasses+=Pass; while ((!Done) && (Pass < MaxPasses)) { fprintf(stderr, "Pass %4s: ", Num2Str(1<<(++Pass))); LoopTime = clock(); if (!Cfg.Macintosh) fprintf(stderr,"AGM Part1"); /* w = (a-b)/2 */ Sign = Sub(AGMWork, AGM_A, AGM_B, Len); if (Sign) Negate(AGMWork,Len); DivBy(AGMWork,AGMWork, 2, Len); {size_t Nz; Nz=FindFirstNonZero(AGMWork,Len); if ((Pass > 4) && (Nz != Len)) if ((1<<(Pass-4)) > Nz) fprintf(stderr,"AGMCheck1 fails. Predicted: %lu Actual: %lu\a\n", (unsigned long)1<<(Pass-4),(ULINT)Nz); } if (!Cfg.Macintosh) BackSpace(9); /* m = w*w */ if (!Cfg.Macintosh) fprintf(stderr,"Sqr1"); if (IsZero(AGMWork,Len/2)) Done=1; if (Done) ClearBigInt(AGMWork,Len); else FullMul(AGMWork, AGMWork, AGMWork, Len); if (!Cfg.Macintosh) BackSpace(4); if (!Cfg.Macintosh) fprintf(stderr,"AGM Part2"); {size_t Nz; Nz=FindFirstNonZero(AGMWork,Len); if ((Pass > 3) && (Nz != Len)) if ((1<<(Pass-3)) > Nz) fprintf(stderr,"AGMCheck2 fails. Predicted: %lu Actual: %lu\a\n", (unsigned long)1<<(Pass-3),(ULINT)Nz); } /* m = m* w^(J+1) */ MulByFloat(AGMWork,Pow2,Len); Pow2 *= 2.0; /* c = c - m */ if (Sign) Add(AGM_C, AGM_C, AGMWork, Len); else Sub(AGM_C, AGM_C, AGMWork, Len); /* See if it's done */ if (IsZero(AGMWork,Len-(Len/16))) Done=1; if (!Cfg.Macintosh) BackSpace(9); /* m = a*b */ if (!Cfg.Macintosh) fprintf(stderr,"Sqr2"); if (Pass==1) Copy(AGMWork,AGM_B,Len); /* first pass, AGM_A = 1.0 */ else if (!Done) /* If last iter, we can skip it. */ FullMul(AGMWork, AGM_A, AGM_B, Len); if (!Cfg.Macintosh) BackSpace(4); /* a = (a+b)/2 */ Add(AGM_A, AGM_A, AGM_B, Len); DivBy(AGM_A,AGM_A, 2, Len); /* b = sqrt(a*b) */ if (!Done) /* Optimization */ AGMSqrt(AGM_B, AGMWork, Len, (Pass>5) ? (2<<(Pass-5)) : 0 ); EndTime=clock(); /* DumpBigInt("AGM_A",AGM_A,Len); DumpBigInt("AGM_B",AGM_B,Len); DumpBigInt("AGM_C",AGM_C,Len); */ DumpDebug("Pass %u took:", Pass); fprintf(stderr, "Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); if (TestKeyboard()) break; if (Cfg.AlwaysSaveData) SaveData(AGM_A,AGM_B,AGM_C,OldRoot,NO_NUM,NO_NUM, ((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); } LoopTime=clock(); if (Done) { fprintf(stderr,"Final : "); if (!Cfg.Macintosh) fprintf(stderr,"Sqr"); SpecialSquare(AGM_A, AGM_A, Len, AGMWork); MulBy(AGM_A,AGM_A,4,Len); if (!Cfg.Macintosh) BackSpace(3); if (Cfg.PiFormulaToUse==3) { Sqrt30(AGM_B,Len); if (!Cfg.Macintosh) fprintf(stderr,"Part 2"); FullMul(AGM_C,AGM_C,AGM_B,Len); SubInt(AGM_C, BI_OneHalf); if (!Cfg.Macintosh) BackSpace(6); } AGMDivide(AGM_B, AGM_A, AGM_C, Len, AGMWork); EndTime=clock(); fprintf(stderr, "Time= %0.2f\n", ((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); DumpTimings(((double)EndTime-(double)LoopTime) /CLOCKS_PER_SEC); if (Cfg.PiFormulaToUse==2) PrintFormattedPi("Slow 1/sqrt(2) AGM",((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC, AGM_B, Len); else PrintFormattedPi("Slow sqrt(3) AGM",((double)EndTime-(double)StartTime) /CLOCKS_PER_SEC, AGM_B, Len); DeleteSaveFile(); } else if (Pass >= FatalPasses) FatalError("The AGM didn't converge.\n"); else SaveData(AGM_A,AGM_B,AGM_C,OldRoot,NO_NUM,NO_NUM, ((double)clock()-(double)StartTime) /CLOCKS_PER_SEC,Pow2,Pass,Len,Cfg.PiFormulaToUse); fprintf(stderr,"\nTotal Execution time: %0.2f seconds.\n\n",((double)clock()-(double)LoopTime) /CLOCKS_PER_SEC); if (!Done) DumpTimings(((double)clock()-(double)LoopTime) /CLOCKS_PER_SEC); return (Done); }
/* ** Computes the square root of 'n' by computing its reciprocal square ** root using the Newton's method, and then multiplying by the original ** number. This is faster than doing the normal Newton 'divide & average' ** method. */ /* static */ void AGMSqrt(BigInt Root, BigInt Num, size_t Len, size_t SubLen) { int Sign; size_t Redo=REDO_LEN; if (SubLen <= 0) SubLen = 2; if (SubLen > Len) SubLen = Len; if (NumIs(Num, 7071067,81186547)) SetNum(OldRoot,2,11892071,15002721); else if (NumIs(Num, 7177499,86377537)) SetNum(OldRoot,2,11803570,64195417); else if (NumIs(Num, 7177700,10976296)) SetNum(OldRoot,2,11803405,99073515); else if (NumIs(Num, 7177700,11046129)) SetNum(OldRoot,2,11803405,99016096); /* The second AGM */ else if (NumIs(Num, 9659258,26289068)) SetNum(OldRoot,2,10174852,23681446); else if (NumIs(Num, 9660709,46551927)) SetNum(OldRoot,2,10174087,99031044); else if (NumIs(Num, 9660709,49277277)) SetNum(OldRoot,2,10174087,97595956); else { DumpBigInt("Unknown Sqrt: ",Num,4); ExitPrg(EXIT_FAILURE); } ClearBigInt(OldRoot+SubLen,Len-SubLen); if (SubLen >= Redo) Redo=0; Num1IsCached = Num2IsCached = 0; FlushFFTCache(0); while (SubLen < Len/2) { SubLen *= 2;if (SubLen > Len) SubLen = Len; if (!Cfg.Macintosh) fprintf(stderr,"Sqrt: %4s",Num2Str(SubLen*RawIntDigits)); FlushFFTCache(0); /* Perform safety check */ {char *Str=GetCheckStr(OldRoot); if ( (strcmp(Str,"1189207115002721")!=0) && (strcmp(Str,"1180357064195417")!=0) && (strcmp(Str,"1180340599073515")!=0) && (strcmp(Str,"1180340599016096")!=0) && (strcmp(Str,"1017485223681446")!=0) && (strcmp(Str,"1017408799031044")!=0) && (strcmp(Str,"1017408797595956")!=0) ) fprintf(stderr,"** WARNING **\a\nAGMSqrt may be failing.\n%s\n",Str); } ClearBigInt(OldRoot+SubLen/2,SubLen/2); if (!Cfg.Macintosh) fputc('.',stderr); SaveNum1FFT = 20; HalfMul(DSWork, OldRoot, OldRoot, SubLen); if (SubLen == Len/2) SaveNum1FFT = 21; if (!Cfg.Macintosh) fputc('|',stderr); FullMul(DSWork, Num, DSWork, SubLen); Sign = RevSubInt(BI_One,DSWork,SubLen); Num1IsCached=20; if (!Cfg.Macintosh) fputc('.',stderr); HalfMul2(DSWork,OldRoot,DSWork,SubLen); if (Sign) Sub(OldRoot,OldRoot,DSWork,SubLen); else Add(OldRoot,OldRoot,DSWork,SubLen); if (Redo == ULONG_MAX) Redo = 0; if (SubLen == Redo) {SubLen/=2;Redo=ULONG_MAX;} if (!Cfg.Macintosh) BackSpace(13); } if (!Cfg.Macintosh) fprintf(stderr,"Sqrt: %4s",Num2Str(Len*RawIntDigits)); FlushFFTCache(21); if (!Cfg.Macintosh) fputc('.',stderr); SaveNum2FFT=20; Num1IsCached=21; HalfMul(Root, Num, OldRoot, Len); ClearBigInt(Root+Len/2,Len/2); if (!Cfg.Macintosh) fputc('.',stderr); HalfMul(DSWork, Root, Root, Len); Sign=Sub(DSWork, Num, DSWork, Len); if (Sign) Negate(DSWork,Len); Num1IsCached = 20; if (!Cfg.Macintosh) fputc('.',stderr); HalfMul2(DSWork,OldRoot,DSWork,Len); if (Sign) Sub(Root, Root, DSWork, Len); else Add(Root, Root, DSWork, Len); if (!Cfg.Macintosh) BackSpace(13); Num1IsCached = Num2IsCached = 0; FlushFFTCache(0); }
/* ** d = a/b by computing the reciprocal of b and then multiplying ** that by a. */ void AGMDivide(BigInt R, BigInt Num1, BigInt Num2, size_t Len, BigInt Work) { int Sign; size_t SubLen=2; size_t Redo=REDO_LEN; if (NumIs(Num2, 9138931,62088927)) SetNum(R,Len,10942198, 7613238); else if (NumIs(Num2,12300397,35639667)) SetNum(R,Len, 8129818,66378456); else { DumpBigInt("Unknown Divisor: ",Num2,4); ExitPrg(EXIT_FAILURE); } if (SubLen >= Redo) Redo=0; Num1IsCached = Num2IsCached = 0; FlushFFTCache(0); while (SubLen < Len/2) { SubLen *= 2;if (SubLen > Len) SubLen = Len; if (!Cfg.Macintosh) fprintf(stderr,"Recip: %4s",Num2Str(SubLen*RawIntDigits)); FlushFFTCache(0); /* Perform safety check */ if ( (strcmp(GetCheckStr(R),"1094219807613238")!=0) && (strcmp(GetCheckStr(R),"0812981866378456")!=0) ) fprintf(stderr,"** WARNING **\a\nAGMDivide may be failing.\n%s\n",GetCheckStr(R)); SaveNum1FFT = 10; if (SubLen==Len/2) SaveNum2FFT=11; ClearBigInt(R+SubLen/2,SubLen/2); if (!Cfg.Macintosh) fputc('|',stderr); N1R0Mul(DSWork, R, Num2, Work,SubLen); Sign = RevSubInt(BI_One,DSWork,SubLen); Num1IsCached=10; if (!Cfg.Macintosh) fputc('.',stderr); HalfMul(DSWork,R,DSWork,SubLen); if (Sign) Sub(R,R,DSWork,SubLen); else Add(R,R,DSWork,SubLen); if (Redo == ULONG_MAX) Redo=0; if (SubLen == Redo) {SubLen/=2;Redo=ULONG_MAX;} if (!Cfg.Macintosh) BackSpace(13); } if (!Cfg.Macintosh) fprintf(stderr,"Recip: %4s",Num2Str(Len*RawIntDigits)); FlushFFTCache(11); ClearBigInt(R+Len/2,Len/2); SaveNum1FFT = 10; if (!Cfg.Macintosh) fputc('.',stderr); HalfMul(OldRoot,R,Num1,Len); ClearBigInt(OldRoot+Len/2,Len/2); Num2IsCached=11; if (!Cfg.Macintosh) fputc('|',stderr); N1R0Mul(DSWork,OldRoot,Num2,Work,Len); Sign=Sub(DSWork,Num1,DSWork,Len); if (Sign) Negate(DSWork,Len); Num1IsCached=10; if (!Cfg.Macintosh) fputc('.',stderr); HalfMul(DSWork,R,DSWork,Len); if (Sign) Sub(R,OldRoot,DSWork,Len); else Add(R,OldRoot,DSWork,Len); if (!Cfg.Macintosh) BackSpace(14); Num1IsCached = Num2IsCached = 0; FlushFFTCache(0); }