using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.ObjectModel; using System.Diagnostics; namespace AutoDiff { /// /// Represents a sum of at least two terms. /// [Serializable] [DebuggerDisplay("Sum: {Terms.Count}")] public class Sum : Term { /// /// Constructs an instance of the class. /// /// The first term in the sum /// The second term in the sum /// The rest of the terms in the sum. public Sum(Term first, Term second, params Term[] rest) { var allTerms = (new Term[] { first, second}).Concat(rest); Terms = allTerms.ToList().AsReadOnly(); } internal Sum(IEnumerable terms) { Terms = Array.AsReadOnly(terms.ToArray()); } /// /// Gets the terms of this sum. /// public ReadOnlyCollection Terms { get; private set; } /// /// Accepts a term visitor /// /// The term visitor to accept. public override void Accept(ITermVisitor visitor) { visitor.Visit(this); } /// /// Accepts a term visitor with a generic result /// /// The type of the result from the visitor's function /// The visitor to accept /// /// The result from the visitor's visit function. /// public override TResult Accept(ITermVisitor visitor) { return visitor.Visit(this); } } }