Пример #1
0
 [TestMethod] public void M4RootCube() => Test(@"\frac{1}{\sqrt[4]{x}^{3}}", MathS.Pow(x, 3m / -4));
Пример #2
0
 [TestMethod] public void IM1Pow() => Test(@"{\left(-1 + i\right)}^{x}", MathS.Pow(im1, x));
Пример #3
0
 [TestMethod] public void SquareRootAsPow() => Test(@"\sqrt{x}", MathS.Pow(x, 1m / 2));
Пример #4
0
 [TestMethod] public void M2ICubeRoot() => Test(@"\sqrt[3]{-2i}", MathS.Pow(m2i, 1m / 3));
Пример #5
0
 [TestMethod] public void PowM2I() => Test(@"{2}^{-2i}", MathS.Pow(2, m2i));
Пример #6
0
 [TestMethod] public void M2Pow() => Test(@"{-2}^{x}", MathS.Pow(-2, x));
Пример #7
0
 [TestMethod] public void Frac34Pow() => Test(@"{\left(\frac{3}{4}\right)}^{x}", MathS.Pow(frac34, x));
Пример #8
0
 private static Entity Sqrt(Entity a)
 => MathS.Pow(a, Number.CreateRational(1, 2));
Пример #9
0
        public void TestPatt1()
        {
            var expr = MathS.Pow(x * 4, 3);

            Assert.IsTrue(expr.Simplify() == 64 * MathS.Pow(x, 3));
        }
Пример #10
0
 [TestMethod] public void PowPowNumber() => Test(@"{\left({12}^{23}\right)}^{34}", MathS.Pow(MathS.Pow(12, 23), 34));
Пример #11
0
 private static Entity Cubt(Entity a)
 => MathS.Pow(a, Number.CreateRational(1, 3));
Пример #12
0
 [TestMethod] public void PowPow() => Test("{x}^{{x}^{x}}", MathS.Pow(x, MathS.Pow(x, x)));
Пример #13
0
 [TestMethod] public void PowBase10() => Test("{10}^{x}", MathS.Pow(10, x));
Пример #14
0
 [TestMethod] public void PowBase2() => Test("{2}^{x}", MathS.Pow(2, x));
Пример #15
0
 [TestMethod] public void PowM1() => Test(@"{x}^{-1}", MathS.Pow(x, m1));
Пример #16
0
        /// <summary>
        /// Inverts operator and returns a set
        /// x^2 = a
        /// => x = sqrt(a)
        /// x = -sqrt(a)
        /// </summary>
        /// <param name="func"></param>
        /// <param name="value"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        public static Set InvertOperatorEntity(OperatorEntity func, Entity value, Entity x)
        {
            Entity a, un;
            int    arg;

            if (func.Children[0].FindSubtree(x) != null)
            {
                a   = func.Children[1];
                un  = func.Children[0];
                arg = 0;
            }
            else
            {
                a   = func.Children[0];
                un  = func.Children[1];
                arg = 1;
            }
            var n = Utils.FindNextIndex(func + value, "n");

            switch (func.Name)
            {
            case "sumf":
                // x + a = value => x = value - a
                return(FindInvertExpression(un, value - a, x));

            case "minusf":
                if (arg == 0)
                {
                    // x - a = value => x = value + a
                    return(FindInvertExpression(un, value + a, x));
                }
                else
                {
                    // a - x = value => x = a - value
                    return(FindInvertExpression(un, a - value, x));
                }

            case "mulf":
                // x * a = value => x = value / a
                return(FindInvertExpression(un, value / a, x));

            case "divf":
                if (arg == 0)
                {
                    // x / a = value => x = a * value
                    return(FindInvertExpression(un, value * a, x));
                }
                else
                {
                    // a / x = value => x = a / value
                    return(FindInvertExpression(un, a / value, x));
                }

            case "powf":
                if (arg == 0)
                {
                    // x ^ a = value => x = value ^ (1/a)
                    if (a.entType == Entity.EntType.NUMBER && a.GetValue().IsInteger())
                    {
                        var res = new Set();
                        foreach (var root in Number.GetAllRoots(1, a.GetValue().AsIntegerNumber()).FiniteSet())
                        {
                            res.AddRange(FindInvertExpression(un, root * MathS.Pow(value, 1 / a), x));
                        }
                        return(res);
                    }
                    else
                    {
                        return(FindInvertExpression(un, MathS.Pow(value, 1 / a), x));
                    }
                }
                else
                {
                    // a ^ x = value => x = log(a, value)
                    return(FindInvertExpression(un, MathS.Log(a, value) + 2 * MathS.i * n * MathS.pi, x));
                }

            default:
                throw new SysException("Unknown operator");
            }
        }
Пример #17
0
 [TestMethod] public void M1Pow() => Test(@"{-1}^{x}", MathS.Pow(m1, x));
Пример #18
0
        /// <summary>
        /// Returns a set of possible roots of a function, e. g.
        /// sin(x) = a =>
        /// x = arcsin(a) + 2 pi n
        /// x = pi - arcsin(a) + 2 pi n
        /// </summary>
        /// <param name="func"></param>
        /// <param name="value"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        public static Set InvertFunctionEntity(FunctionEntity func, Entity value, Entity x)
        {
            Entity a   = func.Children[0];
            Entity b   = func.Children.Count == 2 ? func.Children[1] : null;
            int    arg = func.Children.Count == 2 && func.Children[1].FindSubtree(x) != null ? 1 : 0;
            var    n   = Utils.FindNextIndex(func + value, "n");
            var    res = new Set();
            var    pi  = MathS.pi;

            Set GetNotNullEntites(Set set)
            {
                return(set.FiniteWhere(el => el.entType != Entity.EntType.NUMBER || el.GetValue().IsDefinite()));
            }

            switch (func.Name)
            {
            // Consider case when sin(sin(x)) where double-mention of n occures
            case "sinf":
            {
                // sin(x) = value => x = arcsin(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arcsin(value) + 2 * pi * n, x)));
                // sin(x) = value => x = pi - arcsin(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, pi - MathS.Arcsin(value) + 2 * pi * n, x)));
                return(res);
            }

            case "cosf":
            {
                // cos(x) = value => x = arccos(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arccos(value) + 2 * pi * n, x)));
                // cos(x) = value => x = -arccos(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, -MathS.Arccos(value) - 2 * pi * n, x)));
                return(res);
            }

            case "tanf":
            {
                var inverted = FindInvertExpression(a, MathS.Arctan(value) + pi * n, x);
                // tan(x) = value => x = arctan(value) + pi * n
                res.AddRange(GetNotNullEntites(inverted));
                return(res);
            }

            case "cotanf":
            {
                var inverted = FindInvertExpression(a, MathS.Arccotan(value) + pi * n, x);
                // cotan(x) = value => x = arccotan(value)
                res.AddRange(GetNotNullEntites(inverted));
                return(res);
            }

            case "arcsinf":
                // arcsin(x) = value => x = sin(value)
                if (EntityInBounds(value, ArcsinFrom, ArcsinTo))
                {
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Sin(value), x)));
                }
                else
                {
                    return(Empty);
                }

            case "arccosf":
                // arccos(x) = value => x = cos(value)
                if (EntityInBounds(value, ArccosFrom, ArccosTo))
                {
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Cos(value), x)));
                }
                else
                {
                    return(Empty);
                }

            case "arctanf":
                // arctan(x) = value => x = tan(value)
                return(GetNotNullEntites(FindInvertExpression(a, MathS.Tan(value), x)));

            case "arccotanf":
                // arccotan(x) = value => x = cotan(value)
                return(GetNotNullEntites(FindInvertExpression(a, MathS.Cotan(value), x)));

            case "logf":
                if (arg != 0)
                {
                    // log(x, a) = value => x = a ^ value
                    return(GetNotNullEntites(FindInvertExpression(b, MathS.Pow(a, value), x)));
                }
                else
                {
                    // log(a, x) = value => a = x ^ value => x = a ^ (1 / value)
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Pow(b, 1 / value), x)));
                }

            default:
                throw new SysException("Unknown function");
            }
        }
Пример #19
0
 [TestMethod] public void Frac34CubeRoot() => Test(@"\sqrt[3]{\frac{3}{4}}", MathS.Pow(frac34, 1m / 3));
Пример #20
0
 [TestMethod] public void MPow() => Test(@"{\left(-x\right)}^{x}", MathS.Pow(-x, x));
Пример #21
0
 [TestMethod] public void PowFrac34() => Test(@"\sqrt[4]{2}^{3}", MathS.Pow(2, frac34));
Пример #22
0
 [TestMethod] public void AddPow() => Test(@"{\left(3+4\right)}^{x}", MathS.Pow("3+4", x));
Пример #23
0
 [TestMethod] public void M2IPow() => Test(@"{\left(-2i\right)}^{x}", MathS.Pow(m2i, x));
Пример #24
0
 [TestMethod] public void SubtractPow() => Test(@"{\left(3-4\right)}^{x}", MathS.Pow("3-4", x));
Пример #25
0
 [TestMethod] public void IM1CubeRoot() => Test(@"\sqrt[3]{-1 + i}", MathS.Pow(im1, 1m / 3));
Пример #26
0
 [TestMethod] public void MultiplyPow() => Test(@"{\left(3\times 4\right)}^{x}", MathS.Pow("3*4", x));
Пример #27
0
 [TestMethod] public void PowIM1() => Test(@"{2}^{-1 + i}", MathS.Pow(2, im1));
Пример #28
0
 [TestMethod] public void DividePow() => Test(@"{\left(\frac{3}{4}\right)}^{x}", MathS.Pow("3/4", x));
Пример #29
0
 [TestMethod] public void Cube() => Test(@"{x}^{3}", MathS.Pow(x, 3));
Пример #30
0
 [TestMethod] public void M3Root() => Test(@"\frac{1}{\sqrt[3]{x}}", MathS.Pow(x, 1m / -3));