Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: is modulo function equal to reduce function?
PostPosted: 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 "";
}


Report this post
Top
  
Reply with quote  
 Post subject: Re: is modulo function equal to reduce function?
PostPosted: Tue Feb 07, 2012 12:14 pm 
Code:
        public string[,] kontraHom(string[,] M, int s)
        {
            int n = M.GetLength(1);
            int m = M.GetLength(0);
            int a,b,c;
            string[,] R = new string[s*n,s*m];
            for(b=1;b<=m;b++)
            {
                for(a=1;a<=s;a++)
                {
                    for(c=1;c<=n;c++)
                    {
                        R[(a-1)*n+c,(a-1)*m+b]=M[b,c];
                    }
                }
            }
            return(R);
        }
        public string[,] kohom(string[,] M, int s)
        {
            int n=M.GetLength(1);
            int m=M.GetLength(0);
            int a,b,c;
            string[,] R = new string[s*m,s*n];
            for(b=1;b<=s;b++)
            {
                for(a=1;a<=m;a++)
                {
                    for(c=1;c<=n;c++)
                    {
                        R[(a-1)*s+b,(c-1)*s+b]=M[a,c];
                    }
                }
            }
            return(R);
        }
        public string[,] Hom(string[,] M, string[,] N, List<string> order)
        {
            string[,] F = kontraHom(M, N.GetLength(0));
            string[,] B = kohom(N, M.GetLength(1));
            string[,] C = kohom(N, M.GetLength(0));
            string[,] D = modulo(F, B, order);
            string[,] E = modulo(D, C, order);
            //string[,] D = modulo(F, B);
            //string[,] E = modulo(D, C);
            return (E);
        }
        public string[,] modulo(string[,] A, string[,] B, List<string> order)
        {
            string[,] R = new string[A.GetLength(0),A.GetLength(1)];
            List<List<string>> m = new List<List<string>>();
            for (int row = 0; row < B.GetLength(0); row++)
            {
                List<String> reduce_p = new List<String>();
                for (int col = 0; col < B.GetLength(1); col++)
                {
                    reduce_p.Add(B[row, col]);
                }
                m.Add(reduce_p);
            }
            for (int row = 0; row < A.GetLength(0); row++)
            {
                for (int col = 0; col < A.GetLength(1); col++)
                {
                    R[row, col] = Reduce(A[row, col], m[row], order);
                }
            }
            return R;
        }


Report this post
Top
  
Reply with quote  
 Post subject: Re: is modulo function equal to reduce function?
PostPosted: Tue Feb 07, 2012 12:15 pm 
do not know how modulo it is
is it following?
Programmer wrote:
Code:
        public string[,] kontraHom(string[,] M, int s)
        {
            int n = M.GetLength(1);
            int m = M.GetLength(0);
            int a,b,c;
            string[,] R = new string[s*n,s*m];
            for(b=1;b<=m;b++)
            {
                for(a=1;a<=s;a++)
                {
                    for(c=1;c<=n;c++)
                    {
                        R[(a-1)*n+c,(a-1)*m+b]=M[b,c];
                    }
                }
            }
            return(R);
        }
        public string[,] kohom(string[,] M, int s)
        {
            int n=M.GetLength(1);
            int m=M.GetLength(0);
            int a,b,c;
            string[,] R = new string[s*m,s*n];
            for(b=1;b<=s;b++)
            {
                for(a=1;a<=m;a++)
                {
                    for(c=1;c<=n;c++)
                    {
                        R[(a-1)*s+b,(c-1)*s+b]=M[a,c];
                    }
                }
            }
            return(R);
        }
        public string[,] Hom(string[,] M, string[,] N, List<string> order)
        {
            string[,] F = kontraHom(M, N.GetLength(0));
            string[,] B = kohom(N, M.GetLength(1));
            string[,] C = kohom(N, M.GetLength(0));
            string[,] D = modulo(F, B, order);
            string[,] E = modulo(D, C, order);
            //string[,] D = modulo(F, B);
            //string[,] E = modulo(D, C);
            return (E);
        }
        public string[,] modulo(string[,] A, string[,] B, List<string> order)
        {
            string[,] R = new string[A.GetLength(0),A.GetLength(1)];
            List<List<string>> m = new List<List<string>>();
            for (int row = 0; row < B.GetLength(0); row++)
            {
                List<String> reduce_p = new List<String>();
                for (int col = 0; col < B.GetLength(1); col++)
                {
                    reduce_p.Add(B[row, col]);
                }
                m.Add(reduce_p);
            }
            for (int row = 0; row < A.GetLength(0); row++)
            {
                for (int col = 0; col < A.GetLength(1); col++)
                {
                    R[row, col] = Reduce(A[row, col], m[row], order);
                }
            }
            return R;
        }


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 11:07 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group