/// <summary> /// Obtém a matriz sobre a qual se pretende obter o espaço nulo. /// </summary> /// <param name="matrixList">A matriz original.</param> /// <param name="primesList">A lista dos primos.</param> /// <returns>A matriz de "bits".</returns> private ArrayBitMathMatrix GetBitMatrixFromList(List <int[]> matrixList, List <int> primesList) { var matrix = new ArrayBitMathMatrix(primesList.Count, matrixList.Count, 0); for (int i = 0; i < primesList.Count; ++i) { for (int j = 0; j < matrixList.Count; ++j) { matrix[i, j] = matrixList[j][i] % 2; } } return(matrix); }
/// <summary> /// Multiplca uma matriz pela matriz actual de modo que a a soma dos compoentes seja realizada módulo dois. /// </summary> /// <remarks> /// O resultado terá como valor por defeito o valor associado ao objecto corrente. /// </remarks> /// <param name="right">A matriz a ser adicionada.</param> /// <returns>O resultado da soma de ambas as matrizes.</returns> /// <exception cref="ArgumentNullException">Se a matriz a multiplicar for nula.</exception> /// <exception cref="MathematicsException"> /// Se o número de linhas da matriz corrente não coincidir com o número de colunas da matriz a multplicar. /// </exception> public ArrayBitMathMatrix MultiplyModuloTwo(ArrayBitMathMatrix right) { if (right == null) { throw new ArgumentNullException("right"); } else if (this.columnsNumber != right.columnsNumber) { throw new MathematicsException( "The number of columns in first matrix must match the number of lines in second matrix."); } else { var result = new ArrayBitMathMatrix(this.elementsList.Length, right.columnsNumber, 0); for (int i = 0; i < this.elementsList.Length; ++i) { var currentLeftLine = this.elementsList[i]; for (int j = 0; j < currentLeftLine.Count; ++j) { var sum = 0; var k = 0; for (; k < currentLeftLine.Count; ++k) { var rightLine = right.elementsList[k]; var value = right.defaultValue; if (j < rightLine.Count) { value = rightLine[j]; } var prod = currentLeftLine[k] & value; sum = (sum & ~prod) | (~sum & prod); } if (this.defaultValue == 1) { for (; k < this.columnsNumber; ++k) { var rightLine = right.elementsList[k]; var value = right.defaultValue; if (j < rightLine.Count) { value = rightLine[j]; } sum = (sum & ~value) | (~sum & value); } } if (sum != result.defaultValue) { var currentResultLine = result.elementsList[i]; k = currentResultLine.Count; while (k < j) { currentResultLine.Add(result.defaultValue); } currentResultLine.Add(sum); } } } return(result); } }
/// <summary> /// Adiciona uma matriz à matriz actual de modo que a a soma dos compoentes seja realizada módulo dois. /// </summary> /// <remarks> /// O resultado terá como valor por defeito o valor associado ao objecto corrente. /// </remarks> /// <param name="right">A matriz a ser adicionada.</param> /// <returns>O resultado da soma de ambas as matrizes.</returns> /// <exception cref="ArgumentNullException">Se a matriz a adicionar for nula.</exception> /// <exception cref="ArgumentException"> /// Se as dimensões da matriz a adicionar não conicidirem com as dimensões da matriz corrente. /// </exception> public ArrayBitMathMatrix AddModuloTwo(ArrayBitMathMatrix right) { if (right == null) { throw new ArgumentNullException("right"); } else if (this.elementsList.Length != right.elementsList.Length) { throw new ArgumentException("Can only sum matrices with the same number of lines."); } else if (this.columnsNumber != right.columnsNumber) { throw new ArgumentException("Can only sum matrices with the same number of columns."); } else { var result = new ArrayBitMathMatrix(this.elementsList.Length, this.columnsNumber, this.defaultValue); for (int i = 0; i < this.elementsList.Length; ++i) { var currentThisMatrixLine = this.elementsList[i]; var currentRightMatrixLine = right.elementsList[i]; var minLine = Math.Min(currentThisMatrixLine.Count, currentRightMatrixLine.Count); var j = 0; for (; j < minLine; ++j) { var leftValue = currentThisMatrixLine[j]; var rightValue = currentRightMatrixLine[j]; var sum = (leftValue & ~rightValue) | (~leftValue & rightValue); if (sum != this.defaultValue) { result[i, j] = sum; } } for (; j < currentThisMatrixLine.Count; ++j) { var leftValue = currentThisMatrixLine[j]; var rightValue = right.defaultValue; var sum = (leftValue & ~rightValue) | (~leftValue & rightValue); if (sum != this.defaultValue) { result[i, j] = sum; } } for (; j < currentRightMatrixLine.Count; ++j) { var leftValue = this.defaultValue; var rightValue = currentRightMatrixLine[j]; var sum = (leftValue & ~rightValue) | (~leftValue & rightValue); if (sum != this.defaultValue) { result[i, j] = sum; } } if (this.defaultValue == right.defaultValue && this.defaultValue != 0) { for (; j < this.columnsNumber; ++j) { result.elementsList[i].Add(1); } } else if (this.defaultValue != right.defaultValue && this.defaultValue != 1) { for (; j < currentThisMatrixLine.Count; ++j) { result.elementsList[i].Add(0); } } } return(result); } }