int main(int argc, char* argv[]) { // 50 decimal digits flp_type sqrt2("1.4142135623730950488016887242096980785696718753769"); // Contains calculated guard digits flp_type result(boost::multiprecision::sqrt(flp_type("2"))); // The 50 digits of precision actually ompare equal std::cout << std::setprecision(50) << sqrt2 << std::endl; std::cout << std::setprecision(50) << result << std::endl; // I want this to compare to the specified precision of the type, not the guard digits std::cout << (result==sqrt2) << std::endl; return 0; }
double Costfun::subm_cut_cost() { if (cost_uptodate) return scost; if (~s_uptodate) { find_cut_set(); } std::vector<double> cls(nclasses+1,0); for (unsigned int i=0; i<current_S.size(); i++) { cls[ elist[ current_S[i]].classno ] += elist[ current_S[i]].weight; } double ret = 0; for (int i=0; i<nclasses; i++) { if (cls[i] < threshs[i]) { ret += cls[i]; } else { ret += threshs[i] + sqrt2( cls[i] - threshs[i] ); } } ret += cls[nclasses]; double tg = 1/gamma; for (unsigned int i=0; i<n; i++){ if (myGraph -> what_segment(i,Graph<double,double,double>::SOURCE)==Graph<double,double,double>::SOURCE) { // node is in source segment: cut edge to sink ret += ( (termweights[i]>0) ? 0 : (-tg*termweights[i]) ); } else { // node is in sink segment: cut cost max(termweights[i],0) ret += ( (termweights[i]>0) ? tg*termweights[i] : 0); } } scost = ret; cost_uptodate = true; return ret; }
int main(){ int x; scanf("%d",&x); printf("%lf",sqrt2(x)); return 0; }
void main( ) { float x; for(x=1.0;x<2.0;x+=0.1) printf("%3.1f %f\n",x,sqrt2(x)); }
static void tst3() { enable_trace("nlsat_interval"); unsynch_mpq_manager qm; anum_manager am(qm); small_object_allocator allocator; nlsat::interval_set_manager ism(am, allocator); scoped_anum sqrt2(am), m_sqrt2(am), two(am), m_two(am), three(am), one(am), zero(am); am.set(two, 2); am.set(m_two, -2); am.set(one, 1); am.root(two, 2, sqrt2); am.set(m_sqrt2, sqrt2); am.neg(m_sqrt2); am.set(three, 3); nlsat::literal p1(1, false); nlsat::literal p2(2, false); nlsat::literal p3(3, false); nlsat::literal p4(4, false); nlsat::literal np2(2, true); nlsat::interval_set_ref s1(ism), s2(ism), s3(ism), s4(ism); s1 = ism.mk_empty(); std::cout << "s1: " << s1 << "\n"; s2 = ism.mk(true, true, zero, false, false, sqrt2, np2); std::cout << "s2: " << s2 << "\n"; s3 = ism.mk(false, false, zero, false, false, two, p1); std::cout << "s3: " << s3 << "\n"; s4 = ism.mk_union(s2, s3); std::cout << "s4: " << s4 << "\n"; // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, zero, false, false, two, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, zero, false, false, two, p1); s2 = ism.mk(false, false, m_sqrt2, false, false, one, p2); s3 = ism.mk_union(s1, s2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, one, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, one, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, three, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] // s2: [ ... ] [ ... ] s1 = ism.mk(false, false, m_two, false, false, two, p1); s2 = ism.mk(false, false, m_sqrt2, false, false, zero, p2); s3 = ism.mk(false, false, one, false, false, three, p2); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_two, false, false, two, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, two, false, false, three, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, two, false, false, three, p1); tst_interval(s1, s2, 1); s1 = ism.mk(false, false, m_two, true, false, two, p1); tst_interval(s1, s2, 2); s1 = ism.mk(false, false, two, false, false, two, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] [ ... ] // s2: [ .. ] [ ... ] [ ... ] s1 = ism.mk(false, false, m_two, false, false, zero, p1); s3 = ism.mk(false, false, one, false, false, three, p1); s1 = ism.mk_union(s1, s3); s2 = ism.mk(true, true, zero, false, false, m_sqrt2, p2); tst_interval(s1, s2, 3); s3 = ism.mk(false, false, one, false, false, sqrt2, p2); s2 = ism.mk_union(s2, s3); s3 = ism.mk(false, false, two, true, true, zero, p2); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 4); // Case s1 = ism.mk(true, true, zero, false, false, one, p1); s2 = ism.mk(true, false, one, true, true, zero, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, one, false, false, two, p2); s3 = ism.mk(false, false, two, true, true, zero, p1); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 3); }
int main(int argc, char* argv[]){ int i; for(i = 0; i <= 20; i++){ printf("sqrt2(%d) = %d\n", i, sqrt2(i)); } }
void Costfun::reset_wts2(const std::vector<unsigned int>& S) { // assume S is ordered as elist, and entries in S are indices in elist std::vector<double> clws(nclasses,0.0); // to store class weight sums unsigned int i; int cl; double tmp; unsigned int lastone = S.size(); for (i=0; i<S.size(); i++){ cl = elist[ S[i]].classno; if (cl >= lim) { lastone = i; break; } clws[ cl ] += elist[ S[i]].weight; // set the rhoe if that hasn't happened yet if (rhoEe[ S[i]] < 0){ tmp = (csums[cl] - elist[S[i]].weight); // weight of the other edges if ( tmp < threshs[cl]) { rhoEe[ S[i]] = csumsTrunc[cl] - tmp; } else { rhoEe[ S[i]] = csumsTrunc[cl] - ( threshs[cl] + sqrt2( tmp - threshs[cl]) ); } } } // now we know class weights // so go through elist and re-set weights unsigned int counter = 0; for (unsigned int iC=0; iC<(csizes.size()-1); iC++){ // is class saturated? if (clws[iC] >= threshs[iC]) { double base1 = sqrt2(clws[iC] - threshs[iC]); double base2 = clws[iC] - threshs[iC]; for (i=0; i<csizes[iC]; i++){ tmp = sqrt2( elist[ counter + i ].weight + base2) - base1; myGraph -> set_rcap(elist[i + counter].edgep, tmp); } } else { double miss = threshs[iC] - clws[iC]; for (i=0; i<csizes[iC]; i++){ if (elist[ counter + i].weight <= miss){ tmp = elist[ counter + i].weight; } else { tmp = miss + sqrt2( elist[ counter + i].weight - miss ); } myGraph -> set_rcap(elist[i + counter].edgep, tmp); } } counter += csizes[iC]; } for (i=0; i<lastone; i++){ myGraph -> set_rcap( elist[ S[i]].edgep, rhoEe[ S[i]]); } //re-set modular and terminal edges for (i=submodlim; i<elist.size(); i++) { myGraph -> set_rcap( elist[i].edgep, elist[i].weight); } double tg = 1/gamma; for (i=0; i<n; i++){ myGraph -> set_trcap(i, tg*termweights[i]); } }
void Costfun::setEdges(Edge_data* Estuff, const double* unaryWeights, double threshlim) { n = Estuff->height * Estuff->width; m = Estuff -> m; nclasses = Estuff->nclass; // add terminal edges myGraph = new Graph<double, double, double>(n+1,2*m+1); myGraph -> add_node(n); elist = std::vector<edgeInf>(2*m); sortindex = std::vector<unsigned int>(2*m); cost_uptodate = false; //put the weights into the termweights vector unsigned int i, j; baseflow = 0; double tg = 1/gamma; termweights = std::vector<double>(n); for (i=0; i<n; i++){ termweights[i] = (unaryWeights[i] - unaryWeights[n+i]); if (termweights[i] > 0) { myGraph -> add_tweights(i, tg*termweights[i], 0); baseflow += unaryWeights[n+i]; } else { myGraph -> add_tweights(i, 0, -tg*termweights[i]); baseflow += unaryWeights[i]; } } // add interpixel edges csizes = std::vector<unsigned int>(nclasses+1,0); threshs = std::vector<double>(nclasses,0.0); csums = std::vector<double>(nclasses,0.0); csumsTrunc = std::vector<double>(nclasses); lim = nclasses; std::vector<double> cmaxs(nclasses,0); Graph<double,double,double>::arc_id farc = myGraph -> get_first_arc(); // add edges to graph, row-major node numbering // (i,j) is i*width+j //horizontal unsigned int ct = 0; for (j=0; (int)j< Estuff->width; j++) { for (i=0; (int)i< (Estuff->height)-1; i++) { edgeInf nedge; myGraph -> add_edge( i*Estuff->width + j, (i+1)*Estuff->width + j, 50.0*Estuff->weights[ct], 50.0*Estuff->weights[ct]); nedge.edgep = farc++; nedge.eindex = 2*ct; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct]; if (nedge.classno > nclasses) { printf("nclasses=%d, classno(%d)=%d\n", nclasses, 2*ct, nedge.classno); } if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct] = nedge; csizes[nedge.classno]++; //sister edge nedge.edgep = farc++; nedge.eindex = 2*ct+1; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct + 1]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct+1] = nedge; csizes[nedge.classno]++; ct++; } } // vertical for (j=0; (int)j< (Estuff->width)-1; j++) { for (i=0; (int)i< (Estuff->height); i++) { edgeInf nedge; myGraph -> add_edge( i*Estuff->width + j+1, i*Estuff->width + j, 50.0*Estuff->weights[ct], 50.0*Estuff->weights[ct]); nedge.edgep = farc++; nedge.eindex = 2*ct; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct] = nedge; csizes[nedge.classno]++; //sister edge nedge.edgep = farc++; nedge.eindex = 2*ct+1; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct + 1]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct+1] = nedge; csizes[nedge.classno]++; ct++; } } // right diag down for (j=0; (int)j< (Estuff->width)-1; j++) { for (i=0; (int)i< (Estuff->height)-1; i++) { edgeInf nedge; myGraph -> add_edge( i*Estuff->width + j, (i+1)*Estuff->width + j+1, 50.0*Estuff->weights[ct], 50.0*Estuff->weights[ct]); nedge.edgep = farc++; nedge.eindex = 2*ct; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct] = nedge; csizes[nedge.classno]++; //sister edge nedge.edgep = farc++; nedge.eindex = 2*ct+1; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct + 1]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct+1] = nedge; csizes[nedge.classno]++; ct++; } } // left diag down for (j=0; (int)j< (Estuff->width)-1; j++) { for (i=0; (int)i< (Estuff->height)-1; i++) { edgeInf nedge; myGraph -> add_edge( (i+1)*Estuff->width + j, i*Estuff->width + j+1, 50.0*Estuff->weights[ct], 50.0*Estuff->weights[ct]); nedge.edgep = farc++; nedge.eindex = 2*ct; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct] = nedge; csizes[nedge.classno]++; //sister edge nedge.edgep = farc++; nedge.eindex = 2*ct+1; nedge.weight = 50.0*Estuff->weights[ct]; nedge.classno = Estuff->classes[2*ct + 1]; if (nedge.classno >= lim){ nedge.classno = lim; } else { csums[nedge.classno] += nedge.weight; if (nedge.weight > cmaxs[nedge.classno]){ cmaxs[nedge.classno] = nedge.weight; } } elist[2*ct+1] = nedge; csizes[nedge.classno]++; ct++; } } submodlim = 2*m - csizes[csizes.size()-1]; std::stable_sort(elist.begin(), elist.end(), ::comp); for (i=0; i<2*m; i++){ sortindex[elist[i].eindex] = i; } double tmp; for (i=0; (int)i<nclasses; i++){ tmp = threshlim*csums[i]; // threshold starts at threshlim fraction of class weight if (tmp >= cmaxs[i]){ threshs[i] = tmp; } else { threshs[i] = cmaxs[i]; } csumsTrunc[i] = threshs[i] + sqrt2(csums[i] - threshs[i]); } rhoEe = std::vector<double>(2*m, -1); }
void test_sqrt2() { printf("%f\n", sqrt2(0.4)); }
void tqli(float d[], float e[], int n, float **z) { float tFloat0,tFloat1,tFloat2; int tInt; int m,l,iter,i,k; float s,r,p,g,f,dd,c,b; /*Para uso pelo pythag*/ float absa; float absb; /*Fim: Para uso pelo pythag*/ /*FOR 1: for (i=2;i<=n;i++) */ i = 2; LABELstartOFfor1: if(i>n) { goto LABELendOFfor1; } tInt = i-1; e[ tInt ]=e[i]; // Convenient to renumber the elements of e. i=i+1; goto LABELstartOFfor1; LABELendOFfor1: e[n]=0.0; /*FOR 2: for (l=1;l<=n;l++)*/ l=1; LABELstartOFfor2: if(l>n) { goto LABELendOFfor2; } iter=0; LABELstartOFdowhile: /*do{*/ /*FOR 3:for (m=l;m<=n-1;m++)*/ m=l; LABELstartOFfor3: tInt = n-1; if(m>tInt) { goto LABELendOFfor3; } tFloat0 = d[m]; tFloat1 = fabs(tFloat0); tInt = m+1; tFloat0 = d[ tInt ]; tFloat2 = fabs(tFloat0); dd = tFloat1 + tFloat2; tFloat0 = e[m]; tFloat1 = fabs(tFloat0); tFloat0 = tFloat1 + dd; if ( tFloat0 == dd ) { goto LABELendOFfor3; } m = m+1; goto LABELstartOFfor3; LABELendOFfor3: if ( m == l) { goto LABELendOFif_1; } if ( iter != 30) { goto LABELendOFif_2; } printf("\nNumerical Recipes run-time error...\n"); printf("Too many iterations in tqli\n"); printf("...now exiting to system...\n"); exit(1); LABELendOFif_2: iter=iter+1; tInt = l+1; tFloat0 = d[ tInt ] - d[l]; tFloat1 = 2.0*e[l]; g = (tFloat0)/(tFloat1); /*Substituicao do pythag * r=pythag(g,1.0); */ absa=fabs(g); absb=fabs(1.0); if (absa <= absb) { goto LABELendOFif_3_else_1; } tFloat0 = (absb/absa); if( tFloat0 != 0.0 ) { goto LABELendOFif_4_else_1; } tFloat1 = 0.0; goto LABELendOFif_4; LABELendOFif_4_else_1: tFloat1 = tFloat0*tFloat0; LABELendOFif_4: tFloat1 = 1.0 + tFloat1; tFloat0 = sqrt2( tFloat1 ); r = absa * tFloat0; goto LABELendOFif_3; LABELendOFif_3_else_1: tFloat0 = (absa/absb); if(tFloat0 != 0.0) { goto LABELendOFif_5_else_1; } tFloat1 = 0.0; goto LABELendOFif_5; LABELendOFif_5_else_1: tFloat1=tFloat0*tFloat0; LABELendOFif_5: tFloat0 = 1.0+tFloat1; tFloat1 = sqrt2(tFloat0); if(absb != 0.0) { goto LABELendOFif_6_else_1; } r = 0.0; goto LABELendOFif_6; LABELendOFif_6_else_1: r = absb*tFloat1; LABELendOFif_6: LABELendOFif_3: /*Fim: Substituicao do pythag*/ if( g < 0.0 ) { goto LABELendOFif_7_else_1; } tFloat0 = fabs(r); goto LABELendOFif_7; LABELendOFif_7_else_1: tFloat0 = -fabs(r); LABELendOFif_7: tFloat0 = g + tFloat0; tFloat1 = e[l]/tFloat0; tFloat0 = tFloat1 - d[l]; g = d[m] + tFloat0; c=1.0; s=1.0; p=0.0; i=m-1; LABELstartOFfor4: if(i<l) { goto LABELendOFfor4; } f=s*e[i]; b=c*e[i]; absa=fabs(f); absb=fabs(g); if (absa <= absb) { goto LABELendOFif_8_else_1; } tFloat0 = (absb/absa); if( tFloat0 != 0.0) { goto LABELendOFif_9_else_1; } tFloat1=0.0; goto LABELendOFif_9; LABELendOFif_9_else_1: tFloat1 = tFloat0*tFloat0; LABELendOFif_9: tFloat0 = 1.0 + tFloat1; tFloat1 = sqrt2( tFloat0 ); r = absa*tFloat1; goto LABELendOFif_8; LABELendOFif_8_else_1: tFloat0 = (absa/absb); if(tFloat0 != 0.0) { goto LABELendOFif_10_else_1; } tFloat1 = 0.0; goto LABELendOFif_10; LABELendOFif_10_else_1: tFloat1 = tFloat0*tFloat0; LABELendOFif_10: tFloat0 = 1.0 + tFloat1; tFloat1 = sqrt2(tFloat0); if(absb != 0.0) { goto LABELendOFif_11_else_1; } r = 0.0; goto LABELendOFif_11; LABELendOFif_11_else_1: r = absb*tFloat1; LABELendOFif_11: LABELendOFif_8: tInt = i+1; e[ tInt ] = r; if ( r != 0.0) { goto LABELendOFif_12; } d[ tInt ] = d[ tInt ] - p; e[m]=0.0; goto LABELendOFfor4;/*break;*/ LABELendOFif_12: s=f/r; c=g/r; g = d[ tInt ] - p; tFloat0 = d[i] - g; tFloat1 = tFloat0*s; tFloat0 = c*b; tFloat2 = 2.0*tFloat0; r= tFloat1 + tFloat2; p=s*r; d[ tInt ] = g+p; tFloat0 = c*r; g = tFloat0 - b; /*FOR 5: for (k=1;k<=n;k++) */ k=1; LABELstartOFfor5: if(k>n) { goto LABELendOFfor5; } tInt = i+1; f = z[k][ tInt ]; tFloat0 = s*z[k][i]; tFloat1 = c*f; z[k][ tInt ] = tFloat0+tFloat1; tFloat0 = c*z[k][i]; tFloat1 = s*f; z[k][i]= tFloat0 - tFloat1; k=k+1; goto LABELstartOFfor5; LABELendOFfor5: i = i-1; goto LABELstartOFfor4; LABELendOFfor4: if (r != 0.0) { goto LABELendOFif_13; } if(i >= l) goto LABELstartOFdowhile;/*continue;*/ LABELendOFif_13: d[l] = d[l] - p; e[l]= g; e[m]= 0.0; LABELendOFif_1: /*} while (m != l);*/ if(m != l) { goto LABELstartOFdowhile; } //LABELendOFdowhile: l = l+1; goto LABELstartOFfor2; LABELendOFfor2: asm("nop"); }
static void tst1() { unsynch_mpq_manager nm; polynomial::manager m(nm); polynomial_ref x(m); x = m.mk_polynomial(m.mk_var()); polynomial_ref p(m); p = 3*x - 2; algebraic_numbers::manager am(nm); scoped_anum_vector rs1(am); std::cout << "p: " << p << "\n"; am.isolate_roots(p, rs1); display_anums(std::cout, rs1); SASSERT(rs1.size() == 1); std::cout.flush(); p = (x^2) - 2; std::cout << "p: " << p << "\n"; rs1.reset(); am.isolate_roots(p, rs1); display_anums(std::cout, rs1); SASSERT(rs1.size() == 2); scoped_anum sqrt2(am); am.set(sqrt2, rs1[1]); scoped_mpq q(nm); nm.set(q, 1, 3); scoped_anum aq(am); am.set(aq, q); // create algebraic number representing 1/3 am.add(sqrt2, aq, aq); std::cout << "sqrt(2) + 1/3: "; am.display_decimal(std::cout, aq, 10); std::cout << " "; am.display_interval(std::cout, aq); std::cout << " "; am.display_root(std::cout, aq); std::cout << "\n"; am.set(aq, q); am.add(rs1[0], aq, aq); std::cout << "-sqrt(2) + 1/3: "; am.display_decimal(std::cout, aq, 10); std::cout << " "; am.display_interval(std::cout, aq); std::cout << " "; am.display_root(std::cout, aq); std::cout << "\n"; p = ((x^5) - x - 1)*(x-1)*(x-2); std::cout << "p: " << p << "\n"; rs1.reset(); am.isolate_roots(p, rs1); display_anums(std::cout, rs1); SASSERT(rs1.size() == 3); scoped_anum gauss(am); am.set(gauss, rs1[1]); std::cout << "compare(" << sqrt2 << ", " << gauss << "): " << am.compare(sqrt2, gauss) << "\n"; statistics st; am.collect_statistics(st); st.display_smt2(std::cout); p = ((x^2) - 2)*((x^2) - 3); std::cout << "p: " << p << "\n"; rs1.reset(); am.isolate_roots(p, rs1); display_anums(std::cout, rs1); SASSERT(rs1.size() == 4); scoped_anum hidden_sqrt2(am); am.set(hidden_sqrt2, rs1[2]); std::cout << "compare(" << sqrt2 << ", " << hidden_sqrt2 << "): " << am.compare(sqrt2, hidden_sqrt2) << "\n"; st.reset(); am.collect_statistics(st); st.display_smt2(std::cout); std::cout << "sqrt(2)^4: " << (sqrt2^4) << "\n"; SASSERT(is_int(power(sqrt2, 4))); SASSERT(power(sqrt2, 4) == 4); scoped_anum sqrt2_gauss(am); am.add(sqrt2, gauss, sqrt2_gauss); std::cout << "sqrt2 + gauss: " << sqrt2_gauss << " "; am.display_root(std::cout, sqrt2_gauss); std::cout << "\n"; std::cout << "sqrt2*sqrt2: " << sqrt2*sqrt2 << "\n"; std::cout << "sqrt2*sqrt2 == 2: " << (sqrt2*sqrt2 == 2) << std::endl; scoped_anum three(am); am.set(three, -3); std::cout << "(-3)^(1/5): " << root(three, 5) << "\n"; std::cout << "sqrt(2)^(1/3): " << root(sqrt2, 3) << "\n"; std::cout << "as-root-object(sqrt(2)^(1/3)): " << root_obj_pp(root(sqrt2, 3)) << "\n"; std::cout << "(sqrt(2) + 1)^(1/3): " << root(sqrt2 + 1, 3) << "\n"; std::cout << "as-root-object((sqrt(2) + 1)^(1/3)): " << root_obj_pp(root(sqrt2 + 1, 3)) << "\n"; std::cout << "(sqrt(2) + gauss)^(1/5): " << root(sqrt2 + gauss, 5) << "\n"; std::cout << "as-root-object(sqrt(2) + gauss)^(1/5): " << root_obj_pp(root(sqrt2 + gauss, 5)) << "\n"; std::cout << "(sqrt(2) / sqrt(2)): " << sqrt2 / hidden_sqrt2 << "\n"; std::cout << "(sqrt(2) / gauss): " << sqrt2 / gauss << "\n"; std::cout << "(sqrt(2) / gauss) 30 digits: " << decimal_pp(sqrt2 / gauss, 30) << "\n"; std::cout << "as-root-object(sqrt(2) / gauss): " << root_obj_pp(sqrt2 / gauss) << "\n"; std::cout << "is_int(sqrt(2)^(1/3)): " << am.is_int(root(sqrt2, 3)) << "\n"; scoped_anum tmp(am); scoped_anum four(am); am.set(four, 4); am.set(tmp, sqrt2); am.inv(tmp); std::cout << "1/sqrt(2): " << tmp << "\n"; am.mul(tmp, four, tmp); std::cout << "4*1/sqrt(2): " << tmp << " " << root_obj_pp(tmp) << "\n"; am.mul(tmp, sqrt2, tmp); std::cout << "sqrt(2)*4*(1/sqrt2): " << tmp << " " << root_obj_pp(tmp) << "\n"; std::cout << "is_int(sqrt(2)*4*(1/sqrt2)): " << am.is_int(tmp) << ", after is-int: " << tmp << "\n"; p = (998*x - 1414)*((x^2) - 15); std::cout << "p: " << p << "\n"; rs1.reset(); am.isolate_roots(p, rs1); std::cout << "is-rational(sqrt2): " << am.is_rational(sqrt2) << "\n"; scoped_anum qr(am); am.set(qr, rs1[1]); std::cout << "qr: " << root_obj_pp(qr); std::cout << ", is-rational: " << am.is_rational(qr) << ", val: " << root_obj_pp(qr) << "\n"; return; std::cout << "compare(" << sqrt2 << ", " << gauss << "): " << am.compare(sqrt2, gauss) << "\n"; p = (x^16) - 136*(x^14) + 6476*(x^12) - 141912*(x^10) + 1513334*(x^8) - 7453176*(x^6) + 13950764*(x^4) - 5596840*(x^2) + 46225; std::cout << "p: " << p << "\n"; rs1.reset(); am.isolate_roots(p, rs1); display_anums(std::cout, rs1); }