3 #include <carl-arith/numbers/PrimeFactory.h>
10 std::vector<FormulaT> subformulas;
23 const auto& cLHS = formula.lhs();
27 carl::PrimeFactory<Integer> pFactory;
44 product *= pFactory.next_prime();
55 const auto& cLHS = formula.lhs();
56 assert(carl::is_integer(formula.lhs().constant_part()));
57 Integer cRHS = carl::get_num(formula.lhs().constant_part());
62 for(
const auto& it : cLHS){
64 assert(carl::is_integer(it.coeff()));
67 newLHS +=
TermT(newCoeff, it.single_variable(), 1);
71 if(newLHS.size() == 0 && newRHS > 0){
72 return FormulaT(carl::FormulaType::FALSE);
73 }
else if(newLHS.size() == 0 && newRHS == 0){
74 return FormulaT(carl::FormulaType::TRUE);
78 for(
const auto& it : newLHS){
81 t = carl::floor((t - newRHS) / prime );
83 for(
int i = 0; i < t; i++){
85 newLHS +=
TermT(-t, carl::fresh_boolean_variable(), 1);
95 const auto& cLHS = formula.lhs();
96 std::vector<std::pair<int, Integer>> freq;
99 std::vector<Integer> base;
102 assert(carl::is_integer(it.coeff()));
103 sum += carl::get_num(it.coeff());
107 assert(carl::is_integer(it.coeff()));
110 v.erase( unique( v.begin(), v.end() ), v.end() );
113 auto elem = std::find_if(freq.begin(), freq.end(),
114 [&] (
const std::pair<int, Integer>& elem){
115 return elem.second == i;
117 if(elem != freq.end()){
118 auto distance = std::distance(freq.begin(), elem);
119 freq[(
unsigned long) distance].first = freq[(
unsigned long) distance].first + 1;
121 freq.push_back(std::pair<int, Integer>(1, i));
127 [&](
const std::pair<int, Integer> &p1,
const std::pair<int, Integer> &p2)
129 if(p1.first == p2.first){
130 return (p1.second < p2.second);
132 return(p1.first > p2.first);
139 product *= it.second;
141 base.push_back(it.second);
143 base.push_back(it.second);
150 for(std::size_t i = 0; i < base.size(); i++){
151 if(base[i] == 1 || base[i] == 0){
152 base.erase(base.begin() + (
long) i);
158 std::vector<Integer> RNSEncoder::integerFactorization(
const Integer& coeff) {
160 return mPrimesTable[carl::to_int<carl::uint>(coeff)];
163 std::vector<Integer>
primes;
164 Integer x = carl::ceil(carl::sqrt(coeff));
166 Integer r = carl::floor(carl::sqrt(y));
171 std::vector<Integer> v = integerFactorization(coeff / 2);
178 r = carl::floor(carl::sqrt(y));
186 std::vector<Integer> v = mPrimesTable[carl::to_int<carl::uint>(first)];
190 carl::PrimeFactory<Integer> pFactory;
192 while(prime < first){
193 prime = pFactory.next_prime();
200 std::vector<Integer> v = integerFactorization(first);
208 std::vector<Integer> v = mPrimesTable[carl::to_int<carl::uint>(second)];
211 carl::PrimeFactory<Integer> pFactory;
213 while(prime < second){
214 prime = pFactory.next_prime();
221 std::vector<Integer> v = integerFactorization(second);
234 std::vector<std::vector<Integer>> RNSEncoder::primesTable() {
236 return {{0}, {1}, {2}, {3}, {2, 2}, {5}, {2, 3}, {7}, {2, 2, 2}, {3, 3}, {2, 5}, {11}, {2, 2, 3},
237 {13}, {2, 7}, {3, 5}, {2, 2, 2, 2}, {17}, {2, 3, 3}, {19}, {2, 2, 5}, {3, 7}, {2, 11},
238 {23}, {2, 2, 2, 3}, {5, 5}, {2, 13}, {3, 3, 3}, {2, 2, 7}, {29}, {2, 3, 5}, {31},
239 {2, 2, 2, 2, 2}, {3, 11}, {2, 17}, {5, 7}, {2, 2, 3, 3}, {37}, {2, 19}, {3, 13}, {2, 2, 2, 5},
240 {41}, {2, 3, 7}, {43}, {2, 2, 11}, {3, 3, 5}, {2, 23}, {47}, {2, 2, 2, 2, 3}, {7 ,7}, {2, 5, 5},
241 {3, 17}, {2, 2, 13}, {53}, {2, 3, 3, 3}, {5, 11}, {2, 2, 2, 7}, {3, 19}, {2, 29}, {59},
242 {2, 2, 3, 5}, {61}, {2, 31}, {3, 3, 7}, {2, 2, 2, 2, 2, 2}, {5, 13}, {2, 3, 11}, {67},
243 {2, 2, 17}, {3, 23}, {2, 5, 7}, {71}, {2, 2, 2, 3, 3}, {73}, {2, 37}, {3, 5, 5}, {2, 2, 19},
244 {7, 11}, {2, 3, 13}, {79}, {2, 2, 2, 2, 5}, {3, 3, 3, 3}, {2, 41}, {83}, {2, 2, 3, 7}, {5, 17},
245 {2, 43}, {3, 29}, {2, 2, 2, 11}, {89}, {2, 3, 3, 5}, {7, 13}, {2, 2, 23}, {3, 31}, {2, 47},
246 {5, 19}, {2, 2, 2, 2, 2, 3}, {97}, {2, 7, 7}, {3, 3, 11}, {2, 2, 5, 5}};
std::vector< Integer > integerFactorization(const Integer &coeff)
std::optional< FormulaT > doEncode(const ConstraintT &constraint)
std::vector< Integer > calculateRNSBase(const ConstraintT &formula)
FormulaT rnsTransformation(const ConstraintT &formula, const Integer &prime)
bool isNonRedundant(const std::vector< Integer > &base, const ConstraintT &formula)
static const int primes[nprimes]
void sort(T *array, int size, LessThan lt)
Numeric mod(const Numeric &_valueA, const Numeric &_valueB)
Calculates the result of the first argument modulo the second argument.
Class to create the formulas for axioms.
carl::Term< Rational > TermT
carl::Formula< Poly > FormulaT
carl::MultivariatePolynomial< Rational > Poly
carl::Constraint< Poly > ConstraintT
carl::IntegralType< Rational >::type Integer
#define SMTRAT_LOG_INFO(channel, msg)