z3-src 503.2.2

Source distribution of the Z3 SMT solver, for use as a build dependency
Documentation
/*++
Copyright (c) 2015 Microsoft Corporation

Module Name:

    bvarray2uf_simplifier.h

Abstract:

    Simplifier that rewrites bit-vector arrays into bit-vector
    (uninterpreted) functions.

Author:

    Christoph (cwinter) 2015-11-04

--*/
#pragma once

#include "ast/simplifiers/dependent_expr_state.h"
#include "ast/converters/generic_model_converter.h"
#include "tactic/bv/bvarray2uf_rewriter.h"

class bvarray2uf_simplifier : public dependent_expr_simplifier {
    bvarray2uf_rewriter         m_rw;
    generic_model_converter_ref m_fmc;

public:
    bvarray2uf_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls)
        : dependent_expr_simplifier(m, fmls),
          m_rw(m, p),
          m_fmc(alloc(generic_model_converter, m, "bvarray2uf")) {
        m_rw.set_mcs(m_fmc.get());
    }

    char const* name() const override { return "bvarray2uf"; }

    // bvarray2uf_rewriter does not support proofs
    bool supports_proofs() const override { return false; }

    void reduce() override {
        m_rw.reset();
        m_fmc = alloc(generic_model_converter, m, "bvarray2uf");
        m_rw.set_mcs(m_fmc.get());

        expr_ref  new_curr(m);
        proof_ref new_pr(m);
        for (unsigned idx : indices()) {
            auto const& d = m_fmls[idx];
            m_rw(d.fml(), new_curr, new_pr);
            m_fmls.update(idx, dependent_expr(m, new_curr, nullptr, d.dep()));
        }

        // Add extra assertions generated by the rewriter (e.g., injectivity lemmas)
        for (expr* a : m_rw.m_cfg.extra_assertions)
            m_fmls.add(dependent_expr(m, a, nullptr, nullptr));

        // Register model converter entries for array-to-UF model reconstruction
        for (auto const& entry : m_fmc->entries()) {
            if (entry.m_instruction == generic_model_converter::instruction::HIDE)
                m_fmls.model_trail().hide(entry.m_f);
            else if (entry.m_instruction == generic_model_converter::instruction::ADD)
                m_fmls.model_trail().push(entry.m_f, entry.m_def, nullptr, {});
        }
    }
};