Branch data Line data Source code
1 : : /******************************************************************************
2 : : * This file is part of the cvc5 project.
3 : : *
4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
5 : : * in the top-level source directory and their institutional affiliations.
6 : : * All rights reserved. See the file COPYING in the top-level source
7 : : * directory for licensing information.
8 : : * ****************************************************************************
9 : : *
10 : : * Substitution minimization.
11 : : */
12 : :
13 : : #include "cvc5_private.h"
14 : :
15 : : #ifndef CVC5__THEORY__SUBS_MINIMIZE_H
16 : : #define CVC5__THEORY__SUBS_MINIMIZE_H
17 : :
18 : : #include <vector>
19 : :
20 : : #include "expr/node.h"
21 : : #include "smt/env_obj.h"
22 : :
23 : : namespace cvc5::internal {
24 : : namespace theory {
25 : :
26 : : /** SubstitutionMinimize
27 : : *
28 : : * This class is used for finding a minimal substitution under which an
29 : : * evaluation holds.
30 : : */
31 : : class SubstitutionMinimize : protected EnvObj
32 : : {
33 : : public:
34 : : SubstitutionMinimize(Env& env);
35 : 202 : ~SubstitutionMinimize() {}
36 : : /** find
37 : : *
38 : : * If t { vars -> subs } rewrites to target, this method returns true, and
39 : : * vars[i_1], ..., vars[i_n] are added to reqVars, such that i_1, ..., i_n are
40 : : * distinct, and t { vars[i_1] -> subs[i_1], ..., vars[i_n] -> subs[i_n] }
41 : : * rewrites to target.
42 : : *
43 : : * If t { vars -> subs } does not rewrite to target, this method returns
44 : : * false.
45 : : */
46 : : bool find(Node t,
47 : : Node target,
48 : : const std::vector<Node>& vars,
49 : : const std::vector<Node>& subs,
50 : : std::vector<Node>& reqVars);
51 : : /** find with implied
52 : : *
53 : : * This method should be called on a formula t.
54 : : *
55 : : * If t { vars -> subs } rewrites to true, this method returns true,
56 : : * vars[i_1], ..., vars[i_n] are added to reqVars, and
57 : : * vars[i_{n+1}], ..., vars[i_{n+m}] are added to impliedVars such that
58 : : * i_1...i_{n+m} are distinct, i_{n+1} < ... < i_{n+m}, and:
59 : : *
60 : : * (1) t { vars[i_1]->subs[i_1], ..., vars[i_{n+k}]->subs[i_{n+k}] } implies
61 : : * vars[i_{n+k+1}] = subs[i_{n+k+1}] for k = 0, ..., m-1.
62 : : *
63 : : * (2) t { vars[i_1] -> subs[i_1], ..., vars[i_{n+m}] -> subs[i_{n+m}] }
64 : : * rewrites to true.
65 : : *
66 : : * For example, given (x>0 ^ x = y ^ y = z){ x -> 1, y -> 1, z -> 1, w -> 0 },
67 : : * this method may add { x } to reqVars, and { y, z } to impliedVars.
68 : : *
69 : : * Notice that the order of variables in vars matters. By the semantics above,
70 : : * variables that appear earlier in the variable list vars are more likely
71 : : * to appear in reqVars, whereas those later in the vars are more likely to
72 : : * appear in impliedVars.
73 : : */
74 : : bool findWithImplied(Node t,
75 : : const std::vector<Node>& vars,
76 : : const std::vector<Node>& subs,
77 : : std::vector<Node>& reqVars,
78 : : std::vector<Node>& impliedVars);
79 : :
80 : : private:
81 : : /** Common helper function for the above functions. */
82 : : bool findInternal(Node t,
83 : : Node target,
84 : : const std::vector<Node>& vars,
85 : : const std::vector<Node>& subs,
86 : : std::vector<Node>& reqVars);
87 : : /** is singular arg
88 : : *
89 : : * Returns true if
90 : : * <k>( ... t_{arg-1}, n, t_{arg+1}...) = c
91 : : * always holds for some constant c.
92 : : */
93 : : bool isSingularArg(Node n, Kind k, unsigned arg);
94 : : };
95 : :
96 : : } // namespace theory
97 : : } // namespace cvc5::internal
98 : :
99 : : #endif /* CVC5__THEORY__SUBS_MINIMIZE_H */
|