Ejemplo n.º 1
0
        public void PowerOne()
        {
            var pow      = new Pow(Variable.X, new Number(1));
            var expected = Variable.X;

            SimpleTest(pow, expected);
        }
Ejemplo n.º 2
0
 public PowModel(Pow pow)
 {
     Pow   = pow.Nazwa;
     PowID = pow.PowID;
     Woj   = pow.Woj.Nazwa;
     WojId = pow.WojID;
 }
Ejemplo n.º 3
0
        public void PowerZero()
        {
            var pow      = new Pow(Variable.X, new Number(0));
            var expected = new Number(1);

            SimpleTest(pow, expected);
        }
Ejemplo n.º 4
0
        public void PowerOne()
        {
            var pow      = new Pow(new Variable("x"), new Number(1));
            var expected = new Variable("x");

            SimpleTest(pow, expected);
        }
Ejemplo n.º 5
0
        public void CalculateTest(double firstArgument, double secondArgument, double result, double accracy)
        {
            var testingFunction = new Pow();
            var testResult      = testingFunction.Calculate(firstArgument, secondArgument);

            Assert.AreEqual(result, testResult, accracy);
        }
Ejemplo n.º 6
0
        public override Expression On(Pow e)
        {
            var res = base.On(e);

            if (res is Pow)
            {
                var resB = res as Pow;
                if (_.Same(resB.Arguments[0], 0))
                {
                    return(0);
                }
                if (_.Same(resB.Arguments[1], 0))
                {
                    return(1);
                }
                if (_.Same(resB.Arguments[1], 1))
                {
                    return(resB.Arguments[0]);
                }
                if (_.Same(resB.Arguments[1], 0.5))                 // simplification ?
                {
                    return(_.Sqrt(resB.Arguments[0]));
                }
            }
            return(res);
        }
Ejemplo n.º 7
0
        protected override void OnLayout(float left, float top, float width, float height, Graphics g, Font font, Style style)
        {
            float baseLine = Math.Max(X.FindMaxTop(), Pow.DesiredHeight);

            X.Layout(this, 0, baseLine - X.FindMaxTop(), X.DesiredWidth, X.DesiredHeight, g, font, style);
            Pow.Layout(this, X.DesiredWidth, baseLine - Pow.DesiredHeight, Pow.DesiredWidth, Pow.DesiredHeight, g, font, style);
        }
Ejemplo n.º 8
0
        public void CalculateAdditionTestStrong(double firstValue, double secondValue, double expected)
        {
            ITwoArgumentsCalculator calculator = new Pow();
            double result = calculator.Calculate(5, 2);

            Assert.AreEqual(25, result);
        }
Ejemplo n.º 9
0
        public static Pow[] GetNarrowPowers(this Rational r, Rational[] narrows = null)
        {
            if (narrows == null)
            {
                narrows = NarrowUtils.GetDefault(r.GetInvolvedPowerCount());
            }
            int len = r.GetInvolvedPowerCount();

            if (len > narrows.Length)
            {
                return(null);
            }
            Pow[] res = new Pow[len];
            r = r.Clone();
            for (int i = len - 1; i >= 0; --i)
            {
                Pow e = r.GetPrimePower(i);
                res[i] = e;
                if (e != 0)
                {
                    r /= narrows[i].Power(e);
                }
            }
            return(res);
        }
Ejemplo n.º 10
0
        static public Rational Prime(int primeIndex)
        {
            var pows = new Pow[primeIndex + 1];

            pows[primeIndex] = (Pow)1;
            return(new Rational(pows));
        }
Ejemplo n.º 11
0
        public void ExecuteTest5()
        {
            var complex = new Complex(-3, 2);
            var exp     = new Pow(new ComplexNumber(complex), new Number(10));

            Assert.Equal(Complex.Pow(complex, 10), exp.Execute());
        }
Ejemplo n.º 12
0
 public int Visit(Pow node)
 {
     return
         ((int)Math.Pow(
              Visit((dynamic)node[0]),
              Visit((dynamic)node[1])));
 }
Ejemplo n.º 13
0
        protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            MeasureSpec leftWidth  = null;
            MeasureSpec rightWidth = null;


            if (widthSpec.Mode == MeasureSpecMode.Fixed || widthSpec.Mode == MeasureSpecMode.AtMost)
            {
                leftWidth  = MeasureSpec.MakeFixed(widthSpec.Size * 0.8f);
                rightWidth = MeasureSpec.MakeFixed(widthSpec.Size * 0.2f);
            }
            else if (widthSpec.Mode == MeasureSpecMode.Unspecified)
            {
                leftWidth  = widthSpec;
                rightWidth = widthSpec;
            }


            X.Measure(leftWidth, heightSpec, g, font, style);
            Pow.Measure(rightWidth, heightSpec, g, font, style);

            SetDesiredSize(
                X.DesiredWidth + Pow.DesiredWidth,
                Pow.DesiredHeight + X.FindMaxTop() + X.FindMaxBottom() - 10);
        }
Ejemplo n.º 14
0
        public static DoptimizationAlgorithm SelectState(DoptimizeExperimentTable det)
        {
            IDoptimizationDistributionSelection distributionSelection = null;
            LangleyMethodStandardSelection      langleyMethod         = null;

            if (det.det_DistributionState == 0)
            {
                distributionSelection = new Dop_Noraml();
            }
            else if (det.det_DistributionState == 1)
            {
                distributionSelection = new Dop_Logistic();
            }

            if (det.det_StandardState == 0)
            {
                langleyMethod = new Standard();
            }
            else if (det.det_StandardState == 1)
            {
                langleyMethod = new Ln();
            }
            else if (det.det_StandardState == 2)
            {
                langleyMethod = new Log();
            }
            else if (det.det_StandardState == 3)
            {
                langleyMethod = new Pow(double.Parse(det.det_Power));
            }

            return(new DoptimizationAlgorithm(distributionSelection, langleyMethod));
        }
Ejemplo n.º 15
0
        public void SimpleTest(double first, double second, double expected)
        {
            Pow    calcul = new Pow();
            double result = calcul.Doit(first, second);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 16
0
        public static Pow[] FromInt(Long n)
        {
            if (n <= 0)
            {
                throw new ArgumentException();
            }
            var pows = new List <Pow>();

            for (int i = 0; n != 1; ++i)
            {
                Long p = (Long)Utils.GetPrime(i);
                //if (p == 0) break; // out of known primes
                Pow e = (Pow)0;
                for (;;)
                {
                    Long rem;
                    Long n1 = LongMath.DivRem(n, p, out rem);
                    if (rem != 0)
                    {
                        break;
                    }
                    n  = n1;
                    e += (Pow)1;
                }
                pows.Add(e);
            }
            return(pows.ToArray());
        }
Ejemplo n.º 17
0
        public void CalculateTest(double firstValue, double secondValue, double expected)
        {
            var calculator   = new Pow();
            var actualResult = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
Ejemplo n.º 18
0
        public void CloneTest()
        {
            var exp   = new Pow(Variable.X, new Number(0));
            var clone = exp.Clone();

            Assert.Equal(exp, clone);
        }
Ejemplo n.º 19
0
        public void Calculate(double firstArgument, double secondArgument, double result)
        {
            var calculator = new Pow();
            var testresult = calculator.Calculate(firstArgument, secondArgument);

            Assert.AreEqual(result, testresult);
        }
Ejemplo n.º 20
0
        public static LangleyAlgorithm SelectState(LangleyExperimentTable let)
        {
            LangleyDistributionSelection   distributionSelection = null;
            LangleyMethodStandardSelection langleyMethod         = null;

            if (let.let_DistributionState == 0)
            {
                distributionSelection = new Normal();
            }
            else if (let.let_DistributionState == 1)
            {
                distributionSelection = new Logistic();
            }

            if (let.let_StandardState == 0)
            {
                langleyMethod = new Standard();
            }
            else if (let.let_StandardState == 1)
            {
                langleyMethod = new Ln();
            }
            else if (let.let_StandardState == 2)
            {
                langleyMethod = new Log();
            }
            else if (let.let_StandardState == 3)
            {
                langleyMethod = new Pow(double.Parse(let.let_Power));
            }

            return(new LangleyAlgorithm(distributionSelection, langleyMethod));;
        }
Ejemplo n.º 21
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()));
        }
Ejemplo n.º 22
0
        public void CalculateTest(double argument, double secondArgument, double result)
        {
            var calculator = new Pow();
            var testResult = calculator.Calculate(argument, secondArgument);

            Assert.AreEqual(testResult, result);
        }
 public string Visit(Pow node)
 {
     return("(expt "
            + Visit((dynamic)node[0])
            + " "
            + Visit((dynamic)node[1])
            + ")");
 }
Ejemplo n.º 24
0
        public void TestCalulate()
        {
            Pow operation = new Pow();

            var answer = operation.Calculate(3.0, 2.0);

            Assert.AreEqual(9.0, answer, 1e-9);
        }
Ejemplo n.º 25
0
 public String Visit(Pow node)
 {
     return("(int) pow("
            + Visit((dynamic)node[0])
            + ", "
            + Visit((dynamic)node[1])
            + ")");
 }
Ejemplo n.º 26
0
        public void ExecuteTest4()
        {
            var complex1 = new Complex(-3, 2);
            var complex2 = new Complex(-4, 5);
            var exp      = new Pow(new ComplexNumber(complex1), new ComplexNumber(complex2));

            Assert.Equal(Complex.Pow(complex1, complex2), exp.Execute());
        }
Ejemplo n.º 27
0
        private CommonF Factor()
        {
            Pow     pow   = new Pow();
            CommonF power = Power();

            if (!power.IsZero())
            {
                pow.RaiseTo(power);
            }
            else
            {
                while (IsCaret(look))
                {
                    Match('^');
                    Power();
                }
                return(new Constant(0));
            }
            while (IsCaret(look))
            {
                Match('^');
                power = Power();
                if (!power.IsZero())
                {
                    pow.RaiseTo(power);
                }
                else
                {
                    if (pow.baseAndPower.Count > 1)
                    {
                        pow.baseAndPower.RemoveAt(pow.baseAndPower.Count - 1);
                        while (IsCaret(look))
                        {
                            Match('^');
                            Power();
                        }
                        return(pow);
                    }
                    else
                    {
                        while (IsCaret(look))
                        {
                            Match('^');
                            Power();
                        }
                        return(new Constant(1));
                    }
                }
            }
            if (pow.baseAndPower.Count == 1)
            {
                return(pow.baseAndPower[0]);
            }
            else
            {
                return(pow);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>The result of analysis.</returns>
        public string Analyze(Pow exp)
        {
            if (exp.Parent is BinaryExpression && !(exp.Parent is Add || exp.Parent is Sub || exp.Parent is Mul))
            {
                return(ToString(exp, "({0} ^ {1})"));
            }

            return(ToString(exp, "{0} ^ {1}"));
        }
Ejemplo n.º 29
0
        public void WhenX2Y3_ShouldResult8(
            [Values(2)] double x,
            [Values(3)] double y
            )
        {
            var operation = new Pow(x, y);

            Assert.AreEqual(8, operation.Operate());
        }
Ejemplo n.º 30
0
        public void WhenXMaxValueY2_ShouldArgumentException(
            [Values(double.MaxValue)] double x,
            [Values(2)] double y
            )
        {
            var operation = new Pow(x, y);

            Assert.Throws <ArgumentException>(() => { var result = operation.Operate(); });
        }