示例#1
0
Poly Poly::operator()(const Poly& obj, string str) const
{
    // Copy
    Poly f; f = *this;
    
    // get one of the highest term.
    MonoPoly h0 = *(obj.getHighestTerm(str));
    double h0_coeff = h0.getCoeff();

    // calc.
    //      f - t + (t * h0_coeff / h0) * ((h0 - obj) / h0_coeff)
    // where 
    //      t = term including hterm
    while (1) {
        // search which includes hterm.
        int index;
        if ((index = f.searchIncludeDimMonoPoly(&h0)) == -1) { // if not break
            break;
        } else { // if any substitute
            MonoPoly t = *(f.getMonoPolyWithIndex(index));
            f = (f - t) + (t * h0_coeff / h0) * ((h0 - obj) / h0_coeff);
        }
    }

    f.cleanPoly();
    return f;
}
示例#2
0
bool WuMethod::SingleRun(vector <pair <int, string> > varperm, vector <pair <int, Poly> > polyperm)
{
    vector <string> wuvar;
    vector <Poly> wupoly;
    for (int i = 0; i < varperm.size(); i++) 
        wuvar.push_back(varperm[i].second);
    for (int i = 0; i < varperm.size(); i++) 
        wupoly.push_back(polyperm[i].second);

    vector <Poly> tripoly;
    for (int i = 0; i < getWuVarNum(); i++) {
        tripoly.push_back(wupoly[i]);
        for (int j = 0; j < i; j++) {
            tripoly[i] = tripoly[i](tripoly[j], wuvar[j]);
//            tripoly[i].Print(); cout << "(mod "; tripoly[j].Print(); cout << ") " << wuvar[j] << " #tri" << j << endl;
        }

        // if there is variable not needed, return false
        for (int j = 0; j < i; j++) {
            MonoPoly single = MonoPoly(m_pi, wuvar[j], 1, 1.0);
            if (tripoly[i].searchIncludeDimMonoPoly(&single) != -1) {
                cout << "failed triangulation." << endl;
                return false;
            }
        }
    }
    
    // if there is doubled tripoly, return false
    for (int i = 0; i < tripoly.size(); i++) {
        if (tripoly[i].isZeroPoly()) {
            cout << "failed for 0 poly in tripoly." << endl;
            return false;
        }
    }

    for (int i = 0; i < tripoly.size(); i++) {
        cout << "Tri: ";
        tripoly[i].Print();
        cout << " = 0" << endl;
    }

    Poly conc = m_wuconc;
    for (int i = 0; i < getWuVarNum(); i++) {
        conc = conc(tripoly[i], wuvar[i]);
        // if there is variable not needed, return false
        for (int j = 0; j < i; j++) {
            MonoPoly single = MonoPoly(m_pi, wuvar[j], 1, 1.0);
            if (conc.searchIncludeDimMonoPoly(&single) != -1) {
                conc.Print(); cout << endl;
                cout << "failed for unexpected reminder." << endl;
                return false;
            }
        }
    }

    if (conc.isZeroPoly()) {
        return true;
    } else {
        cout << "failed for unexpected reminder at the end." << endl;
        conc.Print(); cout << endl;
        return false;
    }
}