2015-09-23 07:42:36 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "util/rc.h"
|
2015-09-29 01:28:11 +00:00
|
|
|
#include "util/rb_map.h"
|
2015-09-29 01:55:24 +00:00
|
|
|
#include "library/blast/expr.h"
|
2015-09-23 07:42:36 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
namespace blast {
|
|
|
|
class hypothesis;
|
2015-09-25 19:45:16 +00:00
|
|
|
class branch;
|
2015-09-23 07:42:36 +00:00
|
|
|
class state;
|
|
|
|
|
2015-11-11 08:02:47 +00:00
|
|
|
typedef unsigned hypothesis_idx;
|
2015-09-28 23:40:19 +00:00
|
|
|
typedef rb_tree<unsigned, unsigned_cmp> hypothesis_idx_set;
|
|
|
|
typedef list<unsigned> hypothesis_idx_list;
|
|
|
|
typedef buffer<unsigned> hypothesis_idx_buffer;
|
2015-09-29 01:28:11 +00:00
|
|
|
template<typename T>
|
|
|
|
using hypothesis_idx_map = typename lean::rb_map<unsigned, T, unsigned_cmp>;
|
2015-09-23 07:42:36 +00:00
|
|
|
|
2015-11-18 23:49:02 +00:00
|
|
|
/* trick to make sure the rb_map::erase_min removes the hypothesis with biggest weight */
|
|
|
|
struct inv_double_cmp {
|
|
|
|
int operator()(double const & d1, double const & d2) const { return d1 > d2 ? -1 : (d1 < d2 ? 1 : 0); }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef rb_map<double, hypothesis_idx, inv_double_cmp> hypothesis_priority_queue;
|
|
|
|
|
2015-09-23 07:42:36 +00:00
|
|
|
class hypothesis {
|
2015-11-09 21:19:59 +00:00
|
|
|
friend class state;
|
2015-11-10 17:54:28 +00:00
|
|
|
name m_name; // for pretty printing
|
2015-11-13 19:59:34 +00:00
|
|
|
unsigned m_dead:1;
|
2015-11-10 17:54:28 +00:00
|
|
|
unsigned m_dep_depth; // dependency depth
|
|
|
|
unsigned m_proof_depth; // proof depth when the hypothesis was created
|
|
|
|
hypothesis_idx_set m_deps; // hypotheses used by the type and/or value of this hypothesis.
|
2015-11-10 18:47:41 +00:00
|
|
|
expr m_self;
|
2015-09-28 23:40:19 +00:00
|
|
|
expr m_type;
|
2015-11-10 17:54:28 +00:00
|
|
|
optional<expr> m_value; // justification for this object.
|
2015-10-05 04:27:39 +00:00
|
|
|
// Remark: if blast::is_local(m_value) is true, then the hypothesis is an assumption
|
2015-09-23 07:42:36 +00:00
|
|
|
public:
|
2015-11-13 19:59:34 +00:00
|
|
|
hypothesis():m_dead(false), m_dep_depth(0) {}
|
2015-09-29 01:28:11 +00:00
|
|
|
name const & get_name() const { return m_name; }
|
2015-11-13 19:59:34 +00:00
|
|
|
bool is_dead() const { return m_dead; }
|
2015-11-09 21:29:07 +00:00
|
|
|
unsigned get_dep_depth() const { return m_dep_depth; }
|
2015-11-10 17:54:28 +00:00
|
|
|
unsigned get_proof_depth() const { return m_proof_depth; }
|
2015-09-28 23:40:19 +00:00
|
|
|
hypothesis_idx_set const & get_backward_deps() const { return m_deps; }
|
2015-11-10 18:47:41 +00:00
|
|
|
expr const & get_self() const { return m_self; }
|
2015-09-23 07:42:36 +00:00
|
|
|
expr const & get_type() const { return m_type; }
|
2015-11-09 22:40:39 +00:00
|
|
|
optional<expr> const & get_value() const { return m_value; }
|
2015-09-29 01:55:24 +00:00
|
|
|
/** \brief Return true iff this hypothesis depends on \c h. */
|
2015-09-29 19:13:20 +00:00
|
|
|
bool depends_on(expr const & h) const { return m_deps.contains(href_index(h)); }
|
2015-11-09 22:40:39 +00:00
|
|
|
bool is_assumption() const { return !m_value || is_local_non_href(*m_value); }
|
2015-09-23 07:42:36 +00:00
|
|
|
};
|
2015-11-14 00:10:25 +00:00
|
|
|
|
|
|
|
class hypothesis_idx_buffer_set {
|
|
|
|
friend class state;
|
|
|
|
hypothesis_idx_buffer m_buffer;
|
|
|
|
hypothesis_idx_set m_set;
|
|
|
|
public:
|
|
|
|
hypothesis_idx_buffer_set() {}
|
|
|
|
hypothesis_idx_buffer_set(hypothesis_idx_buffer const & b) {
|
|
|
|
for (auto hidx : b)
|
|
|
|
insert(hidx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void insert(hypothesis_idx h) {
|
|
|
|
if (!m_set.contains(h)) {
|
|
|
|
m_set.insert(h);
|
|
|
|
m_buffer.push_back(h);
|
|
|
|
}
|
|
|
|
}
|
2015-12-03 07:43:15 +00:00
|
|
|
|
|
|
|
void erase(hypothesis_idx h) {
|
|
|
|
m_set.erase(h);
|
|
|
|
m_buffer.erase(h);
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:26:28 +00:00
|
|
|
unsigned size() const { return m_buffer.size(); }
|
|
|
|
bool empty() const { return m_buffer.empty(); }
|
2015-11-14 00:10:25 +00:00
|
|
|
hypothesis_idx_buffer const & as_buffer() const {
|
|
|
|
return m_buffer;
|
|
|
|
}
|
|
|
|
hypothesis_idx_set const & as_set() const {
|
|
|
|
return m_set;
|
|
|
|
}
|
|
|
|
};
|
2015-09-25 19:45:16 +00:00
|
|
|
}}
|