/** * @brief Print the approximations to stdout (or whatever the output * stream currently selected in the mps_context is). * * @param s A pointer to the current mps_context. */ void mps_output (mps_context * s) { int i, ind, num = 0; if (s->DOLOG) fprintf (s->logstr, "--------------------\n"); if (s->output_config->format != MPS_OUTPUT_FORMAT_GNUPLOT && s->output_config->format != MPS_OUTPUT_FORMAT_GNUPLOT_FULL) { if (s->over_max) { mps_warn (s, "Warning: Input precision has been reached during computation, " "so not all the required digits may have been computed."); } } /* Start with plotting instructions in the case of * MPS_OUTPUT_GNUPLOT_FULL, so the output can be * piped directly to gnuplot */ if (s->output_config->format == MPS_OUTPUT_FORMAT_GNUPLOT_FULL) { fprintf (s->outstr, "# MPSolve output for GNUPLOT\n"); fprintf (s->outstr, "# Make user that this output is piped into gnuplot using a command like\n"); fprintf (s->outstr, "# mpsolve -Ogf | gnuplot \n"); fprintf (s->outstr, "set pointsize 0.3\n"); fprintf (s->outstr, "plot '-' title 'Computed roots' with %s\n", s->gnuplot_format); } if (s->output_config->goal == MPS_OUTPUT_GOAL_COUNT) mps_outcount (s); else { if (s->output_config->search_set != MPS_SEARCH_SET_UNITARY_DISC_COMPL) for (i = 0; i < s->zero_roots; i++) mps_outroot (s, ISZERO, num++); for (ind = 0; ind < s->n; ind++) { i = s->order[ind]; if (s->root[i]->inclusion == MPS_ROOT_INCLUSION_OUT) continue; mps_outroot (s, i, num++); } } if (s->output_config->format == MPS_OUTPUT_FORMAT_GNUPLOT_FULL) { fprintf (s->outstr, "e\n"); fprintf (s->outstr, "pause mouse close\n"); fprintf (s->outstr, "# End of MPSolve GNUPLOT output. If you are seeing this maybe\n"); fprintf (s->outstr, "# you forgot to pipe the ***solve command into gnuplot?\n"); } }
/** * @brief Check consistency of data and makes some basic adjustments. * * This routine check, for example, if there are zero roots in the polynomial * (i.e. no costant term) and deflates the polynomial if necessary (shifting * the coefficients). * * It sets the value of the parameter <code>which_case</code> to <code>'f'</code> * if a floating point phase is enough, or to <code>'d'</code> if * a <code>dpe</code> phase is needed. * * @param s The <code>mps_context</code> associated with the current computation. * @param which_case the address of the variable which_case; */ MPS_PRIVATE void mps_check_data (mps_context * s, char *which_case) { rdpe_t min_coeff, max_coeff, tmp; mps_monomial_poly *p = NULL; int i; /* case of user-defined polynomial */ if (! MPS_IS_MONOMIAL_POLY (s->active_poly)) { if (s->output_config->multiplicity) mps_error (s, "Multiplicity detection not yet implemented for user polynomial"); if (s->output_config->root_properties) mps_error (s, "Real/imaginary detection not yet implemented for user polynomial"); *which_case = 'd'; return; } else p = MPS_MONOMIAL_POLY (s->active_poly); /* Check consistency of input */ if (rdpe_eq (p->dap[s->n], rdpe_zero)) { mps_warn (s, "The leading coefficient is zero"); do (s->n)--; while (rdpe_eq (p->dap[s->n], rdpe_zero)); MPS_POLYNOMIAL (p)->degree = s->n; } /* Compute min_coeff */ if (rdpe_lt (p->dap[0], p->dap[s->n])) rdpe_set (min_coeff, p->dap[0]); else rdpe_set (min_coeff, p->dap[s->n]); /* Compute max_coeff and its logarithm */ rdpe_set (max_coeff, p->dap[0]); for (i = 1; i <= s->n; i++) if (rdpe_lt (max_coeff, p->dap[i])) rdpe_set (max_coeff, p->dap[i]); s->lmax_coeff = rdpe_log (max_coeff); /* Multiplicity and sep */ if (s->output_config->multiplicity) { if (MPS_STRUCTURE_IS_INTEGER (s->active_poly->structure)) { mps_compute_sep (s); } else if (MPS_STRUCTURE_IS_RATIONAL (s->active_poly->structure)) { mps_warn (s, "The multiplicity option has not been yet implemented"); s->sep = 0.0; } else { mps_warn (s, "The input polynomial has neither integer nor rational"); mps_warn (s, " coefficients: unable to compute multiplicities"); s->sep = 0.0; } } /* Real/Imaginary detection */ if (s->output_config->root_properties || s->output_config->search_set == MPS_SEARCH_SET_REAL || s->output_config->search_set == MPS_SEARCH_SET_IMAG) { if (MPS_STRUCTURE_IS_INTEGER (s->active_poly->structure)) { mps_compute_sep (s); } else if (MPS_STRUCTURE_IS_RATIONAL (s->active_poly->structure)) { mps_error (s, "The real/imaginary option has not been yet implemented for rational input"); return; } else { mps_error (s, "The input polynomial has neither integer nor rational " "coefficients: unable to perform real/imaginary options"); return; } } /* Select cases (dpe or floating point) * First normalize the polynomial (only the float version) */ rdpe_div (tmp, max_coeff, min_coeff); rdpe_mul_eq_d (tmp, (double)(s->n + 1)); rdpe_mul_eq (tmp, rdpe_mind); rdpe_div_eq (tmp, rdpe_maxd); if (rdpe_lt (tmp, rdpe_one)) { mpc_t m_min_coeff; cdpe_t c_min_coeff; /* if (n+1)*max_coeff/min_coeff < dhuge/dtiny - float case */ *which_case = 'f'; rdpe_mul_eq (min_coeff, max_coeff); rdpe_mul (tmp, rdpe_mind, rdpe_maxd); rdpe_div (min_coeff, tmp, min_coeff); rdpe_sqrt_eq (min_coeff); rdpe_set (cdpe_Re (c_min_coeff), min_coeff); rdpe_set (cdpe_Im (c_min_coeff), rdpe_zero); mpc_init2 (m_min_coeff, mpc_get_prec (p->mfpc[0])); mpc_set_cdpe (m_min_coeff, c_min_coeff); /* min_coeff = sqrt(dhuge*dtiny/(min_coeff*max_coeff)) * NOTE: This is enabled for floating point polynomials only * for the moment, but it may work nicely also for other representations. */ { for (i = 0; i <= s->n; i++) { /* Multiply the MP leading coefficient */ mpc_mul_eq (p->mfpc[i], m_min_coeff); rdpe_mul (tmp, p->dap[i], min_coeff); rdpe_set (p->dap[i], tmp); p->fap[i] = rdpe_get_d (tmp); mpc_get_cdpe (p->dpc[i], p->mfpc[i]); cdpe_get_x (p->fpc[i], p->dpc[i]); } } mpc_clear (m_min_coeff); } else *which_case = 'd'; }