is modulo function equal to reduce function?
programmer · Tue Feb 07, 2012 12:00 pm
actually i do not understand the language of scheme
but i find a reduce function which is a reduce q modulo p, name is quite similar to the modulo, but q is one polynomial and p is a list of polynomial
is reduce function equal to modulo in singular?
if so, for matrix case, if running q on every element of matrix, what is p ? does this p a list of polynomials equal to the row of polynomials of q? or column of q?
public string Reduce(string p, List<string> Q, List<String> order)
{
string r = p;
string q = "0";
string f = "";
Dictionary<String, double> Rrq = new Dictionary<String, double>();
Dictionary<String, double> temp = new Dictionary<String, double>();
// only assume three variables
Dictionary<String,double> order0 = new Dictionary<String, double>();
Dictionary<String,double> order1 = new Dictionary<String,double>();
Dictionary<String,double> order2 = new Dictionary<String,double>();
foreach (String s in Q)
{
int counter = 0;
while(max_deg_var(s)!=order[counter])
{
counter += 1;
}
if (counter == 0)
order0.Add(s, max_deg(s));
if (counter == 1)
order1.Add(s, max_deg(s));
if (counter == 2)
order2.Add(s, max_deg(s));
}
foreach (KeyValuePair<String, double> s in order0.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
foreach (KeyValuePair<String, double> s in order1.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
foreach (KeyValuePair<String, double> s in order2.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
string Mr = "";
while (r != "0")
{
f = selectpoly(r, Rrq, order[0]);
int counter = 0;
while (!string.IsNullOrEmpty(f))
{
if (counter == 3)
Console.WriteLine("");
r = Expand(r + "-(" + Expand(selectpoly_reducer_term(r, Rrq, order[0]) + "*(" + f + ")") + ")");
counter += 1;
//debug
//r = "-3*x*y+5*x-15*x^3-2.857142857*y^3+50*x^2+10*y^2+.428571428571429";
// -3*x*y+5*x-15*x^3-2.85714285714286*y^3+50*x^2+10*y^2+0.42857
f = selectpoly(r, Rrq, order[0]);
}
Mr = Mr_Term(r, Rrq, order[0]);
if (!string.IsNullOrEmpty(Mr))
{
q = Expand(q + "+" + Mr);
r = Expand(r + "-(" + Mr + ")");
}
else
{
return r;
}
}
return q;
}
public List<String> getMonomialList(String q)
{
List<String> result = new List<String>();
List<Term> temp = get_list(q);
foreach (Term t in temp)
{
List<Term> r = new List<Term>();
r.Add(t);
result.Add(get_result(r));
}
return result;
}
public string selectpoly(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach(String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return kv.Key;
}
}
}
return "";
}
public string selectpoly_reducer_term(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach (String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return Divide(t, LeadTerm(kv.Key, main_variable));
}
}
}
return "";
}
public string Mr_Term(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach (String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return t;
}
}
}
return "";
}
but i find a reduce function which is a reduce q modulo p, name is quite similar to the modulo, but q is one polynomial and p is a list of polynomial
is reduce function equal to modulo in singular?
if so, for matrix case, if running q on every element of matrix, what is p ? does this p a list of polynomials equal to the row of polynomials of q? or column of q?
public string Reduce(string p, List<string> Q, List<String> order)
{
string r = p;
string q = "0";
string f = "";
Dictionary<String, double> Rrq = new Dictionary<String, double>();
Dictionary<String, double> temp = new Dictionary<String, double>();
// only assume three variables
Dictionary<String,double> order0 = new Dictionary<String, double>();
Dictionary<String,double> order1 = new Dictionary<String,double>();
Dictionary<String,double> order2 = new Dictionary<String,double>();
foreach (String s in Q)
{
int counter = 0;
while(max_deg_var(s)!=order[counter])
{
counter += 1;
}
if (counter == 0)
order0.Add(s, max_deg(s));
if (counter == 1)
order1.Add(s, max_deg(s));
if (counter == 2)
order2.Add(s, max_deg(s));
}
foreach (KeyValuePair<String, double> s in order0.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
foreach (KeyValuePair<String, double> s in order1.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
foreach (KeyValuePair<String, double> s in order2.OrderByDescending(k => k.Value))
Rrq.Add(s.Key, s.Value);
string Mr = "";
while (r != "0")
{
f = selectpoly(r, Rrq, order[0]);
int counter = 0;
while (!string.IsNullOrEmpty(f))
{
if (counter == 3)
Console.WriteLine("");
r = Expand(r + "-(" + Expand(selectpoly_reducer_term(r, Rrq, order[0]) + "*(" + f + ")") + ")");
counter += 1;
//debug
//r = "-3*x*y+5*x-15*x^3-2.857142857*y^3+50*x^2+10*y^2+.428571428571429";
// -3*x*y+5*x-15*x^3-2.85714285714286*y^3+50*x^2+10*y^2+0.42857
f = selectpoly(r, Rrq, order[0]);
}
Mr = Mr_Term(r, Rrq, order[0]);
if (!string.IsNullOrEmpty(Mr))
{
q = Expand(q + "+" + Mr);
r = Expand(r + "-(" + Mr + ")");
}
else
{
return r;
}
}
return q;
}
public List<String> getMonomialList(String q)
{
List<String> result = new List<String>();
List<Term> temp = get_list(q);
foreach (Term t in temp)
{
List<Term> r = new List<Term>();
r.Add(t);
result.Add(get_result(r));
}
return result;
}
public string selectpoly(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach(String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return kv.Key;
}
}
}
return "";
}
public string selectpoly_reducer_term(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach (String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return Divide(t, LeadTerm(kv.Key, main_variable));
}
}
}
return "";
}
public string Mr_Term(String q, Dictionary<String, double> Rrq, string main_variable)
{
List<String> qx = getMonomialList(q);
foreach (KeyValuePair<String, double> kv in Rrq)
{
foreach (String t in qx)
{
if (!Divide(t, LeadTerm(kv.Key, main_variable)).Contains("^-"))
{
return t;
}
}
}
return "";
}