2using System.Collections.Generic;
3using System.Reflection;
13using System.Threading.Tasks;
22 private readonly
string[] argumentNames;
24 private readonly
int nrArguments;
25 private readonly
bool allNormal;
43 this.allNormal =
true;
48 this.allNormal =
false;
117 return Task.FromResult<
IElement>(
this);
139 return Task.FromResult<
IElement>(
this);
150 if (Arguments.Length !=
this.nrArguments)
160 for (i = 0; i < this.nrArguments; i++)
161 Variables[this.argumentNames[i]] = Arguments[i];
173 return this.EvaluateCanonicalExtension(Arguments,
Variables);
192 if (Arguments.Length !=
this.nrArguments)
202 for (i = 0; i < this.nrArguments; i++)
203 Variables[this.argumentNames[i]] = Arguments[i];
215 return await this.EvaluateCanonicalExtensionAsync(Arguments,
Variables);
231 LinkedList<IElement> Result =
new LinkedList<IElement>();
234 for (j = 0; j < Dimension; j++)
236 for (i = 0; i < this.nrArguments; i++)
238 if (e[i] is
null || !e[i].MoveNext())
239 Arguments2[i] = Arguments[i];
241 Arguments2[i] = e[i].Current;
244 Result.AddLast(this.EvaluateCanonicalExtension(Arguments2,
Variables));
251 for (i = 0; i < this.nrArguments; i++)
252 Variables[this.argumentNames[i]] = Arguments[i];
273 LinkedList<IElement> Result =
new LinkedList<IElement>();
276 for (j = 0; j < Dimension; j++)
278 for (i = 0; i < this.nrArguments; i++)
280 if (e[i] is
null || !e[i].MoveNext())
281 Arguments2[i] = Arguments[i];
283 Arguments2[i] = e[i].Current;
286 Result.AddLast(await this.EvaluateCanonicalExtensionAsync(Arguments2,
Variables));
293 for (i = 0; i < this.nrArguments; i++)
294 Variables[this.argumentNames[i]] = Arguments[i];
316 e =
new IEnumerator<IElement>[this.nrArguments];
320 for (i = 0; i < this.nrArguments; i++)
322 Argument = Arguments[i];
324 switch (this.argumentTypes[i])
351 else if (!((M = Argument as
IMatrix) is
null))
355 else if (M.
Rows != Dimension)
358 LinkedList<IElement> Vectors =
new LinkedList<IElement>();
360 for (j = 0; j < Dimension; j++)
361 Vectors.AddLast(M.
GetRow(j));
363 e[i] = Vectors.GetEnumerator();
367 else if (!((S = Argument as
ISet) is
null))
374 Dimension = Size.Value;
375 else if (Size.Value != Dimension)
390 if (Argument is
ISet)
397 else if (!((M = Argument as
IMatrix) is
null))
401 else if (M.
Rows != Dimension)
404 LinkedList<IElement> Vectors =
new LinkedList<IElement>();
406 for (j = 0; j < Dimension; j++)
407 Vectors.AddLast(M.
GetRow(j));
431 else if (!((S = Argument as
ISet) is
null))
438 Dimension = Size.Value;
439 else if (Size.Value != Dimension)
459 internal static IElement EncapsulateToVector(ICollection<IElement> Elements,
ScriptNode Node)
472 if (DesiredType.GetTypeInfo().IsAssignableFrom(
this.GetType().GetTypeInfo()))
490 if (Array.IndexOf(
this.argumentNames, VariableName) < 0)
491 return new ConstantElement(Objects.DoubleNumber.ZeroElement,
this.Start,
this.Length,
this.Expression);
493 return new LambdaDefinition(this.argumentNames, this.argumentTypes, Differentiable.Differentiate(VariableName,
Variables),
this.Start,
this.Length,
this.Expression);
505 if (this.argumentNames.Length == 1)
506 return this.argumentNames[0];
527 StringBuilder Result =
new StringBuilder();
541 Result.Append(
"[[]]");
569 return Result.ToString();
Script runtime exception.
IElement ReturnValue
Return value.
Script runtime exception.
Class managing a script expression.
Represents a constant element value.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
int Start
Start position in script expression.
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Base class for all unary operators.
ScriptNode Operand
Operand.
Set containing all functions.
static readonly SetOfFunctions Instance
Instance of the set of all functions.
bool IsScalar
If the element represents a scalar value.
override Task< IElement > EvaluateAsync(IElement Operand, Variables Variables)
Evaluates the operator.
static string ToString(ILambdaExpression Expression)
Creates a displayable string for a lambda expression.
ISet AssociatedSet
Associated Set.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
string[] ArgumentNames
Argument Names.
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
int NrArguments
Number of arguments.
object AssociatedObjectValue
Associated object value.
bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the lambda expression.
ArgumentType[] ArgumentTypes
Argument types.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
LambdaDefinition(string[] ArgumentNames, ArgumentType[] ArgumentTypes, ScriptNode Operand, int Start, int Length, Expression Expression)
Lambda Definition.
override Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override IElement Evaluate(IElement Operand, Variables Variables)
Evaluates the operator.
async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the lambda expression.
override string DefaultVariableName
Default variable name, if any, null otherwise.
override string ToString()
ScriptNode Differentiate(string VariableName, Variables Variables)
Differentiates a lambda expression, if possible.
static IMatrix Encapsulate(ICollection< IElement > Rows, ScriptNode Node)
Encapsulates the elements of a matrix.
static IElement Encapsulate(ICollection< IElement > Elements)
Encapsulates the elements of a set.
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
virtual void Push()
Pushes the current set of variables to the stack. This state is restored by calling Pop....
virtual void Pop()
Pops a previously stored set of variables from the stack. Variables are stored on the stack by callin...
Basic interface for all types of elements.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Basic interface for matrices.
IVector GetRow(int Row)
Gets a row vector from the matrix.
int Dimension
Dimension of vector.
Basic interface for all types of module elements.
Basic interface for all types of sets.
int? Size
Size of set, if finite and known, otherwise null is returned.
Base interface for lambda expressions.
Base interface for lambda expressions.
bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
delegate IElement Encapsulation(ICollection< IElement > Elements, ScriptNode Node)
Delegate for encapsulation methods.
ArgumentType
Type of parameter used in a function definition or a lambda definition.