Пример #1
0
        public virtual Algebraic Map(LambdaAlgebraic lambda, Algebraic arg)
        {
            if (arg == null)
            {
                var r = lambda.SymEval(this);

                if (r != null)
                {
                    return(r);
                }

                var fname = lambda.GetType().Name;

                if (fname.StartsWith("Lambda", StringComparison.Ordinal))
                {
                    fname = fname.Substring("Lambda".Length);
                    fname = fname.ToLower();

                    return(FunctionVariable.Create(fname, this));
                }

                throw new SymbolicException("Wrong type of arguments.");
            }

            return(lambda.SymEval(this, arg));
        }
Пример #2
0
        public override Algebraic Map(LambdaAlgebraic f, Algebraic args)
        {
            if (args is Vector && (( Vector )args).Length() == _items.Length)
            {
                // TODO: Check this
                var v = _items.Select((x, n) => x.Map(f, (( Vector )args)[n])).ToList();

                if (v.Any(x => !(x is Algebraic)))
                {
                    throw new SymbolicException("Cannot evaluate function to algebraic.");
                }

                return(new Vector(v.Cast <Algebraic>().ToArray()));
            }
            else
            {
                // TODO: Check this
                var v = _items.Select(x => x.Map(f, args)).ToList();

                if (v.Any(x => !(x is Algebraic)))
                {
                    throw new SymbolicException("Cannot evaluate function to algebraic.");
                }

                return(new Vector(v.Cast <Algebraic>().ToArray()));
            }
        }
Пример #3
0
        public override Algebraic Map(LambdaAlgebraic lambda, Algebraic arg)
        {
            if (arg == null)
            {
                var r = lambda.PreEval(this);

                if (r != null)
                {
                    return(r);
                }
            }

            return(base.Map(lambda, arg));
        }
Пример #4
0
        public override Algebraic Map(LambdaAlgebraic f)
        {
            var cn = CreateRectangularArray <Algebraic>(a.Length, a[0].Length);

            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    cn[i][k] = f.SymEval(a[i][k]);
                }
            }

            return(new Matrix(cn));
        }
Пример #5
0
        public override Algebraic Map(LambdaAlgebraic f, Algebraic arg)
        {
            var b = CreateRectangularArray <Algebraic>(a.Length, a[0].Length);

            if (arg is Matrix && Equalsized(( Matrix )arg))
            {
                for (var i = 0; i < a.Length; i++)
                {
                    for (var k = 0; k < a[0].Length; k++)
                    {
                        var c = (( Matrix )arg)[i, k];

                        object r = a[i][k].Map(f, c);

                        if (r is Algebraic)
                        {
                            b[i][k] = ( Algebraic )r;
                        }
                        else
                        {
                            throw new SymbolicException("Cannot evaluate function to algebraic.");
                        }
                    }
                }
            }
            else
            {
                for (var i = 0; i < a.Length; i++)
                {
                    for (var k = 0; k < a[0].Length; k++)
                    {
                        object r = a[i][k].Map(f, arg);

                        if (r is Algebraic)
                        {
                            b[i][k] = ( Algebraic )r;
                        }
                        else
                        {
                            throw new SymbolicException("Cannot evaluate function to algebraic.");
                        }
                    }
                }
            }

            return(new Matrix(b));
        }
Пример #6
0
 public abstract Algebraic Map(LambdaAlgebraic f);
Пример #7
0
 public override Algebraic Map(LambdaAlgebraic f)
 {
     return(new Vector(_items.Select(f.SymEval).ToArray()));
 }
Пример #8
0
 public override Algebraic Map(LambdaAlgebraic lambda)
 {
     return(lambda.PreEval(this));
 }
Пример #9
0
 public FunctionVariable(string fname, Algebraic fvar, LambdaAlgebraic flambda)
 {
     Name = fname;
     Var  = fvar;
     Body = flambda;
 }
Пример #10
0
 public override Algebraic Map(LambdaAlgebraic f)
 {
     return(poly2exp(base.Map(f)));
 }