Exemple #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;
 }
Exemple #2
0
  public void testHashValueVisitor() {
    HashValueVisitor v = new HashValueVisitor(1);
    IExpr expr = F.Power(F.Sin(F.Log(F.C1)), F.C2);
    int hash = expr.accept(v);
    assertEquals(hash, -1895901688);

    v.setUp();
    expr = F.Power(F.Sin(F.Cos(F.C3)), F.C2);
    hash = expr.accept(v);
    assertEquals(hash, -1895901688);

    v.setUp();
    expr = F.Power(F.Sin(F.$p("x")), F.C2);
    hash = expr.accept(v);
    assertEquals(hash, -1895901688);

    v.setUp();
    expr = F.Power(F.Cos(F.Sin(F.C3)), F.C2);
    hash = expr.accept(v);
    assertEquals(hash, -1896372423);
  }