/// <summary>
        /// Разбивает дробь на левую и правую отзнака неравенства части
        /// </summary>
        /// <param name="generationKey">ключ генерации</param>
        void GenerateLeftAndRightSides(GenerationKey generationKey)
        {
            Random rnd = new Random(generationKey.Seed);

            LeftSide  = new List <Fraction>();
            RightSide = new List <Fraction>();
            List <Fraction> fracList = BigFraction.DecomposeAmountOfFractions(generationKey);

            if (fracList.Count() == 1)
            {
                fracList[0].MultiplyPolynominal(generationKey.Seed, settings);
            }
            for (int i = 0; i < fracList.Count; i++)
            {
                int rndValue = rnd.Next(2);
                if (rndValue == 0)
                {
                    LeftSide.Add(fracList[i]);
                }
                else
                {
                    RightSide.Add(-fracList[i]);
                }
            }
        }
        internal Inequality(GenerationKey generationKey)
        {
            Random rnd = new Random(generationKey.Seed);

            settings = generationKey.Settings;

            Fraction bigFraction = new Fraction(generationKey);

            BigFraction = bigFraction;
            Answer      = bigFraction.Answer;
            Sign        = bigFraction.Sign ? "<" : ">";
            Sign       += Answer.StrictInequality ? "" : "=";
            if (Sign == "<=")
            {
                Sign = "⩽";
            }
            else if (Sign == ">=")
            {
                Sign = "⩾";
            }
            GenerationKey = generationKey;

            if (!settings.OneFraction)
            {
                GenerateLeftAndRightSides(generationKey);
            }
            else
            {
                bigFraction.MultiplyPolynominal(generationKey.Seed, settings);
                LeftSide = new List <Fraction> {
                    bigFraction
                };
                RightSide = new List <Fraction>();
            }

            if (settings.PowerFunc && Answer.IsPowerBorders)
            {
                Fraction   root     = rnd.Next(-50, 51);
                Polynomial argument = new Polynomial("x", root);
                PowerFunc  powFunc  = new PowerFunc(argument, Answer.PowerBase);
                Subs(powFunc);
            }
            else if (settings.Radical && Answer.MinPoint() >= (double)0 && Answer.MaxPoint() > (double)10)
            {
                Fraction   root     = rnd.Next(-200, 201);
                Polynomial argument = new Polynomial("x", root);
                Radical    radical  = new Radical(argument);
                Subs(radical);
            }
            else if (settings.Log && Answer.MinPoint() >= (double)-10 && Answer.MaxPoint() <= (double)10 && Answer.AreAllPointsInteger())
            {
                Fraction   root     = rnd.Next(-100, 100);
                Polynomial argument = new Polynomial("x", root);
                int        rndBase  = rnd.Next(6) == 0 ? 2 : 3;
                Fraction   @base    = Answer.MinPoint() >= (double)-5 && Answer.MaxPoint() <= (double)5 ? rndBase : 2;
                Log        log      = new Log(argument, @base);
                Subs(log);
            }
        }
        internal Part(GenerationKey key)
        {
            //Передаем характиристики варианта
            CountOfTasks = key.CountOfTasks; //Количество заданий
            MetSeeds     = new List <int>();

            //Лист с заданиями
            List <Inequality> tasks = new List <Inequality>();

            //Заполняем лист заданиями
            for (int i = 0; i < key.CountOfTasks; i++)
            {
                if (!MetSeeds.Contains(key.Seed))
                {
                    MetSeeds.Add(key.Seed);
                    Inequality task = null;
                    try
                    {
                        task = new Inequality(key);
                    }
                    catch (OverflowException)
                    {
                        i--;
                        continue;
                    }
                    catch (DivideByZeroException)
                    {
                        i--;
                        continue;
                    }
                    if (task.ToHTML().Contains("/0"))
                    {
                        i--;
                        continue;
                    }
                    tasks.Add(task);
                }
                else
                {
                    i--;
                }

                key++;
            }
            Tasks = tasks;
        }
        internal Intervals(GenerationKey generationKey)
        {
            Random rnd          = new Random(generationKey.Seed);
            int    key          = generationKey.Seed;
            int    countOfTasks = generationKey.CountOfTasks;

            settings = generationKey.Settings;
            RootsOfMultiplicityTwo = new List <Fraction>();
            NotIncludedPoints      = new List <Fraction>();
            IncludedPoints         = new List <Fraction>();
            LeftPoints             = new List <Fraction>();
            RightPoints            = new List <Fraction>();
            StrictInequality       = rnd.Next(2) == 0;
            IncludedPoints         = new List <Fraction>();
            Points            = GenerateIntervalBorders(key + countOfTasks);
            IntervalString    = GenerateInterval(key + countOfTasks, Points);
            StartFromFirstGap = IntervalString[IntervalString.Length - 2] == 'f';
            NotIncludedPoints = GetNotIncludedPoints();
            IntervalsList     = GetIntervalsList();
        }
예제 #5
0
        internal Fraction(GenerationKey generationKey)
        {
            Answer   = new Intervals(generationKey);
            Sign     = !Answer.StartFromFirstGap;
            settings = generationKey.Settings;

            Numenator = new List <Polynomial>();
            foreach (var point in Answer.IncludedPoints)
            {
                Numenator.Add(new Polynomial("x", point));
            }

            Denominator = new List <Polynomial>();
            foreach (var point in Answer.NotIncludedPoints)
            {
                Denominator.Add(new Polynomial("x", point));
            }

            //Создаем числитель
            //Numenator = CreateExpression(generationKey, Answer.IncludedPoints.GetRange(0, Answer.IncludedPoints.Count()));
            //Создаем занаменатель
            //Denominator = CreateExpression(generationKey, Answer.NotIncludedPoints.GetRange(0, Answer.NotIncludedPoints.Count()));
        }
예제 #6
0
        internal List <Fraction> DecomposeAmountOfFractions(GenerationKey generationKey)
        {
            List <Fraction> result = new List <Fraction> {
                this
            };
            Random rnd = new Random(generationKey.Seed);

            int sumNumenatorPowers = SumOfPowersPoly(Numenator);

            if (sumNumenatorPowers >= 1 && Denominator.Count == 1 && sumNumenatorPowers <= settings.MaxPowerPolynomial)
            {
                result = new List <Fraction>();

                List <Polynomial> numenator1   = new List <Polynomial>();
                List <Polynomial> numenator2   = new List <Polynomial>();
                List <Polynomial> denomenator1 = new List <Polynomial>();
                List <Polynomial> denomenator2 = new List <Polynomial>();

                Polynomial bigPoly = new Polynomial();
                foreach (Polynomial poly in Numenator)
                {
                    bigPoly *= poly;
                }
                if (bigPoly.CountNotZeroOdds() > 1)
                {
                    int coef = rnd.Next(-10, 10);
                    coef            = coef >= 0 ? coef + 1 : coef;
                    Denominator[0] *= coef;
                    Numenator[0]   *= coef;
                    int endOdd = rnd.Next(bigPoly.Power);
                    numenator2.Add(bigPoly.SeparatePart(endOdd));
                    Polynomial newPoly = bigPoly - numenator2[0];
                    numenator1.Add(newPoly);
                    denomenator1.Add(Denominator[0]);
                    denomenator2.Add(Denominator[0]);

                    (denomenator1[0], numenator1[0]) = denomenator1[0].Reduction(numenator1[0]);
                    (denomenator2[0], numenator2[0]) = denomenator2[0].Reduction(numenator2[0]);

                    Fraction newFraction1 = new Fraction(numenator1, denomenator1);
                    Fraction newFraction2 = new Fraction(numenator2, denomenator2);
                    result.Add(newFraction1);
                    result.Add(newFraction2);
                }
                else
                {
                    return(new List <Fraction> {
                        this
                    });
                }
            }
            else if (Denominator.Count == 1 && sumNumenatorPowers >= settings.MaxPowerPolynomial)
            {
            }
            else if (Denominator.Count > 1)
            {
                //Многочлены, на которые умножаются параметры
                List <Polynomial> factorsСommonВenominator = new List <Polynomial>();
                //Знаменатели дробей полученные после разложения
                List <Polynomial> resultDenominators = new List <Polynomial>();
                int maxPower = 0;
                //Многочлен, который на который мы будем равнятся при поиске параметров
                Polynomial        bigPoly       = new Polynomial();
                List <Polynomial> outOfBrackets = new List <Polynomial>();
                try
                {
                    foreach (var poly in Denominator)
                    {
                        resultDenominators.Add(poly);
                        int        power       = 0;
                        Polynomial benominator = new Polynomial();
                        foreach (var poly1 in Denominator)
                        {
                            if (poly1 != poly)
                            {
                                benominator *= poly1;
                                power       += poly1.Power;
                            }
                        }
                        factorsСommonВenominator.Add(benominator);

                        maxPower = power > maxPower ? power : maxPower;
                    }

                    foreach (Polynomial poly in Numenator)
                    {
                        if (bigPoly.Power < maxPower)
                        {
                            bigPoly *= poly;
                        }
                        else
                        {
                            outOfBrackets.Add(poly);
                        }
                    }
                }
                catch (OverflowException)
                {
                    return(result);
                }

                //Составляем уравнения системы
                List <Dictionary <char, Fraction> > vcList = new List <Dictionary <char, Fraction> >();
                for (int i = 0; i <= maxPower; i++)
                {
                    vcList.Add(new Dictionary <char, Fraction>());
                }

                for (int i = 0; i < factorsСommonВenominator.Count; i++)
                {
                    Polynomial poly = factorsСommonВenominator[i];
                    for (int j = 0; j <= poly.Power; j++)
                    {
                        vcList[j].Add((char)('A' + i), poly.Odds[j]);
                    }
                }

                //Составляем систему и решаем ее
                List <Equation> equations = new List <Equation>();
                for (int i = 0; i < vcList.Count; i++)
                {
                    if (bigPoly.Power >= i)
                    {
                        equations.Add(new Equation(vcList[i], -bigPoly.Odds[i]));
                    }
                    else
                    {
                        equations.Add(new Equation(vcList[i], 0));
                    }
                }
                EquationSystem eqSys = new EquationSystem(equations);
                Dictionary <char, Fraction> systemAnswers;
                try
                {
                    systemAnswers = eqSys.Solve();
                }
                catch (OverflowException)
                {
                    return(result);
                }

                if (systemAnswers.Count == 0)
                {
                    return(result);
                }

                //Составляем начальные дроби
                result = new List <Fraction>();
                List <Polynomial> zeroFractionsDenoms = new List <Polynomial>();
                for (int i = 0; i < systemAnswers.Count; i++)
                {
                    if (systemAnswers[(char)('A' + i)] != (double)0)
                    {
                        result.Add(new Fraction(systemAnswers[(char)('A' + i)], resultDenominators[i]));
                    }
                    else
                    {
                        zeroFractionsDenoms.Add(resultDenominators[i]);
                    }
                }

                //Приводим все к красивому вижу и предотвращаем потерю корней
                for (int i = 0; i < result.Count; i++)
                {
                    for (int j = 0; j < zeroFractionsDenoms.Count; j++)
                    {
                        result[i].Denominator.Add(zeroFractionsDenoms[j]);
                        result[i].Numenator.Add(zeroFractionsDenoms[j]);
                    }
                }

                for (int i = 0; i < result.Count; i++)
                {
                    foreach (var outFraction in outOfBrackets)
                    {
                        result[i].Numenator.Add(outFraction);
                    }
                }
            }

            bool isOddsBig = false;

            foreach (Fraction frac in result)
            {
                foreach (Polynomial poly in frac.Numenator)
                {
                    foreach (Fraction odd in poly.Odds)
                    {
                        if (Math.Abs(odd.IntNumenator) >= 1000 || Math.Abs(odd.IntDenominator) >= 1000)
                        {
                            isOddsBig = true;
                        }
                    }
                }
            }

            if (isOddsBig)
            {
                return(new List <Fraction> {
                    this
                });
            }
            else
            {
                return(result);
            }
        }