예제 #1
0
        public override INumber Integrate(RuntimeData runtime, string t)
        {
            // 計算し易いように条件を最適化しておく
            var ress = this.Clone().Optimise(runtime);

            if (!(ress is Fraction))
            {
                return(ress.Integrate(runtime, t));
            }

            var res = ress as Fraction;



            // 特殊な定義: ∫(b / x^a)dx → b*log(x) / a
            // ∫(1 / x^2)dxとかはこの条件に当てはまらないので注意しないといけない
            if (runtime.IsConstValue(res.Numerator) &&
                ((res.Denominator is Variable && (res.Denominator as Variable).Name == t) ||
                 (res.Denominator is Member && (res.Denominator as Member).Text == t)) &&
                runtime.IsConstValue(res.Denominator.Pow))
            {
                MultipleFormula mf = new Expression.MultipleFormula();
                mf.AddItem(runtime, res.Numerator);
                mf.AddItem(runtime, new Fraction(res.Denominator.Pow, Number.New(1)));
                mf.AddItem(runtime, new FuncedINumber(
                               runtime.Functions["log"],
                               new INumber[] { new NaturalLogarithm(), res.Denominator }));
                if (runtime.Setting.DoOptimize)
                {
                    return(mf.Optimise(runtime));
                }
                else
                {
                    return(mf);
                }
            }

            // 分母も分子も定数しか含まれていない → 定数として扱う
            if (runtime.IsConstValue(res.Denominator) &&
                runtime.IsConstValue(res.Numerator))
            {
                MultipleFormula mf = new Expression.MultipleFormula();
                mf.AddItem(runtime, res);
                mf.AddItem(runtime, new Variable(t));
                return(mf);
            }

            // 事前に分母と分子に存在する定数を外に出して計算した方がいい
            runtime.Setting.Logger.AddInfo("分数の積分は申し訳程度にしか実装していません。");

            throw new NotImplementedException("分数の積分はあまり対応してない");
        }
예제 #2
0
        public override INumber ForceExecute(RuntimeData runtime, params INumber[] parameters)
        {
            var param = parameters[0].FinalEval(runtime);

            if (runtime.IsConstValue(param))
            {
                return(new FloatNumber((decimal)(System.Math.Tan((double)(param as IConstParameter).ConstValue))));
            }
            return(param);
        }
예제 #3
0
        public override INumber ForceExecute(RuntimeData runtime, params INumber[] parameters)
        {
            var param = parameters[1].FinalEval(runtime);
            var Base  = parameters[0].FinalEval(runtime);

            if (parameters[0] is NaturalLogarithm &&
                parameters[0].Pow is Number &&
                (parameters[0].Pow as Number).Value == 1)
            {
                return(new FloatNumber((decimal)(System.Math.Log(
                                                     (double)(param as IConstParameter).ConstValue))));
            }
            if (runtime.IsConstValue(param) && runtime.IsConstValue(Base))
            {
                return(new FloatNumber((decimal)(System.Math.Log(
                                                     (double)(param as IConstParameter).ConstValue,
                                                     (double)(Base as IConstParameter).ConstValue))));
            }
            return(param);
        }
예제 #4
0
        public override INumber Power(RuntimeData runtime, INumber val)
        {
            var pow = val.FinalEval(runtime);

            if (pow is IConstParameter && (pow as IConstParameter).ConstValue == 0)
            {
                return(Number.New(1));
            }

            if (runtime.IsConstValue(pow))
            {
                var me = this.Clone() as FloatNumber;
                me.value = (decimal)Math.Pow((double)this.value, (double)(pow as IConstParameter).ConstValue);
                return(me);
            }
            return(base.Power(runtime, val));
        }