Exemple #1
0
        public object Evaluate(Frame environment, Expression expression)
        {
            if (expression.GetRest().Count < 2)
            {
                throw new Exception("Invalid let definition");
            }
            Expression definitionList = expression.GetRest()[0];
            List<string> paramNames = new List<string>(definitionList.GetRest().Count + 1);
            Dictionary<string, Procedure> bindings = new Dictionary<string, Procedure>(paramNames.Capacity);

            Expression firstDefinition = definitionList.GetFirst();
            AddDefinition(environment, paramNames, bindings, firstDefinition);
            foreach (Expression definition in definitionList.GetRest())
            {
                AddDefinition(environment, paramNames, bindings, definition);
            }

            List<Expression> body = new List<Expression>(expression.GetRest().Count - 1);
            for (int i = 1; i < expression.GetRest().Count; i++)
            {
                body.Add(expression.GetRest()[i]);
            }

            Lambda block = new Lambda(environment, paramNames, body);

            Frame child = new Frame(bindings, environment, environment, block,true,null);

            return child.Evaluate(block.Body);
        }
Exemple #2
0
        /// <summary>
        /// Construct a check box with a key button.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="name"></param>
        /// <param name="key"></param>
        /// <param name="isChecked"></param>
        /// <param name="OnButtonChecked"></param>
        /// <param name="OnButtonUnchecked"></param>
        public CheckBox(
            Control.ControlCollection controls,
            Point location,
            string name,
            Key key,
            Point keyLocation,
            bool isChecked,
            Lambda OnButtonChecked,
            Lambda OnButtonUnchecked)
            : this(controls, location, name, isChecked, OnButtonChecked, OnButtonUnchecked)
        {
            // Add corresponding button
            System.Windows.Forms.Button button = new System.Windows.Forms.Button();
            button.Location = keyLocation;
            button.Text = key.KeyString;
            button.Click += delegate(Object sender, EventArgs e)
            {
                new UserInputScreen((Action<Keys>)delegate(Keys argKey)
                    {
                        key.KeyString = argKey.ToString().ToLower();
                        button.Text = key.KeyString;
                    });
            };

            controls.Add(button);
        }
Exemple #3
0
        /// <summary>
        /// Construct a new check box with no key button.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="name"></param>
        /// <param name="isChecked"></param>
        /// <param name="OnButtonChecked"></param>
        /// <param name="OnButtonUnchecked"></param>
        public CheckBox(
            Control.ControlCollection controls,
            Point location,
            string name,
            bool isChecked,
            Lambda OnButtonChecked,
            Lambda OnButtonUnchecked)
        {
            box = new System.Windows.Forms.CheckBox();
            box.AutoSize = true;
            box.Location = location;
            box.Checked = isChecked;
            box.Name = name;
            box.Size = new System.Drawing.Size(80, 17);
            box.TabIndex = 0;
            box.Text = name;
            box.UseVisualStyleBackColor = true;

            // Anonymous checked event handler -- callback to provided lambdas for check/uncheck behavior.
            box.CheckedChanged += delegate(Object sender, EventArgs e)
            {
                if (box.Checked)
                {
                    OnButtonChecked();
                }
                else
                {
                    OnButtonUnchecked();
                }
            };

            controls.Add(box);
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the EvaluateDo class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="vars">The variables.</param>
 /// <param name="inits">The initialization expressions.</param>
 /// <param name="steps">The steps.</param>
 /// <param name="exprs">The expressions.</param>
 /// <param name="commands">The commands.</param>
 /// <param name="testProc">The test proc to execute each interation.</param>
 private EvaluateDo(SchemeObject expr, Environment env, Evaluator caller, SchemeObject vars, SchemeObject inits, SchemeObject steps, SchemeObject exprs, SchemeObject commands, Lambda testProc)
     : base(InitialStep, expr, new Environment(env), caller)
 {
     this.vars = vars;
     this.inits = inits;
     this.steps = steps;
     this.exprs = exprs;
     this.commands = commands;
     this.testProc = testProc;
 }
 /// <summary>
 /// 获取列名
 /// </summary>
 /// <typeparam name="TEntity">实体类型</typeparam>
 /// <param name="columns">列名表达式</param>
 /// <param name="propertyAsAlias">是否将属性名映射为列别名</param>
 public string GetColumns <TEntity>(Expression <Func <TEntity, object[]> > columns, bool propertyAsAlias)
 {
     return(Lambda.GetLastNames(columns).Select(column => $"t_{column}").Join());
 }
 public string GetColumn(Expression expression, Type entity, bool right)
 {
     return($"t_{Lambda.GetLastName(expression, right)}");
 }
 protected internal virtual void TraverseLambda(Lambda lambda) { lambda.Unsupported(); } 
Exemple #8
0
 public FunType(Lambda lambda, State env)
 {
     this.lambda = lambda;
     this.env    = env;
 }
 public void defineLambda(Lambda lambda)
 {
     m_code.lambdas.Add(lambda);
 }
Exemple #10
0
 public void VisitLambda(Lambda lambda)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///     添加表达式
 /// </summary>
 /// <param name="property">属性表达式</param>
 /// <param name="operator">运算符</param>
 /// <param name="value">值</param>
 public void Append <TProperty>(Expression <Func <TEntity, TProperty> > property, Operator @operator, object value)
 {
     _result = Extensions.Extensions.And(_result,
                                         Extensions.Extensions.Operation(Extensions.Extensions.Property(_parameter, Lambda.GetMember(property)),
                                                                         @operator, value));
 }
 protected internal override void TraverseLambda(Lambda lambda)
 {
     // todo. return to this when lambdas decompilation is implemented
     _writer.Write(Syms.Lambda);
 }
Exemple #13
0
            public object Create(object request, ISpecimenContext context)
            {
                var type = default(Type);

                if (request is ParameterInfo parameter)
                {
                    type = parameter.ParameterType;
                }
                else if (request is Type typeRequest)
                {
                    type = typeRequest;
                }

                if (type != null)
                {
                    if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == typeof(ImmutableArray <>))
                    {
                        var elementType = type.GetGenericArguments()[0];
                        var arrayType   = elementType.MakeArrayType();
                        var array       = context.Resolve(arrayType);

                        return(typeof(ImmutableArray).GetMethods(BindingFlags.Public | BindingFlags.Static)
                               .Where(x => x.Name == nameof(ImmutableArray.Create))
                               .Where(x => x.GetParameters().Length == 1)
                               .First(x => x.GetParameters()[0].ParameterType.IsArray)
                               .MakeGenericMethod(elementType)
                               .Invoke(null, new[] { array }) !);
                    }

                    if (type == typeof(object))
                    {
                        return(context.Resolve(typeof(string)));
                    }

                    if (type == typeof(Traversal))
                    {
                        return((Traversal)IdentityStep.Instance);
                    }

                    if (type == typeof(Cardinality))
                    {
                        return(Cardinality.Single);
                    }

                    if (type == typeof(ILambda))
                    {
                        return(Lambda.Groovy("lambda"));
                    }

                    if (type == typeof(string))
                    {
                        return("string");
                    }

                    if (type == typeof(double))
                    {
                        return(47.11);
                    }

                    if (type == typeof(int))
                    {
                        return(4711);
                    }

                    if (type == typeof(long))
                    {
                        return(4711);
                    }
                }

                return(new NoSpecimen());
            }
Exemple #14
0
 public PartialParameter(Source src, Lambda lambda, int index)
     : base(src)
 {
     Index    = index;
     Function = new Either <Function, Lambda>(lambda);
 }
Exemple #15
0
 /// <summary>
 /// 设置连接条件组
 /// </summary>
 private List <OnItem> GetOnItems(List <Expression> group)
 {
     return(group.Select(expression => new OnItem(
                             GetColumn(expression, false), GetColumn(expression, true), Lambda.GetOperator(expression).SafeValue()
                             )).ToList());
 }
Exemple #16
0
 public static Expression <Func <double> > ParseExpression(string text)
 {
     return(Lambda.Parse(text));
 }
Exemple #17
0
        /// <summary>
        /// 获取查询条件并添加参数
        /// </summary>
        private ICondition GetCondition(Expression expression, Type type)
        {
            var column = GetColumn(_resolver.GetColumn(expression, type), type);

            return(GetCondition(column, Lambda.GetValue(expression), Lambda.GetOperator(expression).SafeValue()));
        }
Exemple #18
0
 public static Expression LessEqual(this Expression left, object value)
 {
     return(left.LessEqual(Lambda.Constant(value, left)));
 }
Exemple #19
0
 public async Task UpdateStatusAsync()
 {
     Lambda.IntervalFunctionsAsync(null);
     await ReplyNewEmbedAsync("Done.");
 }
 public void AddSubCheckBox(string name, bool isChecked, Lambda OnButtonChecked, Lambda OnButtonUnchecked)
 {
     getView().AddSubCheckBox(name, isChecked, OnButtonChecked, OnButtonUnchecked);
 }
Exemple #21
0
 public void TestParse_Validate_PropertyError()
 {
     Assert.AreEqual("(t.Name == \"A\")", Lambda.ParsePredicate <Test2>("Name1", "A", Operator.Equal).ToStr());
 }
 public void addLambda(Lambda lambda, Lvalues lvalues, Operands arguments)
 {
     DoLambda lambda_stamp = new DoLambda(lvalues, lambda, arguments);
     m_lambda.addStatement(lambda_stamp);
 }
Exemple #23
0
 public void TestParse()
 {
     Assert.AreEqual("t => (t.Name == \"A\")", Lambda.ParsePredicate <Test2>("Name", "A", Operator.Equal).ToStr());
     Assert.AreEqual("t => t.Name.Contains(\"A\")", Lambda.ParsePredicate <Test2>("Name", "A", Operator.Contains).ToStr());
 }
 protected internal override Node TransformLambda(Lambda lambda)
 {
     return Dispatch(lambda);
 }
Exemple #25
0
 public void TestParse_2()
 {
     Assert.AreEqual("Param_0 => (Param_0.Name == \"A\")", Lambda.ParsePredicate <Test2>("Name == \"A\"").ToStr());
     Assert.AreEqual("Param_0 => Param_0.Name.Contains(\"A\")", Lambda.ParsePredicate <Test2>("Name.Contains(\"A\")").ToStr());
 }
Exemple #26
0
 private LambdaMethodValueGetter(Lambda lambda)
 {
     _lambda = lambda;
 }
Exemple #27
0
 public void TestParse_Param()
 {
     Assert.AreEqual("Param_0 => (Param_0.Name == \"A\")", Lambda.ParsePredicate <Test2>("Name == @0", "A").ToStr());
     Assert.AreEqual("Param_0 => Param_0.Name.Contains(\"A\")", Lambda.ParsePredicate <Test2>("Name.Contains(@0)", "A").ToStr());
     Assert.AreEqual("Param_0 => ((Param_0.Name == \"A\") AndAlso (Param_0.Int > 1))", Lambda.ParsePredicate <Test2>("Name == @0 && Int > @1", "A", 1).ToStr());
 }
 protected internal virtual Node TransformLambda(Lambda lambda) { return lambda.AcceptTransformer(this, true); }
Exemple #29
0
 public PrintBlockReplacement(Lambda lambda)
 {
     lambda.Parameters?.Length.Must().BeGreaterThan(0).OrThrow(LOCATION, () => "No parameter provided");
     this.lambda = lambda;
     id          = CompilerState.ObjectID();
 }
Exemple #30
0
        public void Delete_ById_WhenEntityIsNotNull <TEntity, TKey>(
            TKey defaultKey,
            TEntity entity,
            object id,
            bool expectedResult)
            where TEntity : class, IEntity <TKey>
        {
            // Arrange
            var filterExpression = FilterExpressionExtensions.CreateIdFilterExpression <TEntity, TKey>((TKey)id);

            var mockRepository = new Mock <IRepository <TEntity, TKey> >(MockBehavior.Strict);

            mockRepository
            .Setup(
                x => x.Get(
                    It.Is <QueryParameters <TEntity, TKey> >(
                        y => Lambda.Eq(
                            y.Filter.Expression,
                            filterExpression
                            ) &&
                        y.Sort == null &&
                        y.Page == null
                        )
                    )
                )
            .Returns(entity);

            mockRepository
            .Setup(x => x.Delete(entity));

            var repository = mockRepository.Object;

            // Act
            repository.Delete((TKey)id);

            // Assert
            if (id != null)
            {
                Assert.IsType(defaultKey.GetType(), id);
            }

            Assert.Equal(
                expectedResult,
                filterExpression.Compile().Invoke(entity)
                );

            mockRepository
            .Verify(
                x => x.Get(
                    It.Is <QueryParameters <TEntity, TKey> >(
                        y => Lambda.Eq(
                            y.Filter.Expression,
                            filterExpression
                            ) &&
                        y.Sort == null &&
                        y.Page == null
                        )
                    ),
                Times.Once
                );

            mockRepository
            .Verify(
                x => x.Delete(entity),
                Times.Once
                );
        }
Exemple #31
0
        /// <summary>
        /// 设置连接条件组
        /// </summary>
        private void On(List <Expression> group)
        {
            var items = group.Select(expression => new OnItem(
                                         GetColumn(expression, false), GetColumn(expression, true), Lambda.GetOperator(expression).SafeValue()
                                         )).ToList();

            _params.LastOrDefault()?.On(items);
        }
 public string GetColumn <TEntity>(Expression <Func <TEntity, object> > column)
 {
     return($"t_{Lambda.GetLastName(column)}");
 }
Exemple #33
0
 public bool Equals(MProphetPeakScoringModel other)
 {
     return(base.Equals(other) &&
            ColinearWarning.Equals(other.ColinearWarning) &&
            Lambda.Equals(other.Lambda));
 }
Exemple #34
0
 public static Expression Greater(this Expression left, object value)
 {
     return(left.Greater(Lambda.Constant(value, left)));
 }
 public abstract Value Evaluate(NSIterator iterator, Lambda lambda);
 private void Process(Ldftn ldftn)
 {
     (ldftn.Next is New).AssertTrue();
     var style = ldftn.IsVirtual ? InvocationStyle.Virtual : InvocationStyle.NonVirtual;
     var lambda = new Lambda(ldftn.Method, style);
     Push(ldftn.IsVirtual ? new Apply(lambda, _firstArg) : (Expression)lambda);
 }
Exemple #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThemeMap"/> class.
 /// </summary>
 public ThemeMap()
 {
     this.Map(x => x.ThemeName).Length(50).Not.Nullable();
     this.Map(x => x.DateCreated).Not.Nullable();
     this.Map(x => x.DateModified).Not.Nullable();
     this.Map(x => x.IsActive).Nullable();
     this.References(x => x.CreatedBy).Nullable().LazyLoad().Column(Inflector.Uncapitalize(Lambda.Property <Theme>(x => x.CreatedBy)));
     this.References(x => x.ModifiedBy).Nullable().LazyLoad().Column(Inflector.Uncapitalize(Lambda.Property <Theme>(x => x.ModifiedBy)));
 }
 protected internal override void TraverseLambda(Lambda lambda)
 {
     var sig = lambda.Sig.Params.Select(p => p.Type).Concat(lambda.Sig.Ret).ToReadOnly();
     if (sig.Any(t => t == null)) Types.Add(lambda, null);
     else Types.Add(lambda, sig.AsmFType());
 }
Exemple #39
0
        public static FractalGraph CalcIfs(double xCenter, double yCenter, double rDelta, long N,
                                           ILambdaExpression[] Functions, double[] Weights, SKColor[] Colors, int Width, int Height, int Seed,
                                           ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
        {
            ILambdaExpression Lambda;
            double            TotWeight = 0;
            double            Weight;

            bool[]  Real;
            byte[]  Reds;
            byte[]  Greens;
            byte[]  Blues;
            SKColor cl;
            int     i, c = Functions.Length;
            Random  Gen = new Random(Seed);

            if (c < 2)
            {
                throw new ScriptRuntimeException("At least two transformations need to be provided.", Node);
            }

            if (Weights.Length != c)
            {
                throw new ArgumentException("Weights must be of equal length as Functions.", "Weights");
            }

            if (Colors.Length != c)
            {
                throw new ArgumentException("Colors must be of equal length as Functions.", "Colors");
            }

            for (i = 0; i < c; i++)
            {
                Weight = Weights[i];
                if (Weight < 0)
                {
                    throw new ScriptRuntimeException("Weights must be non-negative.", Node);
                }

                Weights[i] += TotWeight;
                TotWeight  += Weight;
            }

            if (TotWeight == 0)
            {
                throw new ScriptRuntimeException("The total weight of all functions must be postitive.", Node);
            }

            for (i = 0; i < c; i++)
            {
                Weights[i] /= TotWeight;
            }

            Real   = new bool[c];
            Reds   = new byte[c];
            Greens = new byte[c];
            Blues  = new byte[c];

            for (i = 0; i < c; i++)
            {
                cl        = Colors[i];
                Reds[i]   = cl.Red;
                Greens[i] = cl.Green;
                Blues[i]  = cl.Blue;

                Lambda = Functions[i];

                switch (Lambda.NrArguments)
                {
                case 1:
                    Real[i] = false;
                    break;

                case 2:
                    Real[i] = true;
                    break;

                default:
                    throw new ScriptRuntimeException("Lambda expressions in calls to IfsFractal() must be either real-values (taking two parameters) or complex valued (taking one parameter).", Node);
                }
            }

            int size = Width * Height * 4;

            byte[] rgb = new byte[size];

            double        AspectRatio = ((double)Width) / Height;
            double        x           = Gen.NextDouble();
            double        y           = Gen.NextDouble();
            int           j;
            double        xMin, xMax, yMin, yMax;
            double        sx, sy;
            DoubleNumber  xv = new DoubleNumber(0);
            DoubleNumber  yv = new DoubleNumber(0);
            ComplexNumber zv = new ComplexNumber(0);

            IElement[] RealParameters    = new IElement[] { xv, yv };
            IElement[] ComplexParameters = new IElement[] { zv };
            Variables  v = new Variables();
            int        xi, yi;

            Variables.CopyTo(v);

            xMin = xCenter - rDelta / 2;
            xMax = xMin + rDelta;
            yMin = yCenter - rDelta / (2 * AspectRatio);
            yMax = yMin + rDelta / AspectRatio;

            sx = Width / (xMax - xMin);
            sy = Height / (yMax - yMin);

            Complex z;

            for (i = 0; i < 20; i++)
            {
                Weight = Gen.NextDouble();
                j      = 0;
                while (j < c - 1 && Weights[j] <= Weight)
                {
                    j++;
                }

                Lambda = Functions[j];

                if (Real[j])
                {
                    xv.Value = x;
                    yv.Value = y;

                    if (!(Lambda.Evaluate(RealParameters, v) is IVector Result) || Result.Dimension != 2)
                    {
                        throw new ScriptRuntimeException("Expected 2-dimensional numeric vector as a result.", Node);
                    }

                    x = Expression.ToDouble(Result.GetElement(0).AssociatedObjectValue);
                    y = Expression.ToDouble(Result.GetElement(1).AssociatedObjectValue);
                }
                else
                {
                    zv.Value = new Complex(x, y);
                    z        = Expression.ToComplex(Lambda.Evaluate(ComplexParameters, v).AssociatedObjectValue);

                    x = z.Real;
                    y = z.Imaginary;
                }
            }

            while (N-- > 0)
            {
                Weight = Gen.NextDouble();
                j      = 0;
                while (j < c - 1 && Weights[j] <= Weight)
                {
                    j++;
                }

                Lambda = Functions[j];

                if (Real[j])
                {
                    xv.Value = x;
                    yv.Value = y;

                    if (!(Lambda.Evaluate(RealParameters, v) is IVector Result) || Result.Dimension != 2)
                    {
                        throw new ScriptRuntimeException("Expected 2-dimensional numeric vector as a result.", Node);
                    }

                    x = Expression.ToDouble(Result.GetElement(0).AssociatedObjectValue);
                    y = Expression.ToDouble(Result.GetElement(1).AssociatedObjectValue);
                }
                else
                {
                    zv.Value = new Complex(x, y);
                    z        = Expression.ToComplex(Lambda.Evaluate(ComplexParameters, v).AssociatedObjectValue);

                    x = z.Real;
                    y = z.Imaginary;
                }

                if (x < xMin || x > xMax || y < yMin || y > yMax)
                {
                    continue;
                }

                xi = (int)((x - xMin) * sx + 0.5);
                yi = Height - 1 - (int)((y - yMin) * sy + 0.5);

                if (xi < 0 || xi >= Width || yi < 0 || yi >= Height)
                {
                    continue;
                }

                i = (yi * Width + xi) << 2;

                if (rgb[i + 3] == 0)
                {
                    rgb[i++] = Blues[j];
                    rgb[i++] = Greens[j];
                    rgb[i++] = Reds[j];
                    rgb[i]   = 0xff;
                }
                else
                {
                    rgb[i] = (byte)((rgb[i] + Blues[j]) >> 1);
                    i++;
                    rgb[i] = (byte)((rgb[i] + Greens[j]) >> 1);
                    i++;
                    rgb[i] = (byte)((rgb[i] + Reds[j]) >> 1);
                }
            }

            using (SKData Data = SKData.Create(new MemoryStream(rgb)))
            {
                SKImage Bitmap = SKImage.FromPixelData(new SKImageInfo(Width, Height, SKColorType.Bgra8888), Data, Width * 4);
                return(new FractalGraph(Bitmap, xMin, yMin, xMax, yMax, rDelta, false, Node, FractalZoomScript, State));
            }
        }
 public void addIf(Lvalues lvalues, Relation conditional, Lambda consequent, Lambda alternate)
 {
     If _if = new If(lvalues, conditional, consequent, alternate);
     m_lambda.addStatement(_if);
 }
 /// <summary>
 /// 获取lambda表达式的值
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 public static object Value <T>(this Expression <Func <T, bool> > expression)
 {
     return(Lambda.GetValue(expression));
 }
 public void defineLambda(Lambda lambda)
 {
     m_lambda.addLambda(lambda);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="isChecked"></param>
        /// <param name="OnButtonChecked"></param>
        /// <param name="OnButtonUnchecked"></param>
        public void AddSubCheckBox(string name, bool isChecked, Lambda OnButtonChecked, Lambda OnButtonUnchecked)
        {
            int y = GetNextY();

            lastElem.AddSubElement(
                new elements.CheckBox(
                this.Controls,
                new Point(currX, y),
                name,
                isChecked,
                OnButtonChecked,
                OnButtonUnchecked)
                );
        }
 internal LambdaBuilder(string name, Types return_types, Code code, Lambda parent)
 {
     m_lambda = new Lambda(name, return_types, parent);
     m_code = code;
 }
        /// <summary>
        /// X, Y, Z, Phi から自励関数 f(q) を計算。
        /// </summary>
        public void SetFunctions(
			Expression2 x, Expression2 y, Expression2 z,
			Expression2 phi)
        {
            var x_ = new Expresso.Symbolic.Lambda(x);
            var y_ = new Expresso.Symbolic.Lambda(y);
            var z_ = new Expresso.Symbolic.Lambda(z);
            var phi_ = new Expresso.Symbolic.Lambda(phi);

            this.X = (Func2)x_.Compile();
            this.Y = (Func2)y_.Compile();
            this.Z = (Func2)z_.Compile();
            this.Phi = (Func2)phi_.Compile();

            var x1 = x_.Derive(0);
            var y1 = y_.Derive(0);
            var z1 = z_.Derive(0);
            var x2 = x_.Derive(1);
            var y2 = y_.Derive(1);
            var z2 = z_.Derive(1);

            /*
            var g111 = x1 * x1;
            var g112 = y1 * y1;
            var g113 = g111 + g112;
            var g114 = g113.Simplify();
            var g115 = g114.Simplify();
            */

            var g11 = x1 * x1 + y1 * y1 + z1 * z1; g11 = g11.Simplify();
            var g12 = x1 * x2 + y1 * y2 + z1 * z2; g12 = g12.Simplify();
            var g22 = x2 * x2 + y2 * y2 + z2 * z2; g22 = g22.Simplify();

            var det = g11 * g22 - g12 * g12; det = det.Simplify();

            var gi11 = g22 / det; gi11 = gi11.Simplify();
            var gi12 = -g12 / det; gi12 = gi12.Simplify();
            var gi22 = g11 / det; gi22 = gi22.Simplify();

            var f = new Lambda[4];

            var p1_ = new Lambda((p1, p2) => p1);
            var p2_ = new Lambda((p1, p2) => p2);

            var f0 = (
                Lambda.ExtendedMultiply(gi11, p1_) +
                Lambda.ExtendedMultiply(gi12, p2_)
                ) / this.M;
            f0 = f0.Simplify();

            var f1 = (
                Lambda.ExtendedMultiply(gi12, p1_) +
                Lambda.ExtendedMultiply(gi22, p2_)
                ) / this.M;
            f1 = f1.Simplify();

            var p11 = p1_ * p1_;
            var p12 = 2 * p1_ * p2_;
            var p22 = p2_ * p2_;
            var dummy = new Lambda((p1, p2) => 1.0);

            var fp =
                    -(
                    Lambda.ExtendedMultiply(gi11, p11) +
                    Lambda.ExtendedMultiply(gi12, p12) +
                    Lambda.ExtendedMultiply(gi22, p22)
                    ) / (2 * this.M) -
                    Lambda.ExtendedMultiply(phi_, dummy);

            var f2 = fp.Derive(0);
            var f3 = fp.Derive(1);

            Function4D f4d = new Function4D(
                (Func4)f0.Compile(),
                (Func4)f1.Compile(),
                (Func4)f2.Compile(),
                (Func4)f3.Compile());

            this.Function = f4d;
        }
Exemple #46
0
 /// <summary>
 /// Creates IBSimilarity from the three components.
 /// <p>
 /// Note that <code>null</code> values are not allowed:
 /// if you want no normalization, instead pass
 /// <seealso cref="NoNormalization"/>. </summary>
 /// <param name="distribution"> probabilistic distribution modeling term occurrence </param>
 /// <param name="lambda"> distribution's &lambda;<sub>w</sub> parameter </param>
 /// <param name="normalization"> term frequency normalization </param>
 public IBSimilarity(Distribution distribution, Lambda lambda, Normalization normalization)
 {
     this.Distribution_Renamed = distribution;
     this.Lambda_Renamed = lambda;
     this.Normalization_Renamed = normalization;
 }
Exemple #47
0
        public Expression TypeCheck(Lambda lambda, Scope scope)
        {
            var position = lambda.Position;
            var parameters = lambda.Parameters;
            var body = lambda.Body;

            var typedParameters = GetTypedParameters(parameters).ToVector();

            var localScope = CreateLocalScope(scope, typedParameters);

            var typedBody = TypeCheck(body, localScope);

            var normalizedParameters = NormalizeTypes(typedParameters);

            var parameterTypes = normalizedParameters.Select(p => p.Type).ToArray();

            return new Lambda(position, normalizedParameters, typedBody, NamedType.Function(parameterTypes, typedBody.Type));
        }
Exemple #48
0
 public FunType(Lambda lambda, State env)
 {
     this.Lambda = lambda;
     this.scope  = env;
 }
 protected override void StartCalc(){
     formula1 = Bars.Close;
     formula2 = new Lambda<double>(_bb => Bars.Close.Average(9, _bb));
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="OnButtonChecked"></param>
        /// <param name="OnButtonUnchecked"></param>
        public void AddCheckBox(
            string name,
            Key key,
            bool isChecked,
            Lambda OnButtonChecked,
            Lambda OnButtonUnchecked)
        {
            int y = GetNextY();

            lastElem = new elements.CheckBox(
                this.Controls,
                new Point(currX, y),
                name,
                key,
                new Point(currX + buttonGap, y + buttonOffset),
                isChecked,
                OnButtonChecked,
                OnButtonUnchecked
                );
        }
Exemple #51
0
 public string GetLabel() => Lambda.GetLabel(false);
 protected internal override void TraverseLambda(Lambda lambda)
 {
     Dispatch(lambda);
 }
Exemple #53
0
 /// <summary>
 /// 获取Lambda表达式的值
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="expression">表达式</param>
 public static object Value <T>(this Expression <Func <T, bool> > expression) => Lambda.GetValue(expression);
Exemple #54
0
 public Macro(string name, LispObject lambdaList, Cons macroBody, LispEnvironment macroEnv)
 {
     this.name = name;
     this.expander = new Lambda(lambdaList, macroBody, macroEnv);
     this.macroEnv = macroEnv;
 }
Exemple #55
0
 /// <summary>
 /// 创建大于等于运算表达式
 /// </summary>
 /// <param name="left">左操作数</param>
 /// <param name="value">值</param>
 public static Expression GreaterEqual(this Expression left, object value) => left.GreaterEqual(Lambda.Constant(value, left));
Exemple #56
0
            internal static expr Convert(Compiler.Ast.Expression expr, expr_context ctx) {
                expr ast;

                if (expr is ConstantExpression)
                    ast = Convert((ConstantExpression)expr);
                else if (expr is NameExpression)
                    ast = new Name((NameExpression)expr, ctx);
                else if (expr is UnaryExpression)
                    ast = new UnaryOp((UnaryExpression)expr);
                else if (expr is BinaryExpression)
                    ast = Convert((BinaryExpression)expr);
                else if (expr is AndExpression)
                    ast = new BoolOp((AndExpression)expr);
                else if (expr is OrExpression)
                    ast = new BoolOp((OrExpression)expr);
                else if (expr is CallExpression)
                    ast = new Call((CallExpression)expr);
                else if (expr is ParenthesisExpression)
                    return Convert(((ParenthesisExpression)expr).Expression);
                else if (expr is LambdaExpression)
                    ast = new Lambda((LambdaExpression)expr);
                else if (expr is ListExpression)
                    ast = new List((ListExpression)expr, ctx);
                else if (expr is TupleExpression)
                    ast = new Tuple((TupleExpression)expr, ctx);
                else if (expr is DictionaryExpression)
                    ast = new Dict((DictionaryExpression)expr);
                else if (expr is ListComprehension)
                    ast = new ListComp((ListComprehension)expr);
                else if (expr is GeneratorExpression)
                    ast = new GeneratorExp((GeneratorExpression)expr);
                else if (expr is MemberExpression)
                    ast = new Attribute((MemberExpression)expr, ctx);
                else if (expr is YieldExpression)
                    ast = new Yield((YieldExpression)expr);
                else if (expr is ConditionalExpression)
                    ast = new IfExp((ConditionalExpression)expr);
                else if (expr is IndexExpression)
                    ast = new Subscript((IndexExpression)expr, ctx);
                else if (expr is SliceExpression)
                    ast = new Slice((SliceExpression)expr);
                else if (expr is BackQuoteExpression)
                    ast = new Repr((BackQuoteExpression)expr);
                else
                    throw new ArgumentTypeException("Unexpected expression type: " + expr.GetType());

                ast.GetSourceLocation(expr);
                return ast;
            }
Exemple #57
0
 /// <summary>
 /// 创建小于运算表达式
 /// </summary>
 /// <param name="left">左操作数</param>
 /// <param name="value">值</param>
 public static Expression Less(this Expression left, object value) => left.Less(Lambda.Constant(value, left));