Пример #1
0
        public void DéfinirUneClasseRealisantUneMultiplication()
        {
            var multiplication = new Multiplication();

            Check.That(multiplication.PeutCalculer("2*3")).IsTrue();
            Check.That(multiplication.PeutCalculer("2+3")).IsFalse();
            Check.That(multiplication.Calculer("2*3")).IsEqualTo(6);
        }
Пример #2
0
        public void Multiplication_Works()
        {
            var multiplication = new Multiplication();

            var result = multiplication.Execute(3,4);

            Assert.AreEqual(12, result);
        }
        public override TreeNodeBase DeepCopy()
        {
            TreeNodeBase left = LeftOperand.DeepCopy();
            TreeNodeBase right = RightOperand.DeepCopy();

            Multiplication node = new Multiplication
            {
                LeftOperand = left,
                RightOperand = right
            };
            return node;
        }
Пример #4
0
        private IExpression GetAdd(ParserContext ctx)
        {
            skipWhiteSpace(ctx);
            var t = GetMul(ctx);

            skipWhiteSpace(ctx);
            while (skipCharacter('*', ctx))
            {
                t = new Multiplication(t, GetMul(ctx));
                skipWhiteSpace(ctx);
            }
            return(t);
        }
Пример #5
0
        public void DéfinirUneInterfaceStrategieAvec2ImplémentationsPrécédentesPasséesEnParamètreDUneClasseCliente()
        {
            var multiplication = new Multiplication();
            var somme = new Somme();

            // La classe Calculatrice ne doit pas analyser l'opération reçue dans la méthode Calculer, elle doit s'appuyer sur les 2 implémentations passées en paramètre du constructeur
            var calculatrice = new Calculatrice(new IOperation[] { multiplication, somme });
            var resultatSomme = calculatrice.Calculer("1+2");
            var resultatProduit = calculatrice.Calculer("2*3");

            Check.That(resultatProduit).IsEqualTo(6);
            Check.That(resultatSomme).IsEqualTo(3);
        }
Пример #6
0
        public Operation Optimize(Operation operation, IFunctionRegistry functionRegistry)
        {
            if (!operation.DependsOnVariables && operation.GetType() != typeof(UnitNumberConstant) &&
                operation.GetType() != typeof(FloatingPointConstant))
            {
                var result = executor.Execute(operation, functionRegistry);
                if (result.DataType == DataType.Number)
                {
                    return(new FloatingPointConstant((double)result.Value));
                }
                else
                {
                    return(new UnitNumberConstant((UnitNumber)result.Value));
                }
            }
            else
            {
                if (operation.GetType() == typeof(Addition))
                {
                    Addition addition = (Addition)operation;
                    addition.Argument1 = Optimize(addition.Argument1, functionRegistry);
                    addition.Argument2 = Optimize(addition.Argument2, functionRegistry);
                }
                else if (operation.GetType() == typeof(Subtraction))
                {
                    Subtraction substraction = (Subtraction)operation;
                    substraction.Argument1 = Optimize(substraction.Argument1, functionRegistry);
                    substraction.Argument2 = Optimize(substraction.Argument2, functionRegistry);
                }
                else if (operation.GetType() == typeof(Multiplication))
                {
                    Multiplication multiplication = (Multiplication)operation;
                    multiplication.Argument1 = Optimize(multiplication.Argument1, functionRegistry);
                    multiplication.Argument2 = Optimize(multiplication.Argument2, functionRegistry);
                }
                else if (operation.GetType() == typeof(Division))
                {
                    Division division = (Division)operation;
                    division.Dividend = Optimize(division.Dividend, functionRegistry);
                    division.Divisor  = Optimize(division.Divisor, functionRegistry);
                }
                else if (operation.GetType() == typeof(Exponentiation))
                {
                    Exponentiation division = (Exponentiation)operation;
                    division.Base     = Optimize(division.Base, functionRegistry);
                    division.Exponent = Optimize(division.Exponent, functionRegistry);
                }

                return(operation);
            }
        }
Пример #7
0
        /// <summary>
        /// Builds an expression from its prefix notation.
        /// </summary>
        ///
        /// <param name="prefixNotation">The prefix notation of the expression.</param>
        ///
        /// <returns>
        /// The abstract syntax tree representing the expression.
        /// </returns>
        static Expression buildExpressionFromPrefixNotation(string[] prefixNotation)
        {
            // The stack is used to build the abstract syntax tree of the expression.
            Stack <Expression> stack      = new Stack <Expression>();
            Expression         expression = null;

            // Process all tokens of the expression.
            foreach (String token in prefixNotation)
            {
                // Determine and create the expression.
                switch (token)
                {
                case "+":

                    expression = new Plus();
                    break;

                case "-":

                    expression = new Minus();
                    break;

                case "*":

                    expression = new Multiplication();
                    break;

                case "/":

                    expression = new Division();
                    break;

                default:

                    int value = Int32.Parse(token);
                    expression = new Operand(value);
                    break;
                }

                // Push the expression onto the stack.
                stack.Push(expression);

                if (expression is Operand)
                {
                    processStack(stack);
                }
            }

            // Return the top of the stack.
            return(stack.Peek());
        }
Пример #8
0
        static void Main(string[] args)
        {
            /// Expression: 1 + 5 * (4 - 3) * (2 + 1 / 2)
            /// Composite 1: 1 + 5 * (4 - 3) * (2 + 1 / 2)
            ///     Number 1: 1
            ///     Operator 1: +
            ///     Composite 2: 5 * (4 - 3) * (2 + 1 / 2)
            ///         Number 2: 5
            ///         Operator 2: *
            ///         Composite 3: (4 - 3) * (2 + 1 / 2)
            ///             Composite 4: 4 - 3
            ///                 Number 3: 4
            ///                 Operator 3: -
            ///                 Number 4: 3
            ///             Operator 4: *
            ///             Composite 5: 2 + 1 / 2
            ///                 Number 5: 2
            ///                 Operator 5: +
            ///                 Composite 6: 1 / 2
            ///                     Number 6: 1
            ///                     Operator 6: /
            ///                     Number 7: 2

            NumbericOperand  number7    = new NumbericOperand(2);
            Operator         operator6  = new Division();
            NumbericOperand  number6    = new NumbericOperand(1);
            CompositeOperand composite6 = new CompositeOperand(number6, number7, operator6);

            NumbericOperand  number5    = new NumbericOperand(2);
            Operator         operator5  = new Summation();
            CompositeOperand composite5 = new CompositeOperand(number5, composite6, operator5);

            NumbericOperand  number3    = new NumbericOperand(4);
            Operator         operator3  = new Subtraction();
            NumbericOperand  number4    = new NumbericOperand(3);
            CompositeOperand composite4 = new CompositeOperand(number3, number4, operator3);

            Operator         operator4  = new Multiplication();
            CompositeOperand composite3 = new CompositeOperand(composite4, composite5, operator4);

            NumbericOperand  number2    = new NumbericOperand(5);
            Operator         operator2  = new Multiplication();
            CompositeOperand composite2 = new CompositeOperand(number2, composite3, operator2);

            NumbericOperand  number1    = new NumbericOperand(1);
            Operator         operator1  = new Summation();
            CompositeOperand composite1 = new CompositeOperand(number1, composite2, operator1);

            Console.WriteLine("1 + 5 * (4 - 3) * (2 + 1 / 2) = " + composite1.Calculate());
        }
Пример #9
0
        static void Main(string[] args)
        {
            Multiplication _multiplication = new Multiplication();
            BigInteger     test            = _multiplication.Multiply("3141592653589793238462643383279502884197169399375105820974944592", "2718281828459045235360287471352662497757247093699959574966967627");

            Console.WriteLine(test);

            using (StreamWriter sw = new StreamWriter("answer.txt"))
            {
                sw.WriteLine(test);
            }

            Console.ReadKey();
        }
        public void MultiplicationZerosMatrixDouble()
        {
            var a = Matrix <double> .CreateZeroMatrix(3, 7);

            var b = Matrix <double> .CreateZeroMatrix(7, 5);

            var resultMatr = Matrix <double> .CreateZeroMatrix(3, 5);

            var mult = new Multiplication <double>(a, b);

            var c = mult.Calculate();

            Assert.AreEqual(resultMatr, c);
        }
Пример #11
0
        public void TestBuildFormula1()
        {
            IFunctionRegistry registry = new MockFunctionRegistry();

            AstBuilder builder   = new AstBuilder(registry);
            Operation  operation = builder.Build(new List <Token>()
            {
                new Token()
                {
                    Value = '(', TokenType = TokenType.LeftBracket
                },
                new Token()
                {
                    Value = 42, TokenType = TokenType.Integer
                },
                new Token()
                {
                    Value = '+', TokenType = TokenType.Operation
                },
                new Token()
                {
                    Value = 8, TokenType = TokenType.Integer
                },
                new Token()
                {
                    Value = ')', TokenType = TokenType.RightBracket
                },
                new Token()
                {
                    Value = '*', TokenType = TokenType.Operation
                },
                new Token()
                {
                    Value = 2, TokenType = TokenType.Integer
                }
            });

            Multiplication multiplication = (Multiplication)operation;
            Addition       addition       = (Addition)multiplication.Argument1;

#if !NETCORE
            Assert.AreEqual(42, ((Constant <int>)addition.Argument1).Value);
            Assert.AreEqual(8, ((Constant <int>)addition.Argument2).Value);
            Assert.AreEqual(2, ((Constant <int>)multiplication.Argument2).Value);
#else
            Assert.Equal(42, ((Constant <int>)addition.Argument1).Value);
            Assert.Equal(8, ((Constant <int>)addition.Argument2).Value);
            Assert.Equal(2, ((Constant <int>)multiplication.Argument2).Value);
#endif
        }
Пример #12
0
        public void TestSinFunction3()
        {
            AstBuilder builder   = new AstBuilder();
            Operation  operation = builder.Build(new List <Token>()
            {
                new Token()
                {
                    Value = "sin", TokenType = TokenType.Text
                },
                new Token()
                {
                    Value = '(', TokenType = TokenType.LeftBracket
                },
                new Token()
                {
                    Value = 2, TokenType = TokenType.Integer
                },
                new Token()
                {
                    Value = '+', TokenType = TokenType.Operation
                },
                new Token()
                {
                    Value = 3, TokenType = TokenType.Integer
                },
                new Token()
                {
                    Value = ')', TokenType = TokenType.RightBracket
                },
                new Token()
                {
                    Value = '*', TokenType = TokenType.Operation
                },
                new Token()
                {
                    Value = 4.9, TokenType = TokenType.FloatingPoint
                }
            });

            Multiplication multiplication = (Multiplication)operation;

            Function sineFunction = (Function)multiplication.Argument1;

            Addition addition = (Addition)sineFunction.Arguments.Single();

            Assert.AreEqual(new IntegerConstant(2), addition.Argument1);
            Assert.AreEqual(new IntegerConstant(3), addition.Argument2);

            Assert.AreEqual(new FloatingPointConstant(4.9), multiplication.Argument2);
        }
        public void TestMultiplication_DecimalInt32()
        {
            ComplexField multiplication = new Multiplication();
            Field        operand1       = new LiteralField("Decimal", "operand1", "3000");
            Field        operand2       = new LiteralField("Int32", "operand2", "-1");
            Field        operand3       = new LiteralField("Decimal", "operand3", "3");

            multiplication.AddField(operand1).AddField(operand2).AddField(operand3);

            Decimal multiplicationResult = (Decimal)multiplication.GetValue(null);
            Decimal expected             = new Decimal(-9000);

            Assert.AreEqual <Decimal>(expected, multiplicationResult);
        }
Пример #14
0
        public static void CanReduceOneTimesXToJustX()
        {
            var transform = GenerateOneTimesXToXTransform();

            var input = new Multiplication(
                Numbers.One,
                Operations.AdditionWithVariable
                );
            var expected = Operations.AdditionWithVariable;
            var result   = transform.Transform(input);

            Assert.AreEqual(expected, result);
            Assert.AreNotEqual(input, result);
        }
Пример #15
0
        public void PowerSimplifier_Changes_Multiplication_To_Power_If_Multiplication_Sides_Are_Of_Same_Value()
        {
            var input = new Multiplication {
                Left = new Constant {
                    Value = 13
                }, Right = new Constant {
                    Value = 13
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should().BeOfType <Power>().Which.Left.Should().BeOfType <Constant>().Which.Value.Should().Be(13);
            result.Should().BeOfType <Power>().Which.Right.Should().BeOfType <Constant>().Which.Value.Should().Be(2);
        }
Пример #16
0
        public RSA()
        {
            var primeNumbers = SieveAtkin.GetPrimeNumbers(limit: 10000000U).ToArray();
            var random = new Random();

            var p = GetRandomPrime(primeNumbers, random);
            var q = GetRandomPrime(primeNumbers, random);
            var modulus = Multiplication.Karatsuba(p, q);
            var totient = modulus - (p + q - 1); // Euler`s function
            var publicExponent = GetRandomPrime(primeNumbers, random);
            var privateExponent = GetModularMultiplicativeInverse(publicExponent, totient);
            
            PrivateKey = new Key(modulus, privateExponent);
            PublicKey = new Key(modulus, publicExponent);
        }
Пример #17
0
        public void Visit(Multiplication multiplication)
        {
            var leftConstant  = multiplication.Left as Constant;
            var rightConstant = multiplication.Right as Constant;

            if (leftConstant != null && leftConstant.Value == 0M)
            {
                mNeedsToBeSetToZero = multiplication;
            }
            else if (rightConstant != null && rightConstant.Value == 0M)
            {
                mNeedsToBeSetToZero = multiplication;
            }
            CheckForParentsAndReplaceIfNecessary();
        }
        public async Task TestPostingNewMultiplyBatch()
        {
            var jsonInString = "{\"BatchCount\":5,\"NumberPerBatch\": 2}";
            var postResponse = await _client.PostAsync("api/orders/", new StringContent(jsonInString, Encoding.UTF8, "application/json"));

            postResponse.EnsureSuccessStatusCode();
            var body    = postResponse.Content.ReadAsStringAsync().Result;
            var jObject = JObject.Parse(body);

            var batch    = new Multiplication((Guid)jObject["orderId"], "1", 123, 222);
            var jsonBody = JsonConvert.SerializeObject(batch);
            var response = await _client.PostAsync("api/Multiply", new StringContent(jsonBody, Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
        }
Пример #19
0
 private void GetVariables(Operation operation, List <Variable> variables)
 {
     if (operation.DependsOnVariables)
     {
         if (operation.GetType() == typeof(Variable))
         {
             variables.Add((Variable)operation);
         }
         else if (operation.GetType() == typeof(Addition))
         {
             Addition addition = (Addition)operation;
             GetVariables(addition.Argument1, variables);
             GetVariables(addition.Argument2, variables);
         }
         else if (operation.GetType() == typeof(Multiplication))
         {
             Multiplication multiplication = (Multiplication)operation;
             GetVariables(multiplication.Argument1, variables);
             GetVariables(multiplication.Argument2, variables);
         }
         else if (operation.GetType() == typeof(Subtraction))
         {
             Subtraction substraction = (Subtraction)operation;
             GetVariables(substraction.Argument1, variables);
             GetVariables(substraction.Argument2, variables);
         }
         else if (operation.GetType() == typeof(Division))
         {
             Division division = (Division)operation;
             GetVariables(division.Dividend, variables);
             GetVariables(division.Divisor, variables);
         }
         else if (operation.GetType() == typeof(Exponentiation))
         {
             Exponentiation exponentiation = (Exponentiation)operation;
             GetVariables(exponentiation.Base, variables);
             GetVariables(exponentiation.Exponent, variables);
         }
         else if (operation.GetType() == typeof(Function))
         {
             Function function = (Function)operation;
             foreach (Operation argument in function.Arguments)
             {
                 GetVariables(argument, variables);
             }
         }
     }
 }
Пример #20
0
        public void Multiplication_By_One_With_One_As_Right_Side_Returns_Copy_Of_Left_Side()
        {
            var input = new Multiplication {
                Right = new Constant {
                    Value = 1
                }, Left = new Variable {
                    Name = "x"
                }
            };
            var underTest = new NeutralElementEliminatingSimplifier();

            var output = underTest.Simplify(input);

            output.Should().BeOfType <Variable>().Which.Name.Should().Be("x");
            output.Should().NotBeSameAs(input.Left);
        }
Пример #21
0
        public Node ExprMul()
        {
            Node expressionPow = ExprPow();

            while (multiplicationOperators.Contains(CurrentToken))
            {
                Node expressionMul = new Multiplication()
                {
                    AnchorToken = OpMul()
                };
                expressionMul.Add(expressionPow);
                expressionMul.Add(ExprPow());
                return(expressionMul);
            }
            return(expressionPow);
        }
Пример #22
0
        public void OperatorPrecedenceForMultiplicationAndDivisionShouldBeHigherThanAdditionAndSubtraction()
        {
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var addition = new Addition();
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var subtraction = new Subtraction();
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var multiplication = new Multiplication();
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var division = new Division();

            Assert.IsTrue(multiplication.GetPrecedence() > addition.GetPrecedence());
            Assert.IsTrue(multiplication.GetPrecedence() > subtraction.GetPrecedence());
            Assert.IsTrue(division.GetPrecedence() > addition.GetPrecedence());
            Assert.IsTrue(division.GetPrecedence() > subtraction.GetPrecedence());
        }
Пример #23
0
    public Example MakeExample(int i)
    {
        Example ex = new Summ();

        switch (i)
        {
        case 0: ex = new Summ(); break;

        case 1: ex = new DifferenceEx(); break;

        case 2: ex = new Multiplication(); break;

        case 3: ex = new Division(); break;
        }
        return(ex);
    }
Пример #24
0
        /// <summary>
        /// To find the percentage of a number
        /// </summary>
        /// <returns>
        /// Percentage of number
        /// </returns>
        public double CalcPercentage(string currentNumber, string currentExpression)
        {
            //Calculating the number from which to find the percentage
            this.currentExpression = currentExpression;
            pos = 0;
            UniversalOperation number = ParsingAnExpression_LowPriority();

            //Calculate the percentage which to find
            this.currentExpression = currentNumber;
            pos = 0;
            UniversalOperation percent = ParsingAnExpression_LowPriority();

            //Calculating the percentage of a number
            UniversalOperation result = new Multiplication(new Division(number, new Number(100)), percent);

            return(result.Operation());
        }
Пример #25
0
        public override BaseExpression VisitMultiplication(Multiplication multiplication)
        {
            // f*g -> f*g` + f`*g
            var f = multiplication.Lhs;
            var g = multiplication.Rhs;

            return(new Addition(
                       lhs: new Multiplication(
                           f,
                           this.VisitExpressionNode(g)
                           ),
                       rhs: new Multiplication(
                           this.VisitExpressionNode(f),
                           g
                           )
                       ));
        }
Пример #26
0
        //[TestMethod]
        //[DataRow(5.0, 7.39, 36.95)]
        public void MultiplicationDoubleTest(double num1, double num2, double expected)
        {
            //arrange:
            double result = 0;

            Multiplication obj = new Multiplication();

            //act:
            result = obj.Calculate(num1, num2);

            //assert:
            string strMessage = string.Format("Input: {0} * {1} = {2}. Expected: {3}",
                                              num1, num2, result, expected
                                              );

            Assert.AreEqual(expected, result, strMessage);
        }
Пример #27
0
        public async Task MultiplyAsync(CancellationToken token, Guid orderId, string batchId, int generatedNumber)
        {
            token.ThrowIfCancellationRequested();
            _logger.Log(LogLevel.Information,
                        $"Started Multiply Simulated work, batch number:'{batchId}', generated number: '{generatedNumber} the order id is: '{orderId}'");
            var factor           = GenerateRandomInt(2, 4);
            var delay            = GenerateRandomInt(5, 10);
            var multipliedNumber = factor * generatedNumber;

            Thread.Sleep(delay * 1000);
            var model = new Multiplication(orderId, batchId, generatedNumber, multipliedNumber);
            var path  = _section["MultiplyPath"];

            _logger.Log(LogLevel.Information, $"Multiply work completed for batch Id '{batchId}', Multiplied number is:{multipliedNumber} the order id is: '{orderId}'");

            _serverClient.PostAsync(token, model, path);
        }
Пример #28
0
        public void Multiplication_Of_Same_Variables_Is_Replaced_With_Square()
        {
            var input = new Multiplication()
            {
                Left = new Variable()
                {
                    Name = "x"
                }, Right = new Variable()
                {
                    Name = "x"
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should().BeOfType <Power>().Which.Left.Should().BeOfType <Variable>().Which.Name.Should().Be("x");
            result.Should().BeOfType <Power>().Which.Right.Should().BeOfType <Constant>().Which.Value.Should().Be(2);
        }
Пример #29
0
        public void Multiplication_With_Sinus_And_Cosine_Doesnt_Change_To_Power_Even_Though_The_Value_Is_The_Same()
        {
            var input = new Multiplication()
            {
                Left = new Sinus()
                {
                    Value = 0
                }, Right = new Cosine()
                {
                    Value = 0
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should().BeOfType <Multiplication>().Which.Left.Should().BeOfType <Sinus>().Which.Value.Should().Be(0);
            result.Should().BeOfType <Multiplication>().Which.Right.Should().BeOfType <Cosine>().Which.Value.Should().Be(0);
        }
Пример #30
0
        public void Multiplication_Of_Different_Variables_Is_Not_Replaced_With_Square()
        {
            var input = new Multiplication()
            {
                Left = new Variable()
                {
                    Name = "x"
                }, Right = new Variable()
                {
                    Name = "y"
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should().BeOfType <Multiplication>().Which.Left.Should().BeOfType <Variable>().Which.Name.Should().Be("x");
            result.Should().BeOfType <Multiplication>().Which.Right.Should().BeOfType <Variable>().Which.Name.Should().Be("y");
        }
        public void Simple_Case()
        {
            var input = new Multiplication
            {
                Left =
                    new ParenthesedExpression
                {
                    Wrapped = new Addition {
                        Left = new Constant {
                            Value = 13
                        }, Right = new Constant {
                            Value = 17
                        }
                    }
                },
                Right = new Constant {
                    Value = 2
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should()
            .BeOfType <Addition>()
            .Which.Left.Should()
            .BeOfType <Multiplication>()
            .Which.Left.Should()
            .BeOfType <Constant>().Which.Value.Should().Be(13);
            result.Should()
            .BeOfType <Addition>()
            .Which.Left.Should()
            .BeOfType <Multiplication>()
            .Which.Right.Should()
            .BeOfType <Constant>().Which.Value.Should().Be(2);
            result.Should()
            .BeOfType <Addition>()
            .Which.Right.Should()
            .BeOfType <Multiplication>()
            .Which.Left.Should()
            .BeOfType <Constant>().Which.Value.Should().Be(17);
            result.Should()
            .BeOfType <Addition>()
            .Which.Right.Should()
            .BeOfType <Multiplication>()
            .Which.Right.Should()
            .BeOfType <Constant>().Which.Value.Should().Be(2);
        }
Пример #32
0
        public void Multiplication_With_Tangents_Changes_To_Power_If_The_Value_Is_The_Same()
        {
            var input = new Multiplication()
            {
                Left = new Tangent()
                {
                    Value = 13
                }, Right = new Tangent()
                {
                    Value = 13
                }
            };
            var result = mUnderTest.Simplify(input);

            result.Should().BeOfType <Power>().Which.Left.Should().BeOfType <Tangent>().Which.Value.Should().Be(13);
            result.Should().BeOfType <Power>().Which.Right.Should().BeOfType <Constant>().Which.Value.Should().Be(2);
        }
Пример #33
0
        public void Multiplication_CheckResult()
        {
            //Arrange
            decimal        a = 4m;
            decimal        b = 2m;
            decimal        expectedResult = 8m;
            Multiplication op             = new Multiplication()
            {
                op1 = a, op2 = b
            };

            //Act
            decimal response = op.CalculateResult();

            //Assert
            Assert.AreEqual(expectedResult, response);
        }
Пример #34
0
        //     /        A
        //    /         |)
        //   /          | )
        //  /           |  )
        // Q------- O---X---) D
        //   \          |  )
        //    \         | )
        //     \        |)
        //      \        C
        //
        // Inscribed Angle(AQC) -> Angle(AQC) = 2 * Arc(AC)
        //
        private static List <EdgeAggregator> InstantiateTheorem(Circle circle, Angle angle)
        {
            List <EdgeAggregator> newGrounded = new List <EdgeAggregator>();

            // Acquire all circles in which the angle is inscribed
            List <Circle> circles = Circle.IsInscribedAngle(angle);

            //
            // Get this particular inscribed circle.
            //
            Circle inscribed = null;

            foreach (Circle c in circles)
            {
                if (circle.StructurallyEquals(c))
                {
                    inscribed = c;
                }
            }

            if (inscribed == null)
            {
                return(newGrounded);
            }

            // Get the intercepted arc
            Arc intercepted = Arc.GetInterceptedArc(inscribed, angle);

            //
            // Create the equation
            //
            Multiplication            product = new Multiplication(new NumericValue(2), angle);
            GeometricAngleArcEquation gaaeq   = new GeometricAngleArcEquation(product, intercepted);

            // For hypergraph
            List <GroundedClause> antecedent = new List <GroundedClause>();

            antecedent.Add(circle);
            antecedent.Add(angle);
            antecedent.Add(intercepted);

            newGrounded.Add(new EdgeAggregator(antecedent, gaaeq, annotation));

            return(newGrounded);
        }
Пример #35
0
 public virtual void Visit(Multiplication node)
 {
 }
 private ISymbolicExpressionTreeNode MakeProduct(ConstantTreeNode c, double weight) {
   var mul = new Multiplication();
   var prod = mul.CreateTreeNode();
   prod.AddSubtree(MakeConstantTreeNode(weight));
   prod.AddSubtree(c);
   return prod;
 }
Пример #37
0
 public void CalculateTest(double firstArgument, double secondArgument, double result)
 {
     var calculator = new Multiplication();
     var testResult = calculator.Calculate(firstArgument,secondArgument);
     Assert.AreEqual(result, testResult);
 }
        void MulDivMod(out Expression exp)
        {
            Expression second;
            UnaryOperator(out exp);
            while (la.kind == 42 || la.kind == 43 || la.kind == 44) {
            if (la.kind == 42) {
                Get();
            } else if (la.kind == 43) {
                Get();
            } else {
                Get();
            }
            Token tok = t;
            UnaryOperator(out second);
            if (!ExpectInt(exp, tok, false)) { return; }
            if (!ExpectInt(second, tok, true)) { return; }
            if (tok.val == "*") {
                exp = new Multiplication((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == "/") {
                exp = new Division((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == "%") {
                exp = new Modulo((TypedExpression<int>)exp, (TypedExpression<int>)second);
            }

            }
        }
Пример #39
0
 private Expression ParseMultiplicativeExpression(TokenSet followers) {
   TokenSet followerOrMultiplicative = followers|Token.Division|Token.Multiplication;
   Expression result = this.ParseRaiseExpression(followerOrMultiplicative);
   while (this.currentToken == Token.Division || this.currentToken == Token.Multiplication) {
     SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation);
     Token operatorToken = this.currentToken;
     this.GetNextToken();
     Expression operand2 = this.ParseRaiseExpression(followerOrMultiplicative);
     slb.UpdateToSpan(operand2.SourceLocation);
     switch (operatorToken) {
       case Token.Division: result = new Division(result, operand2, slb); break;
       case Token.Multiplication: result = new Multiplication(result, operand2, slb); break;
     }
   }
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
 public void Visit(Multiplication visitable) =>
     VisitBinary(visitable, "*");