Example #1
0
        public CompiledFuncTest()
        {
            multiFuncNotCompiled = (MathS.Log(3, x) + MathS.Sqr(x)) * MathS.Sin(x + MathS.Cosec(x));
            multiFunc            = multiFuncNotCompiled.Compile(x);
            Expression <Func <Complex, Complex> > expr = x => (Complex.Log(x, 3) + Complex.Pow(x, 2)) * Complex.Sin(x + 1 / Complex.Sin(x));

            linqFunc = expr.Compile();
        }
Example #2
0
 [TestMethod] public void SetSimplify() => Test(@"\left\{\log_{2}\left(4\right)\right\}", new Set(MathS.Log(2, 4), MathS.Sqrt(MathS.Sqrt(16))));
Example #3
0
 [TestMethod] public void Log() => Test(@"\log_{2}\left(10\right)", MathS.Log(2, 10));
Example #4
0
 [TestMethod] public void LnAlternate() => Test(@"\ln\left(10\right)", MathS.Log(MathS.e, 10));
Example #5
0
 [TestMethod] public void Log10() => Test(@"\log\left(10\right)", MathS.Log(10, 10));
        /// <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");
            }
        }