static public Tuple<List<TaylorStructure>, List<TaylorStructure>> GetExpansionStruct(AST f, string[] variables, int maxOrder) { TaylorStructure[] result = new TaylorStructure[MaxIndex(variables.Length, maxOrder+1) + 1]; Queue<TaylorStructure> queue = new Queue<TaylorStructure>(); Log.Debug.WriteLine("Original ODE: F = {0}", f); TaylorStructure ts = new TaylorStructure(); ts.degrees = new int[variables.Length]; ts.func = f; ts.order = 0; ts.coeff = 1; queue.Enqueue(ts); while (queue.Count > 0) { TaylorStructure e = queue.Dequeue(); int idx = GetIndex(e.degrees, maxOrder); result[idx] = e; Log.Debug.WriteLine("dF / {0} = {1}", GetEquation(e.degrees, variables), e.func); if (e.order == maxOrder) continue; for (int i = 0; i < variables.Length; ++i) { TaylorStructure next = new TaylorStructure(); next.degrees = (int[])e.degrees.Clone(); next.degrees[i]++; int nextidx = GetIndex(next.degrees, maxOrder); if (result[nextidx] != null) continue; // already calculated next.order = e.order + 1; next.coeff = 1; foreach (var d in next.degrees) next.coeff *= fact(d); next.func = e.func.GetDerivative(variables[i]).Simplify(); queue.Enqueue(next); } } Log.Debug.Flush(); List<TaylorStructure> res = new List<TaylorStructure>(); List<TaylorStructure> error = new List<TaylorStructure>(); foreach (TaylorStructure e in result) if (e != null) { if (e.order <= maxOrder) res.Add(e); else error.Add(e); } return Tuple.Create(res,error); }
public override AST Substitute(string var, AST term) { return this; }
public SQRT(AST term) { children = new AST[1]; children[0] = term; type = TYPE.SQRT; }
public override AST Substitute(string var, AST term) { return new SQRT(children[0].Substitute(var, term)); }
public EXP(AST term) { children = new AST[1]; children[0] = term; type = TYPE.EXP; }
public override AST Substitute(string var, AST term) { return new POW(children[0].Substitute(var, term), power); }
public SIN(AST term) { children = new AST[1]; children[0] = term; type = TYPE.SIN; }
public COS(AST term) { children = new AST[1]; children[0] = term; type = TYPE.COS; }
public NEG(AST term) { children = new AST[1]; children[0] = term; type = TYPE.NEG; }
abstract public AST Substitute(string var, AST term);
public override AST Substitute(string var, AST term) { return name.Equals(var) ? term : this; }
public GT(AST lhs, AST rhs) { this.type = TYPE.GT; this.lhs = lhs; this.rhs = rhs; }
public LT(AST lhs, AST rhs) { this.type = TYPE.LT; this.lhs = lhs; this.rhs = rhs; }
public GE(AST lhs, AST rhs) { this.type = TYPE.GE; this.lhs = lhs; this.rhs = rhs; }
public LE(AST lhs, AST rhs) { this.type = TYPE.LE; this.lhs = lhs; this.rhs = rhs; }