1 /******************************************************************************
2 * Top contributors (to current version):
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2021 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.
11 * ****************************************************************************
13 * Extract bounds on variables from theory atoms.
16 #ifndef CVC5__THEORY__ARITH__BOUND_INFERENCE_H
17 #define CVC5__THEORY__ARITH__BOUND_INFERENCE_H
23 #include "expr/node.h"
24 #include "smt/env_obj.h"
32 /** The lower bound value */
34 /** Whether the lower bound is strict or weak */
35 bool lower_strict
= true;
36 /** The lower bound as constraint */
38 /** The origin of the lower bound */
40 /** The upper bound value */
42 /** Whether the upper bound is strict or weak */
43 bool upper_strict
= true;
44 /** The upper bound as constraint */
46 /** The origin of the upper bound */
50 /** Print the current bounds. */
51 std::ostream
& operator<<(std::ostream
& os
, const Bounds
& b
);
54 * A utility class that extracts direct bounds on arithmetic terms from theory
57 class BoundInference
: protected EnvObj
60 BoundInference(Env
& env
);
64 * Get the current interval for lhs. Creates a new (full) interval if
67 Bounds
& get_or_add(const Node
& lhs
);
69 * Get the current interval for lhs. Returns a full interval if no interval
72 Bounds
get(const Node
& lhs
) const;
74 /** Return the current term bounds as an interval assignment. */
75 const std::map
<Node
, Bounds
>& get() const;
78 * Add a new theory atom. Return true if the theory atom induces a new
80 * If onlyVariables is true, the left hand side needs to be a single
81 * variable to induce a bound.
83 bool add(const Node
& n
, bool onlyVariables
= true);
86 * Post-processes a set of nodes and replaces bounds by their origins.
87 * This utility sometimes creates new bounds, either due to tightening of
88 * integer terms or because an equality was derived from two weak
89 * inequalities. While the origins of these new bounds are recorded in
90 * lower_origin and upper_origin, this method can be used to conveniently
91 * replace these new nodes by their origins.
92 * This can be used, for example, when constructing conflicts.
94 void replaceByOrigins(std::vector
<Node
>& nodes
) const;
97 /** The currently strictest bounds for every lhs. */
98 std::map
<Node
, Bounds
> d_bounds
;
100 /** Updates the lower bound for the given lhs */
101 void update_lower_bound(const Node
& origin
,
105 /** Updates the upper bound for the given lhs */
106 void update_upper_bound(const Node
& origin
,
112 /** Print the current variable bounds. */
113 std::ostream
& operator<<(std::ostream
& os
, const BoundInference
& bi
);
116 } // namespace theory