mirror of
https://github.com/Z3Prover/z3
synced 2025-08-22 11:07:51 +00:00
move more converters
This commit is contained in:
parent
06eb460c75
commit
25bb935793
9 changed files with 9 additions and 9 deletions
|
@ -1,8 +1,10 @@
|
|||
z3_add_component(converters
|
||||
SOURCES
|
||||
equiv_proof_converter.cpp
|
||||
generic_model_converter.cpp
|
||||
model_converter.cpp
|
||||
proof_converter.cpp
|
||||
generic_model_converter.cpp
|
||||
replace_proof_converter.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
model
|
||||
)
|
||||
|
|
35
src/ast/converters/equiv_proof_converter.cpp
Normal file
35
src/ast/converters/equiv_proof_converter.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
equiv_proof_converter.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Proof converter that applies equivalence rule to leaves.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2012-11-23
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include "ast/converters/equiv_proof_converter.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/scoped_proof.h"
|
||||
|
||||
void equiv_proof_converter::insert(expr* fml1, expr* fml2) {
|
||||
if (fml1 != fml2) {
|
||||
scoped_proof _sp(m);
|
||||
proof_ref p1(m), p2(m), p3(m);
|
||||
p1 = m.mk_asserted(fml1);
|
||||
p2 = m.mk_rewrite(fml1, fml2);
|
||||
p3 = m.mk_modus_ponens(p1, p2);
|
||||
TRACE("proof_converter", tout << mk_pp(p3.get(), m) << "\n";);
|
||||
SASSERT(m.has_fact(p3));
|
||||
m_replace.insert(p3);
|
||||
}
|
||||
}
|
49
src/ast/converters/equiv_proof_converter.h
Normal file
49
src/ast/converters/equiv_proof_converter.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
equiv_proof_converter.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Proof converter that applies equivalence rule to leaves.
|
||||
|
||||
Given a proof P with occurrences of [asserted fml]
|
||||
replace [asserted fml] by a proof of the form
|
||||
[mp [asserted fml'] [~ fml fml']]
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2012-11-23
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ast/converters/replace_proof_converter.h"
|
||||
|
||||
class equiv_proof_converter : public proof_converter {
|
||||
ast_manager& m;
|
||||
replace_proof_converter m_replace;
|
||||
public:
|
||||
|
||||
equiv_proof_converter(ast_manager& m): m(m), m_replace(m) {}
|
||||
|
||||
proof_ref operator()(ast_manager & m, unsigned num_source, proof * const * source) override {
|
||||
return m_replace(m, num_source, source);
|
||||
}
|
||||
|
||||
proof_converter * translate(ast_translation & translator) override {
|
||||
return m_replace.translate(translator);
|
||||
}
|
||||
|
||||
void insert(expr* fml1, expr* fml2);
|
||||
|
||||
ast_manager& get_manager() { return m; }
|
||||
|
||||
void display(std::ostream & out) override {}
|
||||
};
|
||||
|
83
src/ast/converters/replace_proof_converter.cpp
Normal file
83
src/ast/converters/replace_proof_converter.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
replace_proof_converter.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Proof converter that replaces asserted by sub-proof.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2012-9-16
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include "ast/converters/replace_proof_converter.h"
|
||||
#include "ast/expr_functors.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/for_each_expr.h"
|
||||
|
||||
/**
|
||||
\brief Replace expressions by other expressions.
|
||||
|
||||
replace_map is caching, so inserting src |-> dst has no effect if
|
||||
src is a sub-expression of something that has already been visited.
|
||||
The assumption is that proof replacements are inserted into
|
||||
the replace_proof_converter in the order that they are introduced, so
|
||||
there are no such clashes.
|
||||
|
||||
map_proc is used as expr_replacer behaves differently
|
||||
when proof mode is turned on.
|
||||
*/
|
||||
class replace_map : public map_proc {
|
||||
public:
|
||||
replace_map(ast_manager& m): map_proc(m) {}
|
||||
|
||||
void insert(expr* src, expr* dst) {
|
||||
m_map.insert(src, dst, nullptr);
|
||||
}
|
||||
|
||||
void operator()(var* v) { visit(v); }
|
||||
void operator()(app* a) { if (!get_expr(a)) { reconstruct(a); } }
|
||||
void operator()(quantifier* q) { visit(q); }
|
||||
|
||||
void apply(expr_ref& e) {
|
||||
for_each_expr(*this, e);
|
||||
e = get_expr(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
proof_ref replace_proof_converter::operator()(ast_manager & m, unsigned num_source, proof * const * source) {
|
||||
SASSERT(num_source == 1);
|
||||
replace_map replace(m);
|
||||
proof_ref p(m);
|
||||
expr_ref tmp(source[0], m), e(m), f(m);
|
||||
|
||||
// apply the substitution to the prefix before inserting it.
|
||||
for (unsigned i = 0; i < m_proofs.size(); ++i) {
|
||||
p = m_proofs[i].get();
|
||||
e = p;
|
||||
replace.apply(e);
|
||||
f = m.mk_asserted(m.get_fact(p));
|
||||
replace.insert(f, e);
|
||||
TRACE("proof_converter", tout << f->get_id() << " " << mk_pp(f, m) <<
|
||||
"\n|-> " << mk_pp(e, m) << "\n";);
|
||||
}
|
||||
replace.apply(tmp);
|
||||
TRACE("proof_converter", tout << mk_pp(source[0], m) << "\n";
|
||||
tout << mk_pp(tmp.get(), m) << "\n";);
|
||||
return proof_ref(to_app(tmp), m);
|
||||
}
|
||||
|
||||
proof_converter * replace_proof_converter::translate(ast_translation & translator) {
|
||||
replace_proof_converter* rp = alloc(replace_proof_converter, m);
|
||||
for (proof* p : m_proofs) rp->insert(translator(p));
|
||||
return rp;
|
||||
}
|
||||
|
48
src/ast/converters/replace_proof_converter.h
Normal file
48
src/ast/converters/replace_proof_converter.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
replace_proof_converter.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Proof converter to replace asserted leaves by proofs.
|
||||
|
||||
Given a proof P with occurrences of [asserted fml]
|
||||
Replace [asserted fml] by proofs whose conclusions are fml.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2012-9-16
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ast/converters/proof_converter.h"
|
||||
|
||||
class replace_proof_converter : public proof_converter {
|
||||
ast_manager& m;
|
||||
proof_ref_vector m_proofs;
|
||||
public:
|
||||
|
||||
replace_proof_converter(ast_manager& _m): m(_m), m_proofs(m) {}
|
||||
|
||||
proof_ref operator()(ast_manager & _m, unsigned num_source, proof * const * source) override;
|
||||
|
||||
proof_converter * translate(ast_translation & translator) override;
|
||||
|
||||
void insert(proof* p) { m_proofs.push_back(p); }
|
||||
|
||||
ast_manager& get_manager() { return m; }
|
||||
|
||||
// run the replacements the inverse direction.
|
||||
void invert() { m_proofs.reverse(); }
|
||||
|
||||
void display(std::ostream & out) override {}
|
||||
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue