| 1 | /****************************************************************************** |
| 2 | * Top contributors (to current version): |
| 3 | * Gereon Kremer, Alex Ozdemir, Andres Noetzli |
| 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 | * Implements the CDCAC approach as described in |
| 14 | * https://arxiv.org/pdf/2003.05633.pdf. |
| 15 | */ |
| 16 | |
| 17 | #include "cvc5_private.h"cxx . . $ `<file>/src/include/cvc5_private.h`/ |
| 18 | |
| 19 | #ifndef CVC5__THEORY__ARITH__NL__COVERINGS__LAZARD_EVALUATION_H |
| 20 | #define CVC5__THEORY__ARITH__NL__COVERINGS__LAZARD_EVALUATION_Hcxx . . $ `src/theory/arith/nl/coverings/lazard_evaluation.h:20:9`! |
| 21 | |
| 22 | #ifdef CVC5_POLY_IMP |
| 23 | |
| 24 | #include <poly/polyxx.h> |
| 25 | |
| 26 | #include <memory> |
| 27 | |
| 28 | #include "util/statistics_stats.h" |
| 29 | |
| 30 | namespace cvc5::internal::theory::arith::nl::coverings { |
| 31 | |
| 32 | struct LazardEvaluationStats |
| 33 | { |
| 34 | IntStat d_directAssignments; |
| 35 | IntStat d_ranAssignments; |
| 36 | IntStat d_evaluations; |
| 37 | IntStat d_reductions; |
| 38 | LazardEvaluationStats(StatisticsRegistry& reg); |
| 39 | }; |
| 40 | |
| 41 | struct LazardEvaluationState; |
| 42 | /** |
| 43 | * This class does the heavy lifting for the modified lifting procedure that is |
| 44 | * required for Lazard's projection. |
| 45 | * |
| 46 | * Let p \in Q[x_0, ..., x_n] a multivariate polynomial whose roots we want to |
| 47 | * isolate over the partial sample point A = [x_0 = a_0, ... x_{n-1} = a_{n-1}] |
| 48 | * where a_0, ... a_{n-1} are real algebraic numbers and x_n is the last free |
| 49 | * variable. |
| 50 | * |
| 51 | * The modified lifting procedure conceptually works as follows: |
| 52 | * |
| 53 | * for (x = a) in A: |
| 54 | * while p[x // a] = 0: |
| 55 | * p = p / (x - a) |
| 56 | * p = p[x // a] |
| 57 | * return roots(p) |
| 58 | * |
| 59 | * As the assignment contains real algebraic numbers, though, we can not do any |
| 60 | * of the computations directly, as our polynomials only support coefficients |
| 61 | * from Z or Q, but not extensions (in the algebraic sense) thereof. |
| 62 | * |
| 63 | * Our approach is as follows: |
| 64 | * Let pk be the minimal polynomial for a_k. |
| 65 | * Instead of substituting p[x_k // a_k] we (canonically) embed p into the |
| 66 | * quotient ring Q[x_k]/<p_k> and recursively build a tower of such quotient |
| 67 | * rings that is isomorphic to nesting the corresponding field extensions |
| 68 | * Q(a_1)(a_2)... When we have done that, we obtain p that is reduced with |
| 69 | * respect to all minimal polynomials, but may still contain x_0,... x_{n-1}. To |
| 70 | * get rid of these, we compute a Gröbner basis of p and the minimal polynomials |
| 71 | * (using a suitable elimination order) and extract the polynomial in x_n. This |
| 72 | * polynomial has all roots (and possibly some more) that we are looking for. |
| 73 | * Instead of a Gröbner basis, we can also compute the iterated resultant as |
| 74 | * follows: Res(Res(p, p_{n-1}, x_{n-1}), p_{n-2}, x_{n-2})... |
| 75 | * |
| 76 | * Consider |
| 77 | * http://sunsite.informatik.rwth-aachen.de/Publications/AIB/2020/2020-04.pdf |
| 78 | * Section 2.5.1 for a full discussion. |
| 79 | * |
| 80 | * !!! WARNING !!! |
| 81 | * If CoCoALib is not available, this class will simply fall back to |
| 82 | * poly::infeasible_regions and issue a warning about this. |
| 83 | */ |
| 84 | class LazardEvaluation |
| 85 | { |
| 86 | public: |
| 87 | LazardEvaluation(StatisticsRegistry& reg); |
| 88 | ~LazardEvaluation(); |
| 89 | |
| 90 | /** |
| 91 | * Add the next assigned variable x_k = a_k to this construction. |
| 92 | */ |
| 93 | void add(const poly::Variable& var, const poly::Value& val); |
| 94 | /** |
| 95 | * Finish by adding the free variable x_n. |
| 96 | */ |
| 97 | void addFreeVariable(const poly::Variable& var); |
| 98 | /** |
| 99 | * Reduce the polynomial q. Compared to the above description, there may |
| 100 | * actually be multiple polynomials in the Gröbner basis and instead of |
| 101 | * loosing this knowledge and returning their product, we return them as a |
| 102 | * vector. |
| 103 | */ |
| 104 | std::vector<poly::Polynomial> reducePolynomial( |
| 105 | const poly::Polynomial& q) const; |
| 106 | |
| 107 | /** |
| 108 | * Isolates the real roots of the given polynomials. |
| 109 | */ |
| 110 | std::vector<poly::Value> isolateRealRoots(const poly::Polynomial& q) const; |
| 111 | |
| 112 | /** |
| 113 | * Compute the infeasible regions of q under the given sign condition. |
| 114 | * Uses reducePolynomial and then performs real root isolation on the |
| 115 | * resulting polynomials to obtain the intervals. Mimics |
| 116 | * poly::infeasible_regions, but uses Lazard's evaluation. |
| 117 | */ |
| 118 | std::vector<poly::Interval> infeasibleRegions(const poly::Polynomial& q, |
| 119 | poly::SignCondition sc) const; |
| 120 | |
| 121 | private: |
| 122 | std::unique_ptr<LazardEvaluationState> d_state; |
| 123 | }; |
| 124 | |
| 125 | } // namespace cvc5::internal::theory::arith::nl::coverings |
| 126 | |
| 127 | #endif |
| 128 | #endif |