/// <summary>
 /// Creates a custom function definition given a name, parameter list, definition, and value expression.
 /// </summary>
 /// <param name="name">the name of the function</param>
 /// <param name="args">the arguments to the function</param>
 /// <param name="def">the definition of the function</param>
 /// <param name="val">the expression that uses the function</param>
 public CustomDefinitionExpression(string name, IReadOnlyList <VariableExpression> args, MathExpression def, MathExpression val)
 {
     FunctionName  = name;
     ParameterList = args;
     Definition    = def;
     Value         = val;
 }
Пример #2
0
 /// <summary>
 /// Constructs a new <see cref="BinaryExpression"/> consisting of the specified arguments and type.
 /// </summary>
 /// <param name="left">the left argument</param>
 /// <param name="right">the right argument</param>
 /// <param name="type">the type of the expression</param>
 public BinaryExpression(MathExpression left, MathExpression right, ExpressionType type)
 {
     if (type < ExpressionType.Add || type >= ExpressionType._Count)
     {
         throw new ArgumentException("Invalid ExpressionType value", nameof(type));
     }
     Type      = type;
     Arguments = new List <MathExpression> {
         left, right
     };
 }
        /// <summary>
        /// Creates a custom function definition from a <see cref="BinaryExpression"/> of type
        /// <see cref="BinaryExpression.ExpressionType.Equals"/> as the definition, and an expression
        /// for the value.
        /// </summary>
        /// <param name="assignExpr">the expression to deconstruct for the name and arguments</param>
        /// <param name="valueExpr">the expression to use as a <see cref="Value"/></param>
        public CustomDefinitionExpression(BinaryExpression assignExpr, MathExpression valueExpr)
        {
            if (!(assignExpr is BinaryExpression bexp) || bexp.Type != BinaryExpression.ExpressionType.Equals)
            {
                throw new ArgumentException("Expected Equals expression");
            }
            var fn = bexp.Left;

            if (!(fn is FunctionExpression func) || !func.IsUserDefined)
            {
                throw new ArgumentException("Left side of definition must be a prime function");
            }
            if (!func.Arguments.All(e => e is VariableExpression))
            {
                throw new ArgumentException("Left side of definition cannot contain arguments with expressions");
            }

            FunctionName  = func.Name;
            ParameterList = func.Arguments.Cast <VariableExpression>().ToList();
            Definition    = bexp.Right;
            Value         = valueExpr;
        }
Пример #4
0
 /// <summary>
 /// Compares this expression to the parameter for equality.
 /// </summary>
 /// <param name="other">the expression to compare to</param>
 /// <returns><see langword="true"/> if the two are equal, <see langword="false"/> otherwise</returns>
 public abstract bool Equals(MathExpression other);
Пример #5
0
 /// <inheritdoc/>
 public override bool Equals(MathExpression other)
 => other is MemberExpression mem &&
Пример #6
0
 /// <summary>
 /// Constructs a new <see cref="MemberExpression"/> for a given target and member name.
 /// </summary>
 /// <param name="target">the target of the access</param>
 /// <param name="member">the name of the member to access</param>
 public MemberExpression(MathExpression target, string member)
 {
     Target     = target;
     MemberName = member;
 }
Пример #7
0
 /// <inheritdoc/>
 public override bool Equals(MathExpression other)
 => other is UnaryExpression e &&
Пример #8
0
 /// <summary>
 /// Constructs a new <see cref="UnaryExpression"/> of the specified type, with the given argument.
 /// </summary>
 /// <param name="type">the type of the expression</param>
 /// <param name="arg">the argument of the expression</param>
 public UnaryExpression(ExpressionType type, MathExpression arg)
 {
     Type     = type;
     Argument = arg;
 }
 /// <summary>
 /// Compares this expression to the parameter for equality.
 /// </summary>
 /// <param name="other">the expression to compare to</param>
 /// <returns><see langword="true"/> if the two are equal, <see langword="false"/> otherwise</returns>
 public override bool Equals(MathExpression other)
 => other is CustomDefinitionExpression cde &&
Пример #10
0
 /// <inheritdoc/>
 public override bool Equals(MathExpression other)
 => other is VariableExpression v && v.Name == Name;
Пример #11
0
 /// <inheritdoc/>
 public override bool Equals(MathExpression other)
 => other is FunctionExpression f &&