3using System.Reflection;
5using System.Threading.Tasks;
24 private readonly
string[] argumentNames;
26 private readonly
int nrArguments;
27 private readonly
bool allNormal;
45 this.allNormal =
true;
50 this.allNormal =
false;
130 return Task.FromResult<
IElement>(
this);
152 return Task.FromResult<
IElement>(
this);
163 if (Arguments.Length !=
this.nrArguments)
173 for (i = 0; i < this.nrArguments; i++)
174 Variables[this.argumentNames[i]] = Arguments[i];
199 return this.EvaluateCanonicalExtension(Arguments,
Variables);
218 if (Arguments.Length !=
this.nrArguments)
228 for (i = 0; i < this.nrArguments; i++)
229 Variables[this.argumentNames[i]] = Arguments[i];
254 return await this.EvaluateCanonicalExtensionAsync(Arguments,
Variables);
275 for (j = 0; j < Dimension; j++)
277 for (i = 0; i < this.nrArguments; i++)
279 if (e[i] is
null || !e[i].MoveNext())
280 Arguments2[i] = Arguments[i];
282 Arguments2[i] = e[i].Current;
285 Result.
Add(this.EvaluateCanonicalExtension(Arguments2,
Variables));
292 for (i = 0; i < this.nrArguments; i++)
293 Variables[this.argumentNames[i]] = Arguments[i];
320 for (i = 0, j = e?.
Length ?? 0; i < j; i++)
338 for (j = 0; j < Dimension; j++)
340 for (i = 0; i < this.nrArguments; i++)
342 if (e[i] is
null || !e[i].MoveNext())
343 Arguments2[i] = Arguments[i];
345 Arguments2[i] = e[i].Current;
348 Result.
Add(await this.EvaluateCanonicalExtensionAsync(Arguments2,
Variables));
355 for (i = 0; i < this.nrArguments; i++)
356 Variables[this.argumentNames[i]] = Arguments[i];
383 for (i = 0, j = e?.
Length ?? 0; i < j; i++)
397 e =
new IEnumerator<IElement>[this.nrArguments];
401 for (i = 0; i < this.nrArguments; i++)
403 Argument = Arguments[i];
405 switch (this.argumentTypes[i])
432 else if (!((M = Argument as
IMatrix) is
null))
436 else if (M.
Rows != Dimension)
441 for (j = 0; j < Dimension; j++)
448 else if (!((S = Argument as
ISet) is
null))
455 Dimension = Size.Value;
456 else if (Size.Value != Dimension)
471 if (Argument is
ISet)
478 else if (!((M = Argument as
IMatrix) is
null))
482 else if (M.
Rows != Dimension)
487 for (j = 0; j < Dimension; j++)
512 else if (!((S = Argument as
ISet) is
null))
519 Dimension = Size.Value;
520 else if (Size.Value != Dimension)
540 internal static IElement EncapsulateToVector(ICollection<IElement> Elements,
ScriptNode Node)
553 if (DesiredType.IsAssignableFrom(
this.GetType().GetTypeInfo()))
571 if (Array.IndexOf(
this.argumentNames, VariableName) < 0)
572 return new ConstantElement(Objects.DoubleNumber.ZeroElement,
this.Start,
this.Length,
this.Expression);
574 return new LambdaDefinition(this.argumentNames, this.argumentTypes, Differentiable.Differentiate(VariableName,
Variables),
this.Start,
this.Length,
this.Expression);
586 if (this.argumentNames.Length == 1)
587 return this.argumentNames[0];
608 StringBuilder Result =
new StringBuilder();
622 Result.Append(
"[[]]");
650 return Result.ToString();
A chunked list is a linked list of chunks of objects of type T .
IEnumerator< T > GetEnumerator()
Returns an enumerator for the collection.
void Add(T Item)
Adds an item to the collection.
Exception thrown if argument dimensions are not consistent.
Exception used to break a loop.
Exception used to continue a loop.
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.
static readonly ObjectValue Null
Null value.
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.
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
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(ChunkedList< 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.