3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-25 15:23:41 +00:00
z3/src/ackermannization/ackr_bound_probe.cpp
LeeYoungJoon 0a93ff515d
Centralize and document TRACE tags using X-macros (#7657)
* Introduce X-macro-based trace tag definition
- Created trace_tags.def to centralize TRACE tag definitions
- Each tag includes a symbolic name and description
- Set up enum class TraceTag for type-safe usage in TRACE macros

* Add script to generate Markdown documentation from trace_tags.def
- Python script parses trace_tags.def and outputs trace_tags.md

* Refactor TRACE_NEW to prepend TraceTag and pass enum to is_trace_enabled

* trace: improve trace tag handling system with hierarchical tagging

- Introduce hierarchical tag-class structure: enabling a tag class activates all child tags
- Unify TRACE, STRACE, SCTRACE, and CTRACE under enum TraceTag
- Implement initial version of trace_tag.def using X(tag, tag_class, description)
  (class names and descriptions to be refined in a future update)

* trace: replace all string-based TRACE tags with enum TraceTag
- Migrated all TRACE, STRACE, SCTRACE, and CTRACE macros to use enum TraceTag values instead of raw string literals

* trace : add cstring header

* trace : Add Markdown documentation generation from trace_tags.def via mk_api_doc.py

* trace : rename macro parameter 'class' to 'tag_class' and remove Unicode comment in trace_tags.h.

* trace : Add TODO comment for future implementation of tag_class activation

* trace : Disable code related to tag_class until implementation is ready (#7663).
2025-05-28 14:31:25 +01:00

81 lines
2.4 KiB
C++

/*++
Copyright (c) 2016 Microsoft Corporation
Module Name:
ackr_bound_probe.cpp
Abstract:
Author:
Mikolas Janota
Revision History:
--*/
#include "ast/array_decl_plugin.h"
#include "ast/ast_smt2_pp.h"
#include "ackermannization/ackr_helper.h"
#include "ackermannization/ackr_bound_probe.h"
/*
For each function f, calculate the number of its occurrences o_f and compute "o_f choose 2".
The probe then sums up these for all functions.
This upper bound might be crude because some congruence lemmas trivially simplify to true.
*/
class ackr_bound_probe : public probe {
struct proc {
typedef ackr_helper::fun2terms_map fun2terms_map;
typedef ackr_helper::sel2terms_map sel2terms_map;
typedef ackr_helper::app_set app_set;
ast_manager& m;
fun2terms_map m_fun2terms; // a map from functions to occurrences
sel2terms_map m_sel2terms; // a map from functions to occurrences
ackr_helper m_ackr_helper;
expr_mark m_non_select;
proc(ast_manager & m) : m(m), m_ackr_helper(m) { }
~proc() {
for (auto & kv : m_fun2terms) {
dealloc(kv.m_value);
}
for (auto & kv : m_sel2terms) {
dealloc(kv.m_value);
}
}
void prune_non_select() {
m_ackr_helper.prune_non_select(m_sel2terms, m_non_select);
}
void operator()(quantifier *) {}
void operator()(var *) {}
void operator()(app * a) {
m_ackr_helper.mark_non_select(a, m_non_select);
m_ackr_helper.insert(m_fun2terms, m_sel2terms, a);
}
};
public:
result operator()(goal const & g) override {
proc p(g.m());
unsigned sz = g.size();
expr_fast_mark1 visited;
for (unsigned i = 0; i < sz; i++) {
for_each_expr_core<proc, expr_fast_mark1, true, true>(p, visited, g.form(i));
}
p.prune_non_select();
double total = ackr_helper::calculate_lemma_bound(p.m_fun2terms, p.m_sel2terms);
TRACE(ackermannize, tout << "total=" << total << std::endl;);
return result(total);
}
inline static unsigned n_choose_2(unsigned n) { return n & 1 ? (n * (n >> 1)) : (n >> 1) * (n - 1); }
};
probe * mk_ackr_bound_probe() {
return alloc(ackr_bound_probe);
}