private IElement EvaluateCanonicalExtension(IElement[] Arguments, Variables Variables)
        {
            ICollection <IElement> ChildElements;

            IEnumerator <IElement>[] e = new IEnumerator <IElement> [this.nrArguments];
            IElement            Argument;
            Encapsulation       Encapsulation = null;
            IMatrix             M;
            ISet                S;
            IVectorSpaceElement V;
            int Dimension = -1;
            int i, j;

            for (i = 0; i < this.nrArguments; i++)
            {
                Argument = Arguments[i];

                switch (this.argumentTypes[i])
                {
                case ArgumentType.Normal:
                    e[i] = null;
                    break;

                case ArgumentType.Scalar:
                    if (Argument.IsScalar)
                    {
                        e[i] = null;
                    }
                    else
                    {
                        ChildElements = Argument.ChildElements;

                        if (Dimension < 0)
                        {
                            Dimension = ChildElements.Count;
                        }
                        else if (ChildElements.Count != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        e[i] = ChildElements.GetEnumerator();
                        if (Encapsulation is null)
                        {
                            Encapsulation = Argument.Encapsulate;
                        }
                    }
                    break;

                case ArgumentType.Vector:
                    if (Argument is IVectorSpaceElement)
                    {
                        e[i] = null;
                    }
                    else if (!((M = Argument as IMatrix) is null))
                    {
                        if (Dimension < 0)
                        {
                            Dimension = M.Rows;
                        }
                        else if (M.Rows != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        LinkedList <IElement> Vectors = new LinkedList <IElement>();

                        for (j = 0; j < Dimension; j++)
                        {
                            Vectors.AddLast(M.GetRow(j));
                        }

                        e[i] = Vectors.GetEnumerator();
                        if (Encapsulation is null)
                        {
                            Encapsulation = EncapsulateToVector;
                        }
                    }
                    else if (!((S = Argument as ISet) is null))
                    {
                        int?Size = S.Size;
                        if (!Size.HasValue)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        if (Dimension < 0)
                        {
                            Dimension = Size.Value;
                        }
                        else if (Size.Value != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        e[i] = S.ChildElements.GetEnumerator();
                        if (Encapsulation is null)
                        {
                            Encapsulation = Argument.Encapsulate;
                        }
                    }
Example #2
0
        private IElement EvaluateCanonicalExtension(IElement[] Arguments, Variables Variables)
        {
            ICollection <IElement> ChildElements;

            IEnumerator <IElement>[] e = new IEnumerator <IElement> [this.nrArguments];
            IElement            Argument;
            Encapsulation       Encapsulation = null;
            IMatrix             M;
            ISet                S;
            IVectorSpaceElement V;
            int Dimension = -1;
            int i, j;

            for (i = 0; i < this.nrArguments; i++)
            {
                Argument = Arguments[i];

                switch (this.argumentTypes[i])
                {
                case ArgumentType.Normal:
                    e[i] = null;
                    break;

                case ArgumentType.Scalar:
                    if (Argument.IsScalar)
                    {
                        e[i] = null;
                    }
                    else
                    {
                        ChildElements = Argument.ChildElements;

                        if (Dimension < 0)
                        {
                            Dimension = ChildElements.Count;
                        }
                        else if (ChildElements.Count != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        e[i] = ChildElements.GetEnumerator();
                        if (Encapsulation == null)
                        {
                            Encapsulation = Argument.Encapsulate;
                        }
                    }
                    break;

                case ArgumentType.Vector:
                    if (Argument is IVector)
                    {
                        e[i] = null;
                    }
                    else if ((M = Argument as IMatrix) != null)
                    {
                        if (Dimension < 0)
                        {
                            Dimension = M.Rows;
                        }
                        else if (M.Rows != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        LinkedList <IElement> Vectors = new LinkedList <IElement>();

                        for (j = 0; j < Dimension; j++)
                        {
                            Vectors.AddLast(M.GetRow(j));
                        }

                        e[i] = Vectors.GetEnumerator();
                        if (Encapsulation == null)
                        {
                            Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
                        }
                    }
                    else if ((S = Argument as ISet) != null)
                    {
                        int?Size = S.Size;
                        if (!Size.HasValue)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        if (Dimension < 0)
                        {
                            Dimension = Size.Value;
                        }
                        else if (Size.Value != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        e[i] = S.ChildElements.GetEnumerator();
                        if (Encapsulation == null)
                        {
                            Encapsulation = Argument.Encapsulate;
                        }
                    }
                    else
                    {
                        Arguments[i] = Operators.Vectors.VectorDefinition.Encapsulate(new IElement[] { Argument }, false, this);
                        e[i]         = null;
                    }
                    break;

                case ArgumentType.Set:
                    if (Argument is ISet)
                    {
                        e[i] = null;
                    }
                    else if ((V = Argument as IVectorSpaceElement) != null)
                    {
                        Arguments[i] = Operators.Sets.SetDefinition.Encapsulate(V.ChildElements, this);
                        e[i]         = null;
                    }
                    else if ((M = Argument as IMatrix) != null)
                    {
                        if (Dimension < 0)
                        {
                            Dimension = M.Rows;
                        }
                        else if (M.Rows != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        LinkedList <IElement> Vectors = new LinkedList <IElement>();

                        for (j = 0; j < Dimension; j++)
                        {
                            Vectors.AddLast(M.GetRow(j));
                        }

                        Arguments[i]  = Argument = Operators.Sets.SetDefinition.Encapsulate(Vectors, this);
                        ChildElements = Argument.ChildElements;

                        e[i] = ChildElements.GetEnumerator();
                        if (Encapsulation == null)
                        {
                            Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
                        }
                    }
                    else
                    {
                        Arguments[i] = Operators.Sets.SetDefinition.Encapsulate(new IElement[] { Argument }, this);
                        e[i]         = null;
                    }
                    break;

                case ArgumentType.Matrix:
                    if (Argument is IMatrix)
                    {
                        e[i] = null;
                    }
                    else if ((V = Argument as IVectorSpaceElement) != null)
                    {
                        Arguments[i] = Operators.Matrices.MatrixDefinition.Encapsulate(V.ChildElements, 1, V.Dimension, this);
                        e[i]         = null;
                    }
                    else if ((S = Argument as ISet) != null)
                    {
                        int?Size = S.Size;
                        if (!Size.HasValue)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        if (Dimension < 0)
                        {
                            Dimension = Size.Value;
                        }
                        else if (Size.Value != Dimension)
                        {
                            throw new ScriptRuntimeException("Argument dimensions not consistent.", this);
                        }

                        e[i] = S.ChildElements.GetEnumerator();
                        if (Encapsulation == null)
                        {
                            Encapsulation = Argument.Encapsulate;
                        }
                    }
                    else
                    {
                        Arguments[i] = Operators.Matrices.MatrixDefinition.Encapsulate(new IElement[] { Argument }, 1, 1, this);
                        e[i]         = null;
                    }
                    break;

                default:
                    throw new ScriptRuntimeException("Unhandled argument type.", this);
                }
            }

            if (Encapsulation != null)
            {
                LinkedList <IElement> Result     = new LinkedList <IElement>();
                IElement[]            Arguments2 = new IElement[this.nrArguments];

                for (j = 0; j < Dimension; j++)
                {
                    for (i = 0; i < this.nrArguments; i++)
                    {
                        if (e[i] == null || !e[i].MoveNext())
                        {
                            Arguments2[i] = Arguments[i];
                        }
                        else
                        {
                            Arguments2[i] = e[i].Current;
                        }
                    }

                    Result.AddLast(this.EvaluateCanonicalExtension(Arguments2, Variables));
                }

                return(Encapsulation(Result, this));
            }
            else
            {
                return(this.Evaluate(Arguments, Variables));
            }
        }
Example #3
0
 IEnumerator <IHtml> IEnumerable <IHtml> .GetEnumerator() => ChildElements.GetEnumerator();