| 1 | /****************************************************************************** |
| 2 | * Top contributors (to current version): |
| 3 | * Andrew Reynolds, Gereon Kremer, Aina Niemetz |
| 4 | * |
| 5 | * This file is part of the cvc5 project. |
| 6 | * |
| 7 | * Copyright (c) 2009-2025 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 | * **************************************************************************** |
| 12 | * |
| 13 | * Solving for handling exponential function. |
| 14 | */ |
| 15 | |
| 16 | #ifndef CVC5__THEORY__ARITH__NL__TRANSCENDENTAL__SINE_SOLVER_H |
| 17 | #define CVC5__THEORY__ARITH__NL__TRANSCENDENTAL__SINE_SOLVER_Hcxx . . $ `src/theory/arith/nl/transcendental/sine_solver.h:17:9`! |
| 18 | |
| 19 | #include <map> |
| 20 | |
| 21 | #include "expr/node.h"cxx . . $ `<file>/src/expr/node.h`/ |
| 22 | #include "smt/env_obj.h"cxx . . $ `<file>/src/smt/env_obj.h`/ |
| 23 | #include "theory/arith/nl/transcendental/transcendental_state.h"cxx . . $ `<file>/src/theory/arith/nl/transcendental/transcendental_state.h`/ |
| 24 | |
| 25 | namespace cvc5cxx . . $ cvc5/::internalcxx . . $ cvc5/internal/ { |
| 26 | namespace theorycxx . . $ cvc5/internal/theory/ { |
| 27 | namespace arithcxx . . $ cvc5/internal/theory/arith/ { |
| 28 | namespace nlcxx . . $ cvc5/internal/theory/arith/nl/ { |
| 29 | namespace transcendentalcxx . . $ cvc5/internal/theory/arith/nl/transcendental/ { |
| 30 | |
| 31 | /** Transcendental solver class |
| 32 | * |
| 33 | * This class implements model-based refinement schemes |
| 34 | * for transcendental functions, described in: |
| 35 | * |
| 36 | * - "Satisfiability Modulo Transcendental |
| 37 | * Functions via Incremental Linearization" by Cimatti |
| 38 | * et al., CADE 2017. |
| 39 | * |
| 40 | * It's main functionality are methods that implement lemma schemas below, |
| 41 | * which return a set of lemmas that should be sent on the output channel. |
| 42 | */ |
| 43 | class SineSolvercxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver# : protected EnvObjcxx . . $ cvc5/internal/EnvObj# |
| 44 | { |
| 45 | public: |
| 46 | SineSolvercxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#SineSolver(5860bda783e852cb).(Envcxx . . $ cvc5/internal/Env#& env, TranscendentalStatecxx . . $ cvc5/internal/theory/arith/nl/transcendental/TranscendentalState#* tstate); |
| 47 | ~cxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#`~SineSolver`(ced63f7c635d850d).SineSolvercxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#(); |
| 48 | |
| 49 | /** do reductions |
| 50 | * |
| 51 | * This method determines any applications of sin(x) that can be reasoned |
| 52 | * about "precisely", either via symmetry: |
| 53 | * x = -y => sin(x) = -sin(y) |
| 54 | * or via boundary points, e.g.: |
| 55 | * x = pi/2 => sin(x) = 1 |
| 56 | * Each application of sin(x) for which a reduction of the latter form exists |
| 57 | * is removed from the range of d_funcMap in the transcendental state, and |
| 58 | * thus will not be considered for other lemma schemas. |
| 59 | */ |
| 60 | void doReductionscxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#doReductions(49f6e7a06ebc5aa8).(); |
| 61 | /** |
| 62 | * Introduces new_a as purified version of a which is also shifted to the main |
| 63 | * phase (from -pi to pi). new_a[0] is the new skolem used for purification. |
| 64 | */ |
| 65 | void doPhaseShiftcxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#doPhaseShift(4952da49611e0114).(TNodecxx . . $ cvc5/internal/TNode# a, TNodecxx . . $ cvc5/internal/TNode# new_a); |
| 66 | |
| 67 | /** |
| 68 | * check initial refine |
| 69 | * |
| 70 | * Constructs a set of valid theory lemmas, based on |
| 71 | * simple facts about the sine function. |
| 72 | * This mostly follows the initial axioms described in |
| 73 | * Section 4 of "Satisfiability |
| 74 | * Modulo Transcendental Functions via Incremental |
| 75 | * Linearization" by Cimatti et al., CADE 2017. |
| 76 | * |
| 77 | * Examples: |
| 78 | * |
| 79 | * sin( x ) = -sin( -x ) |
| 80 | * ( PI > x > 0 ) => 0 < sin( x ) < 1 |
| 81 | */ |
| 82 | void checkInitialRefinecxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#checkInitialRefine(49f6e7a06ebc5aa8).(); |
| 83 | |
| 84 | /** |
| 85 | * check monotonicity |
| 86 | * |
| 87 | * Constructs a set of valid theory lemmas, based on a |
| 88 | * lemma scheme that ensures that applications |
| 89 | * of the sine function respect monotonicity. |
| 90 | * |
| 91 | * Examples: |
| 92 | * |
| 93 | * PI/2 > x > y > 0 => sin( x ) > sin( y ) |
| 94 | * PI > x > y > PI/2 => sin( x ) < sin( y ) |
| 95 | */ |
| 96 | void checkMonotoniccxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#checkMonotonic(49f6e7a06ebc5aa8).(); |
| 97 | |
| 98 | /** Sent tangent lemma around c for e */ |
| 99 | void doTangentLemmacxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#doTangentLemma(1c61f55044595069).( |
| 100 | TNodecxx . . $ cvc5/internal/TNode# e, TNodecxx . . $ cvc5/internal/TNode# c, TNodecxx . . $ cvc5/internal/TNode# poly_approx, int region, stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t# d); |
| 101 | |
| 102 | /** Sent secant lemmas around c for e */ |
| 103 | void doSecantLemmascxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#doSecantLemmas(7f8149a39bba2306).(TNodecxx . . $ cvc5/internal/TNode# e, |
| 104 | TNodecxx . . $ cvc5/internal/TNode# poly_approx, |
| 105 | TNodecxx . . $ cvc5/internal/TNode# c, |
| 106 | TNodecxx . . $ cvc5/internal/TNode# poly_approx_c, |
| 107 | unsigned d, |
| 108 | unsigned actual_d, |
| 109 | int region); |
| 110 | |
| 111 | /** |
| 112 | * Does n of the form sin(x) have an exact model value? This is true if |
| 113 | * the model value of x is in the domain of d_mpointsSine. |
| 114 | */ |
| 115 | bool hasExactModelValuecxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#hasExactModelValue(6a67ff56991b0442).(TNodecxx . . $ cvc5/internal/TNode# n) const; |
| 116 | |
| 117 | /** |
| 118 | * In the following let y be (@transcendental_purify_arg x) and let s |
| 119 | * be (@transcendental_sine_phase_shift x). |
| 120 | * Make the lemma for the phase shift of arguments to SINE x and y, where |
| 121 | * s is the (integral) shift. The lemma conceptually says that y is |
| 122 | * in the bounds [-pi, pi] and y is offset from x by an integral factor of |
| 123 | * 2*pi. |
| 124 | */ |
| 125 | static Nodecxx . . $ cvc5/internal/Node# getPhaseShiftLemmacxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#getPhaseShiftLemma(681b52e52973167e).(const Nodecxx . . $ cvc5/internal/Node#& x); |
| 126 | |
| 127 | private: |
| 128 | stdcxx . . $ std/::paircxx . . $ std/pair#<Nodecxx . . $ cvc5/internal/Node#, Nodecxx . . $ cvc5/internal/Node#> getSecantBoundscxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#getSecantBounds(31a7652bafeadd2).(TNodecxx . . $ cvc5/internal/TNode# e, |
| 129 | TNodecxx . . $ cvc5/internal/TNode# c, |
| 130 | unsigned d, |
| 131 | int region); |
| 132 | |
| 133 | /** region to lower bound |
| 134 | * |
| 135 | * Returns the term corresponding to the lower |
| 136 | * bound of the region of transcendental function |
| 137 | * with kind k. Returns Node::null if the region |
| 138 | * is invalid, or there is no lower bound for the |
| 139 | * region. |
| 140 | */ |
| 141 | Nodecxx . . $ cvc5/internal/Node# regionToLowerBoundcxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#regionToLowerBound(55cb49dc8b244695).(int region) const |
| 142 | { |
| 143 | if (region >= 1 && region <= 4) |
| 144 | { |
| 145 | size_t index = static_cast<size_t>(region); |
| 146 | return d_mpointscxx . . $ cvc5/internal/NodeTemplate#NodeTemplate(9eda7521f8ea1fca).[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).index]; |
| 147 | } |
| 148 | return Nodecxx . . $ cvc5/internal/Node#(); |
| 149 | } |
| 150 | |
| 151 | /** region to upper bound |
| 152 | * |
| 153 | * Returns the term corresponding to the upper |
| 154 | * bound of the region of transcendental function |
| 155 | * with kind k. Returns Node::null if the region |
| 156 | * is invalid, or there is no upper bound for the |
| 157 | * region. |
| 158 | */ |
| 159 | Nodecxx . . $ cvc5/internal/Node# regionToUpperBoundcxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#regionToUpperBound(55cb49dc8b244695).(int region) const |
| 160 | { |
| 161 | if (region >= 1 && region <= 4) |
| 162 | { |
| 163 | size_t index = static_cast<size_t>(region - 1); |
| 164 | return d_mpointscxx . . $ cvc5/internal/NodeTemplate#NodeTemplate(9eda7521f8ea1fca).[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).index]; |
| 165 | } |
| 166 | return Nodecxx . . $ cvc5/internal/Node#(); |
| 167 | } |
| 168 | |
| 169 | int regionToMonotonicityDircxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#regionToMonotonicityDir(7ccb52b1bfe01045).(int region) const |
| 170 | { |
| 171 | switch (region) |
| 172 | { |
| 173 | case 1: |
| 174 | case 4: return -1; |
| 175 | case 2: |
| 176 | case 3: return 1; |
| 177 | default: return 0; |
| 178 | } |
| 179 | } |
| 180 | Convexitycxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity# regionToConvexitycxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#regionToConvexity(bcd39bdd90340812).(int region) const |
| 181 | { |
| 182 | switch (region) |
| 183 | { |
| 184 | case 1: |
| 185 | case 2: return Convexitycxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#::CONCAVEcxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#CONCAVE.; |
| 186 | case 3: |
| 187 | case 4: return Convexitycxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#::CONVEXcxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#CONVEX.; |
| 188 | default: return Convexitycxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#::UNKNOWNcxx . . $ cvc5/internal/theory/arith/nl/transcendental/Convexity#UNKNOWN.; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** Holds common state for transcendental solvers */ |
| 193 | TranscendentalStatecxx . . $ cvc5/internal/theory/arith/nl/transcendental/TranscendentalState#* d_datacxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_data.; |
| 194 | |
| 195 | /** The transcendental functions we have done initial refinements on */ |
| 196 | stdcxx . . $ std/::mapcxx . . $ std/map#<Nodecxx . . $ cvc5/internal/Node#, bool> d_tf_initial_refinecxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_tf_initial_refine.; |
| 197 | |
| 198 | /** PI, -PI */ |
| 199 | Nodecxx . . $ cvc5/internal/Node# d_picxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_pi.; |
| 200 | Nodecxx . . $ cvc5/internal/Node# d_neg_picxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_neg_pi.; |
| 201 | /** the boundary points */ |
| 202 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<Nodecxx . . $ cvc5/internal/Node#> d_mpointscxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_mpoints.; |
| 203 | /** mapping from values c to known points for sin(c) */ |
| 204 | stdcxx . . $ std/::mapcxx . . $ std/map#<Nodecxx . . $ cvc5/internal/Node#, Nodecxx . . $ cvc5/internal/Node#> d_mpointsSinecxx . . $ cvc5/internal/theory/arith/nl/transcendental/SineSolver#d_mpointsSine.; |
| 205 | }; /* class SineSolver */ |
| 206 | |
| 207 | } // namespace transcendental |
| 208 | } // namespace nl |
| 209 | } // namespace arith |
| 210 | } // namespace theory |
| 211 | } // namespace cvc5::internal |
| 212 | |
| 213 | #endif /* CVC5__THEORY__ARITH__TRANSCENDENTAL_SOLVER_H */ |