public RationalNumber Exprational(int power)
    {
        int numerator   = Convert.ToInt32(Math.Pow(Convert.ToDouble(this.x), power));
        int denominator = Convert.ToInt32(Math.Pow(Convert.ToDouble(this.y), power));

        return(Simplifier.Simplify(numerator, denominator));
    }
    public RationalNumber Mul(RationalNumber r)
    {
        int denominator = this.y * r.y;
        int numerator   = this.x * r.x;

        return(Simplifier.Simplify(numerator, denominator));
    }
        public void Simplify()
        {
            ToDefault();

            var vertices = GetVertices();
            var holes    = GetHoles();
            var newSimplifiedPolygons = Simplifier.Simplify(vertices, holes);
            var polygonTr             = polygon.transform;
            var polygonPos            = polygonTr.position;
            var polygonRot            = polygonTr.rotation;

            for (var i = 0; i < newSimplifiedPolygons.Count; i++)
            {
                var simplifiedPolygon = newSimplifiedPolygons[i];
                var newPolygon        = Polygon.NewPolygon(simplifiedPolygon, polygonPos, polygonRot, transform, nameof(Polygon) + " " + i);
                newPolygon.Centralize();
                simplifiedPolygons.Add(newPolygon);
            }

            polygon.gameObject.SetActive(false);
            for (var i = 0; i < this.holes.Count; i++)
            {
                this.holes[i].gameObject.SetActive(false);
            }
            polygonMode = Polygon.PolygonMode.Simplified;
        }
Beispiel #4
0
        void Equal(object sender, EventArgs e)
        {
            if (Equation.Text == "")
            {
                Equation.Text = "";
            }
            else
            {
                try
                {
                    Equation.Text = Equation.Text.Replace(",", ".");
                    List <Node> nodes = t.Tokenize(RealEquation(Equation.Text));
                    Node        nf    = p.Parse(nodes);
                    Node        ns    = simp.Simplify(nf);


                    Result.Text = RealResult(OrganizeTree(ns, ns));
                    Result.Text = Result.Text.Replace(",", ".");
                    ans         = Result.Text;
                }
                catch
                {
                    Result.Text = "Error";
                }
            }
        }
Beispiel #5
0
        public void Simplify_TestStringArray_ExpectedResultString()
        {
            var strings          = "eedadn,drvtee,eandsr,raavrd,atevrs,tsrnev,sdttsa,rasrtv,nssdts,ntnada,svetve,tesnvt,vntsnd,vrdear,dvrsen,enarar".Split(",");
            var convertedStrings = InputTransposer.Convert(strings);

            var simplifiedString = Simplifier.Simplify(convertedStrings);

            Assert.AreEqual("easter", simplifiedString);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Tokenizer  t    = new Tokenizer();
            Parser     p    = new Parser();
            Solver     s    = new Solver();
            Derivator  d    = new Derivator();
            Simplifier simp = new Simplifier(); //ha he's a simp

            Console.Write("Solve equation (S/I/D):");
            string decision = Console.ReadLine();

            while (true)
            {
                Console.Write("Equation:");
                List <Node> nodes = t.Tokenize(Console.ReadLine());
                foreach (Node n in nodes)
                {
                    Console.WriteLine(n.t + " " + n.op + " " + n.value + " " + n.var + " " + n.f + " " + n.priority_value + "\n");
                }
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Node nf = p.Parse(nodes);
                PrintTree(nf, "", true);
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.Write(OrganizeTree(nf, nf));
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                Console.WriteLine("\n");
                if (decision == "S" || decision == "S")
                {
                    Console.WriteLine(s.Solve(nf));
                }
                else if (decision == "I" || decision == "i")
                {
                    Node origin_simp = simp.Simplify(nf);
                    PrintTree(origin_simp, "", true);
                    Console.WriteLine(OrganizeTree(origin_simp, origin_simp));
                }
                else if (decision == "D" || decision == "d")
                {
                    nf.f = Flags.Derivate;
                    Node derivated = d.Derivate(nf);
                    PrintTree(derivated, "", true);
                    Console.WriteLine(OrganizeTree(derivated, derivated));
                }
            }
        }
        public double Compute(string input)
        {
            var fixedString = input
                              .Replace("a", "+")
                              .Replace("b", "-")
                              .Replace("c", "*")
                              .Replace("d", "/")
                              .Replace("e", "(")
                              .Replace("f", ")");

            //simplify any parenthesis
            var simplifiedString = Simplifier.Simplify(fixedString);

            Processor _p = new Processor();

            return(_p.Process(simplifiedString));
        }
Beispiel #8
0
        public void FifthRuleTestingMultiplication1()
        {
            for (int i = 0; i <= 100000; i++)
            {
                int exponent1 = r.Next(1, 10000000);
                int exponent2 = r.Next(1, 10000000);

                Node actual   = simp.Simplify(p.Parse(t.Tokenize("x^" + exponent1.ToString() + "*x^" + exponent2.ToString())));
                Node expected = p.Parse(t.Tokenize("x^" + (exponent1 + exponent2).ToString()));
                Assert.AreEqual(actual, expected);
            }
        }
Beispiel #9
0
        public int?Compute(string input)
        {
            var _fixedString = input
                               .Replace("a", "+")
                               .Replace("b", "-")
                               .Replace("c", "*")
                               .Replace("d", "/")
                               .Replace("e", "(")
                               .Replace("f", ")");

            if (_fixedString.Contains("("))
            {
                _fixedString = Simplifier.Simplify(_fixedString);
            }

            Processor _p = new Processor();

            return(_p.Process(_fixedString));
        }
        public void Simplify()
        {
            ToDefault();
            var tr  = transform;
            var pos = tr.position;
            var rot = tr.rotation;

            var simplifiedPolygons     = Simplifier.Simplify(vertices);
            var simplifiedPolygonCount = simplifiedPolygons.Count;

            if (simplifiedPolygonCount > 1)
            {
                for (var i = 0; i < simplifiedPolygonCount; i++)
                {
                    var simplifiedPolygon = simplifiedPolygons[i];
                    var newPolygon        = NewPolygon(simplifiedPolygon, pos, rot, tr, "SubPolygon " + i);
                    newPolygon.Centralize();
                    this.simplifiedPolygons.Add(newPolygon);
                }
                polygonMode = PolygonMode.Simplified;
            }
        }
 public RationalNumber Reduce()
 {
     return(Simplifier.Simplify(this.x, this.y));
 }