Esempio n. 1
0
        public void ResultTypeMatrixVectorTest()
        {
            var mul = new Mul(new Matrix(new[] { new Vector(new[] { new Number(2) }) }),
                              new Vector(new[] { new Number(1) }));

            Assert.Equal(ExpressionResultType.Matrix, mul.ResultType);
        }
Esempio n. 2
0
        public void testMultiplication()
        {
            decimal op1 = 2.4m;
            decimal op2 = 5.8m;

            Assert.AreEqual(op1 * op2, Mul.Multiplication(op1, op2));
        }
        private void btnIgual_Click(object sender, EventArgs e)
        {
            segundo = double.Parse(tbxScreen.Text);

            double Sum;
            double Res;
            double Mul;
            double Div;

            switch (operador)
            {
            case "+":
                Sum            = obj.Sumar((primeiro), (segundo));
                tbxScreen.Text = Sum.ToString();
                break;

            case "-":
                Res            = obj2.Restar((primeiro), (segundo));
                tbxScreen.Text = Res.ToString();
                break;

            case "*":
                Mul            = obj3.Multiplicar((primeiro), (segundo));
                tbxScreen.Text = Mul.ToString();
                break;

            case "/":
                Div            = obj4.Dividir((primeiro), (segundo));
                tbxScreen.Text = Div.ToString();
                break;
            }
        }
Esempio n. 4
0
        public static void Main()
        {
            var e1 = new Add(new CstI(17), new Var("z")); // => Add(17, z)

            // WriteLine automatically calls .ToString on objects passed to it
            Console.WriteLine(e1);

            // (ii) Create three more expressions and print them
            //      Easter egg: I totally stole them from Intro2.fs
            var e2 = new CstI(17);                       // => 17
            var e3 = new Add(new CstI(3), new Var("a")); // => Add(3, a)
            var e4 = new Add(new Mul(new Var("b"), new CstI(9)), new Var("a"));

            // => Add(Mul(b, 9), a)

            Console.WriteLine(string.Format("{0}\n{1}\n{2}", e2, e3, e4));

            // (iii) Add the eval function to each subclass of `Expr`
            var env = new Dictionary <string, int> {
                { "x", 5 },
                { "y", 42 }
            };
            var e5 = new Add(new Var("x"), new CstI(5));

            Console.WriteLine(e5.Eval(env)); // => 10

            // (iv) Add the simplify function to each subclass of `Expr`
            var e6 = new Add(new Var("x"), new CstI(0)); // => x
            var e7 = new Sub(new Var("x"), new CstI(0)); // => x
            var e8 = new Mul(new CstI(5), new CstI(0));  // => 0
            var e9 = new Mul(new Var("x"), new CstI(1)); // => x

            Console.WriteLine(string.Format("{0}\n{1}\n{2}\n{3}",
                                            e6.Simplify(), e7.Simplify(), e8.Simplify(), e9.Simplify()));
        }
Esempio n. 5
0
        public void MulDiffNumMul_NumMulVar_()
        {
            var mul      = new Mul(new Number(2), new Mul(new Number(2), Variable.X));
            var expected = new Mul(new Number(4), Variable.X);

            SimpleTest(mul, expected);
        }
Esempio n. 6
0
        public void MulDiff_VarMulNum_MulNum()
        {
            var mul      = new Mul(new Mul(Variable.X, new Number(2)), new Number(2));
            var expected = new Mul(new Number(4), Variable.X);

            SimpleTest(mul, expected);
        }
Esempio n. 7
0
        public void MulSecondOne()
        {
            var mul      = new Mul(Variable.X, new Number(1));
            var expected = Variable.X;

            SimpleTest(mul, expected);
        }
Esempio n. 8
0
        public void MulTwoNumbers()
        {
            var mul      = new Mul(new Number(2), new Number(3));
            var expected = new Number(6);

            SimpleTest(mul, expected);
        }
Esempio n. 9
0
        public void MulByZero()
        {
            var mul      = new Mul(Variable.X, new Number(0));
            var expected = new Number(0);

            SimpleTest(mul, expected);
        }
Esempio n. 10
0
        public void MulFirstOne()
        {
            var mul      = new Mul(new Number(1), Variable.X);
            var expected = Variable.X;

            SimpleTest(mul, expected);
        }
Esempio n. 11
0
        public void MulDiff_NumMulVar_MulNum()
        {
            var mul      = new Mul(new Mul(new Number(2), new Variable("x")), new Number(2));
            var expected = new Mul(new Number(4), new Variable("x"));

            SimpleTest(mul, expected);
        }
Esempio n. 12
0
        public void MulSecondOne()
        {
            var mul      = new Mul(new Variable("x"), new Number(1));
            var expected = new Variable("x");

            SimpleTest(mul, expected);
        }
Esempio n. 13
0
        private void botonIgual_Click(object sender, EventArgs e)
        {
            segundo = double.Parse(tbxScreen.Text);
            double Sum;
            double Res;
            double Mul;
            double Div;

            switch (operador)
            {
            case "+":
                Sum            = primero + segundo;
                tbxScreen.Text = Sum.ToString();
                break;

            case "-":
                Res            = primero - segundo;
                tbxScreen.Text = Res.ToString();
                break;

            case "*":
                Mul            = primero * segundo;
                tbxScreen.Text = Mul.ToString();
                break;

            case "/":
                Div            = primero / segundo;
                tbxScreen.Text = Div.ToString();
                break;
            }
        }
Esempio n. 14
0
        public void TestMulRightMatrixLeftException()
        {
            var mul = new Mul(new Bool(false),
                              new Matrix(new[] { new Vector(new[] { new Number(1) }) }));

            TestBinaryException(mul);
        }
Esempio n. 15
0
        public void TestMulVectorMatrixTest()
        {
            var mul = new Mul(new Vector(new[] { new Number(1) }),
                              new Matrix(new[] { new Vector(new[] { new Number(2) }) }));

            Test(mul, ResultType.Matrix);
        }
Esempio n. 16
0
 private void BtnMul_Click(object sender, RoutedEventArgs e)
 {
     if (IsInputValid())
     {
         Mul?.Invoke(this, new ButtonClickEventArgs(Model.Operations.Mul));
     }
 }
Esempio n. 17
0
        public override TreeNode GetAstCodeGenerator(SymbolTable t)
        {
            switch (op)
            {
            case "+":
                var plus = new Plus((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(plus);
                return(plus);

            case "-":
                var sub = new Sub((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(sub);
                return(sub);

            case "*":
                var mul = new Mul((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(mul);
                return(mul);

            case "/":
                var div = new Divide((MIPSCodeGenerator.Expression)Left.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)Rigth.GetAstCodeGenerator(t), Line);
                SetGeneratorType(div);
                return(div);

            default: throw new InvalidOperationException();
            }
        }
Esempio n. 18
0
        private void btnIgual_Click(object sender, EventArgs e)
        {
            valor2 = double.Parse(tbxScreen.Text);
            double Sum;
            double Sub;
            double Mul;
            double Div;

            switch (operador)
            {
            case "+":
                Sum            = objeto.Somar((valor1), (valor2));
                tbxScreen.Text = Sum.ToString();
                break;

            case "-":
                Sub            = objeto2.Dividir((valor1), (valor2));
                tbxScreen.Text = Sub.ToString();
                break;

            case "*":
                Mul            = objeto3.Multiplicar((valor1), (valor2));
                tbxScreen.Text = Mul.ToString();
                break;

            case "/":
                Div            = objeto4.Dividir((valor1), valor2);
                tbxScreen.Text = Div.ToString();
                break;
            }
        }
Esempio n. 19
0
        private Layer ConvertMul(tflite.Operator op)
        {
            var inputs = op.GetInputsArray();
            var inputA = _graph.Tensors(inputs[0]).Value;
            var inputB = _graph.Tensors(inputs[1]).Value;

            if (inputA.ShapeLength == 0)
            {
                var layer = new Mul(inputB.GetShapeArray().ToNCHW(), _model.GetScalar <float>(inputA));
                _inputs.Add(layer.Input, inputs[1]);
                _outputs.Add(op.Outputs(0), layer.Output);
                return(layer);
            }
            else if (inputB.ShapeLength == 0)
            {
                var layer = new Mul(inputA.GetShapeArray().ToNCHW(), _model.GetScalar <float>(inputB));
                _inputs.Add(layer.Input, inputs[0]);
                _outputs.Add(op.Outputs(0), layer.Output);
                return(layer);
            }
            else
            {
                throw new LayerNotSupportedException(op.ToString(), "Only scalar multiply is supported");
            }
        }
Esempio n. 20
0
        public void ExecuteMulNumberByComplexTest()
        {
            var exp      = new Mul(new Number(2), new ComplexNumber(3, 2));
            var expected = new Complex(6, 4);

            Assert.Equal(expected, exp.Execute());
        }
Esempio n. 21
0
        public void ExecuteMulNumberBySqrtComplexTest()
        {
            var exp      = new Mul(new Number(2), new Sqrt(new Number(-9)));
            var expected = new Complex(0, 6);

            Assert.Equal(expected, exp.Execute());
        }
Esempio n. 22
0
        public void ExecuteMulComplexByComplexTest()
        {
            var exp      = new Mul(new ComplexNumber(2, 5), new ComplexNumber(3, 2));
            var expected = new Complex(-4, 19);

            Assert.Equal(expected, exp.Execute());
        }
Esempio n. 23
0
        public void ExecuteMulComplexByNumberTest()
        {
            var exp      = new Mul(new ComplexNumber(2, 5), new Number(2));
            var expected = new Complex(4, 10);

            Assert.Equal(expected, exp.Execute());
        }
Esempio n. 24
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>
        /// The result of analysis.
        /// </returns>
        public override IExpression Analyze(Mul exp)
        {
            if (!Helpers.HasVariable(exp, Variable))
            {
                return(new Number(0));
            }

            var first  = Helpers.HasVariable(exp.Left, Variable);
            var second = Helpers.HasVariable(exp.Right, Variable);

            if (first && second)
            {
                var mul1 = new Mul(exp.Left.Clone().Analyze(this), exp.Right.Clone());
                var mul2 = new Mul(exp.Left.Clone(), exp.Right.Clone().Analyze(this));
                var add  = new Add(mul1, mul2);

                return(add);
            }

            if (first)
            {
                return(new Mul(exp.Left.Clone().Analyze(this), exp.Right.Clone()));
            }

            // if (second)
            return(new Mul(exp.Left.Clone(), exp.Right.Clone().Analyze(this)));
        }
Esempio n. 25
0
        public void CloneTest()
        {
            var exp   = new Mul(Variable.X, new Number(0));
            var clone = exp.Clone();

            Assert.Equal(exp, clone);
        }
Esempio n. 26
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>
        /// The result of analysis.
        /// </returns>
        public override IExpression Analyze(Div exp)
        {
            if (!Helpers.HasVariable(exp, Variable))
            {
                return(new Number(0));
            }

            var first  = Helpers.HasVariable(exp.Left, Variable);
            var second = Helpers.HasVariable(exp.Right, Variable);

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

                return(division);
            }

            if (second)
            {
                var mul2     = new Mul(exp.Left.Clone(), exp.Right.Clone().Analyze(this));
                var unMinus  = new UnaryMinus(mul2);
                var inv      = new Pow(exp.Right.Clone(), new Number(2));
                var division = new Div(unMinus, inv);

                return(division);
            }

            //if (first)
            return(new Div(exp.Left.Clone().Analyze(this), exp.Right.Clone()));
        }
Esempio n. 27
0
        private void btnigual_Click(object sender, EventArgs e)
        { // Programando o botão de = com base nas classes criadas //
            segundo = double.Parse(tbxScreen.Text);

            double Som;
            double Su;
            double Mul;
            double Div;

            switch (operador)
            {
            case "+":
                Som            = obj.Somar((primeiro), (segundo));
                tbxScreen.Text = Som.ToString();
                break;

            case "-":
                Su             = obj2.subtracao((primeiro), (segundo));
                tbxScreen.Text = Su.ToString();
                break;

            case "*":
                Mul            = obj3.Multiplicao((primeiro), (segundo));
                tbxScreen.Text = Mul.ToString();
                break;

            case "/":
                Div            = obj4.Divisao((primeiro), (segundo));
                tbxScreen.Text = Div.ToString();
                break;
            }
        }
Esempio n. 28
0
        public void TestMulVectorNumber()
        {
            var mul = new Mul(new Vector(new[] { new Number(1) }),
                              new Number(2));

            Test(mul, ResultType.Vector);
        }
Esempio n. 29
0
        public void ExecuteMulBoolByComplex()
        {
            var boolean = new Bool(true);
            var complex = new ComplexNumber(3, 2);
            var mul     = new Mul(boolean, complex);

            Assert.Throws <ResultIsNotSupportedException>(() => mul.Execute());
        }
Esempio n. 30
0
        public void ExecuteDotProductTest()
        {
            var vector1 = new Maths.Expressions.Matrices.Vector(new[] { new Number(1), new Number(2), new Number(3) });
            var vector2 = new Maths.Expressions.Matrices.Vector(new[] { new Number(4), new Number(5), new Number(6) });
            var exp     = new Mul(vector1, vector2);

            Assert.Equal(32.0, exp.Execute());
        }
Esempio n. 31
0
    static void Main(string[] args)
    {
        var env = new System.Collections.Generic.Dictionary<string, int>();
        env.Add("z",5);
        env.Add("x",2);

        Expr e1 = new Add(new CstI(17), new Var("z")).Simplify();
        Expr e2 = new Mul(new Var("x"), new Var("z")).Simplify();
        Expr e3 = new Sub(new Mul(new CstI(17), new CstI(5)), new Var("z")).Simplify();
        Expr e4 = new Add(new CstI(17), new CstI(0)).Simplify();

        System.Console.Out.WriteLine(e1.ToString() + " = " + e1.Eval(env));
        System.Console.Out.WriteLine(e2.ToString() + " = " + e2.Eval(env));
        System.Console.Out.WriteLine(e3.ToString() + " = " + e3.Eval(env));
        System.Console.Out.WriteLine(e4.ToString() + " = " + e4.Eval(env));
        System.Console.ReadLine();
    }
Esempio n. 32
0
 public void Mul_MultiplyRegisters_ResultAndOverflowAreCorrect()
 {
     var prev = new MutableState().Set(Register.A, 0x345).Set(Register.B, 0x678);
     var state = new Mul(new Reg(Register.A), new Reg(Register.B)).Apply(prev);
     Assert.AreEqual(0x2658, state.Get(Register.A));
     Assert.AreEqual(0x15, state.Get(Register.O));
 }