mirror of
https://github.com/Z3Prover/z3
synced 2025-10-11 10:18:06 +00:00
wip - updated version of elim_uncstr_tactic
- remove reduce_invertible. It is subsumed by reduce_uncstr(2) - introduce a simplifier for reduce_unconstrained. It uses reference counting to deal with inefficiency bug of legacy reduce_uncstr. It decomposes theory plugins into expr_inverter. reduce_invertible is a tactic used in most built-in scenarios. It is useful for removing subterms that can be eliminated using "cheap" quantifier elimination. Specifically variables that occur only once can be removed in many cases by computing an expression that represents the effect computing a value for the eliminated occurrence. The theory plugins for variable elimination are very partial and should be augmented by extensions, esp. for the case of bit-vectors where the invertibility conditions are thoroughly documented by Niemetz and Preiner.
This commit is contained in:
parent
689af3b4df
commit
efbe0a6554
20 changed files with 1334 additions and 621 deletions
84
src/ast/simplifiers/elim_unconstrained.h
Normal file
84
src/ast/simplifiers/elim_unconstrained.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*++
|
||||
Copyright (c) 2022 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
elim_unconstrained.h
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2022-11-2.
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/heap.h"
|
||||
#include "ast/simplifiers/dependent_expr_state.h"
|
||||
#include "ast/rewriter/th_rewriter.h"
|
||||
#include "ast/converters/expr_inverter.h"
|
||||
|
||||
|
||||
class elim_unconstrained : public dependent_expr_simplifier {
|
||||
|
||||
struct node {
|
||||
unsigned m_refcount;
|
||||
expr* m_term;
|
||||
expr* m_orig;
|
||||
ptr_vector<expr> m_parents;
|
||||
};
|
||||
struct var_lt {
|
||||
elim_unconstrained& s;
|
||||
var_lt(elim_unconstrained& s) : s(s) {}
|
||||
bool operator()(int v1, int v2) const {
|
||||
return s.get_node(v1).m_refcount < s.get_node(v2).m_refcount;
|
||||
}
|
||||
};
|
||||
struct stats {
|
||||
unsigned m_num_eliminated = 0;
|
||||
void reset() { m_num_eliminated = 0; }
|
||||
};
|
||||
expr_inverter m_inverter;
|
||||
vector<node> m_nodes;
|
||||
var_lt m_lt;
|
||||
heap<var_lt> m_heap;
|
||||
expr_ref_vector m_trail;
|
||||
ptr_vector<expr> m_args;
|
||||
expr_mark m_frozen;
|
||||
stats m_stats;
|
||||
|
||||
bool operator()(int v1, int v2) const { return get_node(v1).m_refcount < get_node(v2).m_refcount; }
|
||||
|
||||
node& get_node(unsigned n) { return m_nodes[n]; }
|
||||
node const& get_node(unsigned n) const { return m_nodes[n]; }
|
||||
node& get_node(expr* t) { return m_nodes[t->get_id()]; }
|
||||
node const& get_node(expr* t) const { return m_nodes[t->get_id()]; }
|
||||
unsigned get_refcount(expr* t) const { return get_node(t).m_refcount; }
|
||||
void inc_ref(expr* t) { ++get_node(t).m_refcount; if (is_uninterp_const(t)) m_heap.increased(t->get_id()); }
|
||||
void dec_ref(expr* t) { --get_node(t).m_refcount; if (is_uninterp_const(t)) m_heap.decreased(t->get_id()); }
|
||||
void gc(expr* t);
|
||||
|
||||
expr* get_parent(unsigned n) const;
|
||||
void init_refcounts();
|
||||
void dec_refcounts(expr* t);
|
||||
|
||||
void add_term(expr* t);
|
||||
void init_terms(expr_ref_vector const& terms);
|
||||
|
||||
void init_nodes();
|
||||
void eliminate();
|
||||
void reconstruct_terms();
|
||||
void assert_normalized(vector<dependent_expr>& old_fmls);
|
||||
void update_model_trail(generic_model_converter& mc, vector<dependent_expr> const& old_fmls);
|
||||
|
||||
public:
|
||||
|
||||
elim_unconstrained(ast_manager& m, dependent_expr_state& fmls);
|
||||
|
||||
void reduce() override;
|
||||
|
||||
void collect_statistics(statistics& st) const override { st.update("elim-unconstr", m_stats.m_num_eliminated); }
|
||||
|
||||
void reset_statistics() override { m_stats.reset(); }
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue