Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ObjectMatrix.cs
1using System;
3using System.Text;
11
13{
17 public sealed class ObjectMatrix : RingElement, IMatrix
18 {
19 private IElement[,] values;
20 private ICollection<IElement> elements;
21 private string[] columnNames = null;
22 private readonly int rows;
23 private readonly int columns;
24
30 {
31 this.values = Values;
32 this.elements = null;
33 this.rows = Values.GetLength(0);
34 this.columns = Values.GetLength(1);
35 }
36
41 public ObjectMatrix(object[,] Values)
42 {
43 int i, j, c, d;
44 IElement[,] Values2 = new IElement[c = Values.GetLength(0), d = Values.GetLength(1)];
45
46 for (i = 0; i < c; i++)
47 {
48 for (j = 0; j < d; j++)
49 Values2[i, j] = Expression.Encapsulate(Values[i, j]);
50 }
51
52 this.values = Values2;
53 this.elements = null;
54 this.rows = Values.GetLength(0);
55 this.columns = Values.GetLength(1);
56 }
57
64 public ObjectMatrix(int Rows, int Columns, ICollection<IElement> Elements)
65 {
66 this.values = null;
67 this.elements = Elements;
68 this.rows = Rows;
69 this.columns = Columns;
70 }
71
75 public IElement[,] Values
76 {
77 get
78 {
79 if (this.values is null)
80 {
81 IElement[,] v = new IElement[this.rows, this.columns];
82 int x = 0;
83 int y = 0;
84
85 if (this.elements is ChunkedList<IElement> Values)
86 {
87 ChunkNode<IElement> Loop = Values.FirstChunk;
88 int i, c;
89
90 while (!(Loop is null))
91 {
92 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
93 {
94 v[y, x++] = Loop[i];
95 if (x >= this.columns)
96 {
97 y++;
98 x = 0;
99 }
100 }
101
102 Loop = Loop.Next;
103 }
104 }
105 else
106 {
107 foreach (IElement Element in this.elements)
108 {
109 v[y, x++] = Element;
110 if (x >= this.columns)
111 {
112 y++;
113 x = 0;
114 }
115 }
116 }
117
118 this.values = v;
119 }
120
121 return this.values;
122 }
123 }
124
128 public IElement[,] MatrixElements => this.Values;
129
133 public ICollection<IElement> Elements
134 {
135 get
136 {
137 if (this.elements is null)
138 {
139 int x, y, i = 0;
140 IElement[] v = new IElement[this.rows * this.columns];
141
142 for (y = 0; y < this.rows; y++)
143 {
144 for (x = 0; x < this.columns; x++)
145 v[i++] = this.values[y, x];
146 }
147
148 this.elements = v;
149 }
150
151 return this.elements;
152 }
153 }
154
158 public int Rows => this.rows;
159
163 public int Columns => this.columns;
164
168 public string[] ColumnNames
169 {
170 get => this.columnNames;
171 set
172 {
173 if (!(value is null) && value.Length != this.columns)
174 throw new ArgumentException("Number of columns does not match actual number of columns.", nameof(value));
175
176 this.columnNames = value;
177 }
178 }
179
183 public bool HasColumnNames => !(this.columnNames is null);
184
191 public IElement this[string ColumnName]
192 {
193 get
194 {
195 if (!(this.columnNames is null))
196 {
197 int i, c = this.columnNames.Length;
198
199 for (i = 0; i < c; i++)
200 {
201 if (string.Compare(this.columnNames[i], ColumnName, true) == 0)
202 return this.GetColumn(i);
203 }
204 }
205
206 throw new ArgumentException("No column named " + ColumnName + " found.");
207 }
208 }
209
211 public override string ToString()
212 {
213 IElement[,] v = this.Values;
214 StringBuilder sb = null;
215 bool First;
216 int x, y;
217
218 for (y = 0; y < this.rows; y++)
219 {
220 if (sb is null)
221 sb = new StringBuilder("[[");
222 else
223 sb.Append(",\r\n [");
224
225 First = true;
226 for (x = 0; x < this.columns; x++)
227 {
228 if (First)
229 First = false;
230 else
231 sb.Append(", ");
232
233 sb.Append(Expression.ToExpressionString(v[y, x]));
234 }
235
236 sb.Append(']');
237 }
238
239 if (sb is null)
240 sb = new StringBuilder("[[]]");
241 else
242 sb.Append(']');
243
244 return sb.ToString();
245 }
246
250 public override IRing AssociatedRing
251 {
252 get
253 {
254 if (this.associatedMatrixSpace is null)
255 this.associatedMatrixSpace = new ObjectMatrices(this.rows, this.columns);
256
257 return this.associatedMatrixSpace;
258 }
259 }
260
261 private ObjectMatrices associatedMatrixSpace = null;
262
266 public override object AssociatedObjectValue => this;
267
274 {
275 IElement[,] Values = this.Values;
276 IElement[,] v;
277 IElement n;
278 int x, y, z;
279
280 if (Element.IsScalar)
281 {
282 v = new IElement[this.rows, this.columns];
283
284 for (y = 0; y < this.rows; y++)
285 {
286 for (x = 0; x < this.columns; x++)
287 v[y, x] = Multiply.EvaluateMultiplication(Element, Values[y, x], null);
288 }
289
290 return new ObjectMatrix(v);
291 }
292 else if (Element is IMatrix Matrix)
293 {
294 if (Matrix.Columns != this.rows)
295 return null;
296
297 IElement[,] Values2 = Matrix.MatrixElements;
298
299 v = new IElement[Matrix.Rows, this.columns];
300
301 for (y = 0; y < Matrix.Rows; y++)
302 {
303 for (x = 0; x < this.columns; x++)
304 {
305 n = null;
306
307 for (z = 0; z < this.rows; z++)
308 {
309 if (n is null)
310 n = Multiply.EvaluateMultiplication(Values2[y, z], Values[z, x], null);
311 else
312 {
313 n = Operators.Arithmetics.Add.EvaluateAddition(n,
314 Multiply.EvaluateMultiplication(Values2[y, z], Values[z, x], null), null);
315 }
316 }
317
318 v[y, x] = n;
319 }
320 }
321
322 return new ObjectMatrix(v);
323 }
324 else
325 return null;
326 }
327
334 {
335 IElement[,] Values = this.Values;
336 IElement[,] v;
337 IElement n;
338 int x, y, z;
339
340 if (Element.IsScalar)
341 {
342 v = new IElement[this.rows, this.columns];
343
344 for (y = 0; y < this.rows; y++)
345 {
346 for (x = 0; x < this.columns; x++)
347 v[y, x] = Multiply.EvaluateMultiplication(Element, Values[y, x], null);
348 }
349
350 return new ObjectMatrix(v);
351 }
352 else if (Element is IMatrix Matrix)
353 {
354 if (this.columns != Matrix.Rows)
355 return null;
356
357 IElement[,] Values2 = Matrix.MatrixElements;
358
359 v = new IElement[this.rows, Matrix.Columns];
360
361 for (y = 0; y < this.rows; y++)
362 {
363 for (x = 0; x < Matrix.Columns; x++)
364 {
365 n = null;
366
367 for (z = 0; z < this.columns; z++)
368 {
369 if (n is null)
370 n = Multiply.EvaluateMultiplication(Values[y, z], Values2[z, x], null);
371 else
372 {
373 n = Operators.Arithmetics.Add.EvaluateAddition(n,
374 Multiply.EvaluateMultiplication(Values[y, z], Values2[z, x], null), null);
375 }
376 }
377
378 v[y, x] = n;
379 }
380 }
381
382 return new ObjectMatrix(v);
383 }
384 else
385 return null;
386 }
387
392 public override IRingElement Invert()
393 {
394 if (this.rows != this.columns)
395 return null;
396
397 IElement[,] Values = this.Values;
398 int c2 = this.columns << 1;
399 IElement[,] v = new IElement[this.rows, c2];
400 IElement E;
401 int x, y;
402
403 for (y = 0; y < this.rows; y++)
404 {
405 for (x = 0; x < this.columns; x++)
406 {
407 v[y, x] = E = Values[y, x];
409 return null;
410
411 v[y, x + this.columns] = (x == y ? E2.One : E2.Zero);
412 }
413 }
414
415 if (Reduce(v, true, true, out _) < 0)
416 return null;
417
418 IElement[,] v2 = new IElement[this.rows, this.columns];
419
420 for (y = 0; y < this.rows; y++)
421 {
422 for (x = 0; x < this.columns; x++)
423 v2[y, x] = v[y, x + this.columns];
424 }
425
426 return new ObjectMatrix(v2);
427 }
428
440 public IMatrix Reduce(bool Eliminate, bool BreakIfZero, out int Rank, out ICommutativeRingWithIdentityElement Factor)
441 {
442 IElement[,] M = (IElement[,])this.Values.Clone();
443 Rank = Reduce(M, Eliminate, BreakIfZero, out Factor);
444 return new ObjectMatrix(M);
445 }
446
458 public static int Reduce(IElement[,] Matrix, bool Eliminate, bool BreakIfZero, out ICommutativeRingWithIdentityElement Factor)
459 {
460 int x, y, u, z;
461 int Rows = Matrix.GetLength(0);
462 int Columns = Matrix.GetLength(1);
463 int MinCount = Math.Min(Rows, Columns);
465 IElement w;
466 int Rank = 0;
467 bool Sign = false;
468
469 Factor = null;
470
471 for (x = 0; x < MinCount; x++)
472 {
473 a = Matrix[x, x] as ICommutativeRingWithIdentityElement;
474 if (a is null)
475 return -1;
476
477 if (a.Equals(a.Zero))
478 {
479 z = x;
480 for (y = x + 1; y < Rows; y++)
481 {
482 b = Matrix[y, x] as ICommutativeRingWithIdentityElement;
483 if (b is null)
484 return -1;
485
486 if (!b.Equals(b.Zero))
487 {
488 a = b;
489 z = y;
490 break;
491 }
492 }
493
494 if (z != x)
495 {
496 for (u = x; u < Columns; u++)
497 {
498 w = Matrix[x, u];
499 Matrix[x, u] = Matrix[z, u];
500 Matrix[z, u] = w;
501 }
502
503 Sign = !Sign;
504 }
505 else
506 {
507 if (BreakIfZero)
508 return -1;
509 else
510 continue;
511 }
512 }
513
514 Rank++;
515
516 if (a != a.One)
517 {
518 for (u = x; u < Columns; u++)
519 Matrix[x, u] = Divide.EvaluateDivision(Matrix[x, u], a, null);
520
521 if (Factor is null)
522 Factor = a;
523 else
524 {
526 if (Factor is null)
527 return -1;
528 }
529 }
530
531 for (y = Eliminate ? 0 : x + 1; y < Rows; y++)
532 {
533 if (y != x)
534 {
535 a = Matrix[y, x] as ICommutativeRingWithIdentityElement;
536 if (a is null)
537 return -1;
538
539 if (!a.Equals(a.Zero))
540 {
541 for (u = x; u < Columns; u++)
542 {
543 Matrix[y, u] = Subtract.EvaluateSubtraction(Matrix[y, u],
544 Multiply.EvaluateMultiplication(a, Matrix[x, u], null), null);
545 }
546 }
547 }
548 }
549 }
550
551 if (Factor is null)
552 Factor = new DoubleNumber(1);
553
554 if (Sign)
555 {
556 Factor = Factor.Negate() as ICommutativeRingWithIdentityElement;
557 if (Factor is null)
558 return -1;
559 }
560
561 return Rank;
562 }
563
570 {
571 IElement[,] Values = this.Values;
572 IElement[,] v;
573 int x, y;
574
575 if (Element.IsScalar)
576 {
577 v = new IElement[this.rows, this.columns];
578
579 for (y = 0; y < this.rows; y++)
580 {
581 for (x = 0; x < this.columns; x++)
582 v[y, x] = Operators.Arithmetics.Add.EvaluateAddition(Element, this.values[y, x], null);
583 }
584
585 return new ObjectMatrix(v);
586 }
587 else if (Element is IMatrix Matrix)
588 {
589 if (this.columns != Matrix.Columns || this.rows != Matrix.Rows)
590 return null;
591
592 IElement[,] Values2 = Matrix.MatrixElements;
593
594 v = new IElement[this.rows, this.columns];
595 for (y = 0; y < this.rows; y++)
596 {
597 for (x = 0; x < this.columns; x++)
598 v[y, x] = Operators.Arithmetics.Add.EvaluateAddition(Values[y, x], Values2[y, x], null);
599 }
600
601 return new ObjectMatrix(v);
602 }
603 else
604 return null;
605 }
606
611 public override IGroupElement Negate()
612 {
613 IElement[,] Values = this.Values;
614 IElement[,] v = new IElement[this.rows, this.columns];
615 int x, y;
616
617 for (y = 0; y < this.rows; y++)
618 {
619 for (x = 0; x < this.columns; x++)
620 v[y, x] = Operators.Arithmetics.Negate.EvaluateNegation(Values[y, x]);
621 }
622
623 return new ObjectMatrix(v);
624 }
625
631 public override bool Equals(object obj)
632 {
633 if (!(obj is IMatrix Matrix))
634 return false;
635
636 if (this.columns != Matrix.Columns || this.rows != Matrix.Rows)
637 return false;
638
639 IElement[,] V1 = this.Values;
640 IElement[,] V2 = Matrix.MatrixElements;
641 int x, y;
642
643 for (y = 0; y < this.rows; y++)
644 {
645 for (x = 0; x < this.columns; x++)
646 {
647 if (V1[y, x] != V2[y, x])
648 return false;
649 }
650 }
651
652 return true;
653 }
654
659 public override int GetHashCode()
660 {
661 int Result = 0;
662 int x, y;
663
664 for (y = 0; y < this.rows; y++)
665 {
666 for (x = 0; x < this.columns; x++)
667 Result ^= this.values[y, x].GetHashCode();
668 }
669
670 return Result;
671 }
672
676 public override bool IsScalar => false;
677
681 public override ICollection<IElement> ChildElements => this.Elements;
682
689 public override IElement Encapsulate(ChunkedList<IElement> Elements, ScriptNode Node)
690 {
691 return MatrixDefinition.Encapsulate(Elements, this.rows, this.columns, Node);
692 }
693
700 public override IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
701 {
702 return MatrixDefinition.Encapsulate(Elements, this.rows, this.columns, Node);
703 }
704
709 {
710 get { throw new ScriptException("Zero element not defined for generic object matrices."); }
711 }
712
716 public int Dimension => this.rows;
717
721 public ICollection<IElement> VectorElements
722 {
723 get
724 {
725 if (!(this.rowVectors is null))
726 return this.rowVectors;
727
729 int x, y;
730
731 if (!(this.values is null))
732 {
733 for (y = 0; y < this.rows; y++)
734 {
736
737 for (x = 0; x < this.columns; x++)
738 Row.Add(this.values[y, x]);
739
740 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row, false, null));
741 }
742 }
743 else
744 {
745 ChunkedList<IElement> Row = null;
746
747 x = 0;
748 foreach (IElement Element in this.elements)
749 {
750 if (Row is null)
751 Row = new ChunkedList<IElement>();
752
753 Row.Add(Element);
754 x++;
755 if (x >= this.columns)
756 {
757 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row, false, null));
758 Row = null;
759 x = 0;
760 }
761 }
762
763 if (!(Row is null))
764 Rows.Add(Operators.Vectors.VectorDefinition.Encapsulate(Row, false, null));
765 }
766
767 this.rowVectors = Rows;
768 return Rows;
769 }
770 }
771
772 private ChunkedList<IElement> rowVectors = null;
773
779 {
780 IElement[,] v = new IElement[this.columns, this.rows];
781 IElement[,] Values = this.Values;
782 int x, y;
783
784 for (y = 0; y < this.rows; y++)
785 {
786 for (x = 0; x < this.columns; x++)
787 v[x, y] = Values[y, x];
788 }
789
790 return new ObjectMatrix(v);
791 }
792
798 {
799 return this.Transpose();
800 }
801
807 public IElement GetElement(int Index)
808 {
809 if (Index < 0 || Index >= this.rows)
810 throw new ScriptException("Index out of bounds.");
811
812 IElement[,] M = this.Values;
813 IElement[] V = new IElement[this.columns];
814 int i;
815
816 for (i = 0; i < this.columns; i++)
817 V[i] = M[Index, i];
818
819 return Operators.Vectors.VectorDefinition.Encapsulate(V, false, null);
820 }
821
827 public void SetElement(int Index, IElement Value)
828 {
829 if (Index < 0 || Index >= this.rows)
830 throw new ScriptException("Index out of bounds.");
831
832 if (!(Value is IVector V))
833 throw new ScriptException("Invalid row vector.");
834
835 if (V.Dimension != this.columns)
836 throw new ScriptException("Dimension mismatch.");
837
838 IElement[,] M = this.Values;
839 this.elements = null;
840
841 int i = 0;
842
843 foreach (IElement E in V.ChildElements)
844 M[Index, i++] = E;
845 }
846
853 public IElement GetElement(int Column, int Row)
854 {
855 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
856 throw new ScriptException("Index out of bounds.");
857
858 return this.Values[Row, Column];
859 }
860
867 public void SetElement(int Column, int Row, IElement Value)
868 {
869 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
870 throw new ScriptException("Index out of bounds.");
871
872 IElement[,] M = this.Values;
873 this.elements = null;
874
875 M[Row, Column] = Value;
876 }
877
883 public IVector GetRow(int Row)
884 {
885 if (Row < 0 || Row >= this.rows)
886 throw new ScriptException("Index out of bounds.");
887
888 IElement[,] M = this.Values;
889 IElement[] V = new IElement[this.columns];
890 int i;
891
892 for (i = 0; i < this.columns; i++)
893 V[i] = M[Row, i];
894
895 return Operators.Vectors.VectorDefinition.Encapsulate(V, false, null);
896 }
897
903 public IVector GetColumn(int Column)
904 {
905 if (Column < 0 || Column >= this.columns)
906 throw new ScriptException("Index out of bounds.");
907
908 IElement[,] M = this.Values;
909 IElement[] V = new IElement[this.rows];
910 int i;
911
912 for (i = 0; i < this.rows; i++)
913 V[i] = M[i, Column];
914
915 return Operators.Vectors.VectorDefinition.Encapsulate(V, false, null);
916 }
917
923 public void SetRow(int Row, IVector Vector)
924 {
925 if (Row < 0 || Row >= this.rows)
926 throw new ScriptException("Index out of bounds.");
927
928 if (Vector.Dimension != this.columns)
929 throw new ScriptException("Vector dimension does not match number of columns");
930
931 IElement[,] M = this.Values;
932 this.elements = null;
933 int i = 0;
934
935 foreach (IElement E in Vector.VectorElements)
936 M[Row, i++] = E;
937 }
938
944 public void SetColumn(int Column, IVector Vector)
945 {
946 if (Column < 0 || Column >= this.columns)
947 throw new ScriptException("Index out of bounds.");
948
949 if (Vector.Dimension != this.rows)
950 throw new ScriptException("Vector dimension does not match number of rows");
951
952 IElement[,] M = this.Values;
953 this.elements = null;
954 int i = 0;
955
956 foreach (IElement E in Vector.VectorElements)
957 M[i++, Column] = E;
958 }
959
968 public bool TryFind(IElement Element, out int Column, out int Row)
969 {
970 return this.TryFind(Element, 0, 0, out Column, out Row);
971 }
972
983 public bool TryFind(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
984 {
985 return this.TryFind(Element.AssociatedObjectValue, FromColumn, FromRow, out Column, out Row);
986 }
987
998 public bool TryFind(object Element, int FromColumn, int FromRow, out int Column, out int Row)
999 {
1000 object[,] Values = this.Values;
1001 object Item;
1002
1003 while (FromRow < this.rows)
1004 {
1005 while (FromColumn < this.columns)
1006 {
1007 Item = Values[FromRow, FromColumn];
1008
1009 if (Item?.Equals(Element) ?? (Element is null))
1010 {
1011 Column = FromColumn;
1012 Row = FromRow;
1013
1014 return true;
1015 }
1016
1017 FromColumn++;
1018 }
1019
1020 FromColumn = 0;
1021 FromRow++;
1022 }
1023
1024 Column = -1;
1025 Row = -1;
1026
1027 return false;
1028 }
1029
1038 public bool TryFindLast(IElement Element, out int Column, out int Row)
1039 {
1040 return this.TryFindLast(Element, this.columns - 1, this.rows - 1, out Column, out Row);
1041 }
1042
1053 public bool TryFindLast(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
1054 {
1055 return this.TryFindLast(Element.AssociatedObjectValue, FromColumn, FromRow, out Column, out Row);
1056 }
1057
1068 public bool TryFindLast(object Element, int FromColumn, int FromRow, out int Column, out int Row)
1069 {
1070 object[,] Values = this.Values;
1071 object Item;
1072
1073 while (FromRow >= 0)
1074 {
1075 while (FromColumn >= 0)
1076 {
1077 Item = Values[FromRow, FromColumn];
1078
1079 if (Item?.Equals(Element) ?? (Element is null))
1080 {
1081 Column = FromColumn;
1082 Row = FromRow;
1083
1084 return true;
1085 }
1086
1087 FromColumn--;
1088 }
1089
1090 FromColumn = this.columns - 1;
1091 FromRow--;
1092 }
1093
1094 Column = -1;
1095 Row = -1;
1096
1097 return false;
1098 }
1099
1100 }
1101}
Node referencing a chunk in a ChunkedList<T>
Definition: ChunkNode.cs:11
ChunkNode< T > Next
Next chunk
Definition: ChunkNode.cs:26
int Pos
Index after the last element in chunk.
Definition: ChunkNode.cs:51
int Start
Index of first element in chunk.
Definition: ChunkNode.cs:46
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
Base class for all types of elements.
Definition: Element.cs:14
virtual bool IsScalar
If the element represents a scalar value.
Definition: Element.cs:48
Element()
Base class for all types of elements.
Definition: Element.cs:18
Base class for all types of ring elements.
Definition: RingElement.cs:10
Base class for script exceptions.
Class managing a script expression.
Definition: Expression.cs:41
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:5241
static string ToExpressionString(object Value)
Converts an object to a string, that can be parsed as part of an expression.
Definition: Expression.cs:5052
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Pseudo-ring of Object-valued matrices.
bool TryFindLast(object Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find the last element in the matrix, continuing search from a given position in the matrix....
IVector GetColumn(int Column)
Gets a column vector from the matrix.
IElement GetElement(int Index)
Gets an element of the vector.
IMatrix ConjugateTranspose()
Returns a conjugate transposed matrix.
void SetElement(int Column, int Row, IElement Value)
Sets an element in the matrix.
override IRing AssociatedRing
Associated Ring.
override IRingElement MultiplyRight(IRingElement Element)
Tries to multiply an element to the current element, from the right.
bool HasColumnNames
If the matrix has column names defined.
ObjectMatrix(IElement[,] Values)
Object-valued matrix.
Definition: ObjectMatrix.cs:29
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool TryFind(object Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find an element in the matrix, continuing search from a given position in the matrix....
IElement GetElement(int Column, int Row)
Gets an element of the matrix.
override object AssociatedObjectValue
Associated object value.
ICollection< IElement > Elements
Matrix elements.
void SetColumn(int Column, IVector Vector)
Gets a column vector from the matrix.
IMatrix Reduce(bool Eliminate, bool BreakIfZero, out int Rank, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
IVector GetRow(int Row)
Gets a row vector from the matrix.
static int Reduce(IElement[,] Matrix, bool Eliminate, bool BreakIfZero, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
ObjectMatrix(object[,] Values)
Object-valued matrix.
Definition: ObjectMatrix.cs:41
bool TryFindLast(IElement Element, out int Column, out int Row)
Tries to find the last element in the matrix. Search is done, right to left, bottom to top.
override IRingElement Invert()
Inverts the element, if possible.
IElement[,] MatrixElements
Matrix elements
override int GetHashCode()
Calculates a hash code of the element.
ObjectMatrix(int Rows, int Columns, ICollection< IElement > Elements)
Object-valued vector.
Definition: ObjectMatrix.cs:64
bool TryFindLast(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find the last element in the matrix, continuing search from a given position in the matrix....
override IRingElement MultiplyLeft(IRingElement Element)
Tries to multiply an element to the current element, from the left.
override IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
override IAbelianGroupElement Zero
Returns the zero element of the group.
void SetElement(int Index, IElement Value)
Sets an element in the vector.
bool TryFind(IElement Element, int FromColumn, int FromRow, out int Column, out int Row)
Tries to find an element in the matrix, continuing search from a given position in the matrix....
bool TryFind(IElement Element, out int Column, out int Row)
Tries to find an element in the matrix. Search is done, left to right, top to bottom.
IElement[,] Values
Matrix element values.
Definition: ObjectMatrix.cs:76
ICollection< IElement > VectorElements
Vector of row vectors.
override bool Equals(object obj)
Compares the element to another.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
string[] ColumnNames
Contains optional column names.
override IGroupElement Negate()
Negates the element.
override bool IsScalar
If the element represents a scalar value.
int Dimension
Dimension of matrix, if seen as a vector of row vectors.
IMatrix Transpose()
Returns a transposed matrix.
void SetRow(int Row, IVector Vector)
Gets a row vector from the matrix.
static IElement EvaluateDivision(IElement Left, IElement Right, ScriptNode Node)
Divides the right operand from the left one.
Definition: Divide.cs:65
static IElement EvaluateMultiplication(IElement Left, IElement Right, ScriptNode Node)
Multiplies two operands.
Definition: Multiply.cs:69
static IElement EvaluateSubtraction(IElement Left, IElement Right, ScriptNode Node)
Subtracts the right operand from the left one.
Definition: Subtract.cs:65
static IMatrix Encapsulate(ICollection< IElement > Rows, ScriptNode Node)
Encapsulates the elements of a matrix.
Basic interface for all types of abelian group elements.
IAbelianGroupElement Zero
Returns the zero element of the group.
Basic interface for all types of commutative ring with identity elements.
ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:50
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
Basic interface for all types of group elements.
Definition: IGroupElement.cs:9
Basic interface for matrices.
Definition: IMatrix.cs:7
Basic interface for all types of ring elements.
Definition: IRingElement.cs:10
Basic interface for vectors.
Definition: IVector.cs:9
int Dimension
Dimension of vector.
Definition: IVector.cs:14
Basic interface for all types of rings.
Definition: IRing.cs:10
Definition: ImplTypes.g.cs:58