z3-src 501.0.1

Source distribution of the Z3 SMT solver, for use as a build dependency
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/*++
Copyright (c) 2010 Microsoft Corporation

Module Name:

    dl_check_table.cpp

Abstract:

    <abstract>

Author:

    Nikolaj Bjorner (nbjorner) 2010-11-15
    

Revision History:

--*/


#include "muz/rel/dl_check_table.h"
#include "muz/rel/dl_table.h"


namespace datalog {
    
    bool check_table_plugin::can_handle_signature(table_signature const& s) {
        return m_tocheck.can_handle_signature(s) && m_checker.can_handle_signature(s);
    }


    check_table & check_table_plugin::get(table_base& r) {
        return static_cast<check_table&>(r);
    }
    
    check_table const & check_table_plugin::get(table_base const& r) {
        return static_cast<check_table const &>(r);
    }

     table_base& check_table_plugin::checker(table_base& r) { return *get(r).m_checker; }
     table_base const& check_table_plugin::checker(table_base const& r) { return *get(r).m_checker; }
     table_base* check_table_plugin::checker(table_base* r) { return r?(get(*r).m_checker):nullptr; }
     table_base const* check_table_plugin::checker(table_base const* r) { return r?(get(*r).m_checker):nullptr; }
     table_base& check_table_plugin::tocheck(table_base& r) { return *get(r).m_tocheck; }
     table_base const& check_table_plugin::tocheck(table_base const& r) { return *get(r).m_tocheck; }
     table_base* check_table_plugin::tocheck(table_base* r) { return r?(get(*r).m_tocheck):nullptr; }
     table_base const* check_table_plugin::tocheck(table_base const* r) { return r?(get(*r).m_tocheck):nullptr; }

    table_base * check_table_plugin::mk_empty(const table_signature & s) {
        IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
        table_base* checker = m_checker.mk_empty(s);
        table_base* tocheck = m_tocheck.mk_empty(s);
        return alloc(check_table, *this, s, tocheck, checker);
    }
    
    class check_table_plugin::join_fn : public table_join_fn {
        scoped_ptr<table_join_fn> m_tocheck;
        scoped_ptr<table_join_fn> m_checker;
    public:
        join_fn(check_table_plugin& p, 
                const table_base & t1, const table_base & t2,
                unsigned col_cnt, const unsigned * cols1, const unsigned * cols2) {
            m_tocheck = p.get_manager().mk_join_fn(tocheck(t1), tocheck(t2), col_cnt, cols1, cols2);
            m_checker = p.get_manager().mk_join_fn(checker(t1), checker(t2), col_cnt, cols1, cols2);
        }

        table_base* operator()(const table_base & t1, const table_base & t2) override {
            IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
            table_base* ttocheck = (*m_tocheck)(tocheck(t1), tocheck(t2));
            table_base* tchecker = (*m_checker)(checker(t1), checker(t2));
            check_table* result = alloc(check_table, get(t1).get_plugin(), ttocheck->get_signature(), ttocheck, tchecker);
            return result;
        }
    };

    table_join_fn * check_table_plugin::mk_join_fn(const table_base & t1, const table_base & t2,
                                                  unsigned col_cnt, const unsigned * cols1, const unsigned * cols2) {
        if (!check_kind(t1) || !check_kind(t2)) {
            return nullptr;
        }
        return alloc(join_fn, *this, t1, t2, col_cnt, cols1, cols2);    
    }

    class check_table_plugin::join_project_fn : public table_join_fn {
        scoped_ptr<table_join_fn> m_tocheck;
        scoped_ptr<table_join_fn> m_checker;
    public:
        join_project_fn(check_table_plugin& p, const table_base & t1, const table_base & t2,
                        unsigned col_cnt, const unsigned * cols1, const unsigned * cols2,
                        unsigned removed_col_cnt, const unsigned * removed_cols) {
            m_tocheck = p.get_manager().mk_join_project_fn(tocheck(t1), tocheck(t2), col_cnt, cols1, cols2, removed_col_cnt, removed_cols);
            m_checker = p.get_manager().mk_join_project_fn(checker(t1), checker(t2), col_cnt, cols1, cols2, removed_col_cnt, removed_cols);
        }

        table_base* operator()(const table_base & t1, const table_base & t2) override {
            table_base* ttocheck = (*m_tocheck)(tocheck(t1), tocheck(t2));
            table_base* tchecker = (*m_checker)(checker(t1), checker(t2));
            check_table* result = alloc(check_table, get(t1).get_plugin(), ttocheck->get_signature(), ttocheck, tchecker);
            return result;
        }
    };

    table_join_fn * check_table_plugin::mk_join_project_fn(const table_base & t1, const table_base & t2,
            unsigned col_cnt, const unsigned * cols1, const unsigned * cols2, unsigned removed_col_cnt, 
            const unsigned * removed_cols) {
        if (!check_kind(t1) || !check_kind(t2)) {
            return nullptr;
        }
        return alloc(join_project_fn, *this, t1, t2, col_cnt, cols1, cols2, removed_col_cnt, removed_cols);    
    }

    class check_table_plugin::union_fn : public table_union_fn {
        scoped_ptr<table_union_fn> m_tocheck;
        scoped_ptr<table_union_fn> m_checker;
    public:
        union_fn(check_table_plugin& p, table_base const& tgt, const table_base& src, table_base const* delta) {
            m_tocheck = p.get_manager().mk_union_fn(tocheck(tgt), tocheck(src), tocheck(delta));
            m_checker = p.get_manager().mk_union_fn(checker(tgt), checker(src), checker(delta));
        }
        
        void operator()(table_base& tgt, const table_base& src, table_base* delta) override {
            IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
            (*m_tocheck)(tocheck(tgt), tocheck(src), tocheck(delta));
            (*m_checker)(checker(tgt), checker(src), checker(delta));
            get(tgt).well_formed();
            if (delta) {
                get(*delta).well_formed();
            }
        }
    };

    table_union_fn * check_table_plugin::mk_union_fn(const table_base & tgt, const table_base & src, const table_base * delta) {
        if (!check_kind(tgt) || !check_kind(src) || (delta && !check_kind(*delta))) {
            return nullptr;
        }
        return alloc(union_fn, *this, tgt, src, delta);
        
    }

    class check_table_plugin::project_fn : public table_transformer_fn {
        scoped_ptr<table_transformer_fn> m_checker;
        scoped_ptr<table_transformer_fn> m_tocheck;
    public:
        project_fn(check_table_plugin& p, const table_base & t, unsigned col_cnt, const unsigned * removed_cols) {
            m_checker = p.get_manager().mk_project_fn(checker(t), col_cnt, removed_cols);
            m_tocheck = p.get_manager().mk_project_fn(tocheck(t), col_cnt, removed_cols);
        }

        table_base* operator()(table_base const& src) override {
            table_base* tchecker = (*m_checker)(checker(src));
            table_base* ttocheck = (*m_tocheck)(tocheck(src));
            check_table* result = alloc(check_table, get(src).get_plugin(), tchecker->get_signature(), ttocheck, tchecker);
            return result;
        }
    };
    
    table_transformer_fn * check_table_plugin::mk_project_fn(const table_base & t, unsigned col_cnt, const unsigned * removed_cols) {
        if (!check_kind(t)) {
            return nullptr;
        }
        return alloc(project_fn, *this, t, col_cnt, removed_cols);        
    }

    class check_table_plugin::select_equal_and_project_fn : public table_transformer_fn {
        scoped_ptr<table_transformer_fn> m_checker;
        scoped_ptr<table_transformer_fn> m_tocheck;
    public:
        select_equal_and_project_fn(check_table_plugin& p, const table_base & t, const table_element & value, unsigned col) {
            m_checker = p.get_manager().mk_select_equal_and_project_fn(checker(t), value, col);
            m_tocheck = p.get_manager().mk_select_equal_and_project_fn(tocheck(t), value, col);
        }

        table_base* operator()(table_base const& src) override {
            table_base* tchecker = (*m_checker)(checker(src));
            table_base* ttocheck = (*m_tocheck)(tocheck(src));
            check_table* result = alloc(check_table, get(src).get_plugin(), tchecker->get_signature(), ttocheck, tchecker);
            return result;
        }
    };

    table_transformer_fn * check_table_plugin::mk_select_equal_and_project_fn(const table_base & t, 
            const table_element & value, unsigned col) {
        if (!check_kind(t)) {
            return nullptr;
        }
        return alloc(select_equal_and_project_fn, *this, t, value, col);        
    }

    class check_table_plugin::rename_fn : public table_transformer_fn {
        scoped_ptr<table_transformer_fn> m_checker;
        scoped_ptr<table_transformer_fn> m_tocheck;
    public:
        rename_fn(check_table_plugin& p, const table_base & t, unsigned cycle_len, unsigned const* cycle) {
            m_checker = p.get_manager().mk_rename_fn(checker(t), cycle_len, cycle);
            m_tocheck = p.get_manager().mk_rename_fn(tocheck(t), cycle_len, cycle);
        }

        table_base* operator()(table_base const& src) override {
            IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
            table_base* tchecker = (*m_checker)(checker(src));
            table_base* ttocheck = (*m_tocheck)(tocheck(src));
            check_table* result = alloc(check_table, get(src).get_plugin(), ttocheck->get_signature(), ttocheck, tchecker);
            return result;
        }
    };
    
    table_transformer_fn * check_table_plugin::mk_rename_fn(const table_base & t, unsigned len, const unsigned * cycle) {
        if (!check_kind(t)) {
            return nullptr;
        }
        return alloc(rename_fn, *this, t, len, cycle);
    }

    class check_table_plugin::filter_identical_fn : public table_mutator_fn {
        scoped_ptr<table_mutator_fn> m_checker;
        scoped_ptr<table_mutator_fn> m_tocheck;
    public:
        filter_identical_fn(check_table_plugin& p, const table_base & t,unsigned cnt, unsigned const* cols)
        {
            m_checker = p.get_manager().mk_filter_identical_fn(checker(t), cnt, cols);
            m_tocheck = p.get_manager().mk_filter_identical_fn(tocheck(t), cnt, cols);        
        }

        void operator()(table_base & t) override {
            (*m_checker)(checker(t));
            (*m_tocheck)(tocheck(t));
            get(t).well_formed();
        }
    };

    table_mutator_fn * check_table_plugin::mk_filter_identical_fn(const table_base & t, unsigned col_cnt, 
        const unsigned * identical_cols) {
        if (check_kind(t)) {
            return alloc(filter_identical_fn, *this, t, col_cnt, identical_cols);
        }
        return nullptr;
    }

    class check_table_plugin::filter_equal_fn : public table_mutator_fn {
        scoped_ptr<table_mutator_fn> m_checker;
        scoped_ptr<table_mutator_fn> m_tocheck;
    public:
        filter_equal_fn(check_table_plugin& p, const table_base & t, const table_element & v, unsigned col)
        {
            m_checker = p.get_manager().mk_filter_equal_fn(checker(t), v, col);
            m_tocheck = p.get_manager().mk_filter_equal_fn(tocheck(t), v, col); 
        }

        void operator()(table_base& src) override {
            (*m_checker)(checker(src));
            (*m_tocheck)(tocheck(src));
            get(src).well_formed();
        }
    };

    table_mutator_fn * check_table_plugin::mk_filter_equal_fn(const table_base & t, const table_element & value, unsigned col) {
        if (check_kind(t)) {
            return alloc(filter_equal_fn, *this, t, value, col);
        }
        return nullptr;
    }

    class check_table_plugin::filter_interpreted_fn : public table_mutator_fn {
        scoped_ptr<table_mutator_fn> m_checker;
        scoped_ptr<table_mutator_fn> m_tocheck;
    public:
        filter_interpreted_fn(check_table_plugin& p, const table_base & t, app * condition)
        {
            m_checker = p.get_manager().mk_filter_interpreted_fn(checker(t), condition);
            m_tocheck = p.get_manager().mk_filter_interpreted_fn(tocheck(t), condition); 
        }

        void operator()(table_base& src) override {
            (*m_checker)(checker(src));
            (*m_tocheck)(tocheck(src));
            get(src).well_formed();
        }
    };

    table_mutator_fn * check_table_plugin::mk_filter_interpreted_fn(const table_base & t, app * condition) {
        if (check_kind(t)) {
            return alloc(filter_interpreted_fn, *this, t, condition);
        }
        return nullptr;
    }

    class check_table_plugin::filter_interpreted_and_project_fn : public table_transformer_fn {
        scoped_ptr<table_transformer_fn> m_checker;
        scoped_ptr<table_transformer_fn> m_tocheck;
    public:
        filter_interpreted_and_project_fn(check_table_plugin& p, const table_base & t, app * condition,
            unsigned removed_col_cnt, const unsigned * removed_cols)
        {
            m_checker = p.get_manager().mk_filter_interpreted_and_project_fn(checker(t), condition, removed_col_cnt, removed_cols);
            m_tocheck = p.get_manager().mk_filter_interpreted_and_project_fn(tocheck(t), condition, removed_col_cnt, removed_cols); 
        }

        table_base* operator()(table_base const& src) override {
            table_base* tchecker = (*m_checker)(checker(src));
            table_base* ttocheck = (*m_tocheck)(tocheck(src));
            check_table* result = alloc(check_table, get(src).get_plugin(), ttocheck->get_signature(), ttocheck, tchecker);
            return result;
        }
    };

    table_transformer_fn * check_table_plugin::mk_filter_interpreted_and_project_fn(const table_base & t,
        app * condition, unsigned removed_col_cnt, const unsigned * removed_cols) {
        if (check_kind(t)) {
            return alloc(filter_interpreted_and_project_fn, *this, t, condition, removed_col_cnt, removed_cols);
        }
        return nullptr;
    }

    class check_table_plugin::filter_by_negation_fn : public table_intersection_filter_fn {
        scoped_ptr<table_intersection_filter_fn> m_checker;
        scoped_ptr<table_intersection_filter_fn> m_tocheck;
    public:
        filter_by_negation_fn(
            check_table_plugin& p,
            const table_base & t, 
            const table_base & negated_obj, unsigned joined_col_cnt, 
            const unsigned * t_cols, const unsigned * negated_cols) {
            m_checker = p.get_manager().mk_filter_by_negation_fn(checker(t), checker(negated_obj), joined_col_cnt, t_cols, negated_cols);
            m_tocheck = p.get_manager().mk_filter_by_negation_fn(tocheck(t), tocheck(negated_obj), joined_col_cnt, t_cols, negated_cols);
        }

        void operator()(table_base& src, table_base const& negated_obj) override {
            IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
            (*m_checker)(checker(src), checker(negated_obj));
            (*m_tocheck)(tocheck(src), tocheck(negated_obj));
            get(src).well_formed();
        }
        
    };

    table_intersection_filter_fn * check_table_plugin::mk_filter_by_negation_fn(const table_base & t, 
        const table_base & negated_obj, unsigned joined_col_cnt, 
        const unsigned * t_cols, const unsigned * negated_cols) {
        if (check_kind(t) && check_kind(negated_obj)) {
            return alloc(filter_by_negation_fn, *this, t, negated_obj, joined_col_cnt, t_cols, negated_cols);
        }
        return nullptr;
    }

    // ------------------
    // check_table


    check_table::check_table(check_table_plugin & p, const table_signature & sig):
        table_base(p, sig) {
        (well_formed());
    }

    check_table::check_table(check_table_plugin & p, const table_signature & sig, table_base* tocheck, table_base* checker):
        table_base(p, sig),
        m_checker(checker),
        m_tocheck(tocheck) {            
        well_formed();
    }

    check_table::~check_table() {
        m_tocheck->deallocate();
        m_checker->deallocate();
    }

    bool check_table::well_formed() const {
        get_plugin().m_count++;
        iterator it = m_tocheck->begin(), end = m_tocheck->end();
        for (; it != end; ++it) {
            table_fact fact;
            it->get_fact(fact);
            if (!m_checker->contains_fact(fact)) {
                m_tocheck->display(verbose_stream());
                m_checker->display(verbose_stream());
                verbose_stream() << get_plugin().m_count << "\n";
                UNREACHABLE();
                fatal_error(0);
                return false;
            }
        }
        iterator it2 = m_checker->begin(), end2 = m_checker->end();
        for (; it2 != end2; ++it2) {
            table_fact fact;
            it2->get_fact(fact);
            if (!m_tocheck->contains_fact(fact)) {
                m_tocheck->display(verbose_stream());
                m_checker->display(verbose_stream());
                verbose_stream() << get_plugin().m_count << "\n";
                UNREACHABLE();
                fatal_error(0);
                return false;
            }
        }
        return true;
    }

    bool check_table::empty() const {
        if (m_tocheck->empty() != m_checker->empty()) {
            m_tocheck->display(verbose_stream());
            m_checker->display(verbose_stream());
            verbose_stream() << get_plugin().m_count << "\n";
            fatal_error(0);
        }
        return m_tocheck->empty();
    }


    void check_table::add_fact(const table_fact & f) {
        IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
        m_tocheck->add_fact(f);
        m_checker->add_fact(f);
        well_formed();        
    }

    void check_table::remove_fact(const table_element*  f) {
        IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
        m_tocheck->remove_fact(f);
        m_checker->remove_fact(f);
        well_formed();        
    }

    bool check_table::contains_fact(const table_fact & f) const {
        return m_checker->contains_fact(f);
    }
    
    table_base * check_table::clone() const {        
        IF_VERBOSE(1, verbose_stream() << __FUNCTION__ << "\n";);
        check_table* result = alloc(check_table, get_plugin(), get_signature(), m_tocheck->clone(), m_checker->clone());
        return result;
    }

    table_base * check_table::complement(func_decl* p, const table_element * func_columns) const {
        check_table* result = alloc(check_table, get_plugin(), get_signature(), m_tocheck->complement(p, func_columns), m_checker->complement(p, func_columns));
        return result;
    }

}