Ejemplo n.º 1
0
  /**
   * Univariate GenPolynomial algebraic partial fraction decomposition, Rothstein-Trager algorithm.
   *
   * @param A univariate GenPolynomial, deg(A) < deg(P).
   * @param P univariate squarefree GenPolynomial, gcd(A,P) == 1.
   * @return partial fraction container.
   */
  @Deprecated
  public PartialFraction<C> baseAlgebraicPartialFractionIrreducible(
      GenPolynomial<C> A, GenPolynomial<C> P) {
    if (P == null || P.isZERO()) {
      throw new RuntimeException(" P == null or P == 0");
    }
    // System.out.println("\nP_base_algeb_part = " + P);
    GenPolynomialRing<C> pfac = P.ring; // K[x]
    if (pfac.nvar > 1) {
      // System.out.println("facs_base_irred: univ");
      throw new RuntimeException("only for univariate polynomials");
    }
    if (!pfac.coFac.isField()) {
      // System.out.println("facs_base_irred: field");
      throw new RuntimeException("only for field coefficients");
    }
    List<C> cfactors = new ArrayList<C>();
    List<GenPolynomial<C>> cdenom = new ArrayList<GenPolynomial<C>>();
    List<AlgebraicNumber<C>> afactors = new ArrayList<AlgebraicNumber<C>>();
    List<GenPolynomial<AlgebraicNumber<C>>> adenom =
        new ArrayList<GenPolynomial<AlgebraicNumber<C>>>();

    // P linear
    if (P.degree(0) <= 1) {
      cfactors.add(A.leadingBaseCoefficient());
      cdenom.add(P);
      return new PartialFraction<C>(A, P, cfactors, cdenom, afactors, adenom);
    }

    // deriviative
    GenPolynomial<C> Pp = PolyUtil.<C>baseDeriviative(P);
    // no: Pp = Pp.monic();
    // System.out.println("\nP  = " + P);
    // System.out.println("Pp = " + Pp);

    // Q[t]
    String[] vars = new String[] {"t"};
    GenPolynomialRing<C> cfac = new GenPolynomialRing<C>(pfac.coFac, 1, pfac.tord, vars);
    GenPolynomial<C> t = cfac.univariate(0);
    // System.out.println("t = " + t);

    // Q[x][t]
    GenPolynomialRing<GenPolynomial<C>> rfac =
        new GenPolynomialRing<GenPolynomial<C>>(pfac, cfac); // sic
    // System.out.println("rfac = " + rfac.toScript());

    // transform polynomials to bi-variate polynomial
    GenPolynomial<GenPolynomial<C>> Ac = PolyUfdUtil.<C>introduceLowerVariable(rfac, A);
    // System.out.println("Ac = " + Ac);
    GenPolynomial<GenPolynomial<C>> Pc = PolyUfdUtil.<C>introduceLowerVariable(rfac, P);
    // System.out.println("Pc = " + Pc);
    GenPolynomial<GenPolynomial<C>> Pcp = PolyUfdUtil.<C>introduceLowerVariable(rfac, Pp);
    // System.out.println("Pcp = " + Pcp);

    // Q[t][x]
    GenPolynomialRing<GenPolynomial<C>> rfac1 = Pc.ring;
    // System.out.println("rfac1 = " + rfac1.toScript());

    // A - t P'
    GenPolynomial<GenPolynomial<C>> tc = rfac1.getONE().multiply(t);
    // System.out.println("tc = " + tc);
    GenPolynomial<GenPolynomial<C>> At = Ac.subtract(tc.multiply(Pcp));
    // System.out.println("At = " + At);

    GreatestCommonDivisorSubres<C> engine = new GreatestCommonDivisorSubres<C>();
    // = GCDFactory.<C>getImplementation( cfac.coFac );
    GreatestCommonDivisorAbstract<AlgebraicNumber<C>> aengine = null;

    GenPolynomial<GenPolynomial<C>> Rc = engine.recursiveResultant(Pc, At);
    // System.out.println("Rc = " + Rc);
    GenPolynomial<C> res = Rc.leadingBaseCoefficient();
    // no: res = res.monic();
    // System.out.println("\nres = " + res);

    SortedMap<GenPolynomial<C>, Long> resfac = baseFactors(res);
    // System.out.println("resfac = " + resfac + "\n");

    for (GenPolynomial<C> r : resfac.keySet()) {
      // System.out.println("\nr(t) = " + r);
      if (r.isConstant()) {
        continue;
      }
      //             if ( r.degree(0) <= 1L ) {
      //                 System.out.println("warning linear factor in resultant ignored");
      //                 continue;
      //                 //throw new RuntimeException("input not irreducible");
      //             }
      // vars = new String[] { "z_" + Math.abs(r.hashCode() % 1000) };
      vars = pfac.newVars("z_");
      pfac = pfac.clone();
      vars = pfac.setVars(vars);
      r = pfac.copy(r); // hack to exchange the variables
      // System.out.println("r(z_) = " + r);
      AlgebraicNumberRing<C> afac = new AlgebraicNumberRing<C>(r, true); // since irreducible
      logger.debug("afac = " + afac.toScript());
      AlgebraicNumber<C> a = afac.getGenerator();
      // no: a = a.negate();
      // System.out.println("a = " + a);

      // K(alpha)[x]
      GenPolynomialRing<AlgebraicNumber<C>> pafac =
          new GenPolynomialRing<AlgebraicNumber<C>>(afac, Pc.ring);
      // System.out.println("pafac = " + pafac.toScript());

      // convert to K(alpha)[x]
      GenPolynomial<AlgebraicNumber<C>> Pa = PolyUtil.<C>convertToAlgebraicCoefficients(pafac, P);
      // System.out.println("Pa = " + Pa);
      GenPolynomial<AlgebraicNumber<C>> Pap = PolyUtil.<C>convertToAlgebraicCoefficients(pafac, Pp);
      // System.out.println("Pap = " + Pap);
      GenPolynomial<AlgebraicNumber<C>> Aa = PolyUtil.<C>convertToAlgebraicCoefficients(pafac, A);
      // System.out.println("Aa = " + Aa);

      // A - a P'
      GenPolynomial<AlgebraicNumber<C>> Ap = Aa.subtract(Pap.multiply(a));
      // System.out.println("Ap = " + Ap);

      if (aengine == null) {
        aengine = GCDFactory.<AlgebraicNumber<C>>getImplementation(afac);
        // System.out.println("aengine = " + aengine);
      }
      GenPolynomial<AlgebraicNumber<C>> Ga = aengine.baseGcd(Pa, Ap);
      // System.out.println("Ga = " + Ga);
      if (Ga.isConstant()) {
        // System.out.println("warning constant gcd ignored");
        continue;
      }
      afactors.add(a);
      adenom.add(Ga);
      // quadratic case
      if (P.degree(0) == 2 && Ga.degree(0) == 1) {
        GenPolynomial<AlgebraicNumber<C>>[] qra =
            PolyUtil.<AlgebraicNumber<C>>basePseudoQuotientRemainder(Pa, Ga);
        GenPolynomial<AlgebraicNumber<C>> Qa = qra[0];
        if (!qra[1].isZERO()) {
          throw new RuntimeException("remainder not zero");
        }
        // System.out.println("Qa = " + Qa);
        afactors.add(a.negate());
        adenom.add(Qa);
      }
      if (false && P.degree(0) == 3 && Ga.degree(0) == 1) {
        GenPolynomial<AlgebraicNumber<C>>[] qra =
            PolyUtil.<AlgebraicNumber<C>>basePseudoQuotientRemainder(Pa, Ga);
        GenPolynomial<AlgebraicNumber<C>> Qa = qra[0];
        if (!qra[1].isZERO()) {
          throw new RuntimeException("remainder not zero");
        }
        System.out.println("Qa3 = " + Qa);
        // afactors.add( a.negate() );
        // adenom.add( Qa );
      }
    }
    return new PartialFraction<C>(A, P, cfactors, cdenom, afactors, adenom);
  }
Ejemplo n.º 2
0
 /**
  * GenPolynomial base absolute factorization of a irreducible polynomial.
  *
  * @param P irreducible! univariate GenPolynomial.
  * @return factors container: [p_1,...,p_k] with P = prod_{i=1, ..., k} p_i in K(alpha)[x] for
  *     suitable alpha and p_i irreducible over L[x], where K \subset K(alpha) \subset L is an
  *     algebraically closed field over K. <b>Note:</b> K(alpha) not yet minimal.
  */
 public Factors<C> baseFactorsAbsoluteIrreducible(GenPolynomial<C> P) {
   if (P == null) {
     throw new RuntimeException(this.getClass().getName() + " P == null");
   }
   if (P.isZERO()) {
     return new Factors<C>(P);
   }
   // System.out.println("\nP_base_irred = " + P);
   GenPolynomialRing<C> pfac = P.ring; // K[x]
   if (pfac.nvar > 1) {
     // System.out.println("facs_base_irred: univ");
     throw new RuntimeException("only for univariate polynomials");
   }
   if (!pfac.coFac.isField()) {
     // System.out.println("facs_base_irred: field");
     throw new RuntimeException("only for field coefficients");
   }
   if (P.degree(0) <= 1) {
     return new Factors<C>(P);
   }
   // setup field extension K(alpha) where alpha = z_xx
   // String[] vars = new String[] { "z_" + Math.abs(P.hashCode() % 1000) };
   String[] vars = pfac.newVars("z_");
   pfac = pfac.clone();
   vars = pfac.setVars(vars);
   GenPolynomial<C> aP = pfac.copy(P); // hack to exchange the variables
   AlgebraicNumberRing<C> afac = new AlgebraicNumberRing<C>(aP, true); // since irreducible
   if (logger.isInfoEnabled()) {
     logger.info("K(alpha) = " + afac);
     logger.info("K(alpha) = " + afac.toScript());
     // System.out.println("K(alpha) = " + afac);
   }
   GenPolynomialRing<AlgebraicNumber<C>> pafac =
       new GenPolynomialRing<AlgebraicNumber<C>>(afac, aP.ring.nvar, aP.ring.tord, /*old*/ vars);
   // convert to K(alpha)
   GenPolynomial<AlgebraicNumber<C>> Pa = PolyUtil.<C>convertToAlgebraicCoefficients(pafac, P);
   if (logger.isInfoEnabled()) {
     logger.info("P over K(alpha) = " + Pa);
     // logger.info("P over K(alpha) = " + Pa.toScript());
     // System.out.println("P in K(alpha) = " + Pa);
   }
   // factor over K(alpha)
   FactorAbstract<AlgebraicNumber<C>> engine = FactorFactory.<C>getImplementation(afac);
   // System.out.println("K(alpha) engine = " + engine);
   List<GenPolynomial<AlgebraicNumber<C>>> factors = engine.baseFactorsSquarefree(Pa);
   // System.out.println("factors = " + factors);
   if (logger.isInfoEnabled()) {
     logger.info("factors over K(alpha) = " + factors);
     // System.out.println("factors over K(alpha) = " + factors);
   }
   List<GenPolynomial<AlgebraicNumber<C>>> faca =
       new ArrayList<GenPolynomial<AlgebraicNumber<C>>>(factors.size());
   ;
   List<Factors<AlgebraicNumber<C>>> facar = new ArrayList<Factors<AlgebraicNumber<C>>>();
   for (GenPolynomial<AlgebraicNumber<C>> fi : factors) {
     if (fi.degree(0) <= 1) {
       faca.add(fi);
     } else {
       // System.out.println("fi.deg > 1 = " + fi);
       FactorAbsolute<AlgebraicNumber<C>> aengine =
           (FactorAbsolute<AlgebraicNumber<C>>) FactorFactory.<C>getImplementation(afac);
       Factors<AlgebraicNumber<C>> fif = aengine.baseFactorsAbsoluteIrreducible(fi);
       // System.out.println("fif = " + fif);
       facar.add(fif);
     }
   }
   if (facar.size() == 0) {
     facar = null;
   }
   // find minimal field extension K(beta) \subset K(alpha)
   return new Factors<C>(P, afac, Pa, faca, facar);
 }