Esempio n. 1
0
        public void TestArc3()
        {
            var func = MathS.Arccos(2 * x);

            AssertEqEntity(func.Derive(x).Simplify(), (-2) / MathS.Sqrt(1 + (-4) * MathS.Sqr(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");
 }
Esempio n. 3
0
 [TestMethod] public void ArcTrig() =>
 TestSimplify(@"\arcsin\left(\arccos\left(\arctan\left(\arccot\left(x\right)\right)\right)\right)", MathS.Arcsin(MathS.Arccos(MathS.Arctan(MathS.Arccotan(x)))));
        /// <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");
            }
        }
Esempio n. 5
0
        public void TestPatt10()
        {
            var expr = MathS.Arcsin(x * 3) + MathS.Arccos(x * 1);

            Assert.IsTrue(expr.Simplify() == MathS.Arccos(x) + MathS.Arcsin(3 * x));
        }
Esempio n. 6
0
        public void TestPatt7()
        {
            var expr = MathS.Arcsin(x * 3) + MathS.Arccos(x * 3);

            Assert.IsTrue(expr.Simplify() == 0.5 * MathS.pi);
        }
Esempio n. 7
0
        public void TestArc3()
        {
            var func = MathS.Arccos(2 * x);

            Assert.Equal((-1) / MathS.Sqrt(1 - MathS.Sqr(2 * x)) * 2, func.Differentiate(x).Simplify());
        }
Esempio n. 8
0
        public void TestArc3()
        {
            var func = MathS.Arccos(2 * x);

            Assert.IsTrue(func.Derive(x).Simplify() == (-2) * MathS.Pow(1 + (-4) * MathS.Sqr(x), -0.5));
        }