1using System.Collections.Generic;
17 private bool[,] values;
19 private ICollection<IElement> elements;
20 private readonly
int rows;
21 private readonly
int columns;
31 this.matrixElements =
null;
32 this.rows =
Values.GetLength(0);
33 this.columns =
Values.GetLength(1);
46 this.matrixElements =
null;
58 if (this.values is
null)
60 bool[,] v =
new bool[this.rows, this.columns];
70 if (x >= this.columns)
91 if (this.elements is
null)
96 for (y = 0; y < this.rows; y++)
98 for (x = 0; x < this.columns; x++)
105 return this.elements;
116 if (this.matrixElements is
null)
125 if (x >= this.columns)
132 this.matrixElements = v;
135 return this.matrixElements;
153 StringBuilder sb =
null;
157 for (y = 0; y < this.rows; y++)
160 sb =
new StringBuilder(
"[[");
162 sb.Append(
",\r\n [");
165 for (x = 0; x < this.columns; x++)
179 sb =
new StringBuilder(
"[[]]");
183 return sb.ToString();
193 if (this.associatedMatrixSpace is
null)
194 this.associatedMatrixSpace =
new BooleanMatrices(this.rows, this.columns);
196 return this.associatedMatrixSpace;
233 if (this.rows != this.columns)
262 double[,] v =
new double[this.rows, this.columns];
265 for (y = 0; y < this.rows; y++)
267 for (x = 0; x < this.columns; x++)
268 v[y, x] =
Values[y, x] ? 1 : 0;
303 if (this.columns != Matrix.columns ||
this.rows != Matrix.rows)
307 bool[,] V2 = Matrix.Values;
310 for (y = 0; y < this.rows; y++)
312 for (x = 0; x < this.columns; x++)
314 if (V1[y, x] != V2[y, x])
332 for (y = 0; y < this.rows; y++)
334 for (x = 0; x < this.columns; x++)
336 if (this.values[y, x])
375 if (this.zero is
null)
376 this.zero =
new BooleanMatrix(
new bool[this.rows, this.columns]);
396 if (!(this.rowVectors is
null))
397 return this.rowVectors;
400 LinkedList<IElement>
Rows =
new LinkedList<IElement>();
404 for (y = 0; y < this.rows; y++)
406 r =
new bool[this.columns];
408 for (x = 0; x < this.columns; x++)
414 this.rowVectors =
Rows;
419 private LinkedList<IElement> rowVectors =
null;
427 bool[,] v =
new bool[this.columns, this.rows];
431 for (y = 0; y < this.rows; y++)
433 for (x = 0; x < this.columns; x++)
456 if (Index < 0 || Index >= this.rows)
460 bool[] V =
new bool[this.columns];
463 for (i = 0; i < this.columns; i++)
476 if (Index < 0 || Index >= this.rows)
480 throw new ScriptException(
"Row vectors in a boolean matrix are required to be boolean vectors.");
482 if (V.Dimension !=
this.columns)
485 bool[] V2 = V.Values;
487 this.elements =
null;
491 for (i = 0; i < this.columns; i++)
503 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
517 if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows)
521 throw new ScriptException(
"Elements in a boolean matrix must be boolean values.");
524 this.elements =
null;
536 if (Row < 0 || Row >= this.rows)
540 bool[] V =
new bool[this.columns];
543 for (i = 0; i < this.columns; i++)
556 if (Column < 0 || Column >= this.columns)
560 bool[] V =
new bool[this.rows];
563 for (i = 0; i < this.rows; i++)
576 if (Row < 0 || Row >= this.rows)
580 throw new ScriptException(
"Vector dimension does not match number of columns");
583 throw new ScriptException(
"Row vectors in a boolean matrix must be boolean vectors.");
585 bool[] V2 = V.Values;
587 this.elements =
null;
590 for (i = 0; i < this.columns; i++)
601 if (Column < 0 || Column >= this.columns)
605 throw new ScriptException(
"Vector dimension does not match number of rows");
608 throw new ScriptException(
"Column vectors in a boolean matrix must be boolean vectors.");
610 bool[] V2 = V.Values;
612 this.elements =
null;
615 for (i = 0; i < this.rows; i++)
616 M[i, Column] = V2[i];
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.
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.
override bool Equals(object obj)
Compares the element to another.
void SetElement(int Index, IElement Value)
Sets an element in the vector.
BooleanMatrix(bool[,] Values)
Boolean-valued 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.
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.
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 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.