コード例 #1
0
        private static bool NormGetUp(MultiLinker <KeyValuePair <char, string> > s, MonoLinker <MultiLinker <KeyValuePair <char, string> > > mono)
        {
            if (mono.Data.Link == null || mono.Data.Link.Data == null)
            {
                return(false);
            }
            if (!_check20(mono.Data.Data.Key, mono.Data.Link.Data.Data.Key))
            {
                return(false);
            }
            //var p = pair.Data; KeyValuePair<char, string> v1 = p.Data, v2 = p.Link.Data.Data;
            //if((v1.Key != '+' || (v2.Key != '+' && v2.Key != '-')) && (v1.Key != '*' || (v2.Key != '*' && v2.Key != '/'))) return false;
            var copy = mono.Data.Link.GetCopy();

            copy.GetLast().Link = mono.Link;
            //pair.Link = copy; s.Remove(pair);
            if (s.Link == mono)
            {
                s.Link = copy;
            }
            else
            {
                s.Link.GetBefore(mono).Link = copy;
            }
            return(true);
        }
コード例 #2
0
 public void Reverse()
 {
     foreach (var v in List)
     {
         v.Data = new HyperEquation(v.Data[0], v.Data[2], v.Data[1], v.Data.FromEquations);
     }
     List = List.Reverse().Link;
 }
コード例 #3
0
 public bool AddFirst(HyperEquation he)
 {
     if (!AddFirstAble(he))
     {
         return(false);
     }
     List = new MonoLinker <HyperEquation>(he, List);
     return(true);
 }
コード例 #4
0
        public bool RemoveFirst()
        {
            if (List == null)
            {
                return(false);
            }
            var first = List;

            return((List = List.Link) == null || List.Remove(first));
        }
コード例 #5
0
 public bool RemoveLast()
 {
     if (List == null)
     {
         return(false);
     }
     if (List.Link == null)
     {
         List = null; return(true);
     }
     return(List.Remove(List.GetLast()));
 }
コード例 #6
0
        private static MonoLinker <KeyValuePair <char, string> > SplitSome(string s, string separats, string conducts, string dflt, bool rvrs = false)
        {
            if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(separats) ||
                string.IsNullOrEmpty(conducts) || separats.Length < 2)
            {
                return(null);
            }
            char[] sprt = separats.ToCharArray(), cndc = conducts.ToCharArray();
            char   flag = (char)(sprt[0] ^ sprt[1]), chng = sprt[1];
            MonoLinker <KeyValuePair <char, string> > ms = null;
            int i = 0, len = s.Length, br = 0;

            do
            {
                var sign = sprt[0];
                while (i < len && Array.Exists(sprt, s[i].Equals))
                {
                    if (s[i++] == chng)
                    {
                        sign ^= flag;
                    }
                }
                var start = i;
                while (i < len && (br > 0 || !Array.Exists(sprt, s[i].Equals)))
                {
                    if (s[i] == '(')
                    {
                        ++br;
                    }
                    if (s[i] == ')')
                    {
                        --br;
                    }
                    if (br > 0 || !Array.Exists(cndc, s[i].Equals))
                    {
                        ++i;
                    }
                    else
                    {
                        while (++i < len && Array.Exists(sprt, s[i].Equals))
                        {
                        }
                    }
                }
                if (br < 0)
                {
                    i = len;
                }
                ms = new MonoLinker <KeyValuePair <char, string> >(new KeyValuePair <char, string>(sign, i == start ? dflt : s.Substring(start, i - start)), ms);
            } while(i < len);
            return(rvrs ? ms : ms.Reverse());
        }
コード例 #7
0
 public bool AddLast(HyperEquation he)
 {
     if (!AddLastAble(he))
     {
         return(false);
     }
     if (List == null)
     {
         List = new MonoLinker <HyperEquation>(he);
     }
     else
     {
         List.Add(he);
     }
     return(true);
 }
コード例 #8
0
        private void InitPanelXi()
        {
            label1.Font = new Font(Font.Name,
                                   (float)Math.Floor(Font.Size * 4F / 3F),
                                   Font.Style, Font.Unit, Font.GdiCharSet);
            panelXi.SuspendLayout();
            UserControlXi uc = null;
            int           i  = 0;

            while (i < M)
            {
                uc = new UserControlXi {
                    Font = new Font(Font.Name, Font.Size,
                                    Font.Style, Font.Unit, Font.GdiCharSet),
                    labelName =
                    {
                        Font = new Font(Font.Name,
                                        (float)Math.Floor(Font.Size * 4F / 3F),
                                        Font.Style, Font.Unit, Font.GdiCharSet)
                    },
                    labelIndex = { Text = M + @"n+" + ++i },
                    Anchor     = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                    Width      = panelXi.ClientSize.Width,
                    Top        = uc == null ? 0 : uc.Bottom
                };
                panelXi.Controls.Add(uc);
                if (Xi == null)
                {
                    Xi = new MonoLinker <UserControlXi>(uc);
                }
                else
                {
                    Xi.Add(uc);
                }
            }
            if (Xi != null)
            {
                Xi.GetLast().Link = Xi;
            }
            panelXi.ResumeLayout();
        }
コード例 #9
0
        }                                                                                                 //*/

        //
        private static Coef BiOperation(Coef l, Coef r, string s)
        {
            bool add = s == @"+", mlt = s == @"*", sum = add || s == @"-", prd = mlt || s == @"/", sign = false;
            MonoLinker <KeyValuePair <char, string> > ls = Expression.SplitSum(l.StrFunc), rs = Expression.SplitSum(r.StrFunc);

            if (prd && rs.Link == null)
            {
                if (ls.Data.Key == '-' && ls.Link == null)
                {
                    sign ^= true;
                }
                if (rs.Data.Key == '-')
                {
                    sign ^= true;
                }
                var rsp = Expression.SplitProduct(rs.Data.Value);
                return(new Coef(string.Concat(sign ? @"-" : string.Empty,
                                              ls.Link == null ? ls.Data.Value : string.Concat(@"(", l.StrFunc, @")"), s,
                                              mlt || rsp.Link == null ? rs.Data.Value : string.Concat(@"(", rs.Data.Value, @")")), l.AbcShift));
            }
            return(new Coef(string.Concat(
                                sum || (prd && ls.Link == null) ? l.StrFunc : string.Concat(@"(", l.StrFunc, @")"), s,
                                add || (mlt && rs.Link == null) ? r.StrFunc : string.Concat(@"(", r.StrFunc, @")")), l.AbcShift));
        }
コード例 #10
0
 public ContinuedFractionA(Abc sum, MonoLinker <Coef> cfs = null)
 {
     SumAbc = sum; Coefs = cfs;
 }
コード例 #11
0
 public void Clear()
 {
     List = null;
 }
コード例 #12
0
 protected HyperSet(MonoLinker <HyperEquation> list)
 {
     List = list;
 }
コード例 #13
0
        public void InitMono()
        {
            numericUpDownK.Maximum            = (M = Hset.Count) + 1;
            numericUpDownK.Enabled            = M > 1;
            ToolStripMenuItemEvaluate.Enabled = SumAbc != Abc.Zero;
            string text2 = @"F[a,b,c,z]";

            /*
             * if(domainUpDownA.SelectedIndex == 3)
             *      text2 = text2.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownB.SelectedIndex == 3)
             *      text2 = text2.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownC.SelectedIndex == 3)
             *      text2 = text2.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
             * //*/
            labelFs.Text = Coef.GetShiftedStr(text2, Hset.List.Data[1].AbcShift + ShiftAbc, false);
            labelF0.Text = Coef.GetShiftedStr(text2, ShiftAbc, false);
            Coef cf = new Coef(string.Concat(@"-(",
                                             Hset.List.Data[0].StrFunc, @")/(",
                                             Hset.List.Data[1].StrFunc, @")"))[ShiftAbc].Simplify();

            ContFrac = new ContinuedFractionA(SumAbc, new MonoLinker <Coef>(cf));
            string text1 = cf.StrFunc;

            text2 = Coef.One.StrFunc;

            /*
             * if(domainUpDownA.SelectedIndex == 3)
             *      text1 = text1.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownB.SelectedIndex == 3)
             *      text1 = text1.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownC.SelectedIndex == 3)
             *      text1 = text1.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
             * text1 = Expression.Simplify(Expression.Simplify(text1), Coef.SortComparison);
             * //*/
            var product = Expression.SplitSum(text1);

            if (product.Link == null)
            {
                product = Expression.SplitProduct(text1);
                text1   = text2;
                foreach (var v in (IEnumerable <KeyValuePair <char, string> >)product)
                {
                    if (v.Key == '/')
                    {
                        text2 += string.Concat(@"*(", v.Value, @")");
                    }
                    else
                    {
                        text1 += string.Concat(@"*(", v.Value, @")");
                    }
                }
            }
            textBox1.Text = Expression.Simplify(text1, Coef.SortComparison);
            textBox2.Text = Expression.Simplify(text2, Coef.SortComparison);
            if (Xi == null)
            {
                InitPanelXi();
            }
            Abc abc = ShiftAbc;

            foreach (var he in Hset)
            {
                cf = new Coef(string.Concat(@"-(",
                                            Coef.GetShiftedStr(he.Link.Data[1].StrFunc, he.Data[2].AbcShift, true), @")*(",
                                            he.Data[2].StrFunc, @")/(",
                                            Coef.GetShiftedStr(he.Link.Data[0].StrFunc, he.Data[2].AbcShift, true), @")/(",
                                            he.Data[0].StrFunc, @")"))[abc].Simplify();
                ContFrac.Coefs.Add(cf);
                abc  += he.Data[2].AbcShift;
                text1 = cf[SumAbc * 10000].StrFunc.Replace(@"0000", @"*n");
                text2 = Coef.One.StrFunc;

                /*
                 * if(domainUpDownA.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
                 * if(domainUpDownB.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
                 * if(domainUpDownC.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
                 * text1 = Expression.Simplify(Expression.Simplify(text1), Coef.SortComparison);
                 * //*/
                product = Expression.SplitSum(text1);
                if (product.Link == null)
                {
                    product = Expression.SplitProduct(text1);
                    text1   = text2;
                    foreach (var v in (IEnumerable <KeyValuePair <char, string> >)product)
                    {
                        if (v.Key == '/')
                        {
                            text2 += string.Concat(@"*(", v.Value, @")");
                        }
                        else
                        {
                            text1 += string.Concat(@"*(", v.Value, @")");
                        }
                    }
                }
                Xi.Data.textBoxNumerator.Text   = Expression.Simplify(text1, Coef.SortComparison);
                Xi.Data.textBoxDenominator.Text = Expression.Simplify(text2, Coef.SortComparison);
                Xi = Xi.Link;
            }
            ContFrac.Coefs.GetLast().Link = ContFrac.Coefs.Link;
        }