Esempio n. 1
0
        public void TestCosecant()
        {
            Entity func    = "csc(2x)";
            var    derived = func.Differentiate("x");

            Assert.Equal(-2 * MathS.Cosec("2x") * MathS.Cotan("2x"), derived.Simplify());
        }
        public void TestInnerComplex()
        {
            var expr     = MathS.FromString("cotan(x + tan(x))");
            var expected = MathS.Cotan(x + MathS.Tan(x));

            Assert.IsTrue(expr == expected);
        }
        public void TestComplex()
        {
            var expr     = MathS.FromString("ln(x) + sqrt(x) + tan(x) + sec(x) + cosec(x) + cotan(x)");
            var expected = MathS.Ln(x) + MathS.Sqrt(x) +
                           MathS.Tan(x) + MathS.Sec(x) + MathS.Cosec(x) +
                           MathS.Cotan(x);

            Assert.IsTrue(expr == expected);
        }
Esempio n. 4
0
        public void TestCoTan()
        {
            var func = MathS.Cotan(2 * x);

            AssertEqEntity(func.Derive(x).Simplify(), -2 / MathS.Pow(MathS.Sin(2 * x), 2));
        }
Esempio n. 5
0
 [TestMethod] public void Trig() =>
 TestSimplify(@"\sin\left(\cos\left(\tan\left(\cot\left(x\right)\right)\right)\right)", MathS.Sin(MathS.Cos(MathS.Tan(MathS.Cotan(x)))));
 public void Setup()
 {
     exprEasy     = x + MathS.Sqr(x) - 3;
     exprMedium   = MathS.Sin(x + MathS.Cos(x)) + MathS.Sqrt(x + MathS.Sqr(x));
     exprHard     = MathS.Sin(x + MathS.Arcsin(x)) / (MathS.Sqr(x) + MathS.Cos(x)) * MathS.Arccos(x / 1200 + 0.00032 / MathS.Cotan(x + 43));
     exprSolvable = MathS.FromString("3arccos(2x + a)3 + 6arccos(2x + a)2 - a3 + 3");
 }
        /// <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");
            }
        }
 public void Test8() => Assert.Equal(3 * x, MathS.Arccotan(MathS.Cotan(x * 3)).Simplify());
Esempio n. 9
0
        public void TestCoTan()
        {
            var func = MathS.Cotan(2 * x);

            Assert.Equal(-2 / MathS.Pow(MathS.Sin(2 * x), 2), func.Differentiate(x).Simplify());
        }
Esempio n. 10
0
        public void TestCoTan()
        {
            var func = MathS.Cotan(2 * x);

            Assert.IsTrue(func.Derive(x).Simplify() == -2 / MathS.Pow(MathS.Sin(2 * x), 2));
        }
 public void Test8()
 {
     Assert.IsTrue(MathS.Arccotan(MathS.Cotan(x * 3)).Simplify() == 3 * x);
 }