Beispiel #1
0
Poly calcMP(PolyInfrastructure* pi, const string var) 
{
    Poly tmp; tmp = MonoPoly(pi, var, 1, 1.0);
    return tmp;
}
Beispiel #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;
    }
}
Beispiel #3
0
int main(void)
{
    PolyInfrastructure pi;
    Poly f1, f2, f3, f4;
    vector<string> wuvar;
    vector<Poly> wupoly;
    Poly wuconc;
    WuMethod wm = WuMethod();
    vector <string> var_names;

    cout << "/*** Q1 ***/" << endl;
    var_names.clear();
    var_names.push_back("a");
    var_names.push_back("b");
    var_names.push_back("c");
    var_names.push_back("d");
    var_names.push_back("e");

    pi = PolyInfrastructure(var_names);
    f1 = Poly(&pi);
    f1 = f1 + MonoPoly(&pi, "e", 1, 1.0) + MonoPoly(&pi, "a", 1, -2.0);
    f2 = Poly(&pi);
    f2 = f2 + MonoPoly(&pi, "a", 1, 2.0) + MonoPoly(&pi, "b", 1, -1.0) - MonoPoly(&pi, "d", 1, -1.0);
    wuconc = Poly(&pi);
    wuconc = wuconc + calcSQ(calcMP(&pi, "a") - calcMP(&pi, "b")) - calcSQ(calcMP(&pi, "a") - calcMP(&pi, "d"));

    wuvar.clear();
    wuvar.push_back("a");
    wuvar.push_back("b");

    wupoly.clear();
    wupoly.push_back(f1);
    wupoly.push_back(f2);

    wm = WuMethod(&pi, wuvar, wupoly, wuconc);
    wm.Print();
    cout << (wm.Run() ? "TRUE" : "FALSE") << endl;

    cout << "/*** Q2 ***/" << endl;
    var_names.clear();
    var_names.push_back("a");
    var_names.push_back("b");
    var_names.push_back("c");
    var_names.push_back("d");
    var_names.push_back("e");

    pi = PolyInfrastructure(var_names);
    f1 = Poly(&pi);
    f1 = f1 + MonoPoly(&pi, "e", 1, 1.0) + MonoPoly(&pi, "a", 1, -2.0);
    f2 = Poly(&pi);
    f2 = f2 + MonoPoly(&pi, "d", 1, 1.0) + MonoPoly(&pi, "b", 1, -1.0);
    wuconc = Poly(&pi);
    wuconc = wuconc + calcSQ(calcMP(&pi, "a") - calcMP(&pi, "b")) - calcSQ(calcMP(&pi, "a") - calcMP(&pi, "d"));

    wuvar.clear();
    wuvar.push_back("a");
    wuvar.push_back("b");

    wupoly.clear();
    wupoly.push_back(f1);
    wupoly.push_back(f2);

    wm = WuMethod(&pi, wuvar, wupoly, wuconc);
    wm.Print();
    cout << (wm.Run() ? "TRUE" : "FALSE") << endl;

    return 0;
}