diff --git a/MatrixExtensions.cs b/MatrixExtensions.cs index 48d6dc1..15eab6a 100644 --- a/MatrixExtensions.cs +++ b/MatrixExtensions.cs @@ -73,6 +73,29 @@ namespace MatrixExtensions "Добавление нового значения ('аргумент') в конец вектора ('вектор').", FunctionSections.MatricesAndVectors, true, new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.Default)), + + new TermInfo("listInsertAt", TermType.Function, + "Добавление нового значения ('аргумент') в вектор ('вектор') по указанному индексу ('число').", + FunctionSections.MatricesAndVectors, true, + new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.Default), + new ArgumentInfo(ArgumentSections.RealNumber)), + + new TermInfo("listInsertRange", TermType.Function, + "Добавление нового диапазона значений ('2:вектор') в вектор ('1:вектор') по указанному индексу ('число').", + FunctionSections.MatricesAndVectors, true, + new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.ColumnVector), + new ArgumentInfo(ArgumentSections.RealNumber)), + + new TermInfo("listRemoveAt", TermType.Function, + "Удаление элемента вектора ('вектор') по указанному индексу ('число').", + FunctionSections.MatricesAndVectors, true, + new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.RealNumber)), + + new TermInfo("listRemoveRange", TermType.Function, + "Удаление диапазона элементов вектора ('1:вектор') по указанному индексу начала ('2:число') и количеству ('3:число') значений удаляемого диапазона.", + FunctionSections.MatricesAndVectors, true, + new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.RealNumber), + new ArgumentInfo(ArgumentSections.RealNumber)), }; } @@ -161,17 +184,25 @@ namespace MatrixExtensions return true; } - //listSort + //listSortAsText if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listSortAsText") { Entry arg1 = Computation.Preprocessing(value.Items[0], context); TNumber tmp = Computation.NumericCalculation(arg1, context); + BaseEntry be = tmp.obj; + Term[] res = be.ToTerms(16, 16, FractionsType.Decimal, true); + + tmp = Computation.NumericCalculation(Entry.Create(res), context); + List vector = new List(Utilites.EntryMatrix2ArrStr(tmp.obj)); - vector.RemoveAt(vector.Count - 1); - vector.RemoveAt(vector.Count - 1); - vector.Sort(); + if (be.Type == BaseEntryType.Matrix) + { + vector.RemoveAt(vector.Count - 1); + vector.RemoveAt(vector.Count - 1); + vector.Sort(); + } List answer = new List(); foreach (string item in vector) @@ -293,10 +324,80 @@ namespace MatrixExtensions return true; } + if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "listRemoveAt") + { + Entry arg1 = Computation.Preprocessing(value.Items[0], context); + Entry arg2 = Computation.Preprocessing(value.Items[1], context); + + TNumber tmp1 = Computation.NumericCalculation(arg1, context); + TNumber tmp2 = Computation.NumericCalculation(arg2, context); + + BaseEntry be1 = tmp1.obj; + BaseEntry be2 = tmp2.obj; + + List vector = new List(Utilites.EntryMatrix2ArrStr(be1)); + if (be1.Type == BaseEntryType.Matrix) + { + vector.RemoveAt(vector.Count - 1); + vector.RemoveAt(vector.Count - 1); + vector.RemoveAt((int)be2.ToDouble() - 1); + } + + List answer = new List(); + foreach (string item in vector) + { + answer.AddRange(TermsConverter.ToTerms(item)); + } + + answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString())); + answer.AddRange(TermsConverter.ToTerms(1.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count)); + + result = Entry.Create(answer.ToArray()); + return true; + } + + if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "listRemoveRange") + { + Entry arg1 = Computation.Preprocessing(value.Items[0], context); + Entry arg2 = Computation.Preprocessing(value.Items[1], context); + Entry arg3 = Computation.Preprocessing(value.Items[2], context); + + TNumber tmp1 = Computation.NumericCalculation(arg1, context); + TNumber tmp2 = Computation.NumericCalculation(arg2, context); + TNumber tmp3 = Computation.NumericCalculation(arg3, context); + + BaseEntry be1 = tmp1.obj; + BaseEntry be2 = tmp2.obj; + BaseEntry be3 = tmp3.obj; + + List vector = new List(Utilites.EntryMatrix2ArrStr(be1)); + if (be1.Type == BaseEntryType.Matrix) + { + vector.RemoveAt(vector.Count - 1); + vector.RemoveAt(vector.Count - 1); + vector.RemoveRange((int)be2.ToDouble() - 1, (int)be3.ToDouble()); + } + + List answer = new List(); + foreach (string item in vector) + { + answer.AddRange(TermsConverter.ToTerms(item)); + } + + answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString())); + answer.AddRange(TermsConverter.ToTerms(1.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count)); + + result = Entry.Create(answer.ToArray()); + return true; + } + result = null; return false; } + public void Dispose() { }