1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/********************* */
/*! \file term_canonize.h
** \verbatim
** Top contributors (to current version):
** Andrew Reynolds
** This file is part of the CVC4 project.
** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
** \brief Utilities for constructing canonical terms.
**/
#include "cvc4_private.h"
#ifndef __CVC4__THEORY__QUANTIFIERS__TERM_CANONIZE_H
#define __CVC4__THEORY__QUANTIFIERS__TERM_CANONIZE_H
#include <map>
#include "expr/node.h"
namespace CVC4 {
namespace theory {
namespace quantifiers {
/** TermCanonize
*
* This class contains utilities for canonizing terms with respect to
* free variables (which are of kind BOUND_VARIABLE). For example, this
* class infers that terms like f(BOUND_VARIABLE_1) and f(BOUND_VARIABLE_2)
* are effectively the same term.
*/
class TermCanonize
{
public:
TermCanonize();
~TermCanonize() {}
/** Maps operators to an identifier, useful for ordering. */
int getIdForOperator(Node op);
/** Maps types to an identifier, useful for ordering. */
int getIdForType(TypeNode t);
/** get term order
*
* Returns true if a <= b in the term ordering used by this class. The
* term order is determined by the leftmost position in a and b whose
* operators o_a and o_b are distinct at that position. Then a <= b iff
* getIdForOperator( o_a ) <= getIdForOperator( o_b ).
*/
bool getTermOrder(Node a, Node b);
/** get canonical free variable #i of type tn */
Node getCanonicalFreeVar(TypeNode tn, unsigned i);
/** get canonical term
*
* This returns a canonical (alpha-equivalent) version of n, where
* bound variables in n may be replaced by other ones, and arguments of
* commutative operators of n may be sorted (if apply_torder is true).
* In detail, we replace bound variables in n so the the leftmost occurrence
* of a bound variable for type T is the first canonical free variable for T,
* the second leftmost is the second, and so on, for each type T.
*/
Node getCanonicalTerm(TNode n, bool apply_torder = false);
private:
/** the number of ids we have allocated for operators */
int d_op_id_count;
/** map from operators to id */
std::map<Node, int> d_op_id;
/** the number of ids we have allocated for types */
int d_typ_id_count;
/** map from type to id */
std::map<TypeNode, int> d_typ_id;
/** free variables for each type */
std::map<TypeNode, std::vector<Node> > d_cn_free_var;
/** get canonical term
*
* This is a helper function for getCanonicalTerm above. We maintain a
* counter of how many variables we have allocated for each type (var_count),
* and a cache of visited nodes (visited).
*/
Node getCanonicalTerm(TNode n,
bool apply_torder,
std::map<TypeNode, unsigned>& var_count,
std::map<TNode, Node>& visited);
};
} // namespace quantifiers
} // namespace theory
} // namespace CVC4
#endif /* __CVC4__THEORY__QUANTIFIERS__TERM_CANONIZE_H */
|