// recursive factoring (precondition: n composite) // currently only uses ECM void factor_r(vec_pair_ZZ_long& factors, const ZZ& _n, const ZZ& bnd, double failure_prob, bool verbose) { ZZ q; ZZ n(_n); do { // attempt to factor n if (bnd>0) ECM(q,n,bnd,failure_prob,verbose); else ECM(q,n,ZZ::zero(),0,verbose); if (IsOne(q)) { // give up addFactor(factors,n); return; } // compute other factor div(n,n,q); if (n<q) swap(n,q); // q is small factor, n is large factor if (ProbPrime_notd(q)) addFactor(factors,q); else factor_r(factors,q,bnd,failure_prob,verbose); // check if n is still composite if (ProbPrime_notd(n)) { addFactor(factors,n); return; } } while (true); }
void KVWilckeReactionParameters::Print() const { printf("-------------------------------------------\n"); printf("PARAMETERS INDEPENDENT OF BOMBARDING ENERGY\n"); printf("-------------------------------------------\n\n"); KVNucleus fus(ZC,AC); printf("ATOMIC NUMBERS: ZP=%3d ZT=%3d ZC=%3d (%s)\n", ZP, ZT, ZC, fus.GetSymbol()); printf("NEUTRON NUMBERS: NP=%3d NT=%3d NC=%3d\n\n", NP, NT, NC); printf("AP**1/3=%7.3f AT**1/3=%7.3f\n", pow(AP,THIRD), pow(AT,THIRD)); printf("REDUCED MASS NUMBER=%6.2f AP+AT=AC=%3d\n\n", MU, AC); printf("INTERACTION RADIUS RINT=%5.2f fm R0=%5.2f fm\n\n", RINT, R0); printf("MATTER HALF-DENSITY RADII [fm]:\n"); printf("CP=%5.2f CT=%5.2f CT+CP=%5.2f CBAR=%5.2f\n\n", CP, CT, (CP+CT), CBAR); printf("EQUIVALENT SHARP SURFACE RADII [fm]:\n"); printf("RP=%5.2f RT=%5.2f\n\n", RP, RT); printf("COULOMB RADII [fm]:\n"); printf("RCP=%5.2f RCT=%5.2f RC=RCP+RCT=%5.2f\n\n", RCP, RCT, RCTOTAL); printf("BSS-COULOMB POTENTIAL [MeV]:\n"); printf("VC(r)=%5.3f*ZP*ZT/r for r>RC\n", e2_Wilcke); printf("VC(r)=V0-K*r**n for r<RC\n"); printf("V0=%7.2f MeV K=%7.5f n=%5.3f\n",V0, BSS_K, BSS_N); printf("VC(RINT)=%6.1f MeV\n\n", VC_RINT); printf("FISSION-TKE=%5.0f MeV\n", FISSIONTKE); printf("ASYMM. FISSION-TKE=%5.0f MeV\n\n", ASYMMFISSIONTKE); printf("LIQUID DROP PARAMETERS:\n"); printf("GAMMA=%6.3f MeV/fm**2 PROX-FACTOR=%6.2f MeV\n\n", GAMMA, PROXFACTOR); printf("FUSION RELATED PARAMETERS:\n"); printf("R-BARRIER=%5.2f fm V(RB)=%6.1f MeV\n", RBARRIER, VRB); printf("L-CRITICAL=%4.0f HBAR\n", LCRIT); printf("-------------------------------------------------------------------------\n"); printf("EL/u ELAB ECM ECM/VC k ETA LMAX SGMAR SGFUS QP-CM QP-LP EP-QP\n"); printf("-------------------------------------------------------------------------\n"); Double_t e=1; Int_t nlines=0; while(e<51){ printf(" %4.1f %4.0f %4.0f %5.2f %4.1f %5.1f %4.0f %4.0f %4.0f %5.1f %5.1f %4.0f\n", e, AP*e, ECM(e), ECM(e)/VC_RINT, k(e), Eta(e), Lmax(&e,0), SigmaR(&e,0), SigmaFus(&e,0), TMath::RadToDeg()*QuarterPointAngle(&e,0), TMath::RadToDeg()*ProjectileLabQP(e), ProjectileLabEQP(e)); nlines++; if(e<4) e+=1; else if(e<12) e+=0.5; else if(e<20) e+=1; else e+=5; if(!(nlines%5)) printf("\n"); } printf("************************************************************************\n"); }
void chromosome::evaluateChrom(frbs& fis, double** inOutCamp, int numCamp) { double* uscite; //double* distTot = new double[numVar]; uscite = ECM(fis, inOutCamp, numCamp,false); if (TuningPW) objTot[1] = 1-evaluateDistPW(); //objTot[1], fis);//questa va scommentata per il tuning normale else objTot[1]=0; objTot[0]=comp; //complessita objTot[2] =realNumRule; //numero di regole objTot[3]=objTot[6]=objTot[7]=0; objTot[4] = numFeat; //numero feature objTot[5] = uscite[0]; //accuratezza training if (CLASSIFICATION) { objTot[3]=1-uscite[3]; //AUC objTot[6] = 1-uscite[1]; //TPR objTot[7] = uscite[2]; //FPR } for (int i=0;i<sizeObjAlg;i++) objAlg[i]=objTot[objIndex[i]-1]; //delete[] distTot; delete[] uscite; }
//Calcola l'errore della matrice matWM, lo scrive su file ed esce void chromosome::calcolateWMError(frbs& fis) { fstream f; f.open("WMErr", ios::out | ios::app); numRul=dimMatWM; matR=new unsigned int*[numRul]; for (int i=0;i<numRul;i++) { matR[i]=new unsigned[numVar]; for (int j=0;j<numVar;j++) matR[i][j]=matWM[i][j]; } double* usc=ECM(fis,inOutTr,numPatterTr,false); f<<numRul<<' '<<usc[0]<<' '; delete[] usc; usc=ECM(fis,inOutTs,numPatterTs,true); f<<usc[0]<<endl; f.close(); exit(1); }
// ECM primitive void ECM(ZZ& q, const ZZ& n, const ZZ& _bnd, double failure_prob, bool verbose) { ZZ bnd; SqrRoot(bnd,n); if (_bnd>0 && _bnd<bnd) bnd=_bnd; long B1,B2,D; double prob; ECM_parameters(B1,B2,prob,D,NumBits(bnd),NumBits(n)); if (verbose) std::cout<<"ECM: bnd="<<NumBits(bnd)<<"bits B1="<<B1<<" B2="<<B2 <<" D="<<D<<" prob="<<prob<<std::endl; if (failure_prob<=0) { // run "forever" if (verbose) std::cout<<"ECM: expected ncurves="<<(1/prob)<<std::endl; ECM(q,n,NTL_MAX_LONG,B1,B2,D,verbose); } else if (failure_prob>=1) { // run on one curve ECM(q,n,1,B1,B2,D,verbose); } else { // run just the right number of times // failure_prob = (1-prob)^ncurves; double ncurves_d; if (prob<0.1) ncurves_d = to_double(log(failure_prob)/log1p(to_RR(-prob))); else ncurves_d = log(failure_prob)/log(1-prob); long ncurves = ncurves_d<=1 ? 1 : (ncurves_d>=NTL_MAX_LONG ? NTL_MAX_LONG : (long)ncurves_d); if (verbose) std::cout<<"ECM: good_prob="<<prob<<" failure_prob="<<failure_prob <<" ncurves="<<ncurves<<std::endl; ECM(q,n,ncurves,B1,B2,D,verbose); } }
// general purpose factoring method void factor(vec_pair_ZZ_long& factors, const ZZ& _n, const ZZ& bnd, double failure_prob, bool verbose) { ZZ n(_n); if (n<=1) { abs(n,n); if (n<=1) { factors.SetLength(0); return; } } // upper bound on size of smallest prime factor ZZ upper_bound; SqrRoot(upper_bound,n); if (bnd>0 && bnd<upper_bound) upper_bound=bnd; // figure out appropriate lower_bound for trial division long B1,B2,D; double prob; ECM_parameters(B1,B2,prob,D,NumBits(upper_bound),NumBits(n)); ZZ lower_bound; conv(lower_bound,max(B2,1<<14)); if (lower_bound>upper_bound) lower_bound=upper_bound; // start factoring with trial division TrialDivision(factors,n,n,to_long(lower_bound)); if (IsOne(n)) return; if (upper_bound<=lower_bound || ProbPrime_notd(n)) { addFactor(factors,n); return; } /* n is composite and smallest prime factor is assumed to be such that * lower_bound < factor <= upper_bound * * Ramp-up to searching for factors of size upper_bound. This is a good * idea in cases where we have no idea what size factors N might have, * but we don't want to spend too much time doing this. */ for(lower_bound<<=4; lower_bound<upper_bound; lower_bound<<=4) { ZZ q; ECM(q,n,lower_bound,1,verbose); // one curve only if (!IsOne(q)) { div(n,n,q); if (n<q) swap(n,q); // q is small factor, n is large factor if (ProbPrime_notd(q)) addFactor(factors,q); else factor_r(factors,q,bnd,failure_prob,verbose); if (ProbPrime_notd(n)) { addFactor(factors,n); return; } // new upper_bound SqrRoot(upper_bound,n); if (bnd>0 && bnd<upper_bound) upper_bound=bnd; } } // search for factors of size bnd factor_r(factors,n,bnd,failure_prob,verbose); }