3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-08 04:01:22 +00:00

add the pdd evaluator and a unit test for it

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2019-12-23 17:37:29 -08:00
parent 7eb1affc7b
commit a9f09beb8e
2 changed files with 118 additions and 75 deletions

42
src/math/dd/pdd_eval.h Normal file
View file

@ -0,0 +1,42 @@
/*++
Copyright (c) 2019 Microsoft Corporation
Module Name:
dd_pdd.cpp
Abstract:
Poly DD package
Author:
Nikolaj Bjorner (nbjorner) 2019-12-23
Lev Nachmanson (levnach) 2019-12-23
Revision History:
--*/
#include "math/dd/dd_pdd.h"
namespace dd {
// calculates the value of a pdd expression based on the given values of the variables
class pdd_eval {
pdd_manager& m;
std::function<rational (unsigned)> m_var2val;
public:
pdd_eval(pdd_manager& m): m(m) {}
void operator=(std::function<rational (unsigned)>& i2v) { m_var2val = i2v; }
rational operator()(pdd const& p) {
if (p.is_val()) {
return p.val();
}
return (*this)(p.hi()) * m_var2val(p.var()) + (*this)(p.lo());
}
};
}

View file

@ -1,7 +1,8 @@
#include "math/dd/dd_pdd.h"
#include "math/dd/pdd_eval.h"
namespace dd {
static void test1() {
static void test1() {
pdd_manager m(3);
pdd v0 = m.mk_var(0);
pdd v1 = m.mk_var(1);
@ -46,9 +47,9 @@ namespace dd {
c2 = (v0*v1*(v2 + v0)) + v2;
c3 = c2.reduce(c1);
std::cout << c1 << " " << c2 << " reduce: " << c3 << "\n";
}
}
static void test2() {
static void test2() {
std::cout << "\ntest2\n";
// a(b^2)cd + abc + bcd + bc + cd + 3 reduce by bc
pdd_manager m(4);
@ -65,9 +66,9 @@ namespace dd {
pdd r_fe = m.reduce(f, e);
std::cout << "result of reduce " << f << " by " << e << " is " << r_fe << "\n" ;
VERIFY(r_fe == f);
}
}
static void test3() {
static void test3() {
std::cout << "\ntest3\n";
pdd_manager m(4);
pdd a = m.mk_var(0);
@ -81,9 +82,9 @@ namespace dd {
}
e = e * b;
std::cout << e << "\n";
}
}
static void test_reset() {
static void test_reset() {
std::cout << "\ntest reset\n";
pdd_manager m(4);
pdd a = m.mk_var(0);