Esempio n. 1
0
 static public void WriteType(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     int[]   vectorType       = WithoutRepetition.TypeOfPermutation(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Type of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Type of permutation: [");
         string toWrite = "";
         for (int i = 1; i < vectorType.Length; i++)
         {
             if (vectorType[i] != 0)
             {
                 toWrite += i + "^" + vectorType[i] + " ";
             }
         }
         toWrite = toWrite.Remove(toWrite.Length - 1, 1);
         Write(writer, toWrite);
         Write(writer, "]");
         WriteLine(writer);
     }
 }
Esempio n. 2
0
 static public void WritePower(int[] permutation, int power)
 {
     int[][] cyclePermutation       = WithoutRepetition.PermutationToCycle(permutation);
     int[]   resultPermutation      = WithoutRepetition.PowerOfPermutation(permutation, power);
     int[][] resultCyclePermutation = WithoutRepetition.PermutationToCycle(resultPermutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Power of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer, "Power: " + power);
         WriteLine(writer);
         WriteLine(writer, "Result permutation");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, resultPermutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, resultCyclePermutation);
         WriteLine(writer);
     }
 }
Esempio n. 3
0
 static public void WriteReverse(int[] permutation)
 {
     int[]   reversePermutation      = WithoutRepetition.ReversePermutation(permutation);
     int[][] cycleReversePermutation = WithoutRepetition.PermutationToCycle(reversePermutation);
     int[][] cyclePermutation        = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Reverse permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         WriteLine(writer, "Result:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, reversePermutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cycleReversePermutation);
         WriteLine(writer);
     }
 }
Esempio n. 4
0
 static public void WriteIsOneCycle(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "If permutation is one cycle:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Is one cycle? - ");
         if (WithoutRepetition.IsOneCycle(permutation))
         {
             Write(writer, "yes");
         }
         else
         {
             Write(writer, "no");
         }
         WriteLine(writer);
     }
 }
Esempio n. 5
0
        public static string PowerOfPermutationString(string Expression)
        {
            int    index = Expression.IndexOf("^");
            int    power = 0;
            string temp  = Expression.Substring(index + 1);

            power = int.Parse(temp);
            string cyclePermutationString = Expression.Remove(index);

            int[]   permutation             = ParsePermutation(cyclePermutationString);
            int[]   resultPermutation       = WithoutRepetition.PowerOfPermutation(permutation, power);
            int[][] resultPermutationCycle  = WithoutRepetition.PermutationToCycle(resultPermutation);
            string  resultPermutationString = CycleToString(resultPermutationCycle);

            return(resultPermutationString);
        }
Esempio n. 6
0
 static public void WriteOrder(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Order of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Order of permutation: " + WithoutRepetition.OrderOfPermutation(permutation));
         WriteLine(writer);
     }
 }
Esempio n. 7
0
 static public void WriteCompositionOfNeighbouringTranposition2(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     int[][] transpositions   = WithoutRepetition.PermutationToNeighbouringTransposition2(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteCycle(writer, cyclePermutation);
         Write(writer, "=");
         for (int i = 0; i < transpositions.Length - 1; i++)
         {
             int[][] cycleTransposition = WithoutRepetition.PermutationToCycle(transpositions[i]);
             WriteTransposition(writer, cycleTransposition);
             Write(writer, "*");
         }
         int[][] cycleTranspositionLast = WithoutRepetition.PermutationToCycle(transpositions[transpositions.Length - 1]);
         WriteTransposition(writer, cycleTranspositionLast);
         WriteLine(writer); WriteLine(writer);
     }
 }
Esempio n. 8
0
 static public void WriteCountFixedPoints(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Count fixed points of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Number of fixed points " + WithoutRepetition.FixedPointsCount(permutation));
         WriteLine(writer);
     }
 }
Esempio n. 9
0
 static public void WriteCountInversions(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Count inversions of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Number of inversions " + HelpFunctions.inversionsCount(permutation));
         WriteLine(writer);
     }
 }
Esempio n. 10
0
 static public void WriteSign4(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Sign of permutation");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Value of sign: ");
         Write(writer, WithoutRepetition.SignOfPermutation4(permutation) + "");
         WriteLine(writer);
     }
 }
Esempio n. 11
0
        static public void WritePermutationIndexALO(int[] permutation) // ALO- anti lexicographical order
        {
            int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
            long    index            = WithoutRepetition.PermutationIndexInAntiLexOrder(permutation);

            using (StreamWriter writer = new StreamWriter("log.txt", true))
            {
                WriteDate(writer);
                WriteLine(writer, "Permutation index in anti lexicographical order: ");
                WriteLine(writer);
                Write(writer, "One-line notation: ");
                WriteVector(writer, permutation);
                WriteLine(writer);
                Write(writer, "Canonical cycle notation: ");
                WriteCycle(writer, cyclePermutation);
                WriteLine(writer);
                WriteLine(writer);
                WriteLine(writer, "Index: " + index);
                WriteLine(writer);
            }
        }
Esempio n. 12
0
 static public void WriteInversionVector(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     int[]   inversionVector  = WithoutRepetition.InversionVector(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Iversion vector of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Inversion vector: ");
         WriteVector(writer, inversionVector);
         WriteLine(writer);
     }
 }
Esempio n. 13
0
 static public void WriteInversionCommand(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     int[][] listOfInversions = WithoutRepetition.ListOfInversions(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Writing inversions of permutation:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         WriteLine(writer, "Writing inversions");
         WriteLine(writer);
         WriteInversions(writer, listOfInversions);
         WriteLine(writer);
     }
 }
Esempio n. 14
0
 static public void WriteNotations(int[] permutation)
 {
     int[][] cyclePermutation = WithoutRepetition.PermutationToCycle(permutation);
     int[,] matrixPermutation = WithoutRepetition.PermutationToMatrix(permutation);
     using (StreamWriter writer = new StreamWriter("log.txt", true))
     {
         WriteDate(writer);
         WriteLine(writer, "Permutation in different notations:");
         WriteLine(writer);
         Write(writer, "One-line notation: ");
         WriteVector(writer, permutation);
         WriteLine(writer);
         WriteLine(writer);
         Write(writer, "Canonical cycle notation: ");
         WriteCycle(writer, cyclePermutation);
         WriteLine(writer);
         WriteLine(writer);
         WriteLine(writer, "Matrix notation:");
         WriteLine(writer);
         WriteMatrix(writer, matrixPermutation);
         WriteLine(writer);
     }
 }
Esempio n. 15
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);
     }
 }
Esempio n. 16
0
        public static string ParseExpression(string Expression)
        {
            string[]  expressions = Expression.Split('='); //podzielenie na strone prawą i lewą
            string    rightOfExpression = "", leftOfExpression = "";
            string    toReturn  = "";
            Exception exception = new Exception("Bad format of expression.");

            if (expressions.Length != 2)
            {
                throw exception;
            }
            bool flag = false; // flaga czy już zostało znalezione f w wyrażeniu

            for (int i = 0; i < expressions[0].Length; i++)
            {
                if (expressions[0][i] == 'f')
                {
                    if (flag)
                    {
                        throw exception;
                    }
                    else
                    {
                        leftOfExpression  = expressions[0];
                        rightOfExpression = expressions[1];
                        flag = true;
                    }
                }
            }
            for (int i = 0; i < expressions[1].Length; i++)
            {
                if (expressions[1][i] == 'f')
                {
                    if (flag)
                    {
                        throw exception;
                    }
                    else
                    {
                        leftOfExpression  = expressions[1];
                        rightOfExpression = expressions[0];
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                throw exception;
            }
            while (leftOfExpression.Contains("(") || leftOfExpression.Contains(")") || leftOfExpression.Contains("*"))
            {
                string[] divided = DivideExpression(leftOfExpression);
                if (divided.Length == 1)
                {
                    if (isToPower(divided[0]))
                    {
                        int      indexOfPower  = SearchIndexPower(divided[0]);
                        string   divideToPower = divided[0].Substring(1, indexOfPower - 2);
                        string[] toPower       = DivideExpression(divideToPower);
                        int      power         = int.Parse(divided[0].Substring(indexOfPower + 1)); //+1 bo indexOfPower to index '^'
                        for (int i = 0; i < toPower.Length; i++)
                        {
                            if (isToPower(toPower[i]))
                            {
                                int indexOfS = SearchIndexPower(toPower[i]);
                                int powerOfS = int.Parse(toPower[i].Substring(indexOfS + 1));
                                toPower[i] = toPower[i].Substring(0, indexOfS + 1) + (powerOfS * power);
                            }
                            else
                            {
                                toPower[i] = toPower[i] + "^" + power;
                            }
                        }
                        leftOfExpression = "";
                        for (int i = 0; i < toPower.Length; i++)
                        {
                            if (i == toPower.Length - 1)
                            {
                                leftOfExpression += toPower[i];
                            }
                            else
                            {
                                leftOfExpression += toPower[i] + "*";
                            }
                        }
                    }
                    else
                    {
                        leftOfExpression = divided[0].Substring(1, divided[0].Length - 2);
                    }
                }
                else
                {
                    int  indexOfF = 0;
                    bool flagF    = false;
                    for (int i = 0; i < divided.Length; i++)
                    {
                        if (divided[i].Contains("f"))
                        {
                            indexOfF = i;
                            flagF    = true;
                        }
                    }
                    if (!flagF)
                    {
                        throw exception;
                    }
                    string left = "", right = "";
                    for (int i = 0; i < indexOfF; i++)
                    {
                        if (i == indexOfF - 1)
                        {
                            left += "(" + divided[i] + ")^-1";
                        }
                        else
                        {
                            left += "(" + divided[i] + ")^-1" + "*";
                        }
                    }
                    for (int i = divided.Length - 1; i >= indexOfF + 1; i--)
                    {
                        if (i == indexOfF + 1)
                        {
                            right += "(" + divided[i] + ")^-1";
                        }
                        else
                        {
                            right += "(" + divided[i] + ")^-1" + "*";
                        }
                    }

                    if (left.Length > 0)
                    {
                        //left = "(" + left + ")^-1";
                        rightOfExpression = left + "*" + rightOfExpression;
                    }
                    if (right.Length > 0)
                    {
                        //right = "(" + right + ")^-1";
                        rightOfExpression = rightOfExpression + "*" + right;
                    }
                    leftOfExpression = divided[indexOfF];
                }
            }
            //Console.WriteLine("Right: " + rightOfExpression);
            rightOfExpression = CalculateExpression(rightOfExpression);

            if (leftOfExpression.Contains("^"))
            {
                int     i                 = leftOfExpression.IndexOf('^');
                string  toParse           = leftOfExpression.Substring(i + 1);
                int     root              = int.Parse(toParse);
                int[]   permutationToRoot = ParsePermutation(rightOfExpression);
                int[][] Cases             = WithoutRepetition.RootOfPermutation(permutationToRoot, root);
                if (Cases.Length == 0)
                {
                    toReturn += "There aren't any solutions.";
                }
                else
                {
                    int[][] permutationCycle = WithoutRepetition.PermutationToCycle(Cases[0]);
                    toReturn += "f=" + CycleToString(permutationCycle);
                    if (Cases.Length > 1)
                    {
                        for (int k = 1; k < Cases.Length; k++)
                        {
                            permutationCycle = WithoutRepetition.PermutationToCycle(Cases[k]);
                            toReturn        += "||f=" + CycleToString(permutationCycle);
                        }
                    }
                }

                /*
                 * int[][] permutationCycle = WithoutRepetition.PermutationToCycle(Cases);
                 * rightOfExpression = CycleToString(permutationCycle);*/
            }

            return(toReturn);
            //return "f=" + rightOfExpression;
        }
Esempio n. 17
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);
        }