void save_bes_cwi_impl(const equation_system& system, std::ostream& stream) { if (system.initial_state() == system.equations().front().variable()) { bes::bes2cwi(system.equations().begin(), system.equations().end(), stream); } else { mCRL2log(log::warning) << "The initial state " << system.initial_state() << " and the left hand " "side of the first equation " << system.equations().begin()->variable() << " do not correspond." << std::endl; std::vector<typename equation_system::equation_type> equations(system.equations().begin(), system.equations().end()); if (is_boolean_variable(system.initial_state()) && swap_equations(equations, system.initial_state())) { mCRL2log(log::warning) << "Fixed by swapping equations for " << equations[0].variable() << " and " << system.initial_state() << std::endl; } else { add_fresh_equation(equations, system.initial_state()); mCRL2log(log::warning) << "Fixed by prepending a new equation " << equations.front() << "." << std::endl; } bes2cwi(equations.begin(), equations.end(), stream); } }
// Generate the rational approximation x^(pnum/pden) void AlgRemez::generateApprox() { char *fname = "generateApprox()"; Float time = -dclock(); iter = 0; spread = 1.0e37; if (approx_type == RATIONAL_APPROX_ZERO_POLE) { n--; neq--; } initialGuess(); stpini(step); while (spread > tolerance) { //iterate until convergance if (iter++%100==0) VRB.Result(cname,fname,"Iteration %d, spread %e delta %e\n", iter-1,(Float)spread,(Float)delta); equations(); if (delta < tolerance) ERR.General(cname, fname,"Delta too small, try increasing precision\n"); search(step); } int sign; Float error = (Float)getErr(mm[0],&sign); VRB.Result(cname,fname,"Converged at %d iterations, error = %e\n", iter,error); //!< Once the approximation has been generated, calculate the roots if(!root()) ERR.General(cname,fname,"Root finding failed\n"); if (approx_type == RATIONAL_APPROX_ZERO_POLE) { roots[n] = (bigfloat)0.0; n++; neq++; } //!< Now find the partial fraction expansions if (remez_arg->field_type == BOSON) { getPFE(remez_arg->residue, remez_arg->pole, &(remez_arg->norm)); getIPFE(remez_arg->residue_inv, remez_arg->pole_inv, &(remez_arg->norm_inv)); } else { getIPFE(remez_arg->residue, remez_arg->pole, &(remez_arg->norm)); getPFE(remez_arg->residue_inv, remez_arg->pole_inv, &(remez_arg->norm_inv)); } remez_arg->error = error; time += dclock(); print_time(cname,fname,time); }
// Парсит всю формулу (которая может содержать несоклько уравнений) CFormula ParseFormula( const std::string& text ) { std::vector<std::string> equations( 1 ); std::string spaces = " \t\n\r"; for( int i = 0; i < static_cast<int>( text.size() ); ++i ) { if( spaces.find( text[i] ) != std::string::npos ) { continue; } if( text[i] == ',' && !equations.back().empty() ) { equations.push_back( std::string() ); continue; } equations.back().push_back( text[i] ); } CheckEquationsCorrectness( equations ); int spaceDimension = GetSpaceDimension( equations ); assert( spaceDimension >= 2 ); int plotDimension = GetPlotDimension( equations ); std::vector<char> variables = GetEquationsVariables( equations ); CFormula formula( spaceDimension, plotDimension, variables ); for( int i = 0; i < static_cast<int>( equations.size() ); ++i ) { formula.AddEquation( ParseEquation( equations[i] ) ); } return formula; }
// Generate the rational approximation x^(pnum/pden) double AlgRemez::generateApprox(int num_degree, int den_degree, unsigned long pnum, unsigned long pden, int a_len, double *a_param, int *a_pow) { char *fname = "generateApprox(int, unsigned long, unsigned long)"; printf("Degree of the approximation is (%d,%d)\n", num_degree, den_degree); printf("Approximating the function x^(%d/%d)\n", pnum, pden); // Reallocate arrays, since degree has changed if (num_degree != n || den_degree != d) allocate(num_degree,den_degree); if (a_len > SUM_MAX) { printf("Error: a_length > SUM_MAX"); exit(0); } step = new bigfloat[num_degree+den_degree+2]; a_length = a_len; for (int j=0; j<a_len; j++) { a[j]= a_param[j]; a_power[j] = a_pow[j]; } power_num = pnum; power_den = pden; spread = 1.0e37; iter = 0; n = num_degree; d = den_degree; neq = n + d + 1; initialGuess(); stpini(step); while (spread > tolerance) { //iterate until convergance if (iter++%100==0) printf("Iteration %d, spread %e delta %e\n", iter-1,(double)spread,(double)delta); equations(); if (delta < tolerance) { printf("Delta too small, try increasing precision\n"); exit(0); } search(step); } int sign; double error = (double)getErr(mm[0],&sign); printf("Converged at %d iterations, error = %e\n",iter,error); // Once the approximation has been generated, calculate the roots if(!root()) { printf("Root finding failed\n"); } else { foundRoots = 1; } delete [] step; // Return the maximum error in the approximation return error; }