cardinality operation for finite sets (based on my thesis / ijcar16 paper)
[cvc5.git] / src / theory / sets / theory_sets_rewriter.h
1 /********************* */
2 /*! \file theory_sets_rewriter.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Kshitij Bansal, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
11 **
12 ** \brief Sets theory rewriter.
13 **
14 ** Sets theory rewriter.
15 **/
16
17 #include "cvc4_private.h"
18
19 #ifndef __CVC4__THEORY__SETS__THEORY_SETS_REWRITER_H
20 #define __CVC4__THEORY__SETS__THEORY_SETS_REWRITER_H
21
22 #include "theory/rewriter.h"
23
24 namespace CVC4 {
25 namespace theory {
26 namespace sets {
27
28 class TheorySetsRewriter {
29 private:
30 static bool collectSetComponents( Node n, std::map< Node, bool >& c, bool pol );
31 static Node rewriteSet( Node s, std::map< Node, bool >& ca, Node empSet );
32 static Node rewriteSet( Node s );
33 public:
34
35 /**
36 * Rewrite a node into the normal form for the theory of sets.
37 * Called in post-order (really reverse-topological order) when
38 * traversing the expression DAG during rewriting. This is the
39 * main function of the rewriter, and because of the ordering,
40 * it can assume its children are all rewritten already.
41 *
42 * This function can return one of three rewrite response codes
43 * along with the rewritten node:
44 *
45 * REWRITE_DONE indicates that no more rewriting is needed.
46 * REWRITE_AGAIN means that the top-level expression should be
47 * rewritten again, but that its children are in final form.
48 * REWRITE_AGAIN_FULL means that the entire returned expression
49 * should be rewritten again (top-down with preRewrite(), then
50 * bottom-up with postRewrite()).
51 *
52 * Even if this function returns REWRITE_DONE, if the returned
53 * expression belongs to a different theory, it will be fully
54 * rewritten by that theory's rewriter.
55 */
56 static RewriteResponse postRewrite(TNode node);
57
58 /**
59 * Rewrite a node into the normal form for the theory of sets
60 * in pre-order (really topological order)---meaning that the
61 * children may not be in the normal form. This is an optimization
62 * for theories with cancelling terms (e.g., 0 * (big-nasty-expression)
63 * in arithmetic rewrites to 0 without the need to look at the big
64 * nasty expression). Since it's only an optimization, the
65 * implementation here can do nothing.
66 */
67 static RewriteResponse preRewrite(TNode node);
68
69 /**
70 * Rewrite an equality, in case special handling is required.
71 */
72 static Node rewriteEquality(TNode equality) {
73 // often this will suffice
74 return postRewrite(equality).node;
75 }
76
77 /**
78 * Initialize the rewriter.
79 */
80 static inline void init() {
81 // nothing to do
82 }
83
84 /**
85 * Shut down the rewriter.
86 */
87 static inline void shutdown() {
88 // nothing to do
89 }
90 };/* class TheorySetsRewriter */
91
92 }/* CVC4::theory::sets namespace */
93 }/* CVC4::theory namespace */
94 }/* CVC4 namespace */
95
96 #endif /* __CVC4__THEORY__SETS__THEORY_SETS_REWRITER_H */