Exemplo n.º 1
0
 @Override
 public IExpr evaluate(final IAST ast) {
   Validate.checkRange(ast, 2, 3);
   IExpr arg = F.evalExpandAll(ast.get(1));
   try {
     if (arg.isTimes() || arg.isPower()) {
       IExpr[] parts = Apart.getFractionalParts(arg);
       if (parts != null) {
         if (parts[0].isPlus() && parts[1].isPlus()) {
           IAST[] numParts = ((IAST) parts[0]).split(new PolynomialPredicate());
           IAST[] denParts = ((IAST) parts[1]).split(new PolynomialPredicate());
           IExpr denParts0 = F.eval(denParts[0]);
           if (!denParts0.equals(F.C1)) {
             IExpr[] result = Cancel.cancelGCD(numParts[0], denParts0);
             if (result != null) {
               return F.Times(
                   result[0], numParts[1], F.Power(F.Times(result[1], denParts[1]), F.CN1));
             }
           }
         }
       }
     }
   } catch (JASConversionException jce) {
     if (Config.DEBUG) {
       jce.printStackTrace();
     }
   }
   return arg;
 }
Exemplo n.º 2
0
  @Override
  public IExpr evaluate(final IAST lst) {
    if (lst.size() >= 3) {
      try {
        if (lst.get(1).isVector() < 0) {
          return null;
        }
        if (lst.get(2).isVector() < 0) {
          return null;
        }
        if (lst.size() == 3) {
          IAST vars = (IAST) lst.get(2);
          if (vars.size() <= 1) {
            return null;
          }
          List<ISymbol> varList = new ArrayList<ISymbol>(vars.size() - 1);
          String[] pvars = new String[vars.size() - 1];
          for (int i = 1; i < vars.size(); i++) {
            if (!vars.get(i).isSymbol()) {
              return null;
            }
            varList.add((ISymbol) vars.get(i));
            pvars[i - 1] = ((ISymbol) vars.get(i)).toString();
          }
          GroebnerBasePartial<BigRational> gbp = new GroebnerBasePartial<BigRational>();
          IAST polys = (IAST) lst.get(1);
          List<GenPolynomial<BigRational>> polyList =
              new ArrayList<GenPolynomial<BigRational>>(polys.size() - 1);
          JASConvert<BigRational> jas = new JASConvert<BigRational>(varList, BigRational.ZERO);
          for (int i = 1; i < polys.size(); i++) {
            IExpr expr = F.evalExpandAll(polys.get(i));
            GenPolynomial<BigRational> poly = jas.expr2JAS(expr);
            polyList.add(poly);
          }

          OptimizedPolynomialList<BigRational> opl = gbp.partialGB(polyList, pvars);
          // System.out.println(opl);

          IAST resultList = F.List();
          for (GenPolynomial<BigRational> p : opl.list) {
            // System.out.println(p);
            resultList.add(jas.poly2Expr(p, null));
          }
          return resultList;
        }
      } catch (JASConversionException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      }
    }
    return null;
  }