Ejemplo n.º 1
0
 internal static bool isAnyComposition(int[][] permutations)
 {
     for (int i = 0; i < permutations.Length; i++)
     {
         for (int j = 0; j < permutations.Length; j++)
         {
             int[] composition = WithoutRepetition.CompositionOfPermutation(permutations[i], permutations[j]);
             bool  flag        = false;
             for (int k = 0; k < permutations.Length; k++)
             {
                 if (!flag)
                 {
                     if (ArrayFunctions.compareIntArrays(composition, permutations[k]))
                     {
                         flag = true;
                     }
                 }
             }
             if (!flag)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
 static public void WriteComposition(int[] leftPermutation, int[] rightPermutation)
 {
     int[]   resultPermutation      = WithoutRepetition.CompositionOfPermutation(leftPermutation, rightPermutation);
     int[][] resultPermutationCycle = WithoutRepetition.PermutationToCycle(resultPermutation);
     int[][] leftPermutationCycle   = WithoutRepetition.PermutationToCycle(leftPermutation);
     int[][] rightPermutationCycle  = WithoutRepetition.PermutationToCycle(rightPermutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Composition permutations:");
         WriteLine(writer);
         WriteLine(writer, "Left Permutation:");
         Write(writer, "One-line notation: ");
         WriteVector(writer, leftPermutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, leftPermutationCycle);
         WriteLine(writer);
         WriteLine(writer);
         WriteLine(writer, "Right Permutation:");
         Write(writer, "One-line notation: ");
         WriteVector(writer, rightPermutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, rightPermutationCycle);
         WriteLine(writer);
         WriteLine(writer);
         WriteLine(writer, "Result Permutation:");
         Write(writer, "One-line notation: ");
         WriteVector(writer, resultPermutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, resultPermutationCycle);
         WriteLine(writer);
     }
 }
Ejemplo n.º 3
0
        static string CalculateExpression(string Expression)
        {
            while (Expression.Contains("(("))
            {
                int indexFirst = Expression.IndexOf("(("), indexLast = 0;
                int counter = 2;
                for (int i = indexFirst + 2; i < Expression.Length; i++)
                {
                    if (Expression[i] == '(')
                    {
                        counter++;
                    }
                    else if (Expression[i] == ')')
                    {
                        counter--;
                        if (counter == 0)
                        {
                            indexLast = i;
                            break;
                        }
                    }
                }
                string temp = Expression.Substring(indexFirst + 1, (indexLast - 1) - (indexFirst + 1) + 1);

                string newExpression = CalculateExpression(temp);

                string tempExpression = "";
                if (indexFirst != 0)
                {
                    tempExpression += Expression.Substring(0, indexFirst);
                }
                tempExpression += newExpression;
                if (indexLast != (Expression.Length - 1))
                {
                    tempExpression += Expression.Substring(indexLast + 1, Expression.Length - 1 - (indexLast + 1) + 1);
                }
                Expression = tempExpression;
            }
            string[] expressions = Expression.Split('*');

            string returnedExpression = "";

            for (int i = 0; i < expressions.Length; i++)
            {
                if (expressions[i].Contains("^"))
                {
                    expressions[i] = PowerOfPermutationString(expressions[i]);
                }
            }
            if (expressions.Length > 1)
            {
                int[]   returnedPermutation;
                int[][] returnedPermutationCycle;
                int[]   permutation1 = ParsePermutation(expressions[0]);
                int[]   permutation2 = ParsePermutation(expressions[1]);
                returnedPermutation = WithoutRepetition.CompositionOfPermutation(permutation1, permutation2);
                for (int i = 2; i < expressions.Length; i++)
                {
                    int[] permutation = ParsePermutation(expressions[i]);
                    returnedPermutation = WithoutRepetition.CompositionOfPermutation(returnedPermutation, permutation);
                }
                returnedPermutationCycle = WithoutRepetition.PermutationToCycle(returnedPermutation);
                returnedExpression       = CycleToString(returnedPermutationCycle);
            }
            else
            {
                returnedExpression = expressions[0];
            }
            return(returnedExpression);
        }