18 private bool[,] values;
20 private ICollection<IElement> elements;
21 private readonly
int rows;
22 private readonly
int columns;
32 this.matrixElements =
null;
33 this.rows =
Values.GetLength(0);
34 this.columns =
Values.GetLength(1);
47 this.matrixElements =
null;
59 if (this.values is
null)
61 bool[,] v =
new bool[this.rows, this.columns];
70 while (!(Loop is
null))
72 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
78 if (x >= this.columns)
96 if (x >= this.columns)
118 if (this.elements is
null)
123 for (y = 0; y < this.rows; y++)
125 for (x = 0; x < this.columns; x++)
132 return this.elements;
143 if (this.matrixElements is
null)
152 if (x >= this.columns)
159 this.matrixElements = v;
162 return this.matrixElements;
180 StringBuilder sb =
null;
184 for (y = 0; y < this.rows; y++)
187 sb =
new StringBuilder(
"[[");
189 sb.Append(
",\r\n [");
192 for (x = 0; x < this.columns; x++)
206 sb =
new StringBuilder(
"[[]]");
210 return sb.ToString();
220 if (this.associatedMatrixSpace is
null)
221 this.associatedMatrixSpace =
new BooleanMatrices(this.rows, this.columns);
223 return this.associatedMatrixSpace;
260 if (this.rows != this.columns)
289 double[,] v =
new double[this.rows, this.columns];
292 for (y = 0; y < this.rows; y++)
294 for (x = 0; x < this.columns; x++)
295 v[y, x] =
Values[y, x] ? 1 : 0;
330 if (this.columns != Matrix.columns ||
this.rows != Matrix.rows)
334 bool[,] V2 = Matrix.Values;
337 for (y = 0; y < this.rows; y++)
339 for (x = 0; x < this.columns; x++)
341 if (V1[y, x] != V2[y, x])
359 for (y = 0; y < this.rows; y++)
361 for (x = 0; x < this.columns; x++)
363 if (this.values[y, x])
413 if (this.zero is
null)
414 this.zero =
new BooleanMatrix(
new bool[this.rows, this.columns]);
434 if (!(this.rowVectors is
null))
435 return this.rowVectors;
442 for (y = 0; y < this.rows; y++)
444 r =
new bool[this.columns];
446 for (x = 0; x < this.columns; x++)
452 this.rowVectors =
Rows;
465 bool[,] v =
new bool[this.columns, this.rows];
469 for (y = 0; y < this.rows; y++)
471 for (x = 0; x < this.columns; x++)
494 if (Index < 0 || Index >= this.rows)
498 bool[] V =
new bool[this.columns];
501 for (i = 0; i < this.columns; i++)
514 if (Index < 0 || Index >= this.rows)
518 throw new ScriptException(
"Row vectors in a boolean matrix are required to be boolean vectors.");
520 if (V.Dimension !=
this.columns)
523 bool[] V2 = V.Values;
525 this.elements =
null;
529 for (i = 0; i < this.columns; i++)
541 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
555 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
559 throw new ScriptException(
"Elements in a boolean matrix must be boolean values.");
562 this.elements =
null;
574 if (Row < 0 || Row >= this.rows)
578 bool[] V =
new bool[this.columns];
581 for (i = 0; i < this.columns; i++)
594 if (Column < 0 || Column >= this.columns)
598 bool[] V =
new bool[this.rows];
601 for (i = 0; i < this.rows; i++)
614 if (Row < 0 || Row >= this.rows)
618 throw new ScriptException(
"Vector dimension does not match number of columns");
621 throw new ScriptException(
"Row vectors in a boolean matrix must be boolean vectors.");
623 bool[] V2 = V.Values;
625 this.elements =
null;
628 for (i = 0; i < this.columns; i++)
639 if (Column < 0 || Column >= this.columns)
643 throw new ScriptException(
"Vector dimension does not match number of rows");
646 throw new ScriptException(
"Column vectors in a boolean matrix must be boolean vectors.");
648 bool[] V2 = V.Values;
650 this.elements =
null;
653 for (i = 0; i < this.rows; i++)
654 M[i, Column] = V2[i];
667 return this.
TryFind(Element, 0, 0, out Column, out Row);
683 return this.
TryFind(B.Value, FromColumn, FromRow, out Column, out Row);
702 public bool TryFind(
bool Element,
int FromColumn,
int FromRow, out
int Column, out
int Row)
706 while (FromRow < this.rows)
708 while (FromColumn < this.columns)
741 return this.
TryFindLast(Element, this.columns - 1, this.rows - 1, out Column, out Row);
757 return this.
TryFindLast(B.Value, FromColumn, FromRow, out Column, out Row);
782 while (FromColumn >= 0)
795 FromColumn = this.columns - 1;
Node referencing a chunk in a ChunkedList<T>
ChunkNode< T > Next
Next chunk
int Pos
Index after the last element in chunk.
int Start
Index of first element in chunk.
A chunked list is a linked list of chunks of objects of type T .
Base class for all types of elements.
abstract object AssociatedObjectValue
Associated object value.
Base class for all types of ring elements.
Base class for script exceptions.
Class managing a script expression.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Base class for all nodes in a parsed script tree.
Pseudo-ring of Boolean-valued matrices.
IVector GetColumn(int Column)
Gets a column vector from the matrix.
void SetRow(int Row, IVector Vector)
Gets a row vector from the matrix.
override IRingElement Invert()
Inverts the element, if possible.
IMatrix ConjugateTranspose()
Returns a conjugate transposed matrix.
bool TryFind(bool 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....
int Dimension
Dimension of matrix, if seen as a vector of row vectors.
override IRingElement MultiplyLeft(IRingElement Element)
Tries to multiply an element to the current element, from the left.
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
void SetElement(int Column, int Row, IElement Value)
Sets an element in the matrix.
override IAbelianGroupElement Zero
Returns the zero element of the group.
ICollection< IElement > VectorElements
Vector of row vectors.
IElement[,] MatrixElements
Matrix elements
override int GetHashCode()
Calculates a hash code of the element.
IElement GetElement(int Index)
Gets an element of the vector.
override object AssociatedObjectValue
Associated object value.
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.
override bool Equals(object obj)
Compares the element to another.
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....
BooleanMatrix(bool[,] Values)
Boolean-valued matrix.
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....
IMatrix Reduce(bool Eliminate, bool BreakIfZero, out int Rank, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
void SetColumn(int Column, IVector Vector)
Gets a column vector from the matrix.
ICollection< IElement > Elements
Matrix elements.
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 string ToString()
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
DoubleMatrix ToDoubleMatrix()
Converts matrix to a double-valued matrix.
bool[,] Values
Matrix element values.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
bool TryFindLast(bool 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 bool IsScalar
If the element represents a scalar value.
IVector GetRow(int Row)
Gets a row vector from the matrix.
int Columns
Number of columns.
override IGroupElement Negate()
Negates the element.
override IRing AssociatedRing
Associated Ring.
BooleanMatrix(int Rows, int Columns, ICollection< IElement > Elements)
Boolean-valued vector.
IElement GetElement(int Column, int Row)
Gets an element of the matrix.
IMatrix Transpose()
Returns a transposed matrix.
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 IRingElement MultiplyRight(IRingElement Element)
Tries to multiply an element to the current element, from the right.
IMatrix Reduce(bool Eliminate, bool BreakIfZero, out int Rank, out ICommutativeRingWithIdentityElement Factor)
Reduces a matrix.
override IRingElement MultiplyLeft(IRingElement Element)
Tries to multiply an element to the current element, from the left.
override IRingElement MultiplyRight(IRingElement Element)
Tries to multiply an element to the current element, from the right.
override IRingElement Invert()
Inverts the element, if possible.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
static IMatrix Encapsulate(ICollection< IElement > Rows, ScriptNode Node)
Encapsulates the elements of a matrix.
Basic interface for all types of abelian group elements.
Basic interface for all types of commutative ring with identity elements.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
Basic interface for all types of group elements.
Basic interface for matrices.
Basic interface for all types of ring elements.
Basic interface for vectors.
int Dimension
Dimension of vector.
Basic interface for all types of rings.