/*************************
 * Row Operation class   *
 * --------------------- *
 *************************

new RowOperation("scale",row,factor);
new RowOperation("exchange",row1,row2);
new RowOperation("add",factor,pivotRow,row);

[RowOperation].toString()
[RowOperation].inverse()
[RowOperation].transpose()

*/

function RowOperation(type) {
    this.type = type;
    
    switch ( type ) {
      case "scale" :
	this.row    = arguments[1];
	this.factor = arguments[2];
	this.pivotColumn = arguments[3];
	break;
      case "exchange" :
	this.row1 = arguments[1];
	this.row2 = arguments[2];
	this.pivotColumn = arguments[3];
	break;
      case "add" :
	this.factor   = arguments[1];
	this.pivotRow = arguments[2];
	this.row      = arguments[3];
	this.pivotColumn = arguments[4];
    }
}

RowOperation.prototype.toString = function() {
    switch ( this.type ) {
      case "scale" :
	return ( "Scale row " + this.row + " by " + this.factor.toString() + "." );
      case "exchange" :
	return ( "Exchange rows " + this.row1 + " and " + this.row2 + "." );
      case "add" :
	return ( "Add " + this.factor.toString() + " times row " + this.pivotRow
	+ " to row " + this.row + "." );		
    }
    return "";
}

RowOperation.prototype.inverse = function() {
    switch ( this.type ) {
      case "scale" :
	return new RowOperation ( "scale", this.row, this.factor.inverse(), this.pivotColumn );
      case "exchange" :
	return new RowOperation ( "exchange", this.row1, this.row2, this.pivotColumn );
      case "add" :
	return new RowOperation ( "add", this.factor.minus(), this.pivotRow, this.row, this.pivotColumn );
    }
}

RowOperation.prototype.transpose = function() {
    switch ( this.type ) {
      case "scale" :
	return new RowOperation ( "scale", this.row, this.factor, this.pivotColumn );
     case "exchange" :
	return new RowOperation ( "exchange", this.row1, this.row2, this.pivotColumn );
      case "add" :
	return new RowOperation ( "add", this.factor, this.row, this.pivotRow, this.pivotColumn );
    }
}

