/// <summary> /// It's work like this /// x^2 = y /// this = x^2 /// other = y /// this.ReverseAllFunctionsTo(other) /// => this = x /// other = y ^ -2 /// It change current instance! /// </summary> /// <param name="e"></param> /// <returns>Item1 - modified original object, Item2 - modified e param</returns> public Tuple<FunctionElement, FunctionElement> ReverseAllFunctionsTo(FunctionElement e) { FunctionElement e1; if (this.IsLeaf()) { e1 = this.ToLeaf(); } else { e1 = this.Clone() as FunctionElement; } var e2 = e.Clone() as FunctionElement; for (int i = e1.MathFunctions.Count - 1; i >= 0; i--) { if (!e1.MathFunctions[i].Item1.HasReverse()) { break; } List<FunctionElement> pars = new List<FunctionElement>(); pars.Add(e2); pars.AddRange(e1.MathFunctions[i].Item2); e2 = e1.MathFunctions[i].Item1.CalculateReverse(pars.ToArray()); //e2 = e2.ApplyFunction(e1.MathFunctions[i].Item1.FunctionName, e1.MathFunctions[i].Item2); e1.MathFunctions.RemoveAt(i); } Function e11 = new Function(e1); return new Tuple<FunctionElement,FunctionElement>(new Function(e1), e2); }
public override FunctionElement SetVariableValue(string name, FunctionElement value) { if (value.IsDouble()) { return this.SetVariableValue(name, value.ToDouble()); } if (this.Name.Equals(name)) { var temp = value.Clone() as FunctionElement; temp.ForceAddFunctions(this); return temp; } return this.Clone() as FunctionElement; }