Formall.MySql/branches/WebSiteWithPresentation/QrCode/ReedSolomon/Polynomial.cs
/// <summary>
/// divide current polynomial by "other"
/// </summary>
/// <returns>Result polynomial after divide</returns>
divide current polynomial by "other"
divide current polynomial by " other "
internal PolyDivideStruct Divide(Polynomial other)
		{
			if(this.Primitive != other.Primitive)
			{
				throw new ArgumentException("Polynomial can not perform Devide as they don't have same Primitive for GaloisField256");
			}
			if(other.isMonomialZero)
			{
				throw new ArgumentException("Can not devide by Polynomial Zero");
			}
			int aLength = this.Coefficients.Length;
			int[] aCoefficients = new int[aLength];
			Array.Copy(this.Coefficients, 0, aCoefficients, 0, aLength);
			int bLength = other.Coefficients.Length;
			if(aLength < bLength)
				return new PolyDivideStruct(new Polynomial(this.GField, new int[]{0}), this);
			else
			{
				int[] qCoefficients = new int[( aLength - bLength ) + 1];
				int otherLeadingTerm = other.GetCoefficient(other.Degree);
				int inverseOtherLeadingTerm = this.GField.inverse(otherLeadingTerm);
				for(int aIndex = 0; aIndex <= aLength - bLength; aIndex++)
				{
					if(aCoefficients[aIndex] != 0)
					{
						int aScalar = this.GField.Product(inverseOtherLeadingTerm, aCoefficients[aIndex]);
						Polynomial term = other.MultiplyScalar(aScalar);
						qCoefficients[aIndex] = aScalar;
						int[] bCoefficient = term.Coefficients;
						if(bCoefficient[0] != 0)
						{
							for(int bIndex = 0; bIndex < bLength; bIndex++)
							{
								aCoefficients[aIndex + bIndex] = this.GField.Subtraction(aCoefficients[aIndex + bIndex], bCoefficient[bIndex]);
							}
						}
					}
				}
				return new PolyDivideStruct(new Polynomial(this.GField, qCoefficients),
				                            new Polynomial(this.GField, aCoefficients));
			}
		}
internal PolyDivideStruct Divide ( Polynomial other ) { if ( this . Primitive != other . Primitive ) { throw new ArgumentException ( " " ) ; } if ( other . isMonomialZero ) { throw new ArgumentException ( " " ) ; } int aLength = this . Coefficients . Length ; int [ ] aCoefficients = new int [ aLength ] ; Array . Copy ( this . Coefficients , 0 , aCoefficients , 0 , aLength ) ; int bLength = other . Coefficients . Length ; if ( aLength < bLength ) return new PolyDivideStruct ( new Polynomial ( this . GField , new int [ ] { 0 } ) , this ) ; else { int [ ] qCoefficients = new int [ ( aLength - bLength ) + 1 ] ; int otherLeadingTerm = other . GetCoefficient ( other . Degree ) ; int inverseOtherLeadingTerm = this . GField . inverse ( otherLeadingTerm ) ; for ( int aIndex = 0 ; aIndex <= aLength - bLength ; aIndex ++ ) { if ( aCoefficients [ aIndex ] != 0 ) { int aScalar = this . GField . Product ( inverseOtherLeadingTerm , aCoefficients [ aIndex ] ) ; Polynomial term = other . MultiplyScalar ( aScalar ) ; qCoefficients [ aIndex ] = aScalar ; int [ ] bCoefficient = term . Coefficients ; if ( bCoefficient [ 0 ] != 0 ) { for ( int bIndex = 0 ; bIndex < bLength ; bIndex ++ ) { aCoefficients [ aIndex + bIndex ] = this . GField . Subtraction ( aCoefficients [ aIndex + bIndex ] , bCoefficient [ bIndex ] ) ; } } } } return new PolyDivideStruct ( new Polynomial ( this . GField , qCoefficients ) , new Polynomial ( this . GField , aCoefficients ) ) ; } }
divide current polynomial by "other"
divide current polynomial by " other "
//this devide by other = a devide by b //We will make change to aCoefficient. It will return as remainder //quotient coefficients //qLastIndex = alength - blength  qlength = qLastIndex + 1 //Denominator
Result polynomial after divide
Result polynomial after divide
other
Polynomial