using AngouriMath; namespace AIStudio.Tools.Mathematics; /// /// The variables of an expression, as the Mathematics tools count them. /// /// /// AngouriMath counts the constants pi and e among the free variables, so ln(0) has the free /// variable e, the base of its logarithm. Asked for the variables of an expression, the tools mean /// those which have no value, see AngouriMathBehaviorTests. /// public static class MathVariables { /// /// The free variables of an expression without the constants, in the order of their names. /// /// The expression. /// Each variable once. public static IReadOnlyList FreeIn(Entity expression) => expression.FreeVariables .Where(variable => variable is not Entity.Constant) .Distinct() .OrderBy(variable => variable.Name, StringComparer.Ordinal) .ToList(); /// /// Whether an expression has a free variable other than the constants. /// /// The expression. /// True when a variable without a value occurs freely. public static bool HasAny(Entity expression) => expression.FreeVariables.Any(variable => variable is not Entity.Constant); }