Exemple #1
0
  public IExpr evaluate(final IAST ast) {
    Validate.checkSize(ast, 3);

    if (ast.get(1).isSymbol()) {
      if (ast.get(2).isAST("Blank")) {
        IAST blank = (IAST) ast.get(2);
        if (blank.size() == 1) {
          return F.$p((ISymbol) ast.get(1));
        }
        if (blank.size() == 2) {
          return F.$p((ISymbol) ast.get(1), blank.get(1));
        }
      }
      if (ast.get(2).isPattern()) {
        IPattern blank = (IPattern) ast.get(2);
        if (blank.isBlank()) {
          return F.$p((ISymbol) ast.get(1), blank.getCondition());
        }
      }
    }
    return null;
  }
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);
  }