1 /********************* */
3 ** Original author: taking
4 ** Major contributors: none
5 ** Minor contributors (to current version): none
6 ** This file is part of the CVC4 prototype.
7 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
8 ** Courant Institute of Mathematical Sciences
10 ** See the file COPYING in the top-level source directory for licensing
17 #ifndef __CVC4__THEORY__THEORY_UF_H
18 #define __CVC4__THEORY__THEORY_UF_H
20 #include "expr/node.h"
21 #include "expr/attribute.h"
23 #include "theory/theory.h"
25 #include "context/context.h"
26 #include "theory/uf/ecdata.h"
32 class TheoryUF
: public TheoryImpl
<TheoryUF
> {
39 * The associated context. Needed for allocating context dependent objects
40 * and objects in context dependent memory.
42 context::Context
* d_context
;
45 * List of pending equivalence class merges.
48 * Must keep a hard link because new equality terms are created and appended
51 context::CDList
<Node
> d_pending
;
53 /** Index of the next pending equality to merge. */
54 context::CDO
<unsigned> d_currentPendingIdx
;
56 /** List of all disequalities this theory has seen. */
57 context::CDList
<Node
> d_disequality
;
60 * List of all of the terms that are registered in the current context.
61 * When registerTerm is called on a term we want to guarentee that there
62 * is a hard link to the term for the duration of the context in which
63 * register term is called.
64 * This invariant is enough for us to use soft links where we want is the
65 * current implementation as well as making ECAttr() not context dependent.
66 * Soft links used both in ECData, and Link.
68 context::CDList
<Node
> d_registered
;
72 /** Constructs a new instance of TheoryUF w.r.t. the provided context.*/
73 TheoryUF(context::Context
* c
, OutputChannel
& out
);
75 /** Destructor for the TheoryUF object. */
79 //TODO Tim: I am going to delay documenting these functions while Morgan
80 //has pending changes to the contracts
82 void registerTerm(TNode n
);
83 void preRegisterTerm(TNode n
);
85 void check(Effort level
);
87 void propagate(Effort level
) {}
89 void explain(TNode n
, Effort level
) {}
93 * Checks whether 2 nodes are already in the same equivalence class tree.
94 * This should only be used internally, and it should only be done when
95 * the only thing done with the equivalence classes is an equality check.
97 * @returns true iff ccFind(x) == ccFind(y);
99 bool sameCongruenceClass(TNode x
, TNode y
);
102 * Checks whether Node x and Node y are currently congruent
103 * using the equivalence class data structures.
106 * x.getOperator() == y.getOperator() and
107 * forall 1 <= i < n : ccFind(x[i]) == ccFind(y[i])
109 bool equiv(TNode x
, TNode y
);
112 * Merges 2 equivalence classes, checks wether any predecessors need to
113 * be set equal to complete congruence closure.
114 * The class with the smaller class size will be merged.
115 * @pre ecX->isClassRep()
116 * @pre ecY->isClassRep()
118 void ccUnion(ECData
* ecX
, ECData
* ecY
);
121 * Returns the representative of the equivalence class.
122 * May modify the find pointers associated with equivalence classes.
124 ECData
* ccFind(ECData
* x
);
126 /** Performs Congruence Closure to reflect the new additions to d_pending. */
133 * Cleanup function for ECData. This will be used for called whenever
134 * a ECAttr is being destructed.
137 static void cleanup(ECData
* & ec
){
142 /** Unique name to use for constructing ECAttr. */
146 * ECAttr is the attribute that maps a node to an equivalence class.
148 typedef expr::Attribute
<EquivClass
, ECData
* /*, ECCleanupFcn*/> ECAttr
;
150 } /* CVC4::theory::uf namespace */
151 } /* CVC4::theory namespace */
152 } /* CVC4 namespace */
155 #endif /* __CVC4__THEORY__THEORY_UF_H */