private LutFunction(string Name, IEnumerable <Arrow> Points) : base(Name) { parameters = new List <Variable>() { Variable.New("x1") }; foreach (Arrow i in Points) { points.Add((double)i.Left, (double)i.Right); } }
// Expand N(x)/D(x) using partial fractions. private static Expression ExpandPartialFractions(Expression N, Expression D, Expression x) { List <Expression> terms = new List <Expression>(); List <Variable> unknowns = new List <Variable>(); List <Expression> basis = new List <Expression>(); foreach (Expression i in Product.TermsOf(D)) { // Get the multiplicity of this basis term. Expression e = i; int n = Power.IntegralExponentOf(e); if (n != 1) { e = ((Power)i).Left; } // Convert to a polynomial. Polynomial Pi = Polynomial.New(e, x); // Add new terms for each multiplicity n. for (int j = 1; j <= n; ++j) { // Expression for the unknown numerator of this term. Expression unknown = 0; for (int k = 0; k < Pi.Degree; ++k) { Variable Ai = Variable.New("_A" + unknowns.Count.ToString()); unknown += Ai * (x ^ k); unknowns.Add(Ai); } terms.Add(Product.New(unknown, Power.New(e, -j))); } basis.Add(i); } // Equate the original expression with the decomposed expressions. D = Sum.New(terms.Select(j => (Expression)(D * j))).Expand(); Polynomial l = Polynomial.New(N, x); Polynomial r = Polynomial.New(D, x); // Equate terms of equal degree and solve for the unknowns. int degree = Math.Max(l.Degree, r.Degree); List <Equal> eqs = new List <Equal>(degree + 1); for (int i = 0; i <= degree; ++i) { eqs.Add(Equal.New(l[i], r[i])); } List <Arrow> A = eqs.Solve(unknowns); // Substitute the now knowns. return(Sum.New(terms.Select(i => i.Evaluate(A)))); }
private Expression Resolve(string Token) { Expression resolve = context.LookupName(Token).SingleOrDefault(); if (!ReferenceEquals(resolve, null)) { return(resolve); } else { return(Variable.New(Token)); } }
protected override string VisitSet(Set S) { IEnumerable <Expression> members = S.Members; // If there are more than 100 elements in the set, truncate all but 5 elements and append '...'. if (members.Skip(100).Any()) { members = members.Take(5).Append(Variable.New("...")); } string s = "{" + Join(members, ", ") + "}"; return(s); }
public static UnknownFunction New(string Name, int ParamCount) { return(New(Name, Enumerable.Range(0, ParamCount).Select(i => Variable.New("_" + i.ToString())))); }
private static Expression ChildPattern(ref int unique) { unique++; return(Variable.New("_" + unique.ToString())); }