public override INumber Add(Runtime.RuntimeData runtime, INumber val) { if (val is Array) { Array res = new Array(); Array v = val as Array; for (int x = 0; x < Math.Max(this.items.Count, v.items.Count); x++) { int c_count = 0; bool flag1 = false, flag2 = false; if (this.items.Count > x) { c_count = this.items[x].Count; flag1 = true; } if (v.items.Count > x) { c_count = Math.Max(c_count, v.items[x].Count); flag2 = true; } if (x != 0) { res.items.Add(new List <INumber>()); } for (int y = 0; y < c_count; y++) { INumber d = Number.New(0); if (flag1 && this.items[x].Count > y) { d = d.Add(runtime, this.items[x][y]); } if (flag2 && v.items[x].Count > y) { d = d.Add(runtime, v.items[x][y]); } res.items[x].Add(d); } } return(res); } else { var res = this.Clone() as Array; for (int x = 0; x < res.items.Count; x++) { for (int y = 0; y < res.items[x].Count; y++) { res.items[x][y] = res.items[x][y].Add(runtime, val); } } return(res); } }
public INumber Execute(RuntimeData runtime, INumber left, INumber right) { var dt = left.Eval(runtime); runtime.Setting.Spec.Operations.Where(a => a.Key.GetType() == typeof(Substitution)).First().Key .Execute(runtime, left, left.Add(runtime, Number.New(1))); return(dt); }
public override INumber Add(RuntimeData runtime, INumber val) { if (val.Pow is Number && (val.Pow as Number).Value == 1) { if (val is Number) { var me = this.Clone() as Fraction; me.Numerator = me.Numerator.Add(runtime, this.Denominator.Multiple(runtime, val)); return(me); } if (val is Fraction) { var me = this.Clone() as Fraction; // 分母が同じ場合は単純に足す if (this.Denominator.Equals(runtime, val)) { var res = new Fraction(this.Denominator, this.Numerator.Add(runtime, (val as Fraction).Numerator)); if (runtime.Setting.DoOptimize) { return(res.Optimise(runtime)); } else { return(res); } } // 違う場合はいろいろやる else { var res = new Fraction( this.Denominator.Multiple(runtime, (val as Fraction).Denominator), this.Numerator.Multiple(runtime, (val as Fraction).Denominator).Add(runtime, this.Denominator.Multiple(runtime, (val as Fraction).Numerator)) ); if (runtime.Setting.DoOptimize) { return(res.Optimise(runtime)); } else { return(res); } } } } else if (val is Number || val is Fraction) { AdditionFormula af = new AdditionFormula(); af.AddItem(runtime, this); af.AddItem(runtime, val); return(af); } return(val.Add(runtime, this)); }
public override INumber FinalEval(RuntimeData runtime) { INumber res = Number.New(0); for (int i = 0; i < this.items.Count; i++) { res = res.Add(runtime, this.items[i].FinalEval(runtime)); } return(res); }
public INumber Sum(INumber[] arrayNumbers) { INumber res = arrayNumbers[0]; for (var i = 1; i < arrayNumbers.Length; ++i) { res = res.Add(arrayNumbers[i]); } return(res); }
public override INumber Add(RuntimeData runtime, INumber val) { if (val is Number) { if (this.Pow.Equals(runtime, val.Pow)) { return(Number.New(this.Value + (val as Number).Value)); } else { AdditionFormula af = new Expression.AdditionFormula(); af.AddItem(runtime, this); af.AddItem(runtime, val); return(af); } } return(val.Add(runtime, this)); }
public override INumber Multiple(Runtime.RuntimeData runtime, INumber val) { if (val is Array) { throw new NotImplementedException("配列同士の乗はまだ田対応していません。"); var v = val as Array; int max_col = 0; for (int x = 0; x < v.items.Count; x++) { max_col = Math.Max(max_col, v.items[x].Count); } for (int x = 0; x < this.items.Count; x++) { INumber d = Number.New(0); for (int y = 0; y < this.items[x].Count; y++) { if (v.items.Count > y && v.items[y].Count > x) { d = d.Add(runtime, this.items[x][y].Multiple(runtime, v.items[y][x])); } } } } else { var res = this.Clone() as Array; for (int x = 0; x < this.items.Count; x++) { for (int y = 0; y < this.items[x].Count; y++) { res.items[x][y] = res.items[x][y].Multiple(runtime, val); } } return(res); } }
public INumber Execute(RuntimeData runtime, INumber left, INumber right) { return(left.Add(runtime, right)); }
INumber CheckMulti(RuntimeData runtime, string varname, INumber val, out INumber pow) { if (val is IConstParameter) { pow = Number.New(0); return(val); } if (val is Variable) { if ((val as Variable).Name == varname) { pow = val.Pow; return((val as Variable).Multi); } else { pow = Number.New(0); return(val); } } if (val is Member) { if ((val as Member).Text == varname) { pow = val.Pow; return((val as Member).Multi); } else { pow = Number.New(0); return(val); } } if (val is MultipleFormula) { MultipleFormula mf = val as MultipleFormula; INumber res = Number.New(0); INumber pres = Number.New(1); bool flag = false; for (int i = 0; i < mf.Items.Count; i++) { var item = mf.Items[i]; INumber p = null; var r = this.CheckMulti(runtime, varname, item, out p); if (p is Number && (p as Number).Value == 0) { res = res.Multiple(runtime, r); } else { flag = true; pres = pres.Add(runtime, p); res = res.Multiple(runtime, r); } } if (flag) { pow = pres; return(res); } else { pow = Number.New(0); return(res); } } if (val is AdditionFormula) { throw new RuntimeException("バグ: [AF]のアイテム評価関数に[AF]が指定されました。", val); } throw new NotImplementedException("[AF]のアイテム評価関数の未実装"); }