public static Polynom <T, R> operator -(Polynom <T, R> Ax) { var _minusOne = Ax.FRing.Opposite(Ax.FRing.One); var _opposite = new Polynom <T, R>(Ax); _opposite.Mult(_minusOne); return(_opposite); }
public static Polynom <T, R> GetGcdEx(Polynom <T, R> a, Polynom <T, R> b, out Polynom <T, R> u, out Polynom <T, R> v) { var _alocal = new Polynom <T, R>(a); var _zero = new Polynom <T, R>(_alocal.FRing, -1); var _one = new Polynom <T, R>(_alocal.FRing, 0); var gcd = _zero; if (_alocal.Degree < 0) { u = _zero; v = (b.Degree < 0 ? _zero : _one); gcd = b; } else if (b.Degree < 0) { v = _zero; u = (_alocal.Degree < 0 ? _zero : _one); gcd = _alocal; } else { var r1 = b; var r2 = new List <Polynom <T, R> >(); var _quot = _alocal.Div(b, r2); gcd = b; var u1 = _one; var u2 = _zero; var v1 = _one; var v2 = _one; var q = _zero; if (r2.Last().Degree < 0) { u1 = _zero; } else { v1 = -_quot; } var temp = new List <Polynom <T, R> >(); var temp1 = _zero; while (r2.Last().Degree >= 0) { gcd = r2.Last(); q = r1.Div(r2.Last(), temp); //r1 = r2.Last(); r1 = gcd; r2 = temp; temp1 = u1; u1 = u2 - u1 * q; u2 = temp1; temp1 = v1; v1 = v2 - v1 * q; v2 = temp1; } u = u2; v = v2; } var _major = gcd.FCoeffs[gcd.Degree]; if (!_alocal.FRing.Equals(_major, _alocal.FRing.One)) { var _major_1 = _alocal.FRing.Reverse(_major); gcd.Mult(_major_1); } var _sum = u * a + v * b; _major = _sum.FCoeffs[_sum.Degree]; if (!_alocal.FRing.Equals(_major, _alocal.FRing.One)) { var _major_1 = _alocal.FRing.Reverse(_major); u.Mult(_major_1); v.Mult(_major_1); } return(gcd); }
private Polynom <T, R> Div(Polynom <T, R> aDenumerator, List <Polynom <T, R> > aRemainder, bool aIsRight) { if (aRemainder == null) { aRemainder = new List <Polynom <T, R> >(); } var quot = new Polynom <T, R>(this.FRing, -1); if (this.Degree < aDenumerator.Degree) { aRemainder.Add(this); return(quot); } int deg_quot = this.Degree - aDenumerator.Degree; var _rem = new Polynom <T, R>(this); var _minusOne = this.FRing.Opposite(this.FRing.One); var c = this.FRing.Reverse(aDenumerator.FCoeffs[aDenumerator.Degree]); while (_rem.Degree >= aDenumerator.Degree) { int p = _rem.Degree - aDenumerator.Degree; var d = new T[p + 1]; if (aIsRight) { d[p] = this.FRing.Prod(_rem.FCoeffs[_rem.Degree], c); } else { d[p] = this.FRing.Prod(c, _rem.FCoeffs[_rem.Degree]); } var dp = new Polynom <T, R>(this.FRing, d); quot += dp; var dd = new Polynom <T, R>(this.FRing, -1); if (aIsRight) { dd = dp * aDenumerator; } else { dd = aDenumerator * dp; } aRemainder.Add(new Polynom <T, R>(dd)); dd.Mult(_minusOne); _rem += dd; aRemainder.Add(_rem); } if (quot.Degree < deg_quot) { var _shift = new Polynom <T, R>(this.FRing, deg_quot - quot.Degree); quot = quot * _shift; } return(quot); }