Ejemplo n.º 1
0
        public void ExecuteTest2()
        {
            var complex = new Complex(2, 3);
            var exp = new UnaryMinus(new ComplexNumber(complex));

            Assert.Equal(Complex.Negate(complex), exp.Execute());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Sech(Sech expression, Variable variable)
        {
            var tanh = new Tanh(expression.Argument.Clone());
            var mul1 = new Mul(tanh, expression.Clone());
            var mul2 = new Mul(_Differentiate(expression.Argument.Clone(), variable), mul1);
            var unMinus = new UnaryMinus(mul2);

            return unMinus;
        }
Ejemplo n.º 3
0
        public void WithSimplifyTest()
        {
            differentiator.Simplify = true;
            var exp = new UnaryMinus(new Sin(new Variable("x")));
            var deriv = Differentiate(exp);

            Assert.AreEqual("-cos(x)", deriv.ToString());
        }
Ejemplo n.º 4
0
        public void MulNegativeRightParamTest1()
        {
            // sin(cos(x))
            var x = new Variable("x");
            var mul = new Mul(new Cos(new Cos(x)), new UnaryMinus(new Sin(x)));
            var expected = new UnaryMinus(new Mul(new Sin(x), new Cos(new Cos(x))));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 5
0
        public void AddSaveVars11()
        {
            // 3x + -4x
            var var = new Variable("x");
            var exp = new Add(new Mul(new Number(3), var), new Mul(new Number(-4), var));
            var expected = new UnaryMinus(var);

            SimpleTest(exp, expected);
        }
Ejemplo n.º 6
0
        public void SubSameVars5()
        {
            // x - (x * 2)
            var x = new Variable("x");
            var sub = new Sub(x, new Mul(x, new Number(2)));
            var expected = new UnaryMinus(x);

            SimpleTest(sub, expected);
        }
Ejemplo n.º 7
0
        public void SubFirstZero()
        {
            var sub = new Sub(new Number(0), new Variable("x"));
            var expected = new UnaryMinus(new Variable("x"));

            SimpleTest(sub, expected);
        }
Ejemplo n.º 8
0
        public void SubDiffNumSub_VarAddNum_()
        {
            // 2 - (x + 2)
            var sub = new Sub(new Number(2), new Add(new Variable("x"), new Number(2)));
            var expected = new UnaryMinus(new Variable("x"));

            SimpleTest(sub, expected);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arsech(Arsech expression, Variable variable)
        {
            var inv = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(new Number(1), inv);
            var sqrt = new Sqrt(sub);
            var mul = new Mul(expression.Argument.Clone(), sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arcsch(Arcsch expression, Variable variable)
        {
            var inv = new Pow(expression.Argument.Clone(), new Number(2));
            var add = new Add(new Number(1), inv);
            var sqrt = new Sqrt(add);
            var abs = new Abs(expression.Argument.Clone());
            var mul = new Mul(abs, sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arccsc(Arccsc expression, Variable variable)
        {
            var abs = new Abs(expression.Argument.Clone());
            var sqr = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(sqr, new Number(1));
            var sqrt = new Sqrt(sub);
            var mul = new Mul(abs, sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);
            var unary = new UnaryMinus(div);

            return unary;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arccot(Arccot expression, Variable variable)
        {
            var involution = new Pow(expression.Argument.Clone(), new Number(2));
            var add = new Add(new Number(1), involution);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), add);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arccos(Arccos expression, Variable variable)
        {
            var pow = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(new Number(1), pow);
            var sqrt = new Sqrt(sub);
            var division = new Div(_Differentiate(expression.Argument.Clone(), variable), sqrt);
            var unMinus = new UnaryMinus(division);

            return unMinus;
        }
Ejemplo n.º 14
0
        public void ExecuteTest1()
        {
            var exp = new UnaryMinus(new Number(10));

            Assert.Equal(-10.0, exp.Execute());
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Differentiates the specified expression.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="variable">The variable.</param>
 /// <returns>Returns the derivative.</returns>
 protected virtual IExpression UnaryMinus(UnaryMinus expression, Variable variable)
 {
     return new UnaryMinus(_Differentiate(expression.Argument.Clone(), variable));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Cos(Cos expression, Variable variable)
        {
            var sine = new Sin(expression.Argument.Clone());
            var multiplication = new Mul(sine, _Differentiate(expression.Argument.Clone(), variable));
            var unMinus = new UnaryMinus(multiplication);

            return unMinus;
        }
Ejemplo n.º 17
0
        public void UnaryMinusTest2()
        {
            var exp = new UnaryMinus(new Sin(new Variable("z")));
            var deriv = Differentiate(exp);

            Assert.Equal("0", deriv.ToString());
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Cot(Cot expression, Variable variable)
        {
            var sine = new Sin(expression.Argument.Clone());
            var involution = new Pow(sine, new Number(2));
            var division = new Div(_Differentiate(expression.Argument.Clone(), variable), involution);
            var unMinus = new UnaryMinus(division);

            return unMinus;
        }
Ejemplo n.º 19
0
        public void SubDiff_NumSubVar_SubNum()
        {
            var sub = new Sub(new Sub(new Number(2), new Variable("x")), new Number(2));
            var expected = new UnaryMinus(new Variable("x"));

            SimpleTest(sub, expected);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Coth(Coth expression, Variable variable)
        {
            var sinh = new Sinh(expression.Argument.Clone());
            var inv = new Pow(sinh, new Number(2));
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), inv);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
Ejemplo n.º 21
0
        public void SubSameVars2()
        {
            // (x - x) - x
            var x = new Variable("x");
            var sub = new Sub(new Sub(x, x), x);
            var expected = new UnaryMinus(x);

            SimpleTest(sub, expected);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Csc(Csc expression, Variable variable)
        {
            var unary = new UnaryMinus(_Differentiate(expression.Argument.Clone(), variable));
            var cot = new Cot(expression.Argument.Clone());
            var csc = new Csc(expression.Argument.Clone());
            var mul1 = new Mul(cot, csc);
            var mul2 = new Mul(unary, mul1);

            return mul2;
        }
Ejemplo n.º 23
0
        public void UnaryNumber()
        {
            var un = new UnaryMinus(new Number(1));
            var expected = new Number(-1);

            SimpleTest(un, expected);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Csch(Csch expression, Variable variable)
        {
            var coth = new Coth(expression.Argument.Clone());
            var mul1 = new Mul(coth, expression.Clone());
            var mul2 = new Mul(_Differentiate(expression.Argument.Clone(), variable), mul1);
            var unMinus = new UnaryMinus(mul2);

            return unMinus;
        }
Ejemplo n.º 25
0
        public void DoubleUnary()
        {
            var un = new UnaryMinus(new UnaryMinus(new Variable("x")));
            var expected = new Variable("x");

            SimpleTest(un, expected);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Div(Div expression, Variable variable)
        {
            var first = Parser.HasVar(expression.Left, variable);
            var second = Parser.HasVar(expression.Right, variable);

            if (first && second)
            {
                var mul1 = new Mul(_Differentiate(expression.Left.Clone(), variable), expression.Right.Clone());
                var mul2 = new Mul(expression.Left.Clone(), _Differentiate(expression.Right.Clone(), variable));
                var sub = new Sub(mul1, mul2);
                var inv = new Pow(expression.Right.Clone(), new Number(2));
                var division = new Div(sub, inv);

                return division;
            }
            if (first)
            {
                return new Div(_Differentiate(expression.Left.Clone(), variable), expression.Right.Clone());
            }
            if (second)
            {
                var mul2 = new Mul(expression.Left.Clone(), _Differentiate(expression.Right.Clone(), variable));
                var unMinus = new UnaryMinus(mul2);
                var inv = new Pow(expression.Right.Clone(), new Number(2));
                var division = new Div(unMinus, inv);

                return division;
            }

            return new Number(0);
        }
Ejemplo n.º 27
0
        public void MulSameVar11()
        {
            // 2x * -3x
            var var = new Variable("x");
            var mul = new Mul(new Mul(new Number(2), var), new Mul(new Number(-0.5), var));
            var expected = new UnaryMinus(new Pow(var, new Number(2)));

            SimpleTest(mul, expected);
        }
Ejemplo n.º 28
0
        public void UnaryMinusTest()
        {
            var exp = new UnaryMinus(new Sin(new Variable("x")));
            var deriv = Differentiate(exp);

            Assert.AreEqual("-(cos(x) * 1)", deriv.ToString());
        }