public override INumber Add(Runtime.RuntimeData runtime, INumber val) { AdditionFormula af = new AdditionFormula(); af.AddItem(runtime, this); af.AddItem(runtime, val); return(af); }
public override INumber Execute(RuntimeData runtime, params INumber[] parameters) { var res = parameters[1].Integrate(runtime, parameters[0].Token.Text); var c = IntegralConstant.Create(runtime); AdditionFormula af = new AdditionFormula(); af.AddItem(runtime, res); af.AddItem(runtime, c); runtime.AddLogWay("Equal", new FuncedINumber(this, parameters), af); runtime.AddLogCondition("IntegralConstant", c); runtime.SetVariable(runtime, new Variable(c.ToString()), c); return(af); }
private INumber ExecuteDiff(RuntimeData runtime, INumber formula, string t, INumber param0) { if (formula is AdditionFormula) { AdditionFormula af = new AdditionFormula(); AdditionFormula f = formula as AdditionFormula; for (int i = 0; i < f.Count; i++) { var res = DiffExecute(runtime, t, f.Items[i], param0, false); if (res is Number && (res as Number).Value == 0) { continue; } af.AddItem(res); } return(af); } else if (formula is Variable && // 微分しようとした変数がユーザー定義関数だった場合 runtime.Functions.ContainsKey((formula as Variable).Name) && runtime.Functions[(formula as Variable).Name] is UserDefineFunction) { var f = runtime.Functions[(formula as Variable).Name] as UserDefineFunction; return(this.Execute(runtime, param0, f.Formula.Eval(runtime))); } else if (formula is Member && // 微分しようとした変数がユーザー定義関数だった場合 runtime.Functions.ContainsKey((formula as Member).Text) && runtime.Functions[(formula as Member).Text] is UserDefineFunction) { var f = runtime.Functions[(formula as Member).Text] as UserDefineFunction; return(this.Execute(runtime, param0, f.Formula.Eval(runtime))); } else if (formula is MultipleFormula) { throw new NotImplementedException(); } else if (formula is Variable) { return(DiffExecute(runtime, t, formula as Variable, param0, false)); } else if (formula is Member) { var v = new Variable((formula as Member).Token); return(DiffExecute(runtime, t, v, param0, false)); } else if (formula is IConstParameter) { return(Number.New(0)); } throw new NotImplementedException(); }