cloud9_root/src/third_party/stp/src/simplifier/simplifier.cpp
//takes care of some simple ITE Optimizations in the context of equations
takes care of some simple ITE Optimizations in the context of equations
takes care of some simple ITE Optimizations in the context of equations
ASTNode
  Simplifier::ITEOpt_InEqs(const ASTNode& in, ASTNodeMap* VarConstMap)
  {
    CountersAndStats("ITEOpts_InEqs", _bm);
    if (!(EQ == in.GetKind()))
      {
        return in;
      }
    ASTNode output;
    if (CheckSimplifyMap(in, output, false))
      {
        return output;
      }
    const ASTNode& in1 = in[0];
    const ASTNode& in2 = in[1];
    const Kind k1 = in1.GetKind();
    const Kind k2 = in2.GetKind();
    if (in1 == in2)
      {
        output = ASTTrue;
      }
    else if (BVCONST == k1 && BVCONST == k2)
      {
        assert(in1!=in2);
        output = ASTFalse;
      }
    else if (ITE == k1 && BVCONST == in1[1].GetKind() && BVCONST == in1[2].GetKind() && BVCONST == k2)
      {
         c = ITE(cond,c,d) <=> cond
         similarly ITE(cond,c,d) = c <=> cond
         c = ITE(cond,d,c) <=> NOT(cond)
        similarly ITE(cond,d,c) = d <=> NOT(cond)
        ASTNode cond = in1[0];
        if (in1[1] == in2 && (in2 != in1[2]))
          {
            ITE(cond, c, d) = c <=> cond
            output = cond;
          }
        else if (in1[2] == in2 && (in2 != in1[1]))
          {
            cond = SimplifyFormula(cond, true, VarConstMap);
            output = cond;
          }
        else
          {
            last resort is to nf->CreateNode
            output = nf->CreateNode(EQ, in1, in2);
          }
      }
    else if (ITE == k2 && BVCONST == in2[1].GetKind() && BVCONST == in2[2].GetKind() && BVCONST == k1)
      {
        ASTNode cond = in2[0];
        if (in2[1] == in1 && (in1 != in2[2]))
          {
            ITE(cond, c, d) = c <=> cond
            output = cond;
          }
        else if (in2[2] == in1 && (in1 != in2[1]))
          {
            cond = SimplifyFormula(cond, true, VarConstMap);
            output = cond;
          }
        else
          {
            last resort is to CreateNode
            output = nf->CreateNode(EQ, in1, in2);
          }
      }
    else
      {
        last resort is to CreateNode
        output = nf->CreateNode(EQ, in1, in2);
      }
    UpdateSimplifyMap(in, output, false, VarConstMap);
    return output;
  }
ASTNode Simplifier :: ITEOpt_InEqs ( const ASTNode & in , ASTNodeMap * VarConstMap ) { CountersAndStats ( " " , _bm ) ; if ( ! ( EQ == in . GetKind ( ) ) ) { return in ; } ASTNode output ; if ( CheckSimplifyMap ( in , output , false ) ) { return output ; } const ASTNode & in1 = in [ 0 ] ; const ASTNode & in2 = in [ 1 ] ; const Kind k1 = in1 . GetKind ( ) ; const Kind k2 = in2 . GetKind ( ) ; if ( in1 == in2 ) { output = ASTTrue ; } else if ( BVCONST == k1 && BVCONST == k2 ) { assert ( in1 != in2 ) ; output = ASTFalse ; } else if ( ITE == k1 && BVCONST == in1 [ 1 ] . GetKind ( ) && BVCONST == in1 [ 2 ] . GetKind ( ) && BVCONST == k2 ) { ASTNode cond = in1 [ 0 ] ; if ( in1 [ 1 ] == in2 && ( in2 != in1 [ 2 ] ) ) { output = cond ; } else if ( in1 [ 2 ] == in2 && ( in2 != in1 [ 1 ] ) ) { cond = SimplifyFormula ( cond , true , VarConstMap ) ; output = cond ; } else { output = nf -> CreateNode ( EQ , in1 , in2 ) ; } } else if ( ITE == k2 && BVCONST == in2 [ 1 ] . GetKind ( ) && BVCONST == in2 [ 2 ] . GetKind ( ) && BVCONST == k1 ) { ASTNode cond = in2 [ 0 ] ; if ( in2 [ 1 ] == in1 && ( in1 != in2 [ 2 ] ) ) { output = cond ; } else if ( in2 [ 2 ] == in1 && ( in1 != in2 [ 1 ] ) ) { cond = SimplifyFormula ( cond , true , VarConstMap ) ; output = cond ; } else { output = nf -> CreateNode ( EQ , in1 , in2 ) ; } } else { output = nf -> CreateNode ( EQ , in1 , in2 ) ; } UpdateSimplifyMap ( in , output , false , VarConstMap ) ; return output ; }
takes care of some simple ITE Optimizations in the context of equations
takes care of some simple ITE Optimizations in the context of equations
//terms are syntactically the same //if one side is a BVCONST and the other side is an ITE over //BVCONST then we can do the following optimization: // // c = ITE(cond,c,d) <=> cond // // similarly ITE(cond,c,d) = c <=> cond // // c = ITE(cond,d,c) <=> NOT(cond) // //similarly ITE(cond,d,c) = d <=> NOT(cond) //ITE(cond, c, d) = c <=> cond //last resort is to nf->CreateNode //ITE(cond, c, d) = c <=> cond //last resort is to CreateNode //last resort is to CreateNode