3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 11:55:51 +00:00

Shared features from polysat branch (#6567)

* Allow setting default debug action

* Fix dlist and add iterator

* Add var_queue iterator

* Add some helpers

* rational: machine_div2k and pseudo_inverse

* Basic support for non-copyable types in map

* tbv helpers

* pdd updates

* Remove duplicate functions

gcc doesn't like having both versions
This commit is contained in:
Jakob Rath 2023-02-03 22:08:47 +01:00 committed by GitHub
parent be44ace995
commit d69155b9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 456 additions and 62 deletions

View file

@ -153,3 +153,21 @@ bool rational::mult_inverse(unsigned num_bits, rational & result) const {
return true;
}
/**
* Compute the smallest multiplicative pseudo-inverse modulo 2^num_bits:
*
* mod(n * n.pseudo_inverse(bits), 2^bits) == 2^k,
* where k is maximal such that 2^k divides n.
*
* Precondition: number is non-zero.
*/
rational rational::pseudo_inverse(unsigned num_bits) const {
rational result;
rational const& n = *this;
SASSERT(!n.is_zero()); // TODO: or we define pseudo-inverse of 0 as 0.
unsigned const k = n.trailing_zeros();
rational const odd = machine_div2k(n, k);
VERIFY(odd.mult_inverse(num_bits - k, result));
SASSERT_EQ(mod(n * result, rational::power_of_two(num_bits)), rational::power_of_two(k));
return result;
}