Ejemplo n.º 1
0
        public override INumber Multiple(Runtime.RuntimeData runtime, INumber val)
        {
            MultipleFormula mf = new MultipleFormula();

            mf.AddItem(runtime, this);
            mf.AddItem(runtime, val);
            return(mf);
        }
Ejemplo n.º 2
0
 public override bool Equals(Runtime.RuntimeData runtime, INumber val)
 {
     if (val is Pi && val.Pow.Equals(runtime, Number.New(1)))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public override INumber Add(Runtime.RuntimeData runtime, INumber val)
        {
            AdditionFormula af = new AdditionFormula();

            af.AddItem(runtime, this);
            af.AddItem(runtime, val);
            return(af);
        }
Ejemplo n.º 4
0
        public override INumber Add(Runtime.RuntimeData runtime, INumber val)
        {
            if (val is Array)
            {
                Array res = new Array();
                Array v   = val as Array;
                for (int x = 0; x < Math.Max(this.items.Count, v.items.Count); x++)
                {
                    int c_count = 0; bool flag1 = false, flag2 = false;
                    if (this.items.Count > x)
                    {
                        c_count = this.items[x].Count; flag1 = true;
                    }
                    if (v.items.Count > x)
                    {
                        c_count = Math.Max(c_count, v.items[x].Count); flag2 = true;
                    }

                    if (x != 0)
                    {
                        res.items.Add(new List <INumber>());
                    }

                    for (int y = 0; y < c_count; y++)
                    {
                        INumber d = Number.New(0);
                        if (flag1 && this.items[x].Count > y)
                        {
                            d = d.Add(runtime, this.items[x][y]);
                        }
                        if (flag2 && v.items[x].Count > y)
                        {
                            d = d.Add(runtime, v.items[x][y]);
                        }

                        res.items[x].Add(d);
                    }
                }

                return(res);
            }
            else
            {
                var res = this.Clone() as Array;
                for (int x = 0; x < res.items.Count; x++)
                {
                    for (int y = 0; y < res.items[x].Count; y++)
                    {
                        res.items[x][y] =
                            res.items[x][y].Add(runtime, val);
                    }
                }
                return(res);
            }
        }
Ejemplo n.º 5
0
        public INumber Execute(Runtime.RuntimeData runtime, params INumber[] parameters)
        {
            if (this.items.Count == 1)
            {
                var index = parameters[0].Eval(runtime);
                if (!(index is Number))
                {
                    throw new RuntimeException("配列のインデックスに整数以外のパラメータを指定することはできません。", index);
                }

                return(this.items[0][(int)(index as Number).Value]);
            }
            else
            {
                throw new NotImplementedException("二次元配列のインデックス指定はまだ実装していません。");
            }
        }
Ejemplo n.º 6
0
        void RefreshResult()
        {
            // if (result_web == null)
            if (result == null)
            {
                return;
            }

            form = formula.Text;

            StringBuilder html = new StringBuilder();

            using (StreamReader sr = new StreamReader("result.html")) {
                html.Append(sr.ReadToEnd());
            }

            try {
                Analyzer.Analyzer   anal = new Analyzer.Analyzer(form);
                Runtime.RuntimeData d    = new Runtime.RuntimeData(anal.Setting);
                var f   = anal.GetResult();
                var res = f.Eval(d).Optimise(d);

                if (res == null)
                {
                    result.Text = "NULL";
                }
                //     result_web.NavigateToString(html.Replace("{0}", "NULL").ToString());
                else
                {
                    result.Text = res.ToString();
                    //StringBuilder res_mathjax = new StringBuilder(res.Output(Runtime.OutputType.Mathjax));
                    //res_mathjax.Insert(0, "$ ");
                    //res_mathjax.Append(" $");

                    //result_web.NavigateToString(html.Replace("{0}",
                    //   res_mathjax.ToString()).ToString());
                }
            }
            catch (Exception ex) {
                result.Text = ex.Message;
                //result_web.NavigateToString(html.Replace("{0}", ex.Message).ToString());
            }
        }
Ejemplo n.º 7
0
        public override INumber Multiple(Runtime.RuntimeData runtime, INumber val)
        {
            if (val is Array)
            {
                throw new NotImplementedException("配列同士の乗はまだ田対応していません。");

                var v       = val as Array;
                int max_col = 0;
                for (int x = 0; x < v.items.Count; x++)
                {
                    max_col = Math.Max(max_col, v.items[x].Count);
                }

                for (int x = 0; x < this.items.Count; x++)
                {
                    INumber d = Number.New(0);
                    for (int y = 0; y < this.items[x].Count; y++)
                    {
                        if (v.items.Count > y && v.items[y].Count > x)
                        {
                            d = d.Add(runtime, this.items[x][y].Multiple(runtime, v.items[y][x]));
                        }
                    }
                }
            }
            else
            {
                var res = this.Clone() as Array;
                for (int x = 0; x < this.items.Count; x++)
                {
                    for (int y = 0; y < this.items[x].Count; y++)
                    {
                        res.items[x][y] = res.items[x][y].Multiple(runtime, val);
                    }
                }
                return(res);
            }
        }
Ejemplo n.º 8
0
 public override INumber ExecuteDiff(Runtime.RuntimeData runtime, string t)
 {
     return(Number.New(0));
 }
Ejemplo n.º 9
0
 public override bool CanJoin(Runtime.RuntimeData runtime, INumber val)
 {
     return(false);
 }
Ejemplo n.º 10
0
        public RuntimeData CreateNewRuntimedata()
        {
            RuntimeData data = new Runtime.RuntimeData(this);

            return(data);
        }
Ejemplo n.º 11
0
 public override INumber ExecuteDiff(Runtime.RuntimeData runtime, string t)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public override bool CanJoin(Runtime.RuntimeData runtime, INumber val)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 public override INumber Multiple(Runtime.RuntimeData runtime, INumber val)
 {
     throw new NotImplementedException();
 }