mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
add sr
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
5c67c9d907
commit
3125c19049
7 changed files with 1413 additions and 16 deletions
|
@ -41,6 +41,7 @@ z3_add_component(ast
|
|||
reg_decl_plugins.cpp
|
||||
seq_decl_plugin.cpp
|
||||
shared_occs.cpp
|
||||
special_relations_decl_plugin.cpp
|
||||
static_features.cpp
|
||||
used_vars.cpp
|
||||
well_sorted.cpp
|
||||
|
|
79
src/ast/special_relations_decl_plugin.cpp
Normal file
79
src/ast/special_relations_decl_plugin.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*++
|
||||
Copyright (c) 2015 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
special_relations_decl_plugin.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2015-15-9.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include<sstream>
|
||||
#include"ast.h"
|
||||
#include"special_relations_decl_plugin.h"
|
||||
|
||||
|
||||
|
||||
special_relations_decl_plugin::special_relations_decl_plugin():
|
||||
m_lo("linear-order"),
|
||||
m_po("partial-order"),
|
||||
m_po_ao("partial-order-already-ordered"),
|
||||
m_plo("piecewise-linear-order"),
|
||||
m_to("tree-order")
|
||||
{}
|
||||
|
||||
func_decl * special_relations_decl_plugin::mk_func_decl(
|
||||
decl_kind k, unsigned num_parameters, parameter const * parameters,
|
||||
unsigned arity, sort * const * domain, sort * range)
|
||||
{
|
||||
if (arity != 2) {
|
||||
m_manager->raise_exception("special relations should have arity 2");
|
||||
return 0;
|
||||
}
|
||||
if (domain[0] != domain[1]) {
|
||||
m_manager->raise_exception("argument sort missmatch");
|
||||
return 0;
|
||||
}
|
||||
func_decl_info info(m_family_id, k, num_parameters, parameters);
|
||||
symbol name;
|
||||
switch(k) {
|
||||
case OP_SPECIAL_RELATION_PO: name = m_po; break;
|
||||
case OP_SPECIAL_RELATION_PO_AO: name = m_po_ao; break;
|
||||
case OP_SPECIAL_RELATION_LO: name = m_lo; break;
|
||||
case OP_SPECIAL_RELATION_PLO: name = m_plo; break;
|
||||
case OP_SPECIAL_RELATION_TO: name = m_to; break;
|
||||
}
|
||||
return m_manager->mk_func_decl(name, arity, domain, m_manager->mk_bool_sort(), info);
|
||||
}
|
||||
|
||||
void special_relations_decl_plugin::get_op_names(svector<builtin_name> & op_names, symbol const & logic) {
|
||||
if (logic == symbol::null) {
|
||||
op_names.push_back(builtin_name(m_po.bare_str(), OP_SPECIAL_RELATION_PO));
|
||||
op_names.push_back(builtin_name(m_po_ao.bare_str(), OP_SPECIAL_RELATION_PO_AO));
|
||||
op_names.push_back(builtin_name(m_lo.bare_str(), OP_SPECIAL_RELATION_LO));
|
||||
op_names.push_back(builtin_name(m_plo.bare_str(), OP_SPECIAL_RELATION_PLO));
|
||||
op_names.push_back(builtin_name(m_to.bare_str(), OP_SPECIAL_RELATION_TO));
|
||||
}
|
||||
}
|
||||
|
||||
sr_property special_relations_util::get_property(func_decl* f) const {
|
||||
switch (f->get_decl_kind()) {
|
||||
case OP_SPECIAL_RELATION_PO: return sr_po;
|
||||
case OP_SPECIAL_RELATION_PO_AO: return sr_po; // still partial ordered
|
||||
case OP_SPECIAL_RELATION_LO: return sr_lo;
|
||||
case OP_SPECIAL_RELATION_PLO: return sr_plo;
|
||||
case OP_SPECIAL_RELATION_TO: return sr_to;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return sr_po;
|
||||
}
|
||||
}
|
97
src/ast/special_relations_decl_plugin.h
Normal file
97
src/ast/special_relations_decl_plugin.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*++
|
||||
Copyright (c) 2015 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
special_relations_decl_plugin.h
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2015-15-9.
|
||||
Ashutosh Gupta 2016
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef SPECIAL_RELATIONS_DECL_PLUGIN_H_
|
||||
#define SPECIAL_RELATIONS_DECL_PLUGIN_H_
|
||||
|
||||
#include"ast.h"
|
||||
|
||||
|
||||
|
||||
enum special_relations_op_kind {
|
||||
OP_SPECIAL_RELATION_LO,
|
||||
OP_SPECIAL_RELATION_PO,
|
||||
OP_SPECIAL_RELATION_PO_AO,
|
||||
OP_SPECIAL_RELATION_PLO,
|
||||
OP_SPECIAL_RELATION_TO,
|
||||
LAST_SPECIAL_RELATIONS_OP
|
||||
};
|
||||
|
||||
class special_relations_decl_plugin : public decl_plugin {
|
||||
symbol m_lo;
|
||||
symbol m_po;
|
||||
symbol m_po_ao;
|
||||
symbol m_plo;
|
||||
symbol m_to;
|
||||
public:
|
||||
special_relations_decl_plugin();
|
||||
virtual ~special_relations_decl_plugin() {}
|
||||
|
||||
virtual decl_plugin * mk_fresh() {
|
||||
return alloc(special_relations_decl_plugin);
|
||||
}
|
||||
|
||||
virtual func_decl * mk_func_decl(decl_kind k, unsigned num_parameters, parameter const * parameters,
|
||||
unsigned arity, sort * const * domain, sort * range);
|
||||
|
||||
virtual void get_op_names(svector<builtin_name> & op_names, symbol const & logic);
|
||||
|
||||
|
||||
virtual sort * mk_sort(decl_kind k, unsigned num_parameters, parameter const * parameters) { return 0; }
|
||||
};
|
||||
|
||||
enum sr_property {
|
||||
sr_transitive = 0x01, // Rxy & Ryz -> Rxz
|
||||
sr_reflexive = 0x02, // Rxx
|
||||
sr_antisymmetric = 0x04, // Rxy & Ryx -> x = y
|
||||
sr_lefttree = 0x08, // Ryx & Rzx -> Ryz | Rzy
|
||||
sr_righttree = 0x10, // Rxy & Rxz -> Ryx | Rzy
|
||||
sr_po = 0x01 | 0x02 | 0x04, // partial order
|
||||
sr_lo = 0x01 | 0x02 | 0x04 | 0x08 | 0x10, // linear order
|
||||
sr_plo = 0x01 | 0x02 | 0x04 | 0x20, // piecewise linear order
|
||||
sr_to = 0x01 | 0x02 | 0x04 | 0x10, // right-tree
|
||||
};
|
||||
|
||||
class special_relations_util {
|
||||
ast_manager& m;
|
||||
family_id m_fid;
|
||||
public:
|
||||
special_relations_util(ast_manager& m) : m(m), m_fid(m.get_family_id("special_relations")) {}
|
||||
|
||||
bool is_special_relation(func_decl* f) const { return f->get_family_id() == m_fid; }
|
||||
bool is_special_relation(app* e) const { return is_special_relation(e->get_decl()); }
|
||||
sr_property get_property(func_decl* f) const;
|
||||
sr_property get_property(app* e) const { return get_property(e->get_decl()); }
|
||||
|
||||
bool is_lo(expr const * e) const { return is_app_of(e, m_fid, OP_SPECIAL_RELATION_LO); }
|
||||
bool is_po(expr const * e) const { return is_app_of(e, m_fid, OP_SPECIAL_RELATION_PO); }
|
||||
bool is_po_ao(expr const * e) const { return is_app_of(e, m_fid, OP_SPECIAL_RELATION_PO_AO); }
|
||||
bool is_plo(expr const * e) const { return is_app_of(e, m_fid, OP_SPECIAL_RELATION_PLO); }
|
||||
bool is_to(expr const * e) const { return is_app_of(e, m_fid, OP_SPECIAL_RELATION_TO); }
|
||||
|
||||
app * mk_lo (expr * arg1, expr * arg2) { return m.mk_app( m_fid, OP_SPECIAL_RELATION_LO, arg1, arg2); }
|
||||
app * mk_po (expr * arg1, expr * arg2) { return m.mk_app( m_fid, OP_SPECIAL_RELATION_PO, arg1, arg2); }
|
||||
app * mk_po_ao (expr * arg1, expr * arg2) { return m.mk_app( m_fid, OP_SPECIAL_RELATION_PO_AO, arg1, arg2); }
|
||||
app * mk_plo(expr * arg1, expr * arg2) { return m.mk_app( m_fid, OP_SPECIAL_RELATION_PLO, arg1, arg2); }
|
||||
app * mk_to (expr * arg1, expr * arg2) { return m.mk_app( m_fid, OP_SPECIAL_RELATION_TO, arg1, arg2); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* SPECIAL_RELATIONS_DECL_PLUGIN_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue